gvsig-gdal / trunk / org.gvsig.gdal2 / org.gvsig.gdal2.prov / org.gvsig.gdal2.prov.ogr / src / main / java / org / gvsig / gdal / prov / ogr / OGRResourceParameters.java @ 368
History | View | Annotate | Download (3.84 KB)
1 | 368 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2016 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | package org.gvsig.gdal.prov.ogr; |
||
25 | |||
26 | import org.gvsig.fmap.dal.resource.spi.AbstractResourceParameters; |
||
27 | import org.gvsig.tools.ToolsLocator; |
||
28 | import org.gvsig.tools.dataTypes.DataTypes; |
||
29 | import org.gvsig.tools.dynobject.DelegatedDynObject; |
||
30 | import org.gvsig.tools.dynobject.DynClass; |
||
31 | import org.gvsig.tools.persistence.PersistenceManager; |
||
32 | |||
33 | /**
|
||
34 | *
|
||
35 | * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
||
36 | *
|
||
37 | */
|
||
38 | public class OGRResourceParameters extends AbstractResourceParameters { |
||
39 | |||
40 | /**
|
||
41 | *
|
||
42 | */
|
||
43 | public static final String DYNCLASS_NAME = "OGRResourceParameters"; |
||
44 | |||
45 | /**
|
||
46 | *
|
||
47 | */
|
||
48 | private static final String DYNFIELDNAME_NAME = "name"; |
||
49 | |||
50 | /**
|
||
51 | *
|
||
52 | */
|
||
53 | private static final String DYNFIELDNAME_CONNECTION_STRING = "connectionString"; |
||
54 | |||
55 | private DelegatedDynObject delegatedDynObject;
|
||
56 | |||
57 | /**
|
||
58 | *
|
||
59 | */
|
||
60 | public OGRResourceParameters() {
|
||
61 | super();
|
||
62 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
63 | DynClass definition = (DynClass) manager.getDefinition(DYNCLASS_NAME); |
||
64 | this.delegatedDynObject =
|
||
65 | (DelegatedDynObject) ToolsLocator.getDynObjectManager().createDynObject(definition); |
||
66 | } |
||
67 | |||
68 | /**
|
||
69 | *
|
||
70 | * @param connectionString
|
||
71 | * Connection string
|
||
72 | */
|
||
73 | public OGRResourceParameters(String connectionString) { |
||
74 | this();
|
||
75 | setDynValue(DYNFIELDNAME_NAME, |
||
76 | String.valueOf(connectionString.hashCode()).concat("@OGResource")); |
||
77 | setDynValue(DYNFIELDNAME_CONNECTION_STRING, connectionString); |
||
78 | } |
||
79 | |||
80 | /**
|
||
81 | *
|
||
82 | * @param params
|
||
83 | * Array with parameter values
|
||
84 | */
|
||
85 | public OGRResourceParameters(Object[] params) { |
||
86 | this((String) params[0]); |
||
87 | } |
||
88 | |||
89 | @Override
|
||
90 | public String getTypeName() { |
||
91 | return OGRResource.NAME;
|
||
92 | } |
||
93 | |||
94 | @Override
|
||
95 | protected DelegatedDynObject getDelegatedDynObject() {
|
||
96 | return delegatedDynObject;
|
||
97 | } |
||
98 | |||
99 | /**
|
||
100 | * @return String
|
||
101 | */
|
||
102 | public String getName() { |
||
103 | return (String) this.getDynValue(DYNFIELDNAME_NAME); |
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | * @return String
|
||
108 | */
|
||
109 | public String getConnectionString() { |
||
110 | return (String) this.getDynValue(DYNFIELDNAME_CONNECTION_STRING); |
||
111 | } |
||
112 | |||
113 | protected static void registerPersistenceDefinition() { |
||
114 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
115 | DynClass definition = (DynClass) manager.getDefinition(DYNCLASS_NAME); |
||
116 | if (definition == null) { |
||
117 | definition = (DynClass) manager.addDefinition(OGRResourceParameters.class, |
||
118 | DYNCLASS_NAME, DYNCLASS_NAME + " persistence definition", null, null); |
||
119 | |||
120 | definition.addDynField(DYNFIELDNAME_NAME).setType(DataTypes.STRING) |
||
121 | .setDescription("Name of resource");
|
||
122 | definition.addDynField(DYNFIELDNAME_CONNECTION_STRING).setType(DataTypes.STRING) |
||
123 | .setDescription("Connection string");
|
||
124 | } |
||
125 | } |
||
126 | } |