gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / util / persistence / GenericPersistentObject.java @ 1400
History | View | Annotate | Download (3.98 KB)
1 |
package org.gvsig.raster.util.persistence; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
4 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
5 |
import org.gvsig.raster.impl.datastruct.Kernel; |
6 |
import org.gvsig.raster.impl.grid.filter.convolution.ConvolutionUI; |
7 |
import org.gvsig.tools.ToolsLocator; |
8 |
import org.gvsig.tools.dynobject.DynStruct; |
9 |
import org.gvsig.tools.persistence.PersistenceManager; |
10 |
import org.gvsig.tools.persistence.Persistent; |
11 |
|
12 |
/**
|
13 |
*
|
14 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
15 |
*
|
16 |
*/
|
17 |
public abstract class GenericPersistentObject implements Persistent { |
18 |
protected Object obj = null; |
19 |
|
20 |
public static GenericPersistentObject create(Object obj) { |
21 |
GenericPersistentObject result = null;
|
22 |
if(obj instanceof Double) |
23 |
result = new GenericPersistentDouble();
|
24 |
if(obj instanceof Integer) |
25 |
result = new GenericPersistentInt();
|
26 |
if(obj instanceof Boolean) |
27 |
result = new GenericPersistentBoolean();
|
28 |
if(obj instanceof ColorTable) |
29 |
result = new GenericPersistentColorTable();
|
30 |
if(obj instanceof String) |
31 |
result = new GenericPersistentString();
|
32 |
if(obj instanceof ConvolutionUI) |
33 |
result = new GenericPersistentConvolutionUI();
|
34 |
if(obj instanceof double[]) |
35 |
result = new GenericPersistentDoubleArray();
|
36 |
if(obj instanceof int[]) |
37 |
result = new GenericPersistentIntArray();
|
38 |
if(obj instanceof Statistics) |
39 |
result = new GenericPersistentStatistics();
|
40 |
if(result != null) |
41 |
result.setObject(obj); |
42 |
return result;
|
43 |
} |
44 |
|
45 |
public static void registerPersistence() { |
46 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
47 |
|
48 |
DynStruct definition = manager.addDefinition( |
49 |
GenericPersistentDouble.class, |
50 |
"GenericDouble_Persistence",
|
51 |
"Generic Double Persistence",
|
52 |
null,
|
53 |
null
|
54 |
); |
55 |
definition.addDynFieldDouble("value").setMandatory(false); |
56 |
|
57 |
definition = manager.addDefinition( |
58 |
GenericPersistentBoolean.class, |
59 |
"GenericBoolean_Persistence",
|
60 |
"Generic Boolean Persistence",
|
61 |
null,
|
62 |
null
|
63 |
); |
64 |
definition.addDynFieldBoolean("value").setMandatory(false); |
65 |
|
66 |
definition = manager.addDefinition( |
67 |
GenericPersistentInt.class, |
68 |
"GenericInt_Persistence",
|
69 |
"Generic Integer Persistence",
|
70 |
null,
|
71 |
null
|
72 |
); |
73 |
definition.addDynFieldInt("value").setMandatory(false); |
74 |
|
75 |
definition = manager.addDefinition( |
76 |
GenericPersistentColorTable.class, |
77 |
"GenericPersistentColorTable_Persistence",
|
78 |
"Generic Color Table Persistence",
|
79 |
null,
|
80 |
null
|
81 |
); |
82 |
definition.addDynFieldObject("value").setClassOfValue(ColorTable.class).setMandatory(false); |
83 |
|
84 |
definition = manager.addDefinition( |
85 |
GenericPersistentString.class, |
86 |
"GenericPersistentString_Persistence",
|
87 |
"Generic String Persistence",
|
88 |
null,
|
89 |
null
|
90 |
); |
91 |
definition.addDynFieldString("value").setClassOfValue(String.class).setMandatory(false); |
92 |
|
93 |
definition = manager.addDefinition( |
94 |
GenericPersistentConvolutionUI.class, |
95 |
"GenericPersistentConvolutionUI_Persistence",
|
96 |
"Generic ConvolutionUI Persistence",
|
97 |
null,
|
98 |
null
|
99 |
); |
100 |
definition.addDynFieldObject("value").setClassOfValue(Kernel.class).setMandatory(false); |
101 |
|
102 |
definition = manager.addDefinition( |
103 |
GenericPersistentDoubleArray.class, |
104 |
"GenericPersistentDoubleArray_Persistence",
|
105 |
"Generic Double Array Persistence",
|
106 |
null,
|
107 |
null
|
108 |
); |
109 |
definition.addDynFieldList("value").setClassOfItems(double.class).setMandatory(false); |
110 |
|
111 |
definition = manager.addDefinition( |
112 |
GenericPersistentIntArray.class, |
113 |
"GenericPersistentIntArray_Persistence",
|
114 |
"Generic Integer Array Persistence",
|
115 |
null,
|
116 |
null
|
117 |
); |
118 |
definition.addDynFieldList("value").setClassOfItems(int.class).setMandatory(false); |
119 |
|
120 |
|
121 |
definition = manager.addDefinition( |
122 |
GenericPersistentStatistics.class, |
123 |
"GenericPersistentStatistics_Persistence",
|
124 |
"Generic Statistics Persistence",
|
125 |
null,
|
126 |
null
|
127 |
); |
128 |
definition.addDynFieldList("value").setClassOfItems(Statistics.class).setMandatory(false); |
129 |
} |
130 |
|
131 |
public Object getObject() { |
132 |
return obj;
|
133 |
} |
134 |
|
135 |
public void setObject(Object obj) { |
136 |
this.obj = obj;
|
137 |
} |
138 |
} |