KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > data > PropertyListMapping


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  * PropertyListMapping.java
21  *
22  * Created on January 29, 2004, 2:06 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.data;
26
27 import java.io.InputStream JavaDoc;
28
29 import java.util.Iterator JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.regex.Pattern JavaDoc;
33
34 import java.net.URL JavaDoc;
35 import java.net.URLClassLoader JavaDoc;
36
37 import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
38
39 /**
40  *
41  * @author Peter Williams
42  */

43 public class PropertyListMapping implements Comparable JavaDoc {
44     
45     /** constants that define the expected property lists from propertydata.xml
46      */

47     public static final String JavaDoc WEBAPP_JSPCONFIG_PROPERTIES = "WebAppJspConfigProperties"; // NOI18N
48
public static final String JavaDoc WEBAPP_PROPERTIES = "WebAppProperties"; // NOI18N
49
public static final String JavaDoc WEBAPP_CLASSLOADER_PROPERTIES = "WebAppClassloaderProperties"; // NOI18N
50

51     public static final String JavaDoc CACHE_PROPERTIES = "CacheProperties"; // NOI18N
52
public static final String JavaDoc CACHE_DEFAULT_HELPER_PROPERTIES = "CacheDefaultHelperProperties"; // NOI18N
53
public static final String JavaDoc CACHE_HELPER_PROPERTIES = "CacheHelperProperties"; // NOI18N
54

55     public static final String JavaDoc CONFIG_MANAGER_PROPERTIES = "ConfigManagerProperties"; // NOI18N
56
public static final String JavaDoc CONFIG_STORE_PROPERTIES = "ConfigStoreProperties"; // NOI18N
57
public static final String JavaDoc CONFIG_SESSION_PROPERTIES = "ConfigSessionProperties"; // NOI18N
58
public static final String JavaDoc CONFIG_COOKIE_PROPERTIES = "ConfigCookieProperties"; // NOI18N
59

60     public static final String JavaDoc SERVICE_REF_CALL_PROPERTIES = "ServiceRefCallProperties"; // NOI18N
61
public static final String JavaDoc SERVICE_REF_STUB_PROPERTIES = "ServiceRefStubProperties"; // NOI18N
62

63     public static final String JavaDoc EJBJAR_CMP_PROPERTIES = "EjbJarCmpProperties"; // NOI18N
64
public static final String JavaDoc EJBJAR_CMP_SCHEMA_PROPERTIES = "EjbJarCmpSchemaProperties"; // NOI18N
65

66     
67     private final PropertyList propList;
68 // private String displayText;
69

70     /** Creates a new instance of PropertyListMapping
71      * This object does NOT handle a null PropertyList
72      */

73     private PropertyListMapping(final PropertyList l) {
74         propList = l;
75     }
76
77     /** equals() maps to PropertyList.equals()
78      *
79      * @return true/false based on whether the embedded property list objects
80      * compare as equal.
81      */

82     public boolean equals(Object JavaDoc obj) {
83         boolean result = false;
84         
85         if(obj instanceof PropertyListMapping) {
86             if(this == obj) {
87                 result = true;
88             } else {
89                 PropertyListMapping targetMapping = (PropertyListMapping) obj;
90                 PropertyList targetList = targetMapping.getPropertyList();
91                 result = propList.getPropertyName().equals(targetList.getPropertyName());
92             }
93         }
94         return result;
95     }
96     
97     /** hashCode() maps to PropertyList.hashCode()
98      *
99      * @return the hashcode
100      */

101     public int hashCode() {
102         return propList.getPropertyName().hashCode();
103     }
104     
105     /** A more readable display string
106      *
107      * @return A descriptive string
108      */

109     public String JavaDoc toString() {
110         return propList.getPropertyName();
111     }
112
113     /** The property list
114      *
115      * @return the property list this is a mapping for
116      */

117     public PropertyList getPropertyList() {
118         return propList;
119     }
120     
121     /** For sorted collections. We compare the string representations of the
122      * embedded property list.
123      *
124      * @param obj the PropertyListMapping to compare to
125      * @return result of comparison (negative, 0, or positive depending on match)
126      */

127     public int compareTo(Object JavaDoc obj) {
128         int result = -1;
129         
130         if(obj instanceof PropertyListMapping) {
131             if(this == obj) {
132                 result = 0;
133             } else {
134                 PropertyListMapping targetMapping = (PropertyListMapping) obj;
135                 PropertyList targetList = targetMapping.getPropertyList();
136                 result = propList.getPropertyName().compareTo(targetList.getPropertyName());
137             }
138         }
139         
140         return result;
141     }
142     
143     /** -----------------------------------------------------------------------
144      * Loader for property list data and validators
145      */

146     /** Retrieve the specified property list, if it exists.
147      *
148      * @param propertyListName The name of the property list to be found. This
149      * corresponds to the value of the property-name field in the xml file.
150      * @return The property list specified, or null if it was not found.
151      */

152     public static PropertyList getPropertyList(String JavaDoc propertyListName) {
153         return (PropertyList) propertyLists.get(propertyListName);
154     }
155
156     /** Retrieve the Pattern associated with the validator specified. This allows
157      * us to cache the patterns that match an reuse them (which we don't currently
158      * do.)
159      *
160      * !PW This doesn't really belong in this object, but it's a convenient
161      * location to put it since the validators and the property lists are
162      * read from the same XML file.
163      *
164      * @param validatorName The name of the validator to be found. This
165      * corresponds to the value of the validator-name field in the xml file.
166      * @return A Pattern built from the regular expression associated with the
167      * name passed in or null if the name was not found.
168      */

169     public static Pattern JavaDoc getValidator(String JavaDoc validatorName) {
170         return (Pattern JavaDoc) validatorList.get(validatorName);
171     }
172     
173     private static final String JavaDoc PROPERTYDATA_FILENAME =
174         "org/netbeans/modules/j2ee/sun/share/configbean/customizers/data/propertydata.xml"; // NOI18N
175

176     private static Map JavaDoc propertyLists;
177     private static Map JavaDoc validatorList;
178     
179     static {
180         loadPropertyLists();
181     }
182     
183     private static void loadPropertyLists() {
184         propertyLists = new HashMap JavaDoc(37);
185         validatorList = new HashMap JavaDoc(19);
186         
187         try {
188             URL JavaDoc propertyListURL = Utils.getResourceURL(PROPERTYDATA_FILENAME, PropertyListMapping.class);
189             InputStream JavaDoc inputStream = propertyListURL.openStream();
190             
191             DynamicProperties props = DynamicProperties.read(inputStream);
192             for(Iterator JavaDoc iter = props.fetchPropertyListList().iterator(); iter.hasNext(); ) {
193                 PropertyList propList = (PropertyList) iter.next();
194                 String JavaDoc propertyListName = propList.getPropertyName();
195                 propertyLists.put(propertyListName, propList);
196             }
197             
198             for(Iterator JavaDoc iter = props.fetchValidatorList().iterator(); iter.hasNext(); ) {
199                 Validator validator = (Validator) iter.next();
200                 Pattern JavaDoc pattern = Pattern.compile(validator.getValidatorPattern());
201                 validatorList.put(validator.getValidatorName(), pattern);
202             }
203         } catch(Exception JavaDoc ex) {
204             // FIXME issue severe error message if this happens.
205
// (and it's a bug in our dtd or data file)
206
ex.printStackTrace();
207         }
208     }
209 }
210
Popular Tags