pgRouting

Changeset 164

Show
Ignore:
Timestamp:
05/02/08 15:55:44 (7 months ago)
Author:
anton
Message:

Distance limitation added

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/routingservice/src/jp/co/orkney/restlet/geo/ShortestPath.java

    r128 r164  
    2525 
    2626import jp.co.orkney.restlet.util.IOHelper; 
     27import jp.co.orkney.restlet.util.LimitsHelper; 
    2728import jp.co.orkney.restlet.util.Log; 
    2829import jp.co.orkney.restlet.util.Point; 
     
    5354public class ShortestPath extends GeoAction 
    5455{ 
    55         private Point startPoint; 
    56         private Point endPoint; 
    57  
    58  
    59         /** 
    60          * Constructor ShortestPath 
    61          * <p> 
    62          * Creates a new ShortestPath object using the specified Configuration 
    63          * object and extracts X and Y from the data provides by GET or POST request 
    64          * into a new point (for start and end point). 
    65          * </p> 
    66          *  
    67          * @param configuration 
    68          *            the current configuration 
    69          */ 
    70         public ShortestPath(Configuration configuration, DatabaseConnection databaseConnection, IOHelper ioHelper, Log log) 
    71         { 
    72                 super(configuration, databaseConnection, ioHelper, log); 
    73                  
    74                 name = "Shortest path"; 
    75  
    76                 // extract method for Geojson format 
    77                 if (configuration.getFormatIn().getName().equals("geojson")) 
    78                 { 
    79                         startPoint = ioHelper.extractGEOJSONPxPy(configuration.getService().getParameter("point_start").getValue()); 
    80                         endPoint = ioHelper.extractGEOJSONPxPy(configuration.getService().getParameter("point_end").getValue()); 
    81                 } 
    82                 // extract method for Gml format 
    83                 else if (configuration.getFormatIn().getName().equals("gml")) 
    84                 { 
    85                         startPoint = ioHelper.extractGMLPxPy(configuration.getService().getParameter("point_start").getValue()); 
    86                         endPoint = ioHelper.extractGMLPxPy(configuration.getService().getParameter("point_end").getValue()); 
    87                 } 
    88                 // extract method for lonlat format 
    89                 else if (configuration.getFormatIn().getName().equals("lonlat")) 
    90                 { 
    91                         startPoint = ioHelper.extractLONLATPxPy(configuration.getService().getParameter("point_start").getValue()); 
    92                         endPoint = ioHelper.extractLONLATPxPy(configuration.getService().getParameter("point_end").getValue()); 
    93                 } 
    94                 // extract method for wkt format 
    95                 else if (configuration.getFormatIn().getName().equals("wkt")) 
    96                 { 
    97                         startPoint = ioHelper.extractWKTPxPy(configuration.getService().getParameter("point_start").getValue()); 
    98                         endPoint = ioHelper.extractWKTPxPy(configuration.getService().getParameter("point_end").getValue()); 
    99                 } 
    100                 // extract method for kml format 
    101                 else if (configuration.getFormatIn().getName().equals("kml")) 
    102                 { 
    103                         startPoint = ioHelper.extractKMLPxPy(configuration.getService().getParameter("point_start").getValue()); 
    104                         endPoint = ioHelper.extractKMLPxPy(configuration.getService().getParameter("point_end").getValue()); 
    105                 } 
    106         } 
    107  
    108         /** 
    109          * Gets the result of the shortest path algorithm 
    110          *  
    111          * @return this shortest path's result 
    112          */ 
    113         public String get() 
    114         { 
    115                 return result; 
    116         } 
    117  
    118         /** 
    119          * Starts the "shortest path" algorithm 
    120          *  
    121          * @throws SQLException 
    122          *             error to send the query to the database 
    123          * @throws JSONException 
    124          *             Error to transform the result in Geojson format 
    125          */ 
    126         public void start() throws SQLException, JSONException 
    127         { 
    128                 StringTemplate query = this.ioHelper.getQuery(); 
    129                 float bboxSize = Float.parseFloat(configuration.getService().getParameter("bbox").getValue()); 
    130  
    131                 // Makes the SQL query 
    132                 query.setAttribute("sonStartX", startPoint.getX()); 
    133                 query.setAttribute("sonStartY", startPoint.getY()); 
    134                 query.setAttribute("sonEndX", endPoint.getX()); 
    135                 query.setAttribute("sonEndY", endPoint.getY()); 
    136                 query.setAttribute("saBoxSize", bboxSize); 
    137                 query.setAttribute("sridProvider", configuration.getService().getDataProjection()); 
    138                 query.setAttribute("sridIn", configuration.getService().getParameter("sridInput").getValue()); 
    139                 query.setAttribute("sridOut", configuration.getService().getParameter("sridOutput").getValue()); 
    140  
    141                 // System.out.println(query.toString()); 
    142                 this.log.write(query.toString(), 1); 
    143                 ResultSet rs = databaseConnection.getResult(configuration.getService(), query.toString()); 
    144  
    145                 String reqId = configuration.getService().getParameter("request_id").getValue(); 
    146                  
    147                 // Converts the SQL Result in Geojson 
    148                 if (this.configuration.getFormatOut().getName().equals("geojson")) 
    149                 { 
    150                         result = this.ioHelper.shortestPathGEOJSONResult(rs, reqId); 
    151                 } 
    152                 // Converts the SQL Result in HTML 
    153                 else if (this.configuration.getFormatOut().getName().equals("html")) 
    154                 { 
    155                         result = this.ioHelper.shortestPathHTMLResult(rs, startPoint, endPoint, reqId); 
    156                 } 
    157                 // Converts the SQL Result in XML 
    158                 else if (this.configuration.getFormatOut().getName().equals("xml")) 
    159                 { 
    160                         result = this.ioHelper.shortestPathXMLResult(rs, reqId); 
    161                 } 
    162                 // Converts the SQL Result in GML 
    163                 else if (this.configuration.getFormatOut().getName().equals("gml")) 
    164                 { 
    165                         result = this.ioHelper.shortestPathGMLResult(rs, reqId); 
    166                 } 
    167                 // Converts the SQL Result in WKT 
    168                 else if (this.configuration.getFormatOut().getName().equals("wkt")) 
    169                 { 
    170                         result = this.ioHelper.shortestPathWKTResult(rs); 
    171                 } 
    172                 // Converts the SQL Result in KML 
    173                 else if (this.configuration.getFormatOut().getName().equals("kml")) 
    174                 { 
    175                         result = this.ioHelper.shortestPathKMLResult(rs); 
    176                 } 
    177         } 
     56    private Point startPoint; 
     57 
     58    private Point endPoint; 
     59 
     60    /** 
     61     * Constructor ShortestPath 
     62     * <p> 
     63     * Creates a new ShortestPath object using the specified Configuration 
     64     * object and extracts X and Y from the data provides by GET or POST 
     65     * request into a new point (for start and end point). 
     66     * </p> 
     67     *  
     68     * @param configuration 
     69     *                the current configuration 
     70     */ 
     71    public ShortestPath(Configuration configuration, 
     72            DatabaseConnection databaseConnection, IOHelper ioHelper, Log log) 
     73    { 
     74        super(configuration, databaseConnection, ioHelper, log); 
     75 
     76        name = "Shortest path"; 
     77 
     78        // extract method for Geojson format 
     79        if (configuration.getFormatIn().getName().equals("geojson")) 
     80        { 
     81            startPoint = ioHelper.extractGEOJSONPxPy(configuration.getService() 
     82                    .getParameter("point_start").getValue()); 
     83            endPoint = ioHelper.extractGEOJSONPxPy(configuration.getService() 
     84                    .getParameter("point_end").getValue()); 
     85        } 
     86        // extract method for Gml format 
     87        else if (configuration.getFormatIn().getName().equals("gml")) 
     88        { 
     89            startPoint = ioHelper.extractGMLPxPy(configuration.getService() 
     90                    .getParameter("point_start").getValue()); 
     91            endPoint = ioHelper.extractGMLPxPy(configuration.getService() 
     92                    .getParameter("point_end").getValue()); 
     93        } 
     94        // extract method for lonlat format 
     95        else if (configuration.getFormatIn().getName().equals("lonlat")) 
     96        { 
     97            startPoint = ioHelper.extractLONLATPxPy(configuration.getService() 
     98                    .getParameter("point_start").getValue()); 
     99            endPoint = ioHelper.extractLONLATPxPy(configuration.getService() 
     100                    .getParameter("point_end").getValue()); 
     101        } 
     102        // extract method for wkt format 
     103        else if (configuration.getFormatIn().getName().equals("wkt")) 
     104        { 
     105            startPoint = ioHelper.extractWKTPxPy(configuration.getService() 
     106                    .getParameter("point_start").getValue()); 
     107            endPoint = ioHelper.extractWKTPxPy(configuration.getService() 
     108                    .getParameter("point_end").getValue()); 
     109        } 
     110        // extract method for kml format 
     111        else if (configuration.getFormatIn().getName().equals("kml")) 
     112        { 
     113            startPoint = ioHelper.extractKMLPxPy(configuration.getService() 
     114                    .getParameter("point_start").getValue()); 
     115            endPoint = ioHelper.extractKMLPxPy(configuration.getService() 
     116                    .getParameter("point_end").getValue()); 
     117        } 
     118    } 
     119 
     120    /** 
     121     * Gets the result of the shortest path algorithm 
     122     *  
     123     * @return this shortest path's result 
     124     */ 
     125    public String get() 
     126    { 
     127        return result; 
     128    } 
     129 
     130    /** 
     131     * Starts the "shortest path" algorithm 
     132     *  
     133     * @throws SQLException 
     134     *                 error to send the query to the database 
     135     * @throws JSONException 
     136     *                 Error to transform the result in Geojson format 
     137     */ 
     138    public void start() throws SQLException, JSONException 
     139    { 
     140        StringTemplate query = this.ioHelper.getQuery(); 
     141        ResultSet rs = null; 
     142 
     143        float bboxSize = Float.parseFloat(configuration.getService() 
     144                .getParameter("bbox").getValue()); 
     145 
     146        if (LimitsHelper.isDistanceAllowed(startPoint, endPoint, configuration 
     147                .getService().getLimit().getDistance())) 
     148        { 
     149 
     150            // Makes the SQL query 
     151            query.setAttribute("sonStartX", startPoint.getX()); 
     152            query.setAttribute("sonStartY", startPoint.getY()); 
     153            query.setAttribute("sonEndX", endPoint.getX()); 
     154            query.setAttribute("sonEndY", endPoint.getY()); 
     155            query.setAttribute("saBoxSize", bboxSize); 
     156            query.setAttribute("sridProvider", configuration.getService() 
     157                    .getDataProjection()); 
     158            query.setAttribute("sridIn", configuration.getService() 
     159                    .getParameter("sridInput").getValue()); 
     160            query.setAttribute("sridOut", configuration.getService() 
     161                    .getParameter("sridOutput").getValue()); 
     162 
     163            // System.out.println(query.toString()); 
     164            this.log.write(query.toString(), 1); 
     165            rs = databaseConnection.getResult(configuration.getService(), query 
     166                    .toString()); 
     167 
     168        } else 
     169        { 
     170            this.log.write("Distance exceedes limits", 0); 
     171        } 
     172 
     173        String reqId = configuration.getService().getParameter("request_id") 
     174                .getValue(); 
     175 
     176        // Converts the SQL Result in Geojson 
     177        if (this.configuration.getFormatOut().getName().equals("geojson")) 
     178        { 
     179            result = this.ioHelper.shortestPathGEOJSONResult(rs, reqId); 
     180        } 
     181        // Converts the SQL Result in HTML 
     182        else if (this.configuration.getFormatOut().getName().equals("html")) 
     183        { 
     184            result = this.ioHelper.shortestPathHTMLResult(rs, startPoint, 
     185                    endPoint, reqId); 
     186        } 
     187        // Converts the SQL Result in XML 
     188        else if (this.configuration.getFormatOut().getName().equals("xml")) 
     189        { 
     190            result = this.ioHelper.shortestPathXMLResult(rs, reqId); 
     191        } 
     192        // Converts the SQL Result in GML 
     193        else if (this.configuration.getFormatOut().getName().equals("gml")) 
     194        { 
     195            result = this.ioHelper.shortestPathGMLResult(rs, reqId); 
     196        } 
     197        // Converts the SQL Result in WKT 
     198        else if (this.configuration.getFormatOut().getName().equals("wkt")) 
     199        { 
     200            result = this.ioHelper.shortestPathWKTResult(rs); 
     201        } 
     202        // Converts the SQL Result in KML 
     203        else if (this.configuration.getFormatOut().getName().equals("kml")) 
     204        { 
     205            result = this.ioHelper.shortestPathKMLResult(rs); 
     206        } 
     207 
     208    } 
    178209 
    179210} 
  • branches/routingservice/src/jp/co/orkney/restlet/util/Configuration.java

    r128 r164  
     1package jp.co.orkney.restlet.util; 
     2 
    13/** 
    24 * Copyright (c) 2007 Orkney, Inc. <http://www.orkney.co.jp/> 
     
    1517 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    1618 */ 
    17  
    18 package jp.co.orkney.restlet.util; 
    1919 
    2020import java.io.File; 
     
    5858public class Configuration 
    5959{ 
    60         public static final String API_KEY = "api_key"; 
    61         public static final String SIGNATURE = "signature"; 
    62         public static final String CLIENT_ID = "id"; 
    63          
    64         private String urlConfigurationFile = "./configuration.xml"; 
    65         private String urlXMLTemplateQuery = "./pool.xml"; 
    66         private String commandCapabilities = "capabilities"; 
    67         private String versionNumber = "1.0.0"; 
    68  
    69         private String port; 
    70         private String urlLog; 
    71         private int modeLog; 
    72         private String localhost; 
    73         private String urlCss; 
    74         public Vector<Provider> providers; 
    75         private int askCapabilities; // -1 by default, 0 host capabilities, 1 
    76         // provider "x" capabilities 
    77  
    78         private Provider provider; 
    79         private Service service; 
    80         private Format formatIn; 
    81         private Format formatOut; 
    82  
    83         private int iProvider = 0; 
    84         private int iService = 0; 
    85         private int iFormat = 0; 
    86  
    87         /** 
    88          * Constructor Format. 
    89          * <p> 
    90          * Creates a new format with empty data (port, urlLog,...); 
    91          * </p> 
     60    public static final String API_KEY = "api_key"; 
     61 
     62    public static final String SIGNATURE = "signature"; 
     63 
     64    public static final String CLIENT_ID = "id"; 
     65 
     66    private String urlConfigurationFile = "./configuration.xml"; 
     67 
     68    private String urlXMLTemplateQuery = "./pool.xml"; 
     69 
     70    private String commandCapabilities = "capabilities"; 
     71 
     72    private String versionNumber = "1.0.0"; 
     73 
     74    private String port; 
     75 
     76    private String urlLog; 
     77 
     78    private int modeLog; 
     79 
     80    private String localhost; 
     81 
     82    private String urlCss; 
     83 
     84    public Vector<Provider> providers; 
     85 
     86    private int askCapabilities; // -1 by default, 0 host capabilities, 1 
     87 
     88    // provider "x" capabilities 
     89 
     90    private Provider provider; 
     91 
     92    private Service service; 
     93 
     94    private Format formatIn; 
     95 
     96    private Format formatOut; 
     97 
     98    private int iProvider = 0; 
     99 
     100    private int iService = 0; 
     101 
     102    private int iFormat = 0; 
     103 
     104    /** 
     105     * Constructor Format. 
     106     * <p> 
     107     * Creates a new format with empty data (port, urlLog,...); 
     108     * </p> 
     109     */ 
     110    public Configuration() 
     111    { 
     112        port = ""; 
     113        urlLog = ""; 
     114        modeLog = 0; 
     115        localhost = ""; 
     116        urlCss = ""; 
     117        askCapabilities = -1; 
     118        providers = new Vector<Provider>(); 
     119        /* 
     120         * provider = new Provider(); service = new Service(); formatIn = new 
     121         * Format(); formatOut = new Format(); 
    92122         */ 
    93         public Configuration() 
    94         { 
    95                 port = ""; 
    96                 urlLog = ""; 
    97                 modeLog = 0; 
    98                 localhost = ""; 
    99                 urlCss = ""; 
    100                 askCapabilities = -1; 
    101                 providers = new Vector<Provider>(); 
    102                 /* 
    103                 provider = new Provider(); 
    104                 service = new Service(); 
    105                 formatIn = new Format(); 
    106                 formatOut = new Format(); 
    107                 */ 
    108                 provider = null; 
    109                 service = null; 
    110                 formatIn = null; 
    111                 formatOut = null;                
    112         } 
    113  
    114         /** 
    115          * Parses the XML configuration file and puts all this data in a vector<Provider>. 
    116          *  
    117          */ 
    118         @SuppressWarnings("unchecked") 
    119         public void parseXML() 
    120         { 
    121                 SAXBuilder sxb = new SAXBuilder(); 
    122                 Document document = null; 
     123        provider = null; 
     124        service = null; 
     125        formatIn = null; 
     126        formatOut = null; 
     127    } 
     128 
     129    /** 
     130     * Parses the XML configuration file and puts all this data in a vector<Provider>. 
     131     *  
     132     */ 
     133    @SuppressWarnings("unchecked") 
     134    public void parseXML() 
     135    { 
     136        SAXBuilder sxb = new SAXBuilder(); 
     137        Document document = null; 
     138        try 
     139        { 
     140            document = sxb.build(new File(urlConfigurationFile)); 
     141        } 
     142        catch (JDOMException e) 
     143        { 
     144            e.printStackTrace(); 
     145        } 
     146        catch (IOException e) 
     147        { 
     148            e.printStackTrace(); 
     149        } 
     150        Element root = document.getRootElement(); 
     151 
     152        port = root.getChild("port").getText(); 
     153        urlLog = root.getChild("log").getText(); 
     154        modeLog = Integer.parseInt(root.getChild("log").getAttributeValue( 
     155                "mode")); 
     156        localhost = root.getChild("localhost").getText(); 
     157        urlCss = root.getChild("css").getText(); 
     158 
     159        List<Element> listProviders = root.getChild("providers").getChildren( 
     160                "provider"); 
     161        Iterator<Element> itProvider = listProviders.iterator(); 
     162 
     163        while (itProvider.hasNext()) 
     164        { 
     165            Provider provider = new Provider(); 
     166            Element currentProvider = (Element) itProvider.next(); 
     167            provider.setName(currentProvider.getAttributeValue("name")); 
     168            List<Element> listServices = currentProvider.getChild("services") 
     169                    .getChildren("service"); 
     170            Iterator<Element> itService = listServices.iterator(); 
     171            Vector<Service> services = new Vector<Service>(); 
     172 
     173            // TODO Replace it with proper constructor 
     174            while (itService.hasNext()) 
     175            { 
     176                Service service = new Service(); 
     177                Element currentService = itService.next(); 
     178                service.setName(currentService.getAttributeValue("name")); 
     179 
     180                service.setEnable(new Boolean(currentService 
     181                        .getAttributeValue("enable"))); 
     182                service.setDatabaseConfiguration(new DatabaseConfiguration( 
     183                        currentService.getChild("connection") 
     184                                .getAttributeValue("driver"), currentService 
     185                                .getChild("connection").getChildText("url"), 
     186                        currentService.getChild("connection").getChildText( 
     187                                "user"), currentService.getChild("connection") 
     188                                .getChildText("password"))); 
     189                service.setDataProjection(currentService.getChild("projection") 
     190                        .getAttributeValue("srid")); 
     191                // TODO read units from the configuration 
     192                // probably it is better to create Projection class 
    123193                try 
    124194                { 
    125                         document = sxb.build(new File(urlConfigurationFile)); 
     195                    service.setLimit(new Limit(Double 
     196                            .parseDouble(currentService.getChild("limit") 
     197                                    .getAttributeValue("distance")))); 
    126198                } 
    127                 catch (JDOMException e) 
     199                catch (NullPointerException e) 
    128200                { 
    129                         e.printStackTrace(); 
     201                    // This service has no limitations. 
     202                    // Do nothing. 
    130203                } 
    131                 catch (IOException e) 
     204 
     205                List<Element> listSQL = currentService.getChild("sql") 
     206                        .getChildren("query"); 
     207                Iterator<Element> itQuery = listSQL.iterator(); 
     208                while (itQuery.hasNext()) 
    132209                { 
    133                         e.printStackTrace(); 
     210                    Element currentQuery = itQuery.next(); 
     211                    if (currentQuery.getAttributeValue("transformProjectionIn") 
     212                            .equals("false")) 
     213                    { 
     214                        if (currentQuery.getAttributeValue( 
     215                                "transformProjectionOut").equals("false")) 
     216                        { 
     217                            // case: transformProjectionIn = FALSE & 
     218                            // transformProjectionOut = FALSE 
     219                            service.setSQL(currentQuery.getText(), 0); 
     220                        } 
     221                        else 
     222                        { 
     223                            // case: transformProjectionIn = FALSE & 
     224                            // transformProjectionOut = TRUE 
     225                            service.setSQL(currentQuery.getText(), 1); 
     226                        } 
     227 
     228                    } 
     229                    else 
     230                    { 
     231                        if (currentQuery.getAttributeValue( 
     232                                "transformProjectionOut").equals("false")) 
     233                        { 
     234                            // case: transformProjectionIn = TRUE & 
     235                            // transformProjectionOut = FALSE 
     236                            service.setSQL(currentQuery.getText(), 2); 
     237                        } 
     238                        else 
     239                        { 
     240                            // case: transformProjectionIn = TRUE & 
     241                            // transformProjectionOut = TRUE 
     242                            service.setSQL(currentQuery.getText(), 3); 
     243                        } 
     244                    } 
     245 
    134246                } 
    135                 Element root = document.getRootElement(); 
    136  
    137                 port = root.getChild("port").getText(); 
    138                 urlLog = root.getChild("log").getText(); 
    139                 modeLog = Integer.parseInt(root.getChild("log").getAttributeValue("mode")); 
    140                 localhost = root.getChild("localhost").getText(); 
    141                 urlCss = root.getChild("css").getText(); 
    142  
    143                 List<Element> listProviders = root.getChild("providers").getChildren("provider"); 
    144                 Iterator<Element> itProvider = listProviders.iterator(); 
    145  
    146                 while (itProvider.hasNext()) 
     247 
     248                List<Element> listParameters = currentService.getChild( 
     249                        "parameters").getChildren("parameter"); 
     250                Iterator<Element> itParametre = listParameters.iterator(); 
     251                Vector<Parameter> parameters = new Vector<Parameter>(); 
     252 
     253                while (itParametre.hasNext()) 
    147254                { 
    148                         Provider provider = new Provider(); 
    149                         Element currentProvider = (Element) itProvider.next(); 
    150                         provider.setName(currentProvider.getAttributeValue("name")); 
    151                         List<Element> listServices = currentProvider.getChild("services").getChildren("service"); 
    152                         Iterator<Element> itService = listServices.iterator(); 
    153                         Vector<Service> services = new Vector<Service>(); 
    154  
    155                         //TODO Replace it with proper constructor 
    156                         while (itService.hasNext()) 
    157                         { 
    158                                 Service service = new Service(); 
    159                                 Element currentService = itService.next(); 
    160                                 service.setName(currentService.getAttributeValue("name")); 
    161                                                                  
    162                                 service.setEnable(new Boolean(currentService.getAttributeValue("enable"))); 
    163                                 service.setConfigurationConnexion(new DatabaseConfiguration(currentService.getChild("connection").getAttributeValue("driver"), 
    164                                                 currentService.getChild("connection").getChildText("url"), currentService.getChild("connection").getChildText("user"), 
    165                                                 currentService.getChild("connection").getChildText("password"))); 
    166                                 service.setDataProjection(currentService.getChild("projection").getAttributeValue("srid")); 
    167  
    168                                 List<Element> listSQL = currentService.getChild("sql").getChildren("query"); 
    169                                 Iterator<Element> itQuery = listSQL.iterator(); 
    170                                 while (itQuery.hasNext()) 
    171                                 { 
    172                                         Element currentQuery = itQuery.next(); 
    173                                         if (currentQuery.getAttributeValue("transformProjectionIn").equals("false")) 
    174                                         { 
    175                                                 if (currentQuery.getAttributeValue("transformProjectionOut").equals("false")) 
    176                                                 { 
    177                                                         // case: transformProjectionIn = FALSE & 
    178                                                         // transformProjectionOut = FALSE 
    179                                                         service.setSQL(currentQuery.getText(), 0); 
    180                                                 } 
    181                                                 else 
    182                                                 { 
    183                                                         // case: transformProjectionIn = FALSE & 
    184                                                         // transformProjectionOut = TRUE 
    185                                                         service.setSQL(currentQuery.getText(), 1); 
    186                                                 } 
    187  
    188                                         } 
    189                                         else 
    190                                         { 
    191                                                 if (currentQuery.getAttributeValue("transformProjectionOut").equals("false")) 
    192                                                 { 
    193                                                         // case: transformProjectionIn = TRUE & 
    194                                                         // transformProjectionOut = FALSE 
    195                                                         service.setSQL(currentQuery.getText(), 2); 
    196                                                 } 
    197                                                 else 
    198                                                 { 
    199                                                         // case: transformProjectionIn = TRUE & 
    200                                                         // transformProjectionOut = TRUE 
    201                                                         service.setSQL(currentQuery.getText(), 3); 
    202                                                 } 
    203                                         } 
    204  
    205                                 } 
    206  
    207                                 List<Element> listParameters = currentService.getChild("parameters").getChildren("parameter"); 
    208                                 Iterator<Element> itParametre = listParameters.iterator(); 
    209                                 Vector<Parameter> parameters = new Vector<Parameter>(); 
    210  
    211                                 while (itParametre.hasNext()) 
    212                                 { 
    213                                         Parameter parameter = new Parameter(); 
    214                                         Element currentParameter = itParametre.next(); 
    215                                         parameter.setName(currentParameter.getAttributeValue("name")); 
    216                                         parameter.setType(currentParameter.getAttributeValue("type")); 
    217                                         parameter.setCodeName(currentParameter.getAttributeValue("codename")); 
    218                                         parameter.setRequired(new Boolean(currentParameter.getAttributeValue("required"))); 
    219                                         parameter.setDefaultValue(currentParameter.getAttributeValue("default")); 
    220                                         parameter.setValue(currentParameter.getAttributeValue("default")); 
    221                                         parameters.add(parameter); 
    222                                 } 
    223                                 service.setParameters(parameters); 
    224  
    225                                 List<Element> listFormat = currentService.getChild("formats").getChildren("format"); 
    226                                 Iterator<Element> itFormat = listFormat.iterator(); 
    227                                 Vector<Format> formats = new Vector<Format>(); 
    228  
    229                                 while (itFormat.hasNext()) 
    230                                 { 
    231                                         Format format = new Format(); 
    232                                         Element currentFormat = itFormat.next(); 
    233                                         format.setName(currentFormat.getAttributeValue("name")); 
    234                                         format.setSrid(currentFormat.getAttributeValue("srid")); 
    235                                         format.setEnableInput(new Boolean(currentFormat.getAttributeValue("input"))); 
    236                                         format.setEnableOutput(new Boolean(currentFormat.getAttributeValue("output"))); 
    237                                         formats.add(format); 
    238                                 } 
    239                                  
    240                                 if(service.getName().equals("security")) 
    241                                         provider.setAuthService(service); 
    242  
    243                                 service.setFormats(formats); 
    244                                 services.add(service); 
    245                         } 
    246                         provider.setServices(services); 
    247                         providers.add(provider); 
     255                    Parameter parameter = new Parameter(); 
     256                    Element currentParameter = itParametre.next(); 
     257                    parameter.setName(currentParameter 
     258                            .getAttributeValue("name")); 
     259                    parameter.setType(currentParameter 
     260                            .getAttributeValue("type")); 
     261                    parameter.setCodeName(currentParameter 
     262                            .getAttributeValue("codename")); 
     263                    parameter.setRequired(new Boolean(currentParameter 
     264                            .getAttributeValue("required"))); 
     265                    parameter.setDefaultValue(currentParameter 
     266                            .getAttributeValue("default")); 
     267                    parameter.setValue(currentParameter 
     268                            .getAttributeValue("default")); 
     269                    parameters.add(parameter); 
    248270                } 
    249         } 
    250  
    251         /** 
    252          * Parses the URL request to define the provider, the service, the data 
    253          * input and output format. The format of the URL must be: 
    254          * root/version/provider/input_format/service.output_format 
    255          *  
    256          * @param url 
    257          *            the string to parse 
    258          * @throws Exception 
    259          *             Creates an exception if the URL is wrong 
    260          */ 
    261         public void parseURL(String url) throws Exception 
    262         { 
    263                 // FORMAT: /version/provider/input/service.output 
    264  
    265                 String urlSplit[] = url.split("/"); 
    266  
    267                 if (urlSplit[0].equals(commandCapabilities)) 
     271                service.setParameters(parameters); 
     272 
     273                List<Element> listFormat = currentService.getChild("formats") 
     274                        .getChildren("format"); 
     275                Iterator<Element> itFormat = listFormat.iterator(); 
     276                Vector<Format> formats = new Vector<Format>(); 
     277 
     278                while (itFormat.hasNext()) 
    268279                { 
    269                         askCapabilities = 0; 
    270                         return; 
     280                    Format format = new Format(); 
     281                    Element currentFormat = itFormat.next(); 
     282                    format.setName(currentFormat.getAttributeValue("name")); 
     283                    format.setSrid(currentFormat.getAttributeValue("srid")); 
     284                    format.setEnableInput(new Boolean(currentFormat 
     285                            .getAttributeValue("input"))); 
     286                    format.setEnableOutput(new Boolean(currentFormat 
     287                            .getAttributeValue("output"))); 
     288                    formats.add(format); 
    271289                } 
    272                 if (!urlSplit[0].equals(versionNumber)) 
    273                         throw new Exception("Invalid version number"); 
    274  
    275                 if ((iProvider = isProvider(urlSplit[1])) != -1) 
    276                 { 
    277                         provider = providers.get(iProvider); 
    278                         if (urlSplit[1].equals(commandCapabilities)) 
    279                         { 
    280                                 askCapabilities = 1; 
    281                                 return; 
    282                         } 
    283                 } 
    284                 else 
    285                         throw new Exception("Unknown provider"); 
    286  
    287                 if ((iService = isService(urlSplit[3].split("\\.")[0])) != -1) 
    288                 { 
    289                         Service tmpService = provider.getServices().get(iService); 
    290                         service = new Service(tmpService.getName(), tmpService.getDataProjection(), tmpService.getSQL(), tmpService.isEnable(), tmpService 
    291                                         .getParameters(), null, tmpService.getDatabaseConfiguration()); 
    292                 } 
    293                 else 
    294                         throw new Exception("unknown service"); 
    295  
    296                 if ((iFormat = isInput(urlSplit[2])) != -1) 
    297                 { 
    298                         Format tmpFormat = providers.get(iProvider).getServices().get(iService).getFormats().get(iFormat); 
    299                         formatIn = new Format(tmpFormat.getName(), tmpFormat.getSrid(), tmpFormat.isEnableInput(), tmpFormat.isEnableOutput()); 
    300                 } 
    301                 else 
    302                         throw new Exception("unknown input format"); 
    303  
    304                 if ((iFormat = isOutput(urlSplit[3].split("\\.")[1].split("\\?")[0])) != -1) 
    305                 { 
    306                         Format tmpFormat = providers.get(iProvider).getServices().get(iService).getFormats().get(iFormat); 
    307                         formatOut = new Format(tmpFormat.getName(), tmpFormat.getSrid(), tmpFormat.isEnableInput(), tmpFormat.isEnableOutput()); 
    308                         if (formatOut.getSrid() != null && !formatOut.getSrid().equals("")) 
    309                         { 
    310                                 service.getParameter("sridOutput").setValue(formatOut.getSrid()); 
    311                         } 
    312                 } 
    313                 else 
    314                         throw new Exception("unknown output format"); 
    315         } 
    316  
    317         /** 
    318          * Creates an object to write in the log file 
    319          *  
    320          * @return a new Log object 
    321          */ 
    322         public Log createLog() 
    323         { 
    324                 return new Log(urlLog, modeLog); 
    325         } 
    326  
    327         /** 
    328          * Determines whether this string is a provider name. 
    329          *  
    330          * @param name 
    331          *            a string 
    332          * @return index of the provider in the vector<Provider>; otherwise returns 
    333          *         -1 
    334          */ 
    335         public int isProvider(String name) 
    336         { 
    337                 for (int i = 0; i < providers.size(); i++) 
    338                 { 
    339                         if (providers.get(i).getName().equals(name)) 
    340                                 return i; 
    341                 } 
    342                 return -1; 
    343         } 
    344  
    345         /** 
    346          * Determines whether this string is a service name. 
    347          *  
    348          * @param name 
    349          *            a string 
    350          * @return index of the service in the vector<Service> of the parent 
    351          *         provider; otherwise returns -1 
    352          */ 
    353         public int isService(String name) 
    354         { 
    355  
    356                 for (int i = 0; i < providers.get(iProvider).getServices().size(); i++) 
    357                 { 
    358                         if (providers.get(iProvider).getServices().get(i).getName().equals(name)) 
    359                                 return i; 
    360                 } 
    361                 return -1; 
    362         } 
    363  
    364         /** 
    365          * Determines whether this string is a input name and whether is enabled for 
    366          * input data 
    367          *  
    368          * @param name 
    369          *            a string 
    370          * @return index of the format in the vector<Format> of the parent service; 
    371          *         otherwise returns -1 
    372          */ 
    373         public int isInput(String name) 
    374         { 
    375  
    376                 for (int i = 0; i < providers.get(iProvider).getServices().get(iService).getFormats().size(); i++) 
    377                 { 
    378                         if (providers.get(iProvider).getServices().get(iService).getFormats().get(i).getName().equals(name) 
    379 </