KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
23 import java.util.Map JavaDoc;
24 import org.netbeans.modules.xml.wsdl.model.Import;
25 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
26 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
27 import org.netbeans.modules.xml.xam.Model;
28 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
29 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceDecorator;
30 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceCustomizer;
31 import org.openide.util.HelpCtx;
32
33 /**
34  * An import customizer.
35  *
36  * @author Administrator
37  * @author Nathan Fiedler
38  */

39 public class ImportWSDLCustomizer extends ExternalReferenceCustomizer<Import> {
40     private static final long serialVersionUID = 1L;
41     private ExternalReferenceDecorator decorator;
42
43     /**
44      * Creates a new instance of ImportCustomizer
45      *
46      * @param _import component to customize.
47      */

48     public ImportWSDLCustomizer(Import _import) {
49         super(_import, null);
50     }
51
52     @Override JavaDoc
53     public void applyChanges() throws IOException JavaDoc {
54         super.applyChanges();
55         Import _import = (Import) getModelComponent();
56         if (isLocationChanged()) {
57             // Save the file location.
58
_import.setLocation(getEditedLocation());
59         }
60
61         String JavaDoc namespace = getEditedNamespace();
62         if (mustNamespaceDiffer() && isNamespaceChanged()) {
63             // Save the namespace.
64
_import.setNamespace(namespace);
65         }
66
67         WSDLModel model = (WSDLModel) getModelComponent().getModel();
68         if (mustNamespaceDiffer() && isPrefixChanged()) {
69             // Save the prefix.
70
String JavaDoc prefix = getEditedPrefix();
71             if (prefix.length() > 0) {
72                 // Should not have to cast, but Definitions does not
73
// expose the prefixes API.
74
AbstractDocumentComponent def =
75                         (AbstractDocumentComponent) model.getDefinitions();
76                 def.addPrefix(prefix, namespace);
77             }
78         }
79     }
80
81     protected String JavaDoc getReferenceLocation() {
82         Import _import = (Import) getModelComponent();
83         return _import.getLocation();
84     }
85
86     protected String JavaDoc getNamespace() {
87         Import _import = (Import) getModelComponent();
88         return _import.getNamespace();
89     }
90
91     protected String JavaDoc getPrefix() {
92         Import _import = (Import) getModelComponent();
93         String JavaDoc namespace = _import.getNamespace();
94         WSDLModel model = (WSDLModel) getModelComponent().getModel();
95         AbstractDocumentComponent def =
96                 (AbstractDocumentComponent) model.getDefinitions();
97         Map JavaDoc<String JavaDoc, String JavaDoc> prefixMap = def.getPrefixes();
98         for (Map.Entry JavaDoc<String JavaDoc, String JavaDoc> entry : prefixMap.entrySet()) {
99             if (entry.getValue().equals(namespace)) {
100                 return entry.getKey();
101             }
102         }
103 // The alternative to casting to AbstractDocumentComponent is to attempt
104
// to collect the prefixes from the imports.
105
// Collection<Import> imports = model.getDefinitions().getImports();
106
// for (Import entry : imports) {
107
// String ns = entry.getNamespace();
108
// if (ns != null && ns.equals(namespace)) {
109
// return entry.getNamespace();
110
// }
111
// }
112
return null;
113     }
114
115     public HelpCtx getHelpCtx() {
116         return new HelpCtx(ImportWSDLCustomizer.class);
117     }
118
119     protected String JavaDoc getTargetNamespace(Model model) {
120         return ((WSDLModel) model).getDefinitions().getTargetNamespace();
121     }
122
123     protected Map JavaDoc<String JavaDoc, String JavaDoc> getPrefixes(Model model) {
124         WSDLModel wm = (WSDLModel) model;
125         AbstractDocumentComponent def =
126                 (AbstractDocumentComponent) wm.getDefinitions();
127         return def.getPrefixes();
128     }
129
130     protected ExternalReferenceDecorator getNodeDecorator() {
131         if (decorator == null) {
132             decorator = new WSDLReferenceDecorator(this);
133         }
134         return decorator;
135     }
136
137     protected String JavaDoc generatePrefix() {
138         WSDLModel model = (WSDLModel) getModelComponent().getModel();
139         return NameGenerator.getInstance().generateNamespacePrefix(null, model);
140     }
141
142     public boolean mustNamespaceDiffer() {
143         return true;
144     }
145 }
146
Popular Tags