- Timestamp:
- 04/15/09 11:47:32 (17 months ago)
- Location:
- tools/routingservice/branches/wrs-2.0
- Files:
-
- 9 added
- 1 removed
- 10 modified
-
data/resources.xml (modified) (2 diffs)
-
data/services.xml (modified) (1 diff)
-
data/templates.xml (deleted)
-
data/xsd (added)
-
data/xsd/1.1.0 (added)
-
data/xsd/1.1.0/configuration.xsd (added)
-
data/xsd/1.1.0/profile.xsd (added)
-
data/xsd/1.1.0/resource.xsd (added)
-
data/xsd/1.1.0/service.xsd (added)
-
src/WRS.java (modified) (12 diffs)
-
src/handler/PgRoutingHandler.java (modified) (4 diffs)
-
src/model/Service.java (modified) (4 diffs)
-
src/model/Template.java (modified) (4 diffs)
-
src/util/format/FillerFactory.java (added)
-
src/util/format/FormatParser.java (modified) (1 diff)
-
src/util/format/JSONParser.java (modified) (2 diffs)
-
src/util/format/ParserFactory.java (added)
-
src/util/service/ObjectFactory.java (modified) (4 diffs)
-
src/util/service/Services.java (modified) (9 diffs)
-
src/util/service/Template.java (added)
Legend:
- Unmodified
- Added
- Removed
-
tools/routingservice/branches/wrs-2.0/data/resources.xml
r291 r294 6 6 <description>My test profile I use for testing</description> 7 7 <parameters> 8 <parameter name="srid" type="integer" key="srid" value="43 01" />8 <parameter name="srid" type="integer" key="srid" value="4326" /> 9 9 <parameter name="units" type="string" key="units" value="dd" /> 10 <parameter name="box" type="double" key="box" value="0. 01" />10 <parameter name="box" type="double" key="box" value="0.1" /> 11 11 <parameter name="cost_value" type="string" key="cost_value" value="length" /> 12 <parameter name="reverse_cost_value" type="string" key="reverse_cost_value" value="reverse_cost" /> 12 13 <parameter name="directed" type="boolean" key="directed" 13 14 value="true" /> … … 19 20 <parameter name="cost" type="double" key="length(the_geom)"/> 20 21 <parameter name="line" type="geometry" key="astext(the_geom)"/> 22 <parameter name="polygon" type="geometry" key="astext(the_geom)"/> 21 23 22 24 </parameters> -
tools/routingservice/branches/wrs-2.0/data/services.xml
r291 r294 1 1 <?xml version="1.0"?> 2 <services 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:noNamespaceSchemaLocation="http://wrs.postlbs.org/xsd/1.1.0/service.xsd" 5 > 2 <services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:noNamespaceSchemaLocation="http://wrs.postlbs.org/xsd/1.1.0/service.xsd"> 6 4 <service name="route" title="Shortest path"> 7 5 <description>Returns a shortest path between points A and B</description> 6 <templates> 7 <template name="gml" format="xml" url="./data/templates/route/route_gml.st"/> 8 </templates> 8 9 <in> 9 <parameter key="startX" type="double" name="x1" />10 <parameter key="startY" type="double" name="y1" />11 <parameter key="endX" type="double" name="x2" />12 <parameter key="endY" type="double" name="y2" />13 </in> 10 <parameter key="startX" type="double" name="x1" /> 11 <parameter key="startY" type="double" name="y1" /> 12 <parameter key="endX" type="double" name="x2" /> 13 <parameter key="endY" type="double" name="y2" /> 14 </in> 14 15 <out> 15 <parameter name="id" type="integer" key="id" />16 <parameter name="cost" type="double" key="cost" />17 <parameter name="line" type="geometry" key="the_geom" />18 </out> 16 <parameter name="id" type="integer" key="id" /> 17 <parameter name="cost" type="double" key="cost" /> 18 <parameter name="line" type="geometry" key="the_geom" /> 19 </out> 19 20 </service> 20 21 <service name="catch" title="Catchment area"> 22 <description>Returns a polygon representing a catchment area for going from point A within distance D</description> 23 <templates> 24 <template name="kml" format="xml" url="./data/templates/route/route_kml.st"/> 25 </templates> 26 <in> 27 <parameter key="startX" type="double" name="x1" /> 28 <parameter key="startY" type="double" name="y1" /> 29 <parameter key="distance" type="double" name="distance" /> 30 </in> 31 <out> 32 <parameter name="polygon" type="geometry" key="the_geom" /> 33 </out> 34 </service> 35 21 36 </services> -
tools/routingservice/branches/wrs-2.0/src/WRS.java
r291 r294 32 32 import util.conf.Configuration; 33 33 import util.conf.Configuration.Includes.Include; 34 import util.format.FillerFactory; 34 35 import util.format.FormatParser; 35 36 import util.format.GMLTemplateFiller; 36 37 import util.format.JSONParser; 38 import util.format.ParserFactory; 37 39 import util.format.TemplateFiller; 38 40 import util.profile.Profiles; … … 60 62 private Configuration conf; 61 63 62 private Hashtable<String, Template> templates;63 64 private Hashtable<String, Service> services; 64 65 private Hashtable<String, Profile> profiles; … … 67 68 private static final String DEFAULT_VERSION = "1.1.0"; 68 69 69 p ublicenum Includes70 private enum Includes 70 71 { 71 72 TEMPLATES, SERVICES, PROFILES, RESOURCES; 72 73 } 73 74 74 p ublicenum ParameterSources75 private enum ParameterSources 75 76 { 76 77 URL, PROFILE, RESOURCE; 77 78 } 78 79 79 public enum Formats 80 { 81 JSON(JSONParser.class), GEOJSON(null), KML(null), GML(null), XLS(null), GEORSS( 82 null), GPX(null); 83 84 private Class<? extends FormatParser> parserType; 85 86 Formats(Class<? extends FormatParser> p) 87 { 88 this.parserType = p; 89 } 90 91 public FormatParser getInstance() throws InstantiationException, 92 IllegalAccessException 93 { 94 return parserType.newInstance(); 95 } 96 } 97 98 public enum Fillers 99 { 100 JSON(null), GEOJSON(null), KML(null), GML(GMLTemplateFiller.class), XLS( 101 null), GEORSS(null), GPX(null); 102 103 private Class<? extends TemplateFiller> fillerType; 104 105 Fillers(Class<? extends TemplateFiller> p) 106 { 107 this.fillerType = p; 108 } 109 110 public TemplateFiller getInstance() throws InstantiationException, 111 IllegalAccessException 112 { 113 return fillerType.newInstance(); 114 } 80 private enum MIMETypes 81 { 82 TEXT 83 { 84 MediaType getType() 85 { 86 return MediaType.TEXT_ALL; 87 } 88 }, 89 JSON 90 { 91 MediaType getType() 92 { 93 return MediaType.TEXT_JAVASCRIPT; 94 } 95 }, 96 XML 97 { 98 MediaType getType() 99 { 100 return MediaType.TEXT_XML; 101 } 102 }; 103 104 abstract MediaType getType(); 105 115 106 } 116 107 … … 127 118 this.services = new Hashtable<String, Service>(); 128 119 this.profiles = new Hashtable<String, Profile>(); 129 this.templates = new Hashtable<String, Template>();130 120 131 121 this.conf = readConfig(args[0]); … … 185 175 try 186 176 { 187 TemplateFiller filler = Filler s.valueOf(188 templateName.toUpperCase())177 TemplateFiller filler = FillerFactory.Fillers 178 .valueOf(templateName.toUpperCase()) 189 179 .getInstance(); 190 180 result = filler.fillOutputTemplate( … … 255 245 } 256 246 257 response.setEntity(result, MediaType.TEXT_ALL); 247 String templateType = serviceRequest.getTemplate().getFormat(); 248 response.setEntity(result, MIMETypes.valueOf( 249 templateType.toUpperCase()).getType()); 258 250 } 259 251 }; … … 305 297 306 298 String tName = urlSplit[urlIndex].split("\\.")[1].split("\\?")[0]; 307 Template cTemplate = this.templates.get(tName);299 Template cTemplate = cService.getTemplates().get(tName); 308 300 309 301 if (cTemplate == null) … … 368 360 try 369 361 { 370 FormatParser parser = Formats.valueOf(name.toUpperCase())371 .getInstance();362 FormatParser parser = ParserFactory.Formats.valueOf( 363 name.toUpperCase()).getInstance(); 372 364 Hashtable<String, Parameter> params = parser.parse(value); 373 365 addParameters(request.getParameters(), params); … … 402 394 String key = it.next(); 403 395 String value = toAdd.get(key).getValue(); 404 396 405 397 if (parameters.containsKey(key)) 406 398 { … … 448 440 switch (Includes.valueOf(inc.getName().toUpperCase())) 449 441 { 450 case TEMPLATES:451 readTemplates(inc.getUrl());452 break;453 442 case SERVICES: 454 443 readServices(inc.getUrl()); … … 643 632 } 644 633 645 private void readTemplates(String url) 646 { 634 private Template readTemplate(util.service.Template temp) 635 { 636 Template template = new Template(temp.getName(), temp.getFormat()); 637 638 String body; 647 639 try 648 640 { 649 System.out.println("Read templates from " + url + " file."); 650 651 util.template.Templates templates = IOHelper.readConfig( 652 util.template.Templates.class, url); 653 ListIterator<util.template.Templates.Template> li = templates 654 .getTemplate().listIterator(); 655 656 while (li.hasNext()) 657 { 658 util.template.Templates.Template temp = li.next(); 659 Template template = new Template(temp.getName(), temp 660 .getFormat()); 661 662 ListIterator<Sref> si = temp.getServices().getSref() 663 .listIterator(); 664 while (si.hasNext()) 665 { 666 Sref sref = si.next(); 667 Service service = this.services.get(sref.getRef()); 668 if (service != null) 669 { 670 template.getServices().put(service.getName(), service); 671 } 672 else 673 { 674 System.out.println("No such service: " + sref.getRef()); 675 } 676 } 677 678 String body = IOHelper.readFile(temp.getUrl()); 679 template.setBody(body); 680 681 this.templates.put(template.getName(), template); 682 } 683 } 684 catch (SAXException e) 685 { 686 System.out.println("Wrong templates configuration file."); 687 } 688 catch (NullPointerException e) 689 { 690 System.out.println("Wrong templates configuration file."); 641 body = IOHelper.readFile(temp.getUrl()); 642 template.setBody(body); 691 643 } 692 644 catch (IOException e) 693 645 { 694 System.out.println("Can't open profiles configuration file."); 695 } 696 catch (ParserConfigurationException e) 697 { 698 System.out.println("Wrong templates configuration file."); 699 } 700 catch (JAXBException e) 701 { 702 System.out.println("Wrong templates configuration file."); 703 } 646 System.out 647 .println("Can't open template body file " + temp.getUrl()); 648 } 649 650 return template; 704 651 } 705 652 … … 719 666 Service service = new Service(serv.getName()); 720 667 668 ListIterator<util.service.Template> tempi = serv.getTemplates() 669 .getTemplate().listIterator(); 670 while (tempi.hasNext()) 671 { 672 util.service.Template temp = tempi.next(); 673 Template template = readTemplate(temp); 674 service.getTemplates().put(template.getName(), template); 675 } 676 721 677 ListIterator<Parameter> inpi = serv.getIn().getParameter() 722 678 .listIterator(); -
tools/routingservice/branches/wrs-2.0/src/handler/PgRoutingHandler.java
r291 r294 45 45 ArrayList getParameters() 46 46 { 47 String[] p = { "table", "x1", "y1", "x2", "y2", "box", "cost_value", 48 "directed", "hasrc" }; 47 String[] p = { "table", "x1", "y1", "x2", "y2", "box", 48 "cost_value", "reverse_cost_value", "directed", "hasrc" }; 49 return new ArrayList(Arrays.asList(p)); 50 } 51 }, 52 CATCH 53 { 54 ArrayList getParameters() 55 { 56 String[] p = { "table", "x1", "y1", "distance", "box", "cost_value", 57 "reverse_cost_value", "directed", "hasrc" }; 49 58 return new ArrayList(Arrays.asList(p)); 50 59 } … … 60 69 this.functions.put("route", "shootingstar_sp_smart"); 61 70 this.functions.put("travel", "tsp_astar_directed_smart"); 71 this.functions.put("catch", "driving_distance"); 62 72 } 63 73 … … 73 83 String query = fillQueryTemplate(this.resource.getQuery(), request 74 84 .getService(), request.getParameters()); 85 86 System.out.println("Query:" + query); 75 87 76 88 ObjectPool<Connection> pool = this.resource.getPool(); … … 173 185 Parameter p = parameters.get(key); 174 186 String value = p.getValue(); 175 if (p.getType().toLowerCase().equals( 176 STRING)) 187 if (p.getType().toLowerCase().equals(STRING)) 177 188 { 178 189 value = "'" + value + "'"; -
tools/routingservice/branches/wrs-2.0/src/model/Service.java
r290 r294 1 1 package model; 2 2 3 import java.util.ArrayList;4 import java.util.Hashtable;5 3 import java.util.HashMap; 6 4 … … 16 14 private HashMap<String, Parameter> out; 17 15 16 private HashMap<String, Template> templates; 18 17 19 18 public Service(String name) … … 23 22 this.in = new HashMap<String, Parameter>(); 24 23 this.out = new HashMap<String, Parameter>(); 24 this.templates = new HashMap<String, Template>(); 25 25 } 26 26 … … 65 65 } 66 66 67 public HashMap<String, Template> getTemplates() 68 { 69 return templates; 70 } 71 67 72 } -
tools/routingservice/branches/wrs-2.0/src/model/Template.java
r287 r294 1 1 package model; 2 3 import java.util.Hashtable;4 2 5 3 public class Template … … 8 6 private String name; 9 7 private String format; 10 private Hashtable<String, Service> services; 8 11 9 12 10 public Template(String name, String format) … … 15 13 this.name = name; 16 14 this.format = format; 17 this.services = new Hashtable<String, Service>();18 15 } 19 16 … … 38 35 } 39 36 40 public Hashtable<String, Service> getServices()41 {42 return services;43 }44 45 37 } -
tools/routingservice/branches/wrs-2.0/src/util/format/FormatParser.java
r290 r294 11 11 protected enum DataTypes 12 12 { 13 POINTS, LINES, ADDRESSES ;13 POINTS, LINES, ADDRESSES, DISTANCE, UOM, LOCALE, CRS, REQUEST_ID, CREDENTIALS; 14 14 } 15 15 protected abstract Vector<Parameter> parseInput(String text); -
tools/routingservice/branches/wrs-2.0/src/util/format/JSONParser.java
r291 r294 44 44 x.setValue(sst.nextToken()); 45 45 x.setType(ResourceHandler.DOUBLE); 46 46 47 47 params.add(x); 48 48 … … 52 52 y.setValue(sst.nextToken()); 53 53 y.setType(ResourceHandler.DOUBLE); 54 54 55 55 params.add(x); 56 56 params.add(y); 57 57 ++i; 58 58 } 59 break; 60 case DISTANCE: 61 String distance = json.getString(key); 62 Parameter dist = new Parameter(); 63 dist.setName("distance"); 64 dist.setSource("url"); 65 dist.setValue(distance); 66 dist.setType(ResourceHandler.DOUBLE); 67 params.add(dist); 59 68 break; 60 69 } -
tools/routingservice/branches/wrs-2.0/src/util/service/ObjectFactory.java
r287 r294 3 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.0 3.26 at 04:38:38 PM JST5 // Generated on: 2009.04.15 at 11:15:28 AM JST 6 6 // 7 7 … … 40 40 41 41 /** 42 * Create an instance of {@link Services.Service.In } 43 * 44 */ 45 public Services.Service.In createServicesServiceIn() { 46 return new Services.Service.In(); 47 } 48 49 /** 50 * Create an instance of {@link Template } 51 * 52 */ 53 public Template createTemplate() { 54 return new Template(); 55 } 56 57 /** 58 * Create an instance of {@link Services } 59 * 60 */ 61 public Services createServices() { 62 return new Services(); 63 } 64 65 /** 42 66 * Create an instance of {@link Services.Service.Out } 43 67 * … … 48 72 49 73 /** 50 * Create an instance of {@link Services.Service. In}74 * Create an instance of {@link Services.Service.Templates } 51 75 * 52 76 */ 53 public Services.Service.In createServicesServiceIn() { 54 return new Services.Service.In(); 55 } 56 57 /** 58 * Create an instance of {@link Services.Service } 59 * 60 */ 61 public Services.Service createServicesService() { 62 return new Services.Service(); 77 public Services.Service.Templates createServicesServiceTemplates() { 78 return new Services.Service.Templates(); 63 79 } 64 80 … … 72 88 73 89 /** 74 * Create an instance of {@link Services }90 * Create an instance of {@link Services.Service } 75 91 * 76 92 */ 77 public Services createServices() {78 return new Services ();93 public Services.Service createServicesService() { 94 return new Services.Service(); 79 95 } 80 96 -
tools/routingservice/branches/wrs-2.0/src/util/service/Services.java
r287 r294 3 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.0 3.26 at 04:38:38 PM JST5 // Generated on: 2009.04.15 at 11:15:28 AM JST 6 6 // 7 7 … … 31 31 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 32 32 * <sequence> 33 * <element name="service" >33 * <element name="service" maxOccurs="unbounded"> 34 34 * <complexType> 35 35 * <complexContent> … … 37 37 * <sequence> 38 38 * <element name="description" type="{http://www.w3.org/2001/XMLSchema}string"/> 39 * <element name="templates"> 40 * <complexType> 41 * <complexContent> 42 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 43 * <sequence> 44 * <element ref="{}template" maxOccurs="unbounded"/> 45 * </sequence> 46 * </restriction> 47 * </complexContent> 48 * </complexType> 49 * </element> 39 50 * <element name="in"> 40 51 * <complexType> … … 88 99 * Gets the value of the service property. 89 100 * 90 * @return 91 * possible object is 92 * {@link Services.Service } 93 * 101 * <p> 102 * This accessor method returns a reference to the live list, 103 * not a snapshot. Therefore any modification you make to the 104 * returned list will be present inside the JAXB object. 105 * This is why there is not a <CODE>set</CODE> method for the service property. 106 * 107 * <p> 108 * For example, to add a new item, do as follows: 109 * <pre> 110 * getService().add(newItem); 111 * </pre> 112 * 113 * 114 * <p> 115 * Objects of the following type(s) are allowed in the list 116 * {@link Services.Service } 117 * 118 * 94 119 */ 95 120 public List<Services.Service> getService() { 96 return service; 97 } 98 99 /** 100 * Sets the value of the service property. 101 * 102 * @param value 103 * allowed object is 104 * {@link Services.Service } 105 * 106 */ 107 public void setService(List<Services.Service> value) { 108 this.service = value; 121 if (service == null) { 122 service = new ArrayList<Services.Service>(); 123 } 124 return this.service; 109 125 } 110 126 … … 121 137 * <sequence> 122 138 * <element name="description" type="{http://www.w3.org/2001/XMLSchema}string"/> 139 * <element name="templates"> 140 * <complexType> 141 * <complexContent> 142 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 143 * <sequence> 144 * <element ref="{}template" maxOccurs="unbounded"/> 145 * </sequence> 146 * </restriction> 147 * </complexContent> 148 * </complexType> 149 * </element> 123 150 * <element name="in"> 124 151 * <complexType> … … 157 184 @XmlType(name = "", propOrder = { 158 185 "description", 186 "templates", 159 187 "in", 160 188 "out" … … 164 192 @XmlElement(required = true) 165 193 protected String description; 194 @XmlElement(required = true) 195 protected Services.Service.Templates templates; 166 196 @XmlElement(required = true) 167 197 protected Services.Service.In in; … … 197 227 public void setDescription(String value) { 198 228 this.description = value; 229 } 230 231 /** 232 * Gets the value of the templates property. 233 * 234 * @return 235 * possible object is 236 * {@link Services.Service.Templates } 237 * 238 */ 239 public Services.Service.Templates getTemplates() { 240 return templates; 241 } 242 243 /** 244 * Sets the value of the templates property. 245 * 246 * @param value 247 * allowed object is 248 * {@link Services.Service.Templates } 249 * 250 */ 251 public void setTemplates(Services.Service.Templates value) { 252 this.templates = value; 199 253 } 200 254 … … 439 493 } 440 494 495 496 /** 497 * <p>Java class for anonymous complex type. 498 * 499 * <p>The following schema fragment specifies the expected content contained within this class. 500 * 501 * <pre> 502 * <complexType> 503 * <complexContent> 504 * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 505 * <sequence> 506 * <element ref="{}template" maxOccurs="unbounded"/> 507 * </sequence> 508 * </restriction> 509 * </complexContent> 510 * </complexType> 511 * </pre> 512 * 513 * 514 */ 515 @XmlAccessorType(XmlAccessType.FIELD) 516 @XmlType(name = "", propOrder = { 517 "template" 518 }) 519 public static class Templates { 520 521 @XmlElement(required = true) 522 protected List<Template> template; 523 524 /** 525 * Gets the value of the template property. 526 * 527 * <p> 528 * This accessor method returns a reference to the live list, 529 * not a snapshot. Therefore any modification you make to the 530 * returned list will be present inside the JAXB object. 531 * This is why there is not a <CODE>set</CODE> method for the template property. 532 * 533 * <p> 534 * For example, to add a new item, do as follows: 535 * <pre> 536 * getTemplate().add(newItem); 537 * </pre> 538 * 539 * 540 * <p> 541 * Objects of the following type(s) are allowed in the list 542 * {@link Template } 543 * 544 * 545 */ 546 public List<Template> getTemplate() { 547 if (template == null) { 548 template = new ArrayList<Template>(); 549 } 550 return this.template; 551 } 552 553 } 554 441 555 } 442 556
