KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > WSDLReferenceDecorator


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.wsdl.ui.view;
21
22 import java.util.Collection JavaDoc;
23 import org.netbeans.api.project.Project;
24 import org.netbeans.api.project.ProjectUtils;
25 import org.netbeans.modules.xml.retriever.catalog.Utilities;
26 import org.netbeans.modules.xml.wsdl.model.Import;
27 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
28 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
29 import org.netbeans.modules.xml.wsdl.ui.wsdl.nodes.ImportViewNodes;
30 import org.netbeans.modules.xml.xam.Model;
31 import org.netbeans.modules.xml.xam.locator.CatalogModelException;
32 import org.netbeans.modules.xml.xam.ui.customizer.AbstractReferenceCustomizer;
33 import org.netbeans.modules.xml.xam.ui.customizer.AbstractReferenceDecorator;
34 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceDataNode;
35 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceNode;
36 import org.openide.nodes.Node;
37 import org.openide.util.NbBundle;
38
39 /**
40  * The ExternalReferenceDecorator for WSDL components.
41  *
42  * @author Nathan Fiedler
43  */

44 public class WSDLReferenceDecorator extends AbstractReferenceDecorator {
45     /** The customizer that created this decorator. */
46     private AbstractReferenceCustomizer customizer;
47     /** Used to generate unique namespace prefixes. */
48     private int prefixCounter;
49
50     /**
51      * Creates a new instance of WSDLReferenceDecorator.
52      *
53      * @param customizer provides information about the edited component.
54      */

55     public WSDLReferenceDecorator(AbstractReferenceCustomizer customizer) {
56         this.customizer = customizer;
57     }
58
59     public String JavaDoc validate(ExternalReferenceNode node) {
60         if (node.hasModel()) {
61             Model model = node.getModel();
62             if (model == null) {
63                 // If it is supposed to have a model, it must not be null.
64
return NbBundle.getMessage(WSDLReferenceDecorator.class,
65                         "LBL_ReferenceDecorator_NoModel");
66             }
67             Model componentModel = customizer.getComponentModel();
68             if (model.equals(componentModel)) {
69                 return NbBundle.getMessage(WSDLReferenceDecorator.class,
70                         "LBL_ReferenceDecorator_SameModel");
71             }
72             // It had better be a WSDL model, but check anyway.
73
if (componentModel instanceof WSDLModel) {
74                 WSDLModel sm = (WSDLModel) componentModel;
75                 Collection JavaDoc<Import> references =
76                         sm.getDefinitions().getImports();
77                 // Ensure the selected document is not already among the
78
// set that have been included.
79
for (Import ref : references) {
80                     try {
81                         WSDLModel otherModel = ref.getImportedWSDLModel();
82                         if (model.equals(otherModel)) {
83                             return NbBundle.getMessage(WSDLReferenceDecorator.class,
84                                     "LBL_ReferenceDecorator_AlreadyRefd");
85                         }
86                     } catch (CatalogModelException cme) {
87                         // Ignore that one as it does not matter.
88
}
89                 }
90             }
91         }
92         String JavaDoc ns = node.getNamespace();
93         String JavaDoc namespace = customizer.getTargetNamespace();
94         if (customizer.mustNamespaceDiffer()) {
95             // This is an import, which must have no namespace, or a
96
// different one than the customized component.
97
if (ns != null && !Utilities.NO_NAME_SPACE.equals(ns) &&
98                     namespace.equals(ns)) {
99                 return NbBundle.getMessage(WSDLReferenceDecorator.class,
100                         "LBL_ReferenceDecorator_SameNamespace");
101             }
102         } else {
103             // This is an include or redefine, which must have no namespace,
104
// or the same one as the customized component.
105
if (ns != null && !Utilities.NO_NAME_SPACE.equals(ns) &&
106                     !namespace.equals(ns)) {
107                 return NbBundle.getMessage(WSDLReferenceDecorator.class,
108                         "LBL_ReferenceDecorator_DifferentNamespace");
109             }
110         }
111         ImportViewNodes.DuplicateFileCookie cookie =
112                 (ImportViewNodes.DuplicateFileCookie) node.getCookie(
113                 ImportViewNodes.DuplicateFileCookie.class);
114         if (cookie != null) {
115             Project ownerProject = cookie.getPrecedingOwnerProject();
116             String JavaDoc projectName = "";
117             if (ownerProject != null) {
118                 projectName = ProjectUtils.getInformation(ownerProject).getDisplayName();
119             }
120             String JavaDoc fileName = cookie.getFileName();
121             return NbBundle.getMessage(WSDLReferenceDecorator.class,
122                     "LBL_ReferenceDecorator_DupeInDependentProject",
123                     fileName, projectName);
124         }
125         return null;
126     }
127
128     public ExternalReferenceDataNode createExternalReferenceNode(Node original) {
129         return customizer.createExternalReferenceNode(original);
130     }
131
132     protected String JavaDoc generatePrefix(Model model) {
133         Model ourModel = customizer.getComponentModel();
134         if (ourModel instanceof WSDLModel) {
135             return NameGenerator.getInstance().generateNamespacePrefix(
136                     null, (WSDLModel) ourModel, prefixCounter++);
137         }
138         return "";
139     }
140
141     public Utilities.DocumentTypesEnum getDocumentType() {
142         return Utilities.DocumentTypesEnum.wsdl;
143     }
144
145     public String JavaDoc getHtmlDisplayName(String JavaDoc name, ExternalReferenceNode node) {
146         if (validate(node) != null) {
147             return "<s>" + name + "</s>";
148         }
149         return name;
150     }
151
152     public String JavaDoc getNamespace(Model model) {
153         if (model instanceof WSDLModel) {
154             WSDLModel wm = (WSDLModel) model;
155             return wm.getDefinitions().getTargetNamespace();
156         }
157         return null;
158     }
159 }
160
Popular Tags