Revision 24243
trunk/extensions/extMetadata/src/org/gvsig/metadata/extension/gui/MDBasicGUIPanel.java | ||
---|---|---|
80 | 80 |
//Metadata m = layer.getMetadata(); |
81 | 81 |
|
82 | 82 |
ExtendedMetadata auxMD = createMD4Test(); |
83 |
|
|
83 |
System.out.println(auxMD); |
|
84 | 84 |
// ----------------------------------------------------------------------------- |
85 | 85 |
|
86 | 86 |
Iterator it = auxMD.iterator(); |
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/registry/objects/MDElementDefinition.java | ||
---|---|---|
39 | 39 |
public class MDElementDefinition { |
40 | 40 |
|
41 | 41 |
private String name; |
42 |
private Enum type;
|
|
42 |
private MDType type;
|
|
43 | 43 |
private Boolean required; |
44 | 44 |
private Object defaultValue; |
45 | 45 |
private String description; |
46 |
private Map synonyms = new HashMap();
|
|
46 |
private Map<String, Object> synonyms = new HashMap<String, Object>();
|
|
47 | 47 |
|
48 | 48 |
public MDElementDefinition() {} |
49 | 49 |
|
50 |
public MDElementDefinition(String name, Enum type, Boolean required, Object defaultValue, String description) {
|
|
50 |
public MDElementDefinition(String name, MDType type, Boolean required, Object defaultValue, String description) {
|
|
51 | 51 |
this.name = name; |
52 | 52 |
this.type = type; |
53 | 53 |
this.required = required; |
... | ... | |
59 | 59 |
return this.name; |
60 | 60 |
} |
61 | 61 |
|
62 |
public Enum getType() {
|
|
62 |
public MDType getType() {
|
|
63 | 63 |
return this.type; |
64 | 64 |
} |
65 | 65 |
|
... | ... | |
83 | 83 |
this.name = name; |
84 | 84 |
} |
85 | 85 |
|
86 |
public void setType(Enum type) {
|
|
86 |
public void setType(MDType type) {
|
|
87 | 87 |
this.type = type; |
88 | 88 |
} |
89 | 89 |
|
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/MDElement.java | ||
---|---|---|
70 | 70 |
* Retrieves the father of the Metadata object, or null if it doesn't have. |
71 | 71 |
* @return a ExtendedMetadata object or null |
72 | 72 |
*/ |
73 |
public ExtendedMetadata getFather();
|
|
73 |
public Object getFather();
|
|
74 | 74 |
|
75 | 75 |
/** |
76 | 76 |
* Changes the identifier of the object |
... | ... | |
100 | 100 |
* Changes father of the object |
101 | 101 |
* @param father the new father value of the MDElement object |
102 | 102 |
*/ |
103 |
public void setFather(ExtendedMetadata father);
|
|
103 |
public void setFather(Object father);
|
|
104 | 104 |
|
105 | 105 |
/** |
106 | 106 |
* Checks if the ExtendedMetadata has father |
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/manager/MDElementImpl.java | ||
---|---|---|
42 | 42 |
public class MDElementImpl implements MDElement{ |
43 | 43 |
|
44 | 44 |
private String id; |
45 |
private String name = ""; |
|
45 | 46 |
private Object value; |
46 |
private MDElementDefinition type; |
|
47 |
private MDElementDefinition type = null;
|
|
47 | 48 |
private Locale locale; |
48 | 49 |
|
49 |
private ExtendedMetadata father;
|
|
50 |
private Object father;
|
|
50 | 51 |
|
51 | 52 |
|
52 | 53 |
public MDElementImpl() {} |
... | ... | |
58 | 59 |
this.locale = locale; |
59 | 60 |
} |
60 | 61 |
|
62 |
public MDElementImpl(Object value, String name, Locale locale) { |
|
63 |
//this.id = id; Que poner como ID??? |
|
64 |
this.value = value; |
|
65 |
this.name = name; |
|
66 |
this.locale = locale; |
|
67 |
} |
|
68 |
|
|
61 | 69 |
public String getId() { |
62 | 70 |
return this.id; |
63 | 71 |
} |
... | ... | |
91 | 99 |
} |
92 | 100 |
|
93 | 101 |
public String getName() { |
94 |
return this.type.getName(); |
|
102 |
if(this.type != null) |
|
103 |
return this.type.getName(); |
|
104 |
return this.name; |
|
95 | 105 |
} |
96 | 106 |
|
97 | 107 |
public void setName(String name) { |
... | ... | |
101 | 111 |
/** |
102 | 112 |
* @return the father |
103 | 113 |
*/ |
104 |
public ExtendedMetadata getFather() {
|
|
114 |
public Object getFather() {
|
|
105 | 115 |
return father; |
106 | 116 |
} |
107 | 117 |
|
108 | 118 |
/** |
109 | 119 |
* @param father the father to set |
110 | 120 |
*/ |
111 |
public void setFather(ExtendedMetadata father) {
|
|
121 |
public void setFather(Object father) {
|
|
112 | 122 |
this.father = father; |
113 | 123 |
} |
114 | 124 |
|
... | ... | |
119 | 129 |
public int getLevel() { |
120 | 130 |
if(!this.hasFather()) |
121 | 131 |
return 0; |
122 |
else |
|
123 |
return 1 + this.getFather().getLevel(); |
|
132 |
else { |
|
133 |
if(getFather() instanceof MDElement) |
|
134 |
return 1 + ((MDElement)this.getFather()).getLevel(); |
|
135 |
else if(getFather() instanceof ExtendedMetadata) |
|
136 |
return 1 + ((ExtendedMetadata)this.getFather()).getLevel(); |
|
137 |
else |
|
138 |
return 0; |
|
139 |
} |
|
124 | 140 |
} |
141 |
|
|
142 |
public String toString() { |
|
143 |
String aux = "<" + getName() + ">"; |
|
144 |
aux += value.toString(); |
|
145 |
aux += "</" + getName() + ">"; |
|
146 |
return aux; |
|
147 |
} |
|
148 |
|
|
125 | 149 |
} |
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/manager/ExtendedMetadataImpl.java | ||
---|---|---|
50 | 50 |
private Date changeDate; |
51 | 51 |
private MDDefinition type; |
52 | 52 |
private String author; |
53 |
private Map<String, Object> elements = new LinkedHashMap<String, Object>(); |
|
54 |
// Obligar a que el segundo elemento sea MDElement??? Habria que cambiar las funciones set. |
|
53 |
private Map<String, MDElement> elements = new LinkedHashMap<String, MDElement>(); |
|
55 | 54 |
private ExtendedMetadata father; |
56 | 55 |
|
57 | 56 |
|
... | ... | |
76 | 75 |
public Object get(String name) throws NamedMetadataNotFoundException { |
77 | 76 |
if(!hasValue(name)) |
78 | 77 |
throw new NamedMetadataNotFoundException(this.getClass()); |
79 |
return elements.get(name);
|
|
78 |
return ((MDElement) elements.get(name)).getValue();
|
|
80 | 79 |
} |
81 | 80 |
|
82 | 81 |
public boolean getBoolean(String name) throws ClassCastException, NamedMetadataNotFoundException { |
... | ... | |
144 | 143 |
} |
145 | 144 |
|
146 | 145 |
public void set(String name, Object value) { |
147 |
//if (compareToIgnoreCase(value.getClass, "class org.gvsig.metadata.extended.manager.ExtendedMetadataImpl")) |
|
148 |
elements.put(name, value); |
|
146 |
if(value instanceof Boolean) |
|
147 |
setBoolean(name, (Boolean)value); |
|
148 |
else if(value instanceof Date) |
|
149 |
setDate(name, (Date)value); |
|
150 |
else if(value instanceof Double) |
|
151 |
setDouble(name, (Double)value); |
|
152 |
else if(value instanceof Integer) |
|
153 |
setInt(name, (Integer)value); |
|
154 |
else if(value instanceof String) |
|
155 |
setString(name, (String)value); |
|
156 |
else { |
|
157 |
MDElement mde = new MDElementImpl(value, name, null); |
|
158 |
elements.put(name, mde); |
|
159 |
} |
|
149 | 160 |
} |
150 | 161 |
|
151 | 162 |
public void setBoolean(String name, boolean value) { |
152 |
MDElement mde = new MDElementImpl(Boolean.valueOf(value), null, null);
|
|
163 |
MDElement mde = new MDElementImpl(Boolean.valueOf(value), name, null);
|
|
153 | 164 |
elements.put(name, mde); |
154 | 165 |
mde.setFather(this); |
155 | 166 |
} |
156 | 167 |
|
157 | 168 |
public void setDate(String name, Date value) { |
158 |
MDElement mde = new MDElementImpl(value, null, null);
|
|
169 |
MDElement mde = new MDElementImpl(value, name, null);
|
|
159 | 170 |
elements.put(name, mde); |
160 | 171 |
mde.setFather(this); |
161 | 172 |
} |
162 | 173 |
|
163 | 174 |
public void setDouble(String name, double value) { |
164 |
MDElement mde = new MDElementImpl(Double.valueOf(value), null, null);
|
|
175 |
MDElement mde = new MDElementImpl(Double.valueOf(value), name, null);
|
|
165 | 176 |
elements.put(name, mde); |
166 | 177 |
mde.setFather(this); |
167 | 178 |
} |
168 | 179 |
|
169 | 180 |
public void setInt(String name, int value) { |
170 |
MDElement mde = new MDElementImpl(Integer.valueOf(value), null, null);
|
|
181 |
MDElement mde = new MDElementImpl(Integer.valueOf(value), name, null);
|
|
171 | 182 |
elements.put(name, mde); |
172 | 183 |
mde.setFather(this); |
173 | 184 |
} |
174 | 185 |
|
175 | 186 |
public void setString(String name, String value) { |
176 |
MDElement mde = new MDElementImpl(value, null, null);
|
|
187 |
MDElement mde = new MDElementImpl(value, name, null);
|
|
177 | 188 |
elements.put(name, mde); |
178 | 189 |
mde.setFather(this); |
179 | 190 |
} |
... | ... | |
243 | 254 |
return elements.entrySet().iterator(); |
244 | 255 |
} |
245 | 256 |
|
257 |
public String toString() { |
|
258 |
String aux = "<MD_Metadata>"; |
|
259 |
Iterator it = iterator(); |
|
260 |
while (it.hasNext()) { |
|
261 |
Map.Entry e = (Map.Entry)it.next(); |
|
262 |
aux += e.getValue().toString(); |
|
263 |
} |
|
264 |
aux += "</MD_Metadata>"; |
|
265 |
return aux; |
|
266 |
} |
|
267 |
|
|
246 | 268 |
} |
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/persistence/H2Persistence.java | ||
---|---|---|
46 | 46 |
|
47 | 47 |
public H2Persistence() { |
48 | 48 |
|
49 |
try { |
|
50 |
Class.forName("org.h2.Driver"); |
|
51 |
conn = DriverManager.getConnection("jdbc:h2:~/extMetadata", "gvsig", "metadata"); |
|
52 |
} catch (Exception e) { |
|
53 |
// TODO Auto-generated catch block |
|
54 |
e.printStackTrace(); |
|
55 |
} |
|
49 |
try { |
|
50 |
Class.forName("org.h2.Driver"); |
|
51 |
conn = DriverManager.getConnection("jdbc:h2:~/extMetadata", "gvsig", "metadata"); |
|
52 |
} catch (ClassNotFoundException e) { |
|
53 |
// TODO Auto-generated catch block |
|
54 |
e.printStackTrace(); |
|
55 |
} catch (SQLException e) { |
|
56 |
// TODO Auto-generated catch block |
|
57 |
e.printStackTrace(); |
|
58 |
} |
|
56 | 59 |
|
57 | 60 |
} |
58 | 61 |
|
Also available in: Unified diff