- Timestamp:
- 04/07/09 17:13:05 (11 months ago)
- Location:
- tools/routingservice/branches/wrs-2.0
- Files:
-
- 4 added
- 5 modified
-
data/resources.xml (modified) (1 diff)
-
src/WRS.java (modified) (4 diffs)
-
src/handler/HandlerFactory.java (added)
-
src/handler/PgRoutingHandler.java (modified) (3 diffs)
-
src/handler/ResourceHandler.java (modified) (1 diff)
-
src/model/Resource.java (modified) (3 diffs)
-
src/util/ObjectPool.java (added)
-
src/util/db (added)
-
src/util/db/JDBCConnectionPool.java (added)
Legend:
- Unmodified
- Added
- Removed
-
tools/routingservice/branches/wrs-2.0/data/resources.xml
r286 r289 4 4 xsi:noNamespaceSchemaLocation="http://wrs.postlbs.org/xsd/1.1.0/resource.xsd" 5 5 > 6 <resource name="pgrouting" title="pgRouting instance on Dumbo server">6 <resource type="database" name="pgrouting" title="pgRouting instance on Dumbo server"> 7 7 <description>My test profile I use for testing</description> 8 8 <parameters> -
tools/routingservice/branches/wrs-2.0/src/WRS.java
r287 r289 1 import handler.HandlerFactory; 2 import handler.ResourceHandler; 3 1 4 import java.io.IOException; 2 5 import java.util.ArrayList; … … 101 104 ServiceRequest serviceRequest = null; 102 105 String result = ""; 103 106 104 107 try 105 108 { … … 117 120 else 118 121 { 119 result = resource.processRequest(serviceRequest); 120 } 121 122 try 123 { 124 ResourceHandler handler = HandlerFactory.Handler 125 .valueOf(resource.getName().toUpperCase()) 126 .getInstance(); 127 handler.setResource(resource); 128 129 Vector<Parameter> output = handler 130 .handle(serviceRequest); 131 } 132 // TODO process the error more carefully 133 catch (InstantiationException e) 134 { 135 log.logger.warning("Wrong resource " 136 + resource.getName()); 137 } 138 catch (IllegalAccessException e) 139 { 140 log.logger.warning("Wrong resource " 141 + resource.getName()); 142 } 143 } 144 122 145 } 123 146 catch (InvalidVersionException e) … … 335 358 { 336 359 util.resource.Resources.Resource res = li.next(); 337 Resource resource = new Resource(res.getName(), res.getType()); 360 Resource resource = new Resource(res.getName(), res.getType(), 361 res.getUrl(), res.getUser(), res.getPassword()); 338 362 339 363 ListIterator<Parameter> pi = res.getParameters().getParameter() -
tools/routingservice/branches/wrs-2.0/src/handler/PgRoutingHandler.java
r287 r289 1 1 package handler; 2 2 3 import java.sql.Connection; 3 4 import java.util.Hashtable; 4 5 import java.util.Vector; 5 6 6 7 import model.Resource; 8 import util.ObjectPool; 7 9 import util.Parameter; 8 10 import util.ServiceRequest; 11 import util.db.JDBCConnectionPool; 9 12 10 13 import org.antlr.stringtemplate.StringTemplate; … … 14 17 private Resource resource; 15 18 private Hashtable<String, String> functions; 16 19 17 20 public static final String SRID = "srid"; 18 21 public static final String UNITS = "units"; 19 22 20 23 public PgRoutingHandler() 21 24 { … … 30 33 Vector<Parameter> out = new Vector<Parameter>(); 31 34 32 StringTemplate queryTemplate = new StringTemplate(this.resource.getQuery()); 35 if (this.resource != null) 36 { 33 37 38 StringTemplate queryTemplate = new StringTemplate(this.resource 39 .getQuery()); 40 ObjectPool<Connection> pool = this.resource.getPool(); 41 Connection con = pool.checkOut(); 42 43 //TODO send query and get a result 44 45 pool.checkIn(con); 46 } 34 47 return out; 35 48 } -
tools/routingservice/branches/wrs-2.0/src/handler/ResourceHandler.java
r287 r289 9 9 public interface ResourceHandler 10 10 { 11 11 12 public void setResource(Resource resource); 12 13 public Vector<Parameter> handle(ServiceRequest request); 14 13 15 } -
tools/routingservice/branches/wrs-2.0/src/model/Resource.java
r287 r289 1 1 package model; 2 2 3 import handler.HandlerFactory; 4 import handler.PgRoutingHandler; 3 5 import handler.ResourceHandler; 4 6 7 import java.lang.reflect.InvocationTargetException; 5 8 import java.util.Hashtable; 6 9 10 import org.restlet.Handler; 11 12 import util.ObjectPool; 7 13 import util.Parameter; 8 14 import util.ServiceRequest; 15 import util.db.JDBCConnectionPool; 9 16 10 17 public class Resource … … 22 29 private Hashtable<String, Parameter> parameters; 23 30 private Hashtable<String, Service> services; 24 25 private ResourceHandler handler;26 31 27 public Resource(String name, String type) 32 private enum PoolTypes 33 { 34 DATABASE(JDBCConnectionPool.class); 35 36 private Class<? extends ObjectPool> poolType; 37 38 PoolTypes(Class<? extends ObjectPool> p) 39 { 40 this.poolType = p; 41 } 42 43 public ObjectPool getInstance(String url, String user, String password) 44 throws InstantiationException, IllegalAccessException, 45 IllegalArgumentException, SecurityException, 46 InvocationTargetException 47 { 48 System.out.println(">>>>" + poolType.getConstructors()[0].toString()); 49 50 return (ObjectPool) poolType.getConstructors()[0] 51 .newInstance(new Object[] { url, user, password }); 52 } 53 } 54 55 private ObjectPool pool; 56 57 public Resource(String name, String type, String url, String user, String password) 28 58 { 29 59 super(); 30 60 this.name = name; 31 61 this.type = type; 32 62 63 try 64 { 65 this.pool = PoolTypes.valueOf(type.toUpperCase()).getInstance(url, user, password); 66 } 67 // TODO process the error more carefully 68 catch (InstantiationException e) 69 { 70 System.out.println("Wrong resource type " + this.type); 71 e.printStackTrace(); 72 } 73 catch (IllegalAccessException e) 74 { 75 System.out.println("Wrong resource type " + this.type); 76 e.printStackTrace(); 77 } 78 catch (IllegalArgumentException e) 79 { 80 // TODO Auto-generated catch block 81 e.printStackTrace(); 82 } 83 catch (SecurityException e) 84 { 85 // TODO Auto-generated catch block 86 e.printStackTrace(); 87 } 88 catch (InvocationTargetException e) 89 { 90 // TODO Auto-generated catch block 91 e.printStackTrace(); 92 } 93 33 94 parameters = new Hashtable<String, Parameter>(); 34 95 services = new Hashtable<String, Service>(); 35 96 } 36 97 37 98 public String getName() 38 99 { 39 100 return name; 40 } 101 } 41 102 42 103 public String getDescription() … … 120 181 } 121 182 122 public String processRequest(ServiceRequest serviceRequest)183 public String getType() 123 184 { 124 // TODO Auto-generated method stub 125 return null; 185 return type; 186 } 187 188 public ObjectPool getPool() 189 { 190 return pool; 126 191 } 127 192
