001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.jsfcl.std.reference;
042:
043: import java.util.HashMap;
044: import java.util.Map;
045: import java.util.WeakHashMap;
046: import com.sun.jsfcl.util.LoggerUtil;
047: import com.sun.rave.designtime.DesignProject;
048: import com.sun.rave.designtime.DesignProperty;
049:
050: /**
051: * @author eric
052: *
053: * TODO To change the template for this generated type comment go to
054: * Window - Preferences - Java - Code Generation - Code and Comments
055: */
056: public class ReferenceDataManager {
057: public static final String CHARACTER_SETS = "character-sets"; //NOI18N
058: public static final String COMMAND_BUTTON_TYPES = "command-button-types"; // NOI18N
059: public static final String COMPONENT_IDS = "component-ids"; //NOI18N
060: public static final String CONCURRENCY_TYPES = "concurrency-types"; //NOI18N
061: public static final String DATASOURCE_NAMES = "datasource-names"; //NOI18N
062: public static final String DATETIME_STYLES = "datetime-style"; //NOI18N
063: public static final String DATETIME_TYPES = "datetime-type"; //NOI18N
064: public static final String FRAME_TARGETS = "frame-targets"; //NOI18N
065: public static final String IMAGE_MAP_NAMES = "image-map-names"; //NOI18N
066: public static final String LANGUAGE_CODES = "language-code"; //NOI18N
067: public static final String LINK_TYPES = "link-types"; //NOI18N
068: public static final String LOCALES = "locales"; //NOI18N
069: public static final String MANY_CHECKBOX_LAYOUT_STYLES = "many-chekbox-layout-styles"; //NOI18N
070: public static final String MEDIA_TYPES = "media-types"; //NOI18N
071: public static final String MESSAGES_LAYOUTS = "messages-layouts"; //NOI18N
072: public static final String REGION_SHAPES = "region-shape"; // NOI18N
073: public static final String STYLE_CLASSES = "style-classes"; // NOI18N
074: public static final String TABLE_RULES = "table-rules"; // NOI18N
075: public static final String TEXT_DIRECTIONS = "text-direction"; // NOI18N
076: public static final String TFRAMES = "tframes"; //NOI18N
077: public static final String TIME_ZONES = "time-zones"; //NOI18N
078:
079: protected static ReferenceDataManager instance;
080: public static LoggerUtil loggerUtil;
081: protected static WeakHashMap projectRelatedReferenceDataMap = new WeakHashMap();
082:
083: protected Map definersByName;
084: protected Map referenceDataByName;
085: protected Map referenceDataByProperty;
086:
087: static {
088:
089: instance = new ReferenceDataManager();
090: loggerUtil = LoggerUtil.getLogger(ReferenceDataManager.class
091: .getName());
092: }
093:
094: public static ReferenceDataManager getInstance() {
095:
096: return instance;
097: }
098:
099: protected static void setInstance(ReferenceDataManager instance) {
100:
101: ReferenceDataManager.instance = instance;
102: }
103:
104: /**
105: *
106: */
107: protected ReferenceDataManager() {
108:
109: super ();
110: referenceDataByName = new HashMap();
111: referenceDataByProperty = new WeakHashMap();
112: }
113:
114: public BaseReferenceData getBaseReferenceData(String name) {
115: BaseReferenceData result;
116:
117: result = (BaseReferenceData) referenceDataByName.get(name);
118: if (result == null) {
119: ReferenceDataDefiner definer;
120:
121: definer = getDefiner(name);
122: if (definer == null) {
123: throw new RuntimeException("No definer defined for: "
124: + name); //NOI18N
125: }
126: if (!definer.definesBaseItems()) {
127: return null;
128: }
129: result = new BaseReferenceData(this , definer, name);
130: referenceDataByName.put(name, result);
131: }
132: return result;
133: }
134:
135: public ReferenceDataDefiner getDefiner(String name) {
136: ReferenceDataDefiner result;
137:
138: result = (ReferenceDataDefiner) getDefinersByName().get(name);
139: if (result == null) {
140: assert loggerUtil
141: .warning("Found no ReferenceDataDefiner registered under: "
142: + name); //NOI18N
143: }
144: return result;
145: }
146:
147: protected Map getDefinersByName() {
148:
149: if (definersByName == null) {
150: initializeDefinersByName();
151: }
152: return definersByName;
153: }
154:
155: public DesignPropertyAttachedReferenceData getDesignPropertyAttachedReferenceData(
156: String name, DesignProperty property) {
157: DesignPropertyAttachedReferenceData result;
158: Map byName;
159:
160: byName = (Map) referenceDataByProperty.get(property);
161: if (byName == null) {
162: byName = new HashMap();
163: referenceDataByProperty.put(property, byName);
164: }
165: result = (DesignPropertyAttachedReferenceData) byName.get(name);
166: if (result == null) {
167: ReferenceDataDefiner definer;
168:
169: definer = getDefiner(name);
170: if (definer == null) {
171: throw new RuntimeException("No definer defined for: "
172: + name); //NOI18N
173: }
174: if (!definer.definesDesignPropertyItems()) {
175: return null;
176: }
177: result = new DesignPropertyAttachedReferenceData(this ,
178: definer, name, property);
179: byName.put(name, result);
180: }
181: return result;
182: }
183:
184: /**
185: * I return a brand new instance of me for every call.
186: *
187: * @param name
188: * @param project
189: * @param liveProperty
190: * @return
191: */
192: public CompositeReferenceData getCompositeReferenceData(
193: String name, DesignProject project,
194: DesignProperty liveProperty) {
195:
196: return new CompositeReferenceData(this , name, getDefiner(name),
197: getBaseReferenceData(name),
198: getProjectAttachedReferenceData(name, project),
199: getDesignPropertyAttachedReferenceData(name,
200: liveProperty));
201: }
202:
203: public ProjectAttachedReferenceData getProjectAttachedReferenceData(
204: String name, DesignProject project) {
205:
206: HashMap byNameMap = (HashMap) projectRelatedReferenceDataMap
207: .get(project);
208: if (byNameMap == null) {
209: byNameMap = new HashMap();
210: projectRelatedReferenceDataMap.put(project, byNameMap);
211: }
212: ProjectAttachedReferenceData referenceData = (ProjectAttachedReferenceData) byNameMap
213: .get(name);
214: if (referenceData != null) {
215: return referenceData;
216: }
217:
218: ReferenceDataDefiner definer = getDefiner(name);
219: if (definer == null) {
220: throw new RuntimeException("No definer defined for: "
221: + name); //NOI18N
222: }
223: if (!definer.definesProjectItems()) {
224: return null;
225: }
226: referenceData = new ProjectAttachedReferenceData(this , definer,
227: name, project);
228: byNameMap.put(name, referenceData);
229: return referenceData;
230: }
231:
232: protected void initializeDefinersByName() {
233:
234: definersByName = new HashMap();
235: definersByName.put(CHARACTER_SETS,
236: new CharacterSetsReferenceDataDefiner());
237: definersByName.put(COMMAND_BUTTON_TYPES,
238: new CommandButtonTypesReferenceDataDefiner());
239: definersByName.put(COMPONENT_IDS,
240: new ComponentIdsReferenceDataDefiner());
241: definersByName.put(CONCURRENCY_TYPES,
242: new ConcurrencyTypesReferenceDataDefiner());
243: definersByName.put(DATASOURCE_NAMES,
244: new DataSourceNamesReferenceDataDefiner());
245: definersByName.put(DATETIME_STYLES,
246: new DateTimeStylesReferenceDataDefiner());
247: definersByName.put(DATETIME_TYPES,
248: new DateTimeTypesReferenceDataDefiner());
249: definersByName.put(FRAME_TARGETS,
250: new FrameTargetsReferenceDataDefiner());
251: definersByName.put(IMAGE_MAP_NAMES,
252: new ImageMapNamesReferenceDataDefiner());
253: definersByName.put(LANGUAGE_CODES,
254: new LanguageCodesReferenceDataDefiner());
255: definersByName.put(LINK_TYPES,
256: new LinkTypesReferenceDataDefiner());
257: definersByName.put(LOCALES, new LocalesReferenceDataDefiner());
258: definersByName.put(MANY_CHECKBOX_LAYOUT_STYLES,
259: new ManyCheckboxLayoutStylesReferenceDataDefiner());
260: definersByName.put(MEDIA_TYPES,
261: new MediaTypesReferenceDataDefiner());
262: definersByName.put(MESSAGES_LAYOUTS,
263: new MessagesLayoutsReferenceDataDefiner());
264: definersByName.put(REGION_SHAPES,
265: new RegionShapesReferenceDataDefiner());
266: definersByName.put(STYLE_CLASSES,
267: new StyleClassesReferenceDataDefiner());
268: definersByName.put(TABLE_RULES,
269: new TableRulesReferenceDataDefiner());
270: definersByName.put(TEXT_DIRECTIONS,
271: new TextDirectionsReferenceDataDefiner());
272: definersByName.put(TFRAMES, new TFramesReferenceDataDefiner());
273: definersByName.put(TIME_ZONES,
274: new TimeZonesReferenceDataDefiner());
275: }
276:
277: }
|