Revision 43828 branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureReference.java
DefaultFeatureReference.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.lang.ref.WeakReference; |
27 | 27 |
import java.util.Arrays; |
28 |
import java.util.Base64; |
|
28 | 29 |
import java.util.List; |
29 | 30 |
import org.apache.commons.lang3.ArrayUtils; |
30 | 31 |
|
... | ... | |
40 | 41 |
import org.gvsig.tools.persistence.Persistent; |
41 | 42 |
import org.gvsig.tools.persistence.PersistentState; |
42 | 43 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
44 |
import org.json.JSONArray; |
|
45 |
import org.json.JSONObject; |
|
43 | 46 |
|
44 | 47 |
public class DefaultFeatureReference implements |
45 | 48 |
FeatureReferenceProviderServices, Persistent { |
... | ... | |
52 | 55 |
private boolean isNewFeature; |
53 | 56 |
private String featureTypeId; |
54 | 57 |
|
58 |
|
|
59 |
private final int OID_INDEX = 0; |
|
60 |
private final int MYHASHCODE_INDEX = 1; |
|
61 |
private final int ISNEWFEATURE_INDEX = 2; |
|
62 |
private final int FEATURETYPEID_INDEX = 3; |
|
63 |
private final int PKNAMES_SIZE_INDEX = 4; |
|
64 |
private final int PKNAMES_INDEX = 5; |
|
65 |
private final int PK_INDEX = 6; |
|
66 |
|
|
55 | 67 |
/** |
56 | 68 |
* Constructor used by the persistence manager. Don't use directly. |
57 | 69 |
* After to invoke this method, the persistence manager calls |
... | ... | |
108 | 120 |
this.storeRef = new WeakReference(store); |
109 | 121 |
} |
110 | 122 |
|
111 |
private DefaultFeatureStore getStore() { |
|
123 |
public DefaultFeatureReference(FeatureStore store, String code) { |
|
124 |
this.storeRef = new WeakReference(store); |
|
125 |
|
|
126 |
String json = new String(Base64.getDecoder().decode(code.getBytes())); |
|
127 |
|
|
128 |
JSONArray x = new JSONArray(json); |
|
129 |
this.oid = x.get(OID_INDEX); |
|
130 |
if( x.get(MYHASHCODE_INDEX)==JSONObject.NULL ) { |
|
131 |
this.myHashCode = null; |
|
132 |
} else { |
|
133 |
this.myHashCode = x.getInt(MYHASHCODE_INDEX); |
|
134 |
} |
|
135 |
this.isNewFeature = x.getBoolean(ISNEWFEATURE_INDEX); |
|
136 |
this.featureTypeId = x.getString(FEATURETYPEID_INDEX); |
|
137 |
int pkNames_size = x.getInt(PKNAMES_SIZE_INDEX); |
|
138 |
if( pkNames_size<0 ) { |
|
139 |
this.pk = null; |
|
140 |
this.pkNames = null; |
|
141 |
} else { |
|
142 |
this.pk = new Object[pkNames_size]; |
|
143 |
this.pkNames = new String[pkNames_size]; |
|
144 |
JSONArray xx = x.getJSONArray(PKNAMES_INDEX); |
|
145 |
for( int i=0; i<xx.length(); i++ ) { |
|
146 |
this.pkNames[i] = xx.getString(i); |
|
147 |
} |
|
148 |
xx = x.getJSONArray(PKNAMES_INDEX); |
|
149 |
for( int i=0; i<xx.length(); i++ ) { |
|
150 |
this.pk[i] = xx.get(i); |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
// JSONObject x = new JSONObject(json); |
|
155 |
// this.oid = x.get("oid"); |
|
156 |
// this.myHashCode = x.getInt("myHashCode"); |
|
157 |
// this.isNewFeature = x.getBoolean("isNewFeature"); |
|
158 |
// this.featureTypeId = x.getString("featureTypeId"); |
|
159 |
// int pkNames_size = x.getInt("pkNames_size"); |
|
160 |
// if( pkNames_size<0 ) { |
|
161 |
// this.pk = null; |
|
162 |
// this.pkNames = null; |
|
163 |
// } else { |
|
164 |
// this.pk = new Object[pkNames_size]; |
|
165 |
// this.pkNames = new String[pkNames_size]; |
|
166 |
// JSONArray xx = x.getJSONArray("pkNames"); |
|
167 |
// for( int i=0; i<xx.length(); i++ ) { |
|
168 |
// this.pkNames[i] = xx.getString(i); |
|
169 |
// } |
|
170 |
// xx = x.getJSONArray("pk"); |
|
171 |
// for( int i=0; i<xx.length(); i++ ) { |
|
172 |
// this.pk[i] = xx.get(i); |
|
173 |
// } |
|
174 |
// } |
|
175 |
} |
|
176 |
|
|
177 |
private DefaultFeatureStore getStore() { |
|
112 | 178 |
return (DefaultFeatureStore) this.storeRef.get(); |
113 | 179 |
} |
114 | 180 |
|
... | ... | |
263 | 329 |
} |
264 | 330 |
|
265 | 331 |
} |
332 |
|
|
333 |
@Override |
|
334 |
public String getCode() { |
|
335 |
// JSONObject x = new JSONObject(); |
|
336 |
//// x.put("store", (Persistent) storeRef.get()); |
|
337 |
// x.put("oid", oid); |
|
338 |
// x.put("myHashCode", myHashCode); |
|
339 |
// x.put("isNewFeature", isNewFeature); |
|
340 |
// x.put("featureTypeId", featureTypeId); |
|
341 |
// if( this.pk == null ) { |
|
342 |
// x.put("pkNames_size", -1); |
|
343 |
// x.put("pkNames", JSONObject.NULL); |
|
344 |
// x.put("pk", JSONObject.NULL); |
|
345 |
// } else { |
|
346 |
// x.put("pkNames_size", pkNames.length); |
|
347 |
// x.put("pkNames", new JSONArray(this.pkNames)); |
|
348 |
// x.put("pk", new JSONArray(this.pk)); |
|
349 |
// } |
|
350 |
// |
|
351 |
Object[] data = new Object[7]; |
|
352 |
data[OID_INDEX] = this.oid; |
|
353 |
data[MYHASHCODE_INDEX] = this.myHashCode; |
|
354 |
data[ISNEWFEATURE_INDEX] = this.isNewFeature; |
|
355 |
data[FEATURETYPEID_INDEX] = this.featureTypeId; |
|
356 |
if( this.pk == null ) { |
|
357 |
data[PKNAMES_SIZE_INDEX] = -1; |
|
358 |
data[PKNAMES_INDEX] = JSONObject.NULL; |
|
359 |
data[PK_INDEX] = JSONObject.NULL; |
|
360 |
} else { |
|
361 |
data[PKNAMES_SIZE_INDEX] = pkNames.length; |
|
362 |
data[PKNAMES_INDEX] = new JSONArray(this.pkNames); |
|
363 |
data[PK_INDEX] = new JSONArray(this.pk); |
|
364 |
} |
|
365 |
String s = new JSONArray(data).toString(); |
|
366 |
String r = Base64.getEncoder().encodeToString(s.getBytes()); |
|
367 |
|
|
368 |
return r; |
|
369 |
} |
|
266 | 370 |
|
267 | 371 |
public static void registerPersistent() { |
268 | 372 |
DynStruct definition = ToolsLocator.getPersistenceManager().addDefinition( |
Also available in: Unified diff