svn-gvsig-desktop / trunk / libraries / libDataSource / src / org / gvsig / data / vectorial / joinstore / JoinFetureStore.java @ 20412
History | View | Annotate | Download (7.25 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 IVER T.I {{Task}}
|
26 |
*/
|
27 |
|
28 |
/**
|
29 |
*
|
30 |
*/
|
31 |
package org.gvsig.data.vectorial.joinstore; |
32 |
|
33 |
import java.util.ArrayList; |
34 |
import java.util.Iterator; |
35 |
import java.util.List; |
36 |
|
37 |
import org.gvsig.data.DataManager; |
38 |
import org.gvsig.data.IDataCollection; |
39 |
import org.gvsig.data.IDataExplorer; |
40 |
import org.gvsig.data.IDataStoreParameters; |
41 |
import org.gvsig.data.IObservable; |
42 |
import org.gvsig.data.IObserver; |
43 |
import org.gvsig.data.commands.ICommandsRecord; |
44 |
import org.gvsig.data.exception.CloseException; |
45 |
import org.gvsig.data.exception.InitializeException; |
46 |
import org.gvsig.data.exception.OpenException; |
47 |
import org.gvsig.data.exception.ReadException; |
48 |
import org.gvsig.data.exception.WriteException; |
49 |
import org.gvsig.data.vectorial.AbstractFeatureStore; |
50 |
import org.gvsig.data.vectorial.DefaultAttributeDescriptor; |
51 |
import org.gvsig.data.vectorial.FeatureStoreNotification; |
52 |
import org.gvsig.data.vectorial.IFeature; |
53 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
54 |
import org.gvsig.data.vectorial.IFeatureID; |
55 |
import org.gvsig.data.vectorial.IFeatureStore; |
56 |
import org.gvsig.data.vectorial.IFeatureStoreNotification; |
57 |
import org.gvsig.data.vectorial.IFeatureType; |
58 |
import org.gvsig.data.vectorial.IsNotFeatureSettingException; |
59 |
import org.gvsig.exceptions.BaseException; |
60 |
import org.gvsig.metadata.IMetadata; |
61 |
import org.medfoster.sqljep.function.Second; |
62 |
|
63 |
/**
|
64 |
* @author jmvivo
|
65 |
*
|
66 |
*/
|
67 |
public class JoinFetureStore extends AbstractFeatureStore{ |
68 |
public static String DATASTORE_NAME="JoinFeatureStore"; |
69 |
private IFeatureType featureType;
|
70 |
private IFeatureStore storePrimary;
|
71 |
private IFeatureStore storeSecondary;
|
72 |
private String linkFieldSecondary=null; |
73 |
private List featuresList = null; |
74 |
|
75 |
protected JoinFeatureStoreParameters getJoinParameters(){
|
76 |
return (JoinFeatureStoreParameters)this.parameters; |
77 |
} |
78 |
|
79 |
/* (non-Javadoc)
|
80 |
* @see org.gvsig.data.vectorial.IFeatureStore#canAlterFeatureType()
|
81 |
*/
|
82 |
public boolean canAlterFeatureType() { |
83 |
return false; |
84 |
} |
85 |
|
86 |
/* (non-Javadoc)
|
87 |
* @see org.gvsig.data.vectorial.AbstractFeatureStore#doFinishEdition()
|
88 |
*/
|
89 |
protected void doFinishEdition() throws WriteException, ReadException { |
90 |
throw new WriteException("UnsupportedOperation", "JoinFeatureStore"); |
91 |
} |
92 |
|
93 |
/* (non-Javadoc)
|
94 |
* @see org.gvsig.data.vectorial.IFeatureStore#getDataCollection(org.gvsig.data.vectorial.IFeatureType, java.lang.String, java.lang.String)
|
95 |
*/
|
96 |
public IDataCollection getDataCollection(IFeatureType type, String filter, String order) throws ReadException { |
97 |
// TODO Auto-generated method stub
|
98 |
return null; |
99 |
} |
100 |
|
101 |
/* (non-Javadoc)
|
102 |
* @see org.gvsig.data.vectorial.IFeatureStore#getDefaultFeatureType()
|
103 |
*/
|
104 |
public IFeatureType getDefaultFeatureType() {
|
105 |
return this.featureType; |
106 |
} |
107 |
|
108 |
/* (non-Javadoc)
|
109 |
* @see org.gvsig.data.vectorial.IFeatureStore#getDefaultLabelingStrategy()
|
110 |
*/
|
111 |
public Object getDefaultLabelingStrategy() { |
112 |
return null; |
113 |
} |
114 |
|
115 |
/* (non-Javadoc)
|
116 |
* @see org.gvsig.data.vectorial.IFeatureStore#getDefaultLegend()
|
117 |
*/
|
118 |
public Object getDefaultLegend() { |
119 |
return null; |
120 |
} |
121 |
|
122 |
/* (non-Javadoc)
|
123 |
* @see org.gvsig.data.vectorial.IFeatureStore#getFeatureByID(org.gvsig.data.vectorial.IFeatureID)
|
124 |
*/
|
125 |
public IFeature getFeatureByID(IFeatureID id) throws ReadException { |
126 |
// TODO Auto-generated method stub
|
127 |
return null; |
128 |
} |
129 |
|
130 |
/* (non-Javadoc)
|
131 |
* @see org.gvsig.data.vectorial.IFeatureStore#getFeatureTypes()
|
132 |
*/
|
133 |
public List getFeatureTypes() { |
134 |
ArrayList list = new ArrayList(); |
135 |
list.add(this.getDefaultFeatureType());
|
136 |
return list;
|
137 |
} |
138 |
|
139 |
/* (non-Javadoc)
|
140 |
* @see org.gvsig.data.vectorial.IFeatureStore#isWithDefaultLegend()
|
141 |
*/
|
142 |
public boolean isWithDefaultLegend() { |
143 |
return false; |
144 |
} |
145 |
|
146 |
/* (non-Javadoc)
|
147 |
* @see org.gvsig.data.IDataStore#close()
|
148 |
*/
|
149 |
public void close() throws CloseException { |
150 |
this.storePrimary.close();
|
151 |
this.storeSecondary.close();
|
152 |
} |
153 |
|
154 |
/* (non-Javadoc)
|
155 |
* @see org.gvsig.data.IDataStore#dispose()
|
156 |
*/
|
157 |
public void dispose() throws CloseException { |
158 |
this.featureType = null; |
159 |
this.storePrimary.dispose();
|
160 |
this.storeSecondary.dispose();
|
161 |
} |
162 |
|
163 |
/* (non-Javadoc)
|
164 |
* @see org.gvsig.data.IDataStore#getExplorer()
|
165 |
*/
|
166 |
public IDataExplorer getExplorer() throws ReadException { |
167 |
return null; |
168 |
} |
169 |
|
170 |
/* (non-Javadoc)
|
171 |
* @see org.gvsig.data.IDataStore#getName()
|
172 |
*/
|
173 |
public String getName() { |
174 |
return DATASTORE_NAME;
|
175 |
} |
176 |
|
177 |
/* (non-Javadoc)
|
178 |
* @see org.gvsig.data.IDataStore#isEditable()
|
179 |
*/
|
180 |
public boolean isEditable() { |
181 |
return false; |
182 |
} |
183 |
|
184 |
/* (non-Javadoc)
|
185 |
* @see org.gvsig.data.IDataStore#open()
|
186 |
*/
|
187 |
public void open() throws OpenException, IsNotFeatureSettingException { |
188 |
this.storePrimary.open();
|
189 |
this.storeSecondary.open();
|
190 |
|
191 |
} |
192 |
|
193 |
/* (non-Javadoc)
|
194 |
* @see org.gvsig.metadata.IMetadatable#getMetadata()
|
195 |
*/
|
196 |
public IMetadata getMetadata() throws BaseException { |
197 |
// TODO Auto-generated method stub
|
198 |
return null; |
199 |
} |
200 |
|
201 |
public void init(IDataStoreParameters parameters) throws InitializeException { |
202 |
super.init(this.parameters); |
203 |
if (!(this.parameters instanceof JoinFeatureStoreParameters)){ |
204 |
throw new InitializeException("Wrong parameters",this.getName()); |
205 |
} |
206 |
JoinFeatureStoreParameters jParams = this.getJoinParameters();
|
207 |
DataManager dataManager = DataManager.getManager(); |
208 |
this.storePrimary = (IFeatureStore)dataManager.createDataStore(jParams.getStorePrimary());
|
209 |
this.storeSecondary = (IFeatureStore)dataManager.createDataStore(jParams.getStoreSecondary());
|
210 |
|
211 |
this.featureType = this.storePrimary.getDefaultFeatureType().cloneFeatureType(); |
212 |
IFeatureType secondFType = this.storeSecondary.getDefaultFeatureType();
|
213 |
Iterator iter = secondFType.iterator();
|
214 |
String prefix = jParams.getFieldNamePrefix();
|
215 |
while(iter.hasNext()){
|
216 |
DefaultAttributeDescriptor attr = (DefaultAttributeDescriptor) iter.next(); |
217 |
attr.setName(prefix + attr.getName()); |
218 |
this.featureType.add(attr);
|
219 |
} |
220 |
this.linkFieldSecondary = prefix + jParams.getLinkFieldSecondary();
|
221 |
if (this.featureType.getFieldIndex(this.linkFieldSecondary)< 0){ |
222 |
throw new InitializeException("Secondary link field not found: " +jParams.getLinkFieldSecondary(),this.getName()); |
223 |
} |
224 |
|
225 |
String defGeometry = jParams.getDefaultGeometry();
|
226 |
if (defGeometry != null){ |
227 |
if (this.featureType.getFieldIndex(defGeometry) >= 0){ |
228 |
this.featureType.setDefaultGeometry(defGeometry);
|
229 |
} else if (this.featureType.getFieldIndex(prefix+defGeometry) >= 0){ |
230 |
this.featureType.setDefaultGeometry(prefix+defGeometry);
|
231 |
} else {
|
232 |
throw new InitializeException("Default geometry field not found: " +defGeometry,this.getName()); |
233 |
} |
234 |
} |
235 |
|
236 |
|
237 |
|
238 |
|
239 |
} |
240 |
|
241 |
|
242 |
} |
243 |
|