Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / data / vectorial / joinstore / JoinFetureStore.java @ 21511

History | View | Annotate | Download (7.55 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.CloseException;
38
import org.gvsig.data.DataManager;
39
import org.gvsig.data.DataCollection;
40
import org.gvsig.data.DataExplorer;
41
import org.gvsig.data.DataStoreParameters;
42
import org.gvsig.data.InitializeException;
43
import org.gvsig.data.OpenException;
44
import org.gvsig.data.ReadException;
45
import org.gvsig.data.WriteException;
46
import org.gvsig.data.commands.CommandsRecord;
47
import org.gvsig.data.vectorial.AbstractFeatureStore;
48
import org.gvsig.data.vectorial.AttributeDescriptor;
49
import org.gvsig.data.vectorial.DefaultFeatureStoreNotification;
50
import org.gvsig.data.vectorial.Feature;
51
import org.gvsig.data.vectorial.FeatureAttributeDescriptor;
52
import org.gvsig.data.vectorial.FeatureID;
53
import org.gvsig.data.vectorial.FeatureStore;
54
import org.gvsig.data.vectorial.FeatureStoreNotification;
55
import org.gvsig.data.vectorial.FeatureType;
56
import org.gvsig.data.vectorial.IsNotAttributeSettingException;
57
import org.gvsig.data.vectorial.IsNotFeatureSettingException;
58
import org.gvsig.exceptions.BaseException;
59
import org.gvsig.metadata.IMetadata;
60
import org.gvsig.util.observer.Observable;
61
import org.gvsig.util.observer.Observer;
62
import org.medfoster.sqljep.function.Second;
63

    
64
/**
65
 * @author jmvivo
66
 *
67
 */
68
public class JoinFetureStore extends AbstractFeatureStore{
69
        public static String DATASTORE_NAME="JoinFeatureStore";
70
        private FeatureStore storePrimary;
71
        private FeatureStore 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.FeatureStore#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.FeatureStore#getDataCollection(org.gvsig.data.vectorial.FeatureType, java.lang.String, java.lang.String)
95
         */
96
        public DataCollection getDataCollection(FeatureType 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.FeatureStore#getDefaultLabelingStrategy()
103
         */
104
        public Object getDefaultLabelingStrategy() {
105
                return null;
106
        }
107

    
108
        /* (non-Javadoc)
109
         * @see org.gvsig.data.vectorial.FeatureStore#getDefaultLegend()
110
         */
111
        public Object getDefaultLegend() {
112
                return null;
113
        }
114

    
115
        /* (non-Javadoc)
116
         * @see org.gvsig.data.vectorial.FeatureStore#getFeatureByID(org.gvsig.data.vectorial.FeatureID)
117
         */
118
        public Feature getFeatureByID(FeatureID id,FeatureType featureType) throws ReadException {
119
                // TODO Auto-generated method stub
120
                return null;
121
        }
122

    
123
        /* (non-Javadoc)
124
         * @see org.gvsig.data.vectorial.FeatureStore#getFeatureTypes()
125
         */
126
        public List getFeatureTypes() {
127
                ArrayList list = new ArrayList();
128
                list.add(this.getDefaultFeatureType());
129
                return list;
130
        }
131

    
132
        /* (non-Javadoc)
133
         * @see org.gvsig.data.vectorial.FeatureStore#isWithDefaultLegend()
134
         */
135
        public boolean isWithDefaultLegend() {
136
                return false;
137
        }
138

    
139
        /* (non-Javadoc)
140
         * @see org.gvsig.data.FeatureStore#doClose()
141
         */
142
        protected void doClose() throws CloseException {
143
                ((AbstractFeatureStore)this.storePrimary).close();
144
                ((AbstractFeatureStore)this.storeSecondary).close();
145
        }
146

    
147
        /* (non-Javadoc)
148
         * @see org.gvsig.data.FeatureStore#doDispose()
149
         */
150
        protected void doDispose() throws CloseException {
151
                super.doDispose();
152
                this.storePrimary.dispose();
153
                this.storeSecondary.dispose();
154
        }
155

    
156
        /* (non-Javadoc)
157
         * @see org.gvsig.data.DataStore#getExplorer()
158
         */
159
        public DataExplorer getExplorer() throws ReadException {
160
                return null;
161
        }
162

    
163
        /* (non-Javadoc)
164
         * @see org.gvsig.data.DataStore#getName()
165
         */
166
        public String getName() {
167
                return DATASTORE_NAME;
168
        }
169

    
170
        /* (non-Javadoc)
171
         * @see org.gvsig.data.DataStore#isEditable()
172
         */
173
        public boolean isEditable() {
174
                return false;
175
        }
176

    
177
        /* (non-Javadoc)
178
         * @see org.gvsig.data.FeatureStore#doOpen()
179
         */
180
        protected void doOpen() throws OpenException {
181
                ((AbstractFeatureStore)this.storePrimary).open();
182
                ((AbstractFeatureStore)this.storeSecondary).open();
183

    
184
        }
185

    
186
        /* (non-Javadoc)
187
         * @see org.gvsig.metadata.IMetadatable#getMetadata()
188
         */
189
        public IMetadata getMetadata() throws BaseException {
190
                // TODO Auto-generated method stub
191
                return null;
192
        }
193

    
194
        public void init(DataStoreParameters parameters) throws InitializeException {
195
                super.init(this.parameters);
196
                if (!(this.parameters instanceof JoinFeatureStoreParameters)){
197
                        throw new InitializeException("Wrong parameters",this.getName());
198
                }
199
                JoinFeatureStoreParameters jParams = this.getJoinParameters();
200
                DataManager dataManager = DataManager.getManager();
201
                this.storePrimary = (FeatureStore)dataManager.createDataStore(jParams.getStorePrimary());
202
                this.storeSecondary = (FeatureStore)dataManager.createDataStore(jParams.getStoreSecondary());
203

    
204
                this.defaultFeatureType = this.storePrimary.getDefaultFeatureType().cloneFeatureType();
205
                FeatureType secondFType = this.storeSecondary.getDefaultFeatureType();
206
                Iterator iter = secondFType.iterator();
207
                String prefix = jParams.getFieldNamePrefix();
208
                while(iter.hasNext()){
209
                        AttributeDescriptor attr = (AttributeDescriptor) iter.next();
210
                        attr.loading();
211
                        try {
212
                                attr.setName(prefix + attr.getName());
213
                        } catch (IsNotAttributeSettingException e) {
214
                                throw new InitializeException("Is not posible change AttributeDescriptor",this.getName());
215
                        }
216
                        attr.stopLoading();
217
                        this.defaultFeatureType.add(attr);
218
                }
219
                this.linkFieldSecondary = prefix + jParams.getLinkFieldSecondary();
220
                if (this.defaultFeatureType.getFieldIndex(this.linkFieldSecondary)< 0){
221
                        throw new InitializeException("Secondary link field not found: " +jParams.getLinkFieldSecondary(),this.getName());
222
                }
223

    
224
                String defGeometry = jParams.getDefaultGeometry();
225
                if (defGeometry != null){
226
                        if (this.defaultFeatureType.getFieldIndex(defGeometry) >= 0){
227
                                this.defaultFeatureType.setDefaultGeometry(defGeometry);
228
                        } else if (this.defaultFeatureType.getFieldIndex(prefix+defGeometry) >= 0){
229
                                this.defaultFeatureType.setDefaultGeometry(prefix+defGeometry);
230
                        } else {
231
                                throw new InitializeException("Default geometry field not found: " +defGeometry,this.getName());
232
                        }
233
                }
234
        }
235

    
236
        /* (non-Javadoc)
237
         * @see org.gvsig.data.DataStore#refresh()
238
         */
239
        protected void doRefresh() throws OpenException,InitializeException {
240
                this.init(this.parameters);
241
        }
242

    
243

    
244
}
245