Changeset 286 for tools

Show
Ignore:
Timestamp:
03/26/09 13:58:46 (18 months ago)
Author:
anton
Message:

Resource processing added

Location:
tools/routingservice/branches/wrs-2.0
Files:
2 added
6 modified

Legend:

Unmodified
Added
Removed
  • tools/routingservice/branches/wrs-2.0/data/config/configuration.xml

    r285 r286  
    77        <log level="5" url="./logs/wrs-log.log"/> 
    88        <includes> 
     9                <include name="services" url="./data/services.xml"/>     
    910                <include name="templates" url="./data/templates.xml"/> 
    10                 <include name="services" url="./data/services.xml"/> 
     11                <include name="resources" url="./data/resources.xml"/>           
    1112                <include name="profiles" url="./data/profiles.xml"/> 
    12                 <include name="resources" url="./data/resources.xml"/> 
    1313        </includes> 
    1414</configuration> 
  • tools/routingservice/branches/wrs-2.0/src/WRS.java

    r285 r286  
    11import java.io.IOException; 
     2import java.util.Enumeration; 
    23import java.util.Hashtable; 
    34import java.util.ListIterator; 
     
    1314import org.xml.sax.SAXException; 
    1415 
    15  
    1616import util.IOHelper; 
    1717import util.Log; 
     18import util.Parameter; 
    1819import util.conf.Configuration; 
    1920import util.conf.Configuration.Includes.Include; 
    2021import util.profile.Profiles; 
    2122import util.profile.Profiles.Profile.Resources.Rref; 
    22  
     23import util.resource.Resources; 
    2324 
    2425public class WRS 
     
    3839 
    3940        public WRS(String[] args) 
    40         {                
     41        { 
    4142                if (!checkParams(args)) 
    4243                { 
     
    4445                        System.out.println("Usage: java WRS configuration.xml"); 
    4546                        System.exit(0); 
    46                 }                
    47                  
     47                } 
     48 
     49                this.resources = new Hashtable(); 
     50 
    4851                this.conf = readConfig(args[0]); 
    4952 
     
    7881                        { 
    7982                                Include inc = li.next(); 
    80                                  
     83 
    8184                                switch (Includes.valueOf(inc.getName().toUpperCase())) 
    8285                                { 
     
    119122        private void readResources(String url) 
    120123        { 
    121                 System.out.println("Read resources from "+url+" file."); 
     124                System.out.println("Read resources from " + url + " file."); 
     125                Resources resources; 
     126                try 
     127                { 
     128                        resources = IOHelper.readConfig(Resources.class, url); 
     129                        ListIterator<util.resource.Resources.Resource> li = resources 
     130                                        .getResource().listIterator(); 
     131                        while (li.hasNext()) 
     132                        { 
     133                                util.resource.Resources.Resource res = li.next(); 
     134                                Resource resource = new Resource(res.getName(), res.getType()); 
     135 
     136                                ListIterator<Parameter> pi = res.getParameters().getParameter() 
     137                                                .listIterator(); 
     138                                while (pi.hasNext()) 
     139                                { 
     140                                        Parameter p = pi.next(); 
     141                                        if (p.getSource() == null) 
     142                                                p.setSource("resource"); 
     143                                        resource.getParameters().put(p.getName(), p); 
     144                                } 
     145 
     146                                this.resources.put(resource.getName(), resource); 
     147                        } 
     148 
     149                } 
     150                catch (SAXException e) 
     151                { 
     152                        System.out.println("Wrong resources configuration file."); 
     153                } 
     154                catch (IOException e) 
     155                { 
     156                        System.out.println("Can't open resources configuration file."); 
     157                } 
     158                catch (ParserConfigurationException e) 
     159                { 
     160                        System.out.println("Wrong resources configuration file."); 
     161                } 
     162                catch (JAXBException e) 
     163                { 
     164                        System.out.println("Wrong resources configuration file."); 
     165                } 
    122166 
    123167        } 
     
    125169        private void readProfiles(String url) 
    126170        { 
    127                 System.out.println("Read profiles from "+url+" file."); 
     171                System.out.println("Read profiles from " + url + " file."); 
    128172                try 
    129173                { 
    130174                        Profiles profiles = IOHelper.readConfig(Profiles.class, url); 
    131                         ListIterator<util.profile.Profiles.Profile> li = profiles.getProfile().listIterator(); 
    132                         while(li.hasNext()) 
     175                        ListIterator<util.profile.Profiles.Profile> li = profiles 
     176                                        .getProfile().listIterator(); 
     177                        while (li.hasNext()) 
    133178                        { 
    134179                                util.profile.Profiles.Profile prof = li.next(); 
    135180                                Profile profile = new Profile(prof.getName()); 
    136181                                profile.setDescription(prof.getDescription()); 
    137                                 ListIterator<Rref> ri = prof.getResources().getRref().listIterator(); 
    138                                 while(ri.hasNext()) 
     182                                ListIterator<Rref> ri = prof.getResources().getRref() 
     183                                                .listIterator(); 
     184                                while (ri.hasNext()) 
    139185                                { 
    140186                                        Rref rref = ri.next(); 
    141                                          
     187 
    142188                                        try 
    143189                                        { 
    144190                                                Resource res = this.resources.get(rref.getRef()); 
    145                                                 if(res != null) 
     191                                                if (res != null) 
    146192                                                { 
    147                                                         //TODO copy parameters from the resource 
    148                                                         profile.getResources().add(res); 
     193                                                        Enumeration<String> pi = res.getParameters().keys(); 
     194                                                        while (pi.hasMoreElements()) 
     195                                                        { 
     196                                                                String pk = pi.nextElement(); 
     197                                                                profile.getParameters().put(pk, 
     198                                                                                res.getParameters().get(pk)); 
     199                                                        } 
     200 
     201                                                        profile.getResources().put(res.getName(), res); 
     202                                                } 
     203                                                else 
     204                                                { 
     205                                                        System.out.println("No such resource: " 
     206                                                                        + rref.getRef()); 
    149207                                                } 
    150208                                        } 
    151209                                        catch (NullPointerException e) 
    152210                                        { 
    153                                                 System.out.println("No such resource: "+rref.getRef()); 
     211                                                System.out.println("Resource " + rref.getRef() 
     212                                                                + " is not properly configured"); 
    154213                                        } 
     214 
     215                                } 
     216 
     217                                ListIterator<Parameter> pi = prof.getParameters() 
     218                                                .getParameter().listIterator(); 
     219                                while (pi.hasNext()) 
     220                                { 
     221                                        Parameter p = pi.next(); 
     222                                        if (p.getSource() == null) 
     223                                                p.setSource("profile"); 
     224                                        profile.getParameters().put(p.getName(), p); 
    155225                                } 
    156226                        } 
     
    177247        private void readTemplates(String url) 
    178248        { 
    179                 System.out.println("Read templates from "+url+" file."); 
     249                System.out.println("Read templates from " + url + " file."); 
    180250 
    181251        } 
     
    183253        private void readServices(String url) 
    184254        { 
    185                 System.out.println("Read services from "+url+" file."); 
     255                System.out.println("Read services from " + url + " file."); 
    186256        } 
    187257 
  • tools/routingservice/branches/wrs-2.0/src/model/Profile.java

    r285 r286  
    11package model; 
    22 
    3 import java.util.ArrayList; 
     3import java.util.HashMap; 
    44import java.util.Hashtable; 
     5 
     6import org.apache.commons.collections.map.MultiValueMap; 
    57 
    68import util.Parameter; 
     
    1012        private String name; 
    1113        private String description; 
    12         private Hashtable<String, Parameter> parameters; 
    13         private ArrayList<Resource> resources; 
     14        private MultiValueMap parameters; 
     15        private Hashtable<String, Resource> resources; 
     16        private Hashtable<String, Service> services;     
    1417 
    1518        public Profile(String name) 
     
    1720                super(); 
    1821                this.name = name; 
     22                 
     23                HashMap<String, Parameter> hm = new HashMap<String, Parameter>(); 
     24                parameters = MultiValueMap.decorate(hm); 
     25                 
     26                //parameters = new MultiValueMap(); 
     27                resources = new Hashtable<String, Resource>(); 
     28                services = new Hashtable<String, Service>(); 
     29 
    1930        } 
    2031 
     
    3950        } 
    4051 
    41         public Hashtable<String, Parameter> getParameters() 
     52        public MultiValueMap getParameters() 
    4253        { 
    4354                return parameters; 
    4455        } 
    4556 
    46         public void setParameters(Hashtable<String, Parameter> parameters) 
    47         { 
    48                 this.parameters = parameters; 
    49         } 
    5057 
    51         public ArrayList<Resource> getResources() 
     58        public Hashtable<String, Resource> getResources() 
    5259        { 
    5360                return resources; 
    5461        } 
    5562 
    56         public void setResources(ArrayList<Resource> resources) 
     63        public void setResources(Hashtable<String, Resource> resources) 
    5764        { 
    5865                this.resources = resources; 
    5966        } 
    6067 
    61         public void addResource(Resource resource) 
    62         { 
    63                 this.resources.add(resource); 
    64         } 
    65  
    6668} 
  • tools/routingservice/branches/wrs-2.0/src/model/Resource.java

    r285 r286  
    2525                this.name = name; 
    2626                this.type = type; 
     27                 
     28                parameters = new Hashtable<String, Parameter>(); 
     29                services = new Hashtable<String, Service>(); 
    2730        } 
     31         
     32        public String getName() 
     33        { 
     34                return name; 
     35        }        
    2836 
    2937        public String getDescription() 
  • tools/routingservice/branches/wrs-2.0/src/util/resource/ObjectFactory.java

    r285 r286  
    33// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>  
    44// Any modifications to this file will be lost upon recompilation of the source schema.  
    5 // Generated on: 2009.03.25 at 04:41:37 PM JST  
     5// Generated on: 2009.03.26 at 01:00:53 PM JST  
    66// 
    77 
     
    4848 
    4949    /** 
    50      * Create an instance of {@link Resources.Resource.Parameters } 
    51      *  
    52      */ 
    53     public Resources.Resource.Parameters createResourcesResourceParameters() { 
    54         return new Resources.Resource.Parameters(); 
    55     } 
    56  
    57     /** 
    58      * Create an instance of {@link Resources } 
    59      *  
    60      */ 
    61     public Resources createResources() { 
    62         return new Resources(); 
    63     } 
    64  
    65     /** 
    6650     * Create an instance of {@link Resources.Resource.Services.Sref } 
    6751     *  
     
    8771    } 
    8872 
     73    /** 
     74     * Create an instance of {@link Resources } 
     75     *  
     76     */ 
     77    public Resources createResources() { 
     78        return new Resources(); 
     79    } 
     80 
     81    /** 
     82     * Create an instance of {@link Resources.Resource.Parameters } 
     83     *  
     84     */ 
     85    public Resources.Resource.Parameters createResourcesResourceParameters() { 
     86        return new Resources.Resource.Parameters(); 
     87    } 
     88 
    8989} 
  • tools/routingservice/branches/wrs-2.0/src/util/resource/Resources.java

    r285 r286  
    33// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>  
    44// Any modifications to this file will be lost upon recompilation of the source schema.  
    5 // Generated on: 2009.03.25 at 04:41:37 PM JST  
     5// Generated on: 2009.03.26 at 01:00:53 PM JST  
    66// 
    77 
     
    3131 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 
    3232 *       &lt;sequence> 
    33  *         &lt;element name="resource"> 
     33 *         &lt;element name="resource" maxOccurs="unbounded"> 
    3434 *           &lt;complexType> 
    3535 *             &lt;complexContent> 
     
    104104 
    105105    @XmlElement(required = true) 
    106     protected Resources.Resource resource; 
     106    protected List<Resources.Resource> resource; 
    107107 
    108108    /** 
    109109     * Gets the value of the resource property. 
    110110     *  
    111      * @return 
    112      *     possible object is 
    113      *     {@link Resources.Resource } 
    114      *      
     111     * <p> 
     112     * This accessor method returns a reference to the live list, 
     113     * not a snapshot. Therefore any modification you make to the 
     114     * returned list will be present inside the JAXB object. 
     115     * This is why there is not a <CODE>set</CODE> method for the resource property. 
     116     *  
     117     * <p> 
     118     * For example, to add a new item, do as follows: 
     119     * <pre> 
     120     *    getResource().add(newItem); 
     121     * </pre> 
     122     *  
     123     *  
     124     * <p> 
     125     * Objects of the following type(s) are allowed in the list 
     126     * {@link Resources.Resource } 
     127     *  
     128     *  
    115129     */ 
    116     public Resources.Resource getResource() { 
    117         return resource; 
    118     } 
    119  
    120     /** 
    121      * Sets the value of the resource property. 
    122      *  
    123      * @param value 
    124      *     allowed object is 
    125      *     {@link Resources.Resource } 
    126      *      
    127      */ 
    128     public void setResource(Resources.Resource value) { 
    129         this.resource = value; 
     130    public List<Resources.Resource> getResource() { 
     131        if (resource == null) { 
     132            resource = new ArrayList<Resources.Resource>(); 
     133        } 
     134        return this.resource; 
    130135    } 
    131136