root/BH13SPARQLBuilder/src/hozo/sparql/EndpointSettings.java @ 259

リビジョン 17, 8.1 KB (コミッタ: kozaki, 11 年 前)

Commitし直します.

  • 属性 svn:mime-type の設定値 text/plain
行番号 
1package hozo.sparql;
2
3import java.beans.XMLDecoder;
4import java.beans.XMLEncoder;
5import java.io.InputStream;
6import java.io.OutputStream;
7import java.io.Serializable;
8import java.util.ArrayList;
9import java.util.HashMap;
10import java.util.LinkedHashMap;
11import java.util.List;
12
13public class EndpointSettings implements Serializable {
14
15        /**
16         *
17         */
18        private static final long serialVersionUID = -6928422841511501314L;
19
20        public static final int RESULT_TYPE_XML = 0;
21
22        public static final int RESULT_TYPE_JSON = 1;
23
24        public static final int RESULT_TYPE_SSE = 2;
25
26        public static final int RESULT_TYPE_TSV = 3;
27
28        public static final String RESULT_TYPE_XML_STR = "XML/RDF";
29
30        public static final String RESULT_TYPE_JSON_STR = "JSON";
31
32        public static final String RESULT_TYPE_SSE_STR = "SPARQL Syntax Expressions";
33
34        public static final String RESULT_TYPE_TSV_STR = "TSV";
35
36        private static HashMap<String, Integer> dataTypeMap;
37
38
39        private String endpoint;
40
41        private boolean useCustomParam = false;
42
43        private String queryKey = "q";
44
45        private String option = "type=json&LIMIT=100";
46
47        private String encoding = "UTF-8";
48
49        private String namespaces = "";
50
51        private int resultType = EndpointSettings.RESULT_TYPE_JSON;
52
53        private boolean editable = false;
54
55        private String repositoryURL;
56
57        private String repository;
58
59        private String user;
60
61        private String pass;
62       
63        private boolean isTarget = true;
64       
65        private volatile boolean isChanged = false;
66
67        static {
68                dataTypeMap = new LinkedHashMap<String, Integer>();
69                dataTypeMap.put(RESULT_TYPE_XML_STR, new Integer(RESULT_TYPE_XML));
70                dataTypeMap.put(RESULT_TYPE_JSON_STR, new Integer(RESULT_TYPE_JSON));
71                dataTypeMap.put(RESULT_TYPE_SSE_STR, new Integer(RESULT_TYPE_SSE));
72                dataTypeMap.put(RESULT_TYPE_TSV_STR, new Integer(RESULT_TYPE_TSV));
73
74        }
75
76        public EndpointSettings(){
77
78        }
79
80
81        public EndpointSettings(String endpoint){
82                this.endpoint = endpoint;
83
84                this.namespaces = makeDefaultNamespaces(endpoint);
85
86                makeDefaultRepository(endpoint);
87        }
88
89        private String makeDefaultNamespaces(String endpoint){
90                String ret = "";
91
92                if (endpoint == null){
93                        return ret;
94                }
95
96                // endpoint譛€蠕後�"/"繧貞炎髯、
97                if (endpoint.endsWith("/")){
98                        endpoint = endpoint.substring(0, endpoint.length() - "/".length());
99                }
100                int index = endpoint.lastIndexOf("/");
101                if (index > 0){
102                        endpoint = endpoint.substring(0, index);
103                }
104
105                ret = endpoint + "," + endpoint + "/class," + endpoint + "/instance," + endpoint + "/resource";
106
107
108                return ret;
109        }
110
111        private void makeDefaultRepository(String endpoint){
112                int index = endpoint.indexOf("/endpoint/");
113                if (index >= 0){
114                        this.repositoryURL = endpoint.substring(0, index);
115                        this.repository = endpoint.substring(index + "/endpoint/".length());
116                }
117
118        }
119
120        /**
121         * @return endpoint
122         */
123        public String getEndpoint() {
124                return endpoint;
125        }
126
127        /**
128         * @param endpoint 繧サ繝�ヨ縺吶k endpoint
129         */
130        public void setEndpoint(String endpoint) {
131                if (this.endpoint != null && !this.endpoint.equals(endpoint)){
132                        isChanged = true;
133                }
134                this.endpoint = endpoint;
135        }
136
137        /**
138         * @return useCustomParam
139         */
140        public boolean isUseCustomParam() {
141                return useCustomParam;
142        }
143
144        /**
145         * @param useCustomParam 繧サ繝�ヨ縺吶k useCustomParam
146         */
147        public void setUseCustomParam(boolean useCustomParam) {
148                if (this.useCustomParam != useCustomParam){
149                        isChanged = true;
150                }
151
152                this.useCustomParam = useCustomParam;
153        }
154
155        /**
156         * @return queryKey
157         */
158        public String getQueryKey() {
159                return queryKey;
160        }
161
162        /**
163         * @param queryKey 繧サ繝�ヨ縺吶k queryKey
164         */
165        public void setQueryKey(String queryKey) {
166                if (this.queryKey != null && !this.queryKey.equals(queryKey)){
167                        isChanged = true;
168                }
169                this.queryKey = queryKey;
170        }
171
172        /**
173         * @param namespaces 繧サ繝�ヨ縺吶k namespaces
174         */
175        public void setNamespaces(String namespaces) {
176                if (this.namespaces != null && !this.namespaces.equals(namespaces)){
177                        isChanged = true;
178                }
179
180                this.namespaces = namespaces;
181        }
182
183        /**
184         * @return namespaces
185         */
186        public String getNamespaces() {
187                return namespaces;
188        }
189
190        public String[] getNamespaceList(){
191                List<String> ret = new ArrayList<String>();
192                String[] tmp = namespaces.split(",");
193                for (String e : tmp){
194                        ret.add(e.trim());
195                }
196                return ret.toArray(new String[0]);
197        }
198
199        /**
200         * @return option
201         */
202        public String getOption() {
203                return option;
204        }
205
206        /**
207         * @param option 繧サ繝�ヨ縺吶k option
208         */
209        public void setOption(String option) {
210                if (this.option != null && !this.option.equals(option)){
211                        isChanged = true;
212                }
213                this.option = option;
214        }
215
216        /**
217         * @return encoding
218         */
219        public String getEncoding() {
220                return encoding;
221        }
222
223        /**
224         * @param encoding 繧サ繝�ヨ縺吶k encoding
225         */
226        public void setEncoding(String encoding) {
227                if (this.encoding != null && !this.encoding.equals(encoding)){
228                        isChanged = true;
229                }
230                this.encoding = encoding;
231        }
232
233        /**
234         * @param resultType 繧サ繝�ヨ縺吶k resultType
235         */
236        public void setResultType(int resultType) {
237                if (this.resultType != resultType){
238                        isChanged = true;
239                }
240                this.resultType = resultType;
241        }
242
243        /**
244         * @return resultType
245         */
246        public int getResultType() {
247                return resultType;
248        }
249
250        /**
251         * @return editable
252         */
253        public boolean isEditable() {
254                return editable;
255        }
256
257
258        /**
259         * @param editable 繧サ繝�ヨ縺吶k editable
260         */
261        public void setEditable(boolean editable) {
262                if (this.editable != editable){
263                        isChanged = true;
264                }
265                this.editable = editable;
266        }
267
268
269        /**
270         * @return repositoryURL
271         */
272        public String getRepositoryURL() {
273                return repositoryURL;
274        }
275
276
277        /**
278         * @param repositoryURL 繧サ繝�ヨ縺吶k repositoryURL
279         */
280        public void setRepositoryURL(String repositoryURL) {
281                if (this.repositoryURL != null && !this.repositoryURL.equals(repositoryURL)){
282                        isChanged = true;
283                }
284                this.repositoryURL = repositoryURL;
285        }
286
287
288        /**
289         * @return repository
290         */
291        public String getRepository() {
292                return repository;
293        }
294
295
296        /**
297         * @param repository 繧サ繝�ヨ縺吶k repository
298         */
299        public void setRepository(String repository) {
300                if (this.repository != null && !this.repository.equals(repository)){
301                        isChanged = true;
302                }
303                this.repository = repository;
304        }
305
306
307        /**
308         * @return user
309         */
310        public String getUser() {
311                return user;
312        }
313
314
315        /**
316         * @param user 繧サ繝�ヨ縺吶k user
317         */
318        public void setUser(String user) {
319                if (this.user != null && !this.user.equals(user)){
320                        isChanged = true;
321                }
322                this.user = user;
323        }
324
325
326        /**
327         * @return pass
328         */
329        public String getPass() {
330                return pass;
331        }
332
333
334        /**
335         * @param pass 繧サ繝�ヨ縺吶k pass
336         */
337        public void setPass(String pass) {
338                if (this.pass != null && !this.pass.equals(pass)){
339                        isChanged = true;
340                }
341                this.pass = pass;
342        }
343
344
345        /**
346         * @param isTarget 繧サ繝�ヨ縺吶k isTarget
347         */
348        public void setTarget(boolean isTarget) {
349                if (this.isTarget != isTarget){
350                        isChanged = true;
351                }
352                this.isTarget = isTarget;
353        }
354
355
356        /**
357         * @return isTarget
358         */
359        public boolean isTarget() {
360                return isTarget;
361        }
362
363
364        /**
365         * 螟画峩迥カ諷九r繝ェ繧サ繝�ヨ縺吶k
366         */
367        public void resetChanged() {
368                this.isChanged = false;
369        }
370
371        /**
372         *
373         * @return
374         */
375        public boolean isChanged(){
376                return this.isChanged;
377        }
378
379        /* 莉・荳九�util繧ッ繝ゥ繧ケ縺ォ繧上¢繧九⊇縺�′縺�>��*/
380
381        public static String[] getResultDataTypeList(){
382                return dataTypeMap.keySet().toArray(new String[]{});
383        }
384
385        public static Integer getResultDataType(String str){
386                return dataTypeMap.get(str);
387        }
388
389        public static String getResultDataType(Integer type){
390                for (String key : dataTypeMap.keySet()){
391                        if (dataTypeMap.get(key).equals(type)){
392                                return key;
393                        }
394                }
395
396                return null;
397        }
398
399        public static void outputXML(OutputStream os, EndpointSettings[] settings){
400                XMLEncoder enc = new XMLEncoder(os);
401                enc.writeObject(settings);
402                enc.close();
403        }
404
405        public static EndpointSettings[] inputXML(InputStream is){
406                XMLDecoder dec = new XMLDecoder(is);
407                EndpointSettings[] ret = (EndpointSettings[])dec.readObject();
408
409               
410               
411                return ret;
412        }
413}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。