svn-gvsig-desktop / trunk / libraries / libMetadata / src / org / gvsig / metadata / simple / SimpleMetadata.java @ 21170
History | View | Annotate | Download (3.63 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 Geographic Information research group: http://www.geoinfo.uji.es
|
26 |
* Departamento de Lenguajes y Sistemas Inform?ticos (LSI)
|
27 |
* Universitat Jaume I
|
28 |
* {{Task}}
|
29 |
*/
|
30 |
|
31 |
package org.gvsig.metadata.simple; |
32 |
|
33 |
import java.util.Date; |
34 |
import java.util.HashMap; |
35 |
import java.util.Map; |
36 |
|
37 |
import org.gvsig.metadata.Metadata; |
38 |
import org.gvsig.metadata.exceptions.NamedMetadataNotFoundException; |
39 |
|
40 |
public class SimpleMetadata implements Metadata { |
41 |
|
42 |
private Map elements = new HashMap(); |
43 |
private String definitionName; |
44 |
|
45 |
public SimpleMetadata(String definitionName) { |
46 |
this.definitionName = definitionName;
|
47 |
} |
48 |
|
49 |
public Object get(String name) throws NamedMetadataNotFoundException { |
50 |
if(!hasValue(name))
|
51 |
throw new NamedMetadataNotFoundException(this.getClass()); |
52 |
return elements.get(name);
|
53 |
} |
54 |
|
55 |
public boolean getBoolean(String name) throws ClassCastException, NamedMetadataNotFoundException { |
56 |
if(!hasValue(name))
|
57 |
throw new NamedMetadataNotFoundException(this.getClass()); |
58 |
return ((Boolean)elements.get(name)).booleanValue(); |
59 |
} |
60 |
|
61 |
public double getDouble(String name) throws ClassCastException, NamedMetadataNotFoundException { |
62 |
if(!hasValue(name))
|
63 |
throw new NamedMetadataNotFoundException(this.getClass()); |
64 |
return ((Double)elements.get(name)).doubleValue(); |
65 |
} |
66 |
|
67 |
public int getInt(String name) throws ClassCastException, NamedMetadataNotFoundException { |
68 |
if(!hasValue(name))
|
69 |
throw new NamedMetadataNotFoundException(this.getClass()); |
70 |
return ((Integer)elements.get(name)).intValue(); |
71 |
} |
72 |
|
73 |
public String getString(String name) throws ClassCastException, NamedMetadataNotFoundException { |
74 |
if(!hasValue(name))
|
75 |
throw new NamedMetadataNotFoundException(this.getClass()); |
76 |
return (String)elements.get(name).toString(); |
77 |
} |
78 |
|
79 |
public Date getDate(String name) throws ClassCastException, NamedMetadataNotFoundException { |
80 |
if(!hasValue(name))
|
81 |
throw new NamedMetadataNotFoundException(this.getClass()); |
82 |
return (Date)elements.get(name); |
83 |
} |
84 |
|
85 |
public void set(String name, Object value) { |
86 |
elements.put(name, value); |
87 |
} |
88 |
|
89 |
public void setBoolean(String name, boolean value) { |
90 |
elements.put(name, Boolean.valueOf(value));
|
91 |
} |
92 |
|
93 |
public void setDouble(String name, double value) { |
94 |
elements.put(name, Double.valueOf(value));
|
95 |
} |
96 |
|
97 |
public void setInt(String name, int value) { |
98 |
elements.put(name, Integer.valueOf(value));
|
99 |
} |
100 |
|
101 |
public void setString(String name, String value) { |
102 |
elements.put(name, String.valueOf(value));
|
103 |
} |
104 |
|
105 |
public void setDate(String name, Date value) { |
106 |
elements.put(name, value); |
107 |
} |
108 |
|
109 |
public boolean hasValue(String name) { |
110 |
return elements.containsKey(name);
|
111 |
} |
112 |
|
113 |
public boolean isEmpty() { |
114 |
return elements.isEmpty();
|
115 |
} |
116 |
|
117 |
} |