KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > ui > customizer > AbstractReferenceDecorator


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.xam.ui.customizer;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24 import org.netbeans.modules.xml.xam.Model;
25
26 /**
27  * An abstract implementation of ExternalReferenceDecorator that provides
28  * some common functionality for all concrete implementations to share.
29  *
30  * @author Nathan Fiedler
31  */

32 public abstract class AbstractReferenceDecorator implements
33         ExternalReferenceDecorator {
34     /** Set of namespace prefixes, keyed by Model instances. */
35     private Map JavaDoc<Model, String JavaDoc> prefixMap;
36
37     /**
38      * Creates a new instance of AbstractReferenceDecorator.
39      */

40     public AbstractReferenceDecorator() {
41         prefixMap = new HashMap JavaDoc<Model, String JavaDoc>();
42     }
43
44     /**
45      * Generate a unique namespace prefix. The model is provided as a
46      * means of possibly creating a prefix that reflects the model in
47      * some fashion (e.g. using its namespace).
48      *
49      * @param model XAM model, which may be used to generate the prefix.
50      * @return unique prefix value (e.g. "ns1"); must not be null.
51      */

52     protected abstract String JavaDoc generatePrefix(Model model);
53
54     public String JavaDoc generatePrefix(ExternalReferenceNode node) {
55         // It only makes sense to generate a prefix for nodes that have a
56
// model, otherwise folders and non-XML files would have them.
57
if (node.hasModel()) {
58             // Use the model as the key, rather than the node itself, since
59
// there could be multiple nodes representing a single model.
60
Model model = node.getModel();
61             String JavaDoc prefix = prefixMap.get(model);
62             if (prefix == null) {
63                 prefix = generatePrefix(model);
64                 prefixMap.put(model, prefix);
65             }
66             return prefix;
67         }
68         return "";
69     }
70 }
71
Popular Tags