KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > upgrade > systemoptions > PropertyProcessor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.upgrade.systemoptions;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25
26 abstract class PropertyProcessor {
27     private String JavaDoc className;
28     private static Map JavaDoc<String JavaDoc, String JavaDoc> results;
29     private static Map JavaDoc<String JavaDoc, PropertyProcessor> clsname2Delegate = new HashMap JavaDoc<String JavaDoc, PropertyProcessor>();
30     
31     static {
32         //To extend behaviour of this class then regisetr your own implementation
33
registerPropertyProcessor(new TaskTagsProcessor());
34         registerPropertyProcessor(new HostPropertyProcessor());
35         registerPropertyProcessor(new FileProcessor());//AntSettings
36
registerPropertyProcessor(new NbClassPathProcessor());//AntSettings
37
registerPropertyProcessor(new HashMapProcessor());//AntSettings
38
registerPropertyProcessor(new IntrospectedInfoProcessor());//AntSettings
39
registerPropertyProcessor(new ListProcessor());//ProjectUISettings
40
registerPropertyProcessor(new URLProcessor());//ProjectUISettings
41
registerPropertyProcessor(new ColorProcessor());//FormLoaderSettings
42
registerPropertyProcessor(new StringPropertyProcessor());//ProxySettings
43
}
44     
45
46     private static void registerPropertyProcessor(PropertyProcessor instance) {
47         if (clsname2Delegate.put(instance.className, instance) != null) {
48             throw new IllegalArgumentException JavaDoc();
49         }
50     }
51     
52     private static PropertyProcessor DEFAULT = new PropertyProcessor(false) {
53         void processPropertyImpl(final String JavaDoc propertyName, final Object JavaDoc value) {
54             String JavaDoc stringvalue = null;
55             stringvalue = Utils.valueFromObjectWrapper(value);
56             addProperty(propertyName, stringvalue);
57         }
58     };
59     
60     private static PropertyProcessor TYPES = new PropertyProcessor(true) {
61         void processPropertyImpl(final String JavaDoc propertyName, final Object JavaDoc value) {
62             addProperty(propertyName, Utils.getClassNameFromObject(value));
63         }
64     };
65     
66     private boolean types;
67     
68     
69     private PropertyProcessor(boolean types) {
70         this.types = types;
71     }
72     
73     protected PropertyProcessor(String JavaDoc className) {
74         this(false);
75         this.className = className;
76     }
77     
78     static Map JavaDoc<String JavaDoc, String JavaDoc> processProperty(String JavaDoc propertyName, Object JavaDoc value, boolean types) {
79         results = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
80         PropertyProcessor p = (types) ? TYPES : findDelegate(value);
81         if (p == null) {
82             p = DEFAULT;
83         }
84         assert p != null;
85         p.processPropertyImpl(propertyName, value);
86         return results;
87     }
88     
89     abstract void processPropertyImpl(String JavaDoc propertyName, Object JavaDoc value);
90     
91     protected final void addProperty(String JavaDoc propertyName, String JavaDoc value) {
92         if (results.put(propertyName, value) != null) {
93             throw new IllegalArgumentException JavaDoc(propertyName);
94         }
95     }
96     
97     private static PropertyProcessor findDelegate(final Object JavaDoc value) {
98         String JavaDoc clsName = Utils.getClassNameFromObject(value);
99         return (PropertyProcessor)clsname2Delegate.get(clsName);
100     }
101 }
Popular Tags