Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libGPE / src / org / gvsig / gpe / GPEDefaults.java @ 27635

History | View | Annotate | Download (6.09 KB)

1
package org.gvsig.gpe;
2

    
3
import java.util.Iterator;
4
import java.util.Properties;
5

    
6
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
7
 *
8
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
23
 *
24
 * For more information, contact:
25
 *
26
 *  Generalitat Valenciana
27
 *   Conselleria d'Infraestructures i Transport
28
 *   Av. Blasco Ib??ez, 50
29
 *   46010 VALENCIA
30
 *   SPAIN
31
 *
32
 *      +34 963862235
33
 *   gvsig@gva.es
34
 *      www.gvsig.gva.es
35
 *
36
 *    or
37
 *
38
 *   IVER T.I. S.A
39
 *   Salamanca 50
40
 *   46005 Valencia
41
 *   Spain
42
 *
43
 *   +34 963163400
44
 *   dac@iver.es
45
 */
46
/* CVS MESSAGES:
47
 *
48
 * $Id: GPEDefaults.java 373 2008-01-10 09:33:05Z jpiera $
49
 * $Log$
50
 * Revision 1.10  2007/06/20 09:35:37  jorpiell
51
 * Add the javadoc comments
52
 *
53
 * Revision 1.9  2007/06/07 14:52:28  jorpiell
54
 * Add the schema support
55
 *
56
 * Revision 1.8  2007/05/15 10:39:14  jorpiell
57
 * Add the number of decimals property
58
 *
59
 * Revision 1.7  2007/05/15 09:34:39  jorpiell
60
 * the tag names cant have blanc spaces
61
 *
62
 * Revision 1.6  2007/04/26 14:23:16  jorpiell
63
 * Add a getStringProperty method
64
 *
65
 * Revision 1.5  2007/04/19 11:50:20  csanchez
66
 * Actualizacion protoripo libGPE
67
 *
68
 * Revision 1.4  2007/04/18 11:03:36  jorpiell
69
 * Add the default schema property
70
 *
71
 * Revision 1.3  2007/04/14 16:06:13  jorpiell
72
 * The writer handler has been updated
73
 *
74
 * Revision 1.2  2007/04/12 17:06:42  jorpiell
75
 * First GML writing tests
76
 *
77
 * Revision 1.1  2007/04/12 11:39:20  jorpiell
78
 * Add the GPEDefaults class
79
 *
80
 *
81
 */
82
/**
83
 * This class is used to add properties that can be used
84
 * by the GPE parsers and writers.
85
 * <p>
86
 * It is not possible for the consumer application to have any
87
 * dependence with a concrete parser or writer. But sometimes it
88
 * is necessary to establish some configuration parameters
89
 * (principally to write). This class provides a mechanism to
90
 * set all these parameters using the SPI (Service Provider Interface) 
91
 * mechanism  
92
 * </p>
93
 * <h2>Implementation Lookup</h2>
94
 * <p>
95
 * The SPI provides a mechanism to register a set of properties that
96
 * both the parsers and the writers need to work. Every parser (or writer)
97
 * is the responsible to create a set of parameters and register them
98
 * in this class
99
 * </p>
100
 * <p> 
101
 * To register a set of properties a file named <code>org.gvsig.gpe.IGPEProperties</code>
102
 * shall exist in the class path in the implementation's <code>META-INF/services</code> folder.
103
 * </p>
104
 * <p>
105
 * The content of the files for a given implementation consists of full qualified 
106
 * class names, one per line. For example, an hypotetical <code>MyParserProperties</code> 
107
 * in the package <code>org.gvsi.gpe.format</code> and bundled in a jar file 
108
 * called <code>org.gvsig.gpe.format.jar</code> shall provide the following 
109
 * resources:
110
 *  
111
 * <pre>
112
 * <code>
113
 * $jar tvf org.gvsi.gpe.format.jar
114
 * META-INF/services/org.gvsig.gpe.IGPEProperties
115
 * org/gvsig/gpe/MyParserProperties.class
116
 * </code>
117
 * </pre>
118
 * 
119
 * And the content of the file <code>META-INF/services/org.gvsig.gpe.IGPEProperties</code> 
120
 * shall be a single line of text with the <code>org.gpe.gpe.format</code> class name.
121
 * 
122
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
123
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
124
 */
125
public class GPEDefaults {
126
        private static Properties properties = new Properties();
127
                                
128
//        static{                                
129
//                Iterator providers = availableProperties();
130
//                while (providers.hasNext()) {
131
//                        IGPEProperties next = (IGPEProperties) providers.next();
132
//                        Properties parserProperties = next.getProperties();
133
//                        Iterator it = parserProperties.keySet().iterator();
134
//                        while (it.hasNext()){
135
//                                String key = (String)it.next();                                
136
//                                properties.put(key, parserProperties.get(key));
137
//                        }                        
138
//                }
139
//        }
140
//        
141
//        /**
142
//         * Returns an iterator over instances of the registered GPE properties.
143
//         * @return all the registered GPE properties
144
//         */
145
//                private static Iterator availableProperties() {
146
//                Iterator providers = sun.misc.Service.providers(IGPEProperties.class);
147
//                return providers;
148
//        }
149
        
150
        /**
151
         * Returns an iterator with the name of all the properties that 
152
         * has been established.
153
         */
154
        public static Iterator getKeys(){
155
                return properties.keySet().iterator();
156
        }
157
        
158
        /**
159
         * Gets a String property
160
         * @param key
161
         * Property name
162
         * @return
163
         */
164
        public static String getStringProperty(String key){
165
                Object obj = getProperty(key);
166
                if (obj == null){
167
                        return null;
168
                }
169
                return (String)obj;
170
        }
171
        
172
        /**
173
         * Gets a int property
174
         * @param key
175
         * Property name
176
         * @return
177
         * The int property or -1
178
         */
179
        public static int getIntPropertyProperty(String key){
180
                Object obj = getProperty(key);
181
                if (obj == null){
182
                        return -1;
183
                }
184
                if (obj instanceof Integer){
185
                        return ((Integer)obj).intValue();
186
                }return -1;
187
        }
188
        
189
        /**
190
         * Gets a boolean property. If the property doesn't exist
191
         * it returns false.
192
         * @param key
193
         * Property name
194
         * @return
195
         * The boolean property or false
196
         */
197
        public static boolean getBooleanProperty(String key){
198
                Object obj = getProperty(key);
199
                if (obj == null){
200
                        return false;
201
                }
202
                if (obj instanceof Boolean){
203
                        return ((Boolean)obj).booleanValue();
204
                }return false;
205
        }
206
        
207
        /**
208
         * Gets a property
209
         * @param key
210
         * Property name
211
         * @return
212
         */
213
        public static Object getProperty(String key){
214
                return properties.get(key);
215
        }
216
        
217
        /**
218
         * Sets a property
219
         * @param key
220
         * @param value
221
         */
222
        public static void setProperty(String key, Object value){
223
                properties.put(key, value);
224
        }
225
        
226
        
227
}