KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26 import org.netbeans.modules.xml.schema.model.Import;
27 import org.netbeans.modules.xml.schema.model.Schema;
28 import org.netbeans.modules.xml.schema.model.SchemaModel;
29 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
30 import org.netbeans.modules.xml.xam.Model;
31 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
32 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceCreator;
33 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceDataNode;
34 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceDecorator;
35 import org.openide.nodes.Node;
36 import org.openide.util.HelpCtx;
37 import org.openide.util.NbBundle;
38
39 /**
40  * An import customizer for schema in a WSDL document.
41  *
42  * @author Administrator
43  * @author Nathan Fiedler
44  */

45 public class ImportSchemaCustomizer extends ExternalReferenceCreator<Schema> {
46     /** silence compiler warnings */
47     private static final long serialVersionUID = 1L;
48     private ExternalReferenceDecorator decorator;
49     /** The real model from which we get the namespace prefixes. */
50     private WSDLModel mModel;
51
52     /**
53      * Creates a new instance of ImportCustomizer
54      *
55      * @param schema component to contain the import(s).
56      */

57     public ImportSchemaCustomizer(Schema schema, WSDLModel model) {
58         super(schema, model);
59     }
60
61     @Override JavaDoc
62     protected void init(Schema component, Model model) {
63         // Set the model reference now, before the UI initialization occurs.
64
mModel = (WSDLModel) model;
65     }
66
67     @Override JavaDoc
68     public void applyChanges() throws IOException JavaDoc {
69         super.applyChanges();
70         Schema schema = getModelComponent();
71         List JavaDoc<Node> nodes = getSelectedNodes();
72         for (Node node : nodes) {
73             Import schemaImport = schema.getModel().getFactory().createImport();
74             // Save the location.
75
schemaImport.setSchemaLocation(getLocation(node));
76
77             String JavaDoc namespace = getNamespace(node);
78             if (mustNamespaceDiffer()) {
79                 // Save the namespace.
80
schemaImport.setNamespace(namespace);
81             }
82
83             // Save the prefix.
84
if (node instanceof ExternalReferenceDataNode) {
85                 String JavaDoc prefix = ((ExternalReferenceDataNode) node).getPrefix();
86                 if (prefix.length() > 0) {
87                     if (mModel != null) {
88                         AbstractDocumentComponent def =
89                                 (AbstractDocumentComponent) mModel.getDefinitions();
90                         Map JavaDoc prefixes = def.getPrefixes();
91                         if (!prefixes.containsKey(prefix)) {
92                             def.addPrefix(prefix, namespace);
93                         }
94
95                     }
96                 }
97             }
98             schema.addExternalReference(schemaImport);
99         }
100     }
101
102     public HelpCtx getHelpCtx() {
103         return new HelpCtx(ImportSchemaCustomizer.class);
104     }
105
106     /**
107      * Return the WSDL model that contains the embedded schema model.
108      *
109      * @return the containing WSDL model.
110      */

111     public WSDLModel getModel() {
112         return mModel;
113     }
114
115     protected String JavaDoc getTargetNamespace(Model model) {
116         return ((SchemaModel) model).getSchema().getTargetNamespace();
117     }
118
119     protected Map JavaDoc<String JavaDoc, String JavaDoc> getPrefixes(Model model) {
120         if (mModel != null) {
121             return ((AbstractDocumentComponent) mModel.getDefinitions()).getPrefixes();
122         }
123         return new HashMap JavaDoc();
124     }
125
126     protected ExternalReferenceDecorator getNodeDecorator() {
127         if (decorator == null) {
128             decorator = new SchemaReferenceDecorator(this);
129         }
130         return decorator;
131     }
132
133     public boolean mustNamespaceDiffer() {
134         return true;
135     }
136
137     protected String JavaDoc referenceTypeName() {
138         return NbBundle.getMessage(ImportWSDLCreator.class,
139                 "LBL_ImportCreator_Type");
140     }
141 }
142
Popular Tags