KickJava   Java API By Example, From Geeks To Geeks.

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


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.treeeditor;
21
22 import java.io.IOException JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.netbeans.modules.xml.schema.model.Schema;
26 import org.netbeans.modules.xml.schema.model.SchemaComponent;
27 import org.netbeans.modules.xml.schema.model.SchemaModel;
28 import org.netbeans.modules.xml.schema.ui.nodes.SchemaComponentNode;
29 import org.netbeans.modules.xml.schema.ui.nodes.SchemaNodeFactory;
30 import org.netbeans.modules.xml.schema.ui.nodes.categorized.CategorizedSchemaNodeFactory;
31 import org.netbeans.modules.xml.wsdl.model.Binding;
32 import org.netbeans.modules.xml.wsdl.model.BindingFault;
33 import org.netbeans.modules.xml.wsdl.model.BindingInput;
34 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
35 import org.netbeans.modules.xml.wsdl.model.BindingOutput;
36 import org.netbeans.modules.xml.wsdl.model.Definitions;
37 import org.netbeans.modules.xml.wsdl.model.Documentation;
38 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
39 import org.netbeans.modules.xml.wsdl.model.Fault;
40 import org.netbeans.modules.xml.wsdl.model.Import;
41 import org.netbeans.modules.xml.wsdl.model.Input;
42 import org.netbeans.modules.xml.wsdl.model.Message;
43 import org.netbeans.modules.xml.wsdl.model.NotificationOperation;
44 import org.netbeans.modules.xml.wsdl.model.OneWayOperation;
45 import org.netbeans.modules.xml.wsdl.model.Operation;
46 import org.netbeans.modules.xml.wsdl.model.Output;
47 import org.netbeans.modules.xml.wsdl.model.Part;
48 import org.netbeans.modules.xml.wsdl.model.Port;
49 import org.netbeans.modules.xml.wsdl.model.PortType;
50 import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation;
51 import org.netbeans.modules.xml.wsdl.model.Service;
52 import org.netbeans.modules.xml.wsdl.model.SolicitResponseOperation;
53 import org.netbeans.modules.xml.wsdl.model.Types;
54 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
55 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PartnerLinkType;
56 import org.netbeans.modules.xml.wsdl.model.extensions.xsd.WSDLSchema;
57 import org.netbeans.modules.xml.wsdl.ui.actions.ActionHelper;
58 import org.netbeans.modules.xml.wsdl.ui.common.Constants;
59 import org.netbeans.modules.xml.wsdl.ui.cookies.SaveCookieDelegate;
60 import org.netbeans.modules.xml.xam.Component;
61 import org.openide.ErrorManager;
62 import org.openide.nodes.Children;
63 import org.openide.nodes.FilterNode;
64 import org.openide.nodes.Node;
65 import org.openide.util.Lookup;
66 import org.openide.util.lookup.AbstractLookup;
67 import org.openide.util.lookup.InstanceContent;
68
69 public class NodesFactory {
70     
71     private static NodesFactory mInstance = null;
72     
73     private NodesFactory() {
74         
75     }
76     
77     public static NodesFactory getInstance() {
78         if(mInstance == null) {
79             mInstance = new NodesFactory();
80         }
81         
82         return mInstance;
83     }
84     
85     public Node create(Component component) {
86         if (component instanceof Definitions) {
87             return new DefinitionsNode((Definitions) component);
88         } else if (component instanceof Message) {
89             return new MessageNode((Message) component);
90         } else if (component instanceof Binding) {
91             return new BindingNode((Binding) component);
92         } else if (component instanceof PortType) {
93             return new PortTypeNode((PortType) component);
94         } else if (component instanceof Service) {
95             return new ServiceNode((Service) component);
96         } else if (component instanceof Types) {
97             return new TypesNode((Types) component);
98             
99         } else if (component instanceof Import) {
100             Definitions defs = ((Import) component).getModel().getDefinitions();
101             Import imp = (Import) component;
102             String JavaDoc location = imp.getLocation();
103             Node node = null;
104             if(location != null) {
105                 if(location.toLowerCase().endsWith(Constants.XSD_EXT)) {
106                     node = new XSDImportNode(imp);
107                 } else if(location.toLowerCase().endsWith(Constants.WSDL_EXT)) {
108                     node = new WSDLImportNode(imp);
109                 }
110                 
111                 if(node == null) {
112                     
113                     List JavaDoc list = defs.getModel().findSchemas(imp.getNamespace());
114                     if (list != null && list.size() > 0) {
115                         if (list.size() > 0) {
116                             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, new Exception JavaDoc("Found more than one schemas for the targetnamespace"));
117                         }
118                         
119                         node = new XSDImportNode(imp);
120                     } else {
121                         
122                         List JavaDoc<WSDLModel> models = defs.getModel().findWSDLModel(imp.getNamespace());
123                         
124                         if (models != null && ! models.isEmpty()) {
125                             
126                         } else {
127                             node = new ImportNode(Children.LEAF, imp);
128                         }
129                     }
130                 }
131                 
132                 
133             } else {
134                 node = new ImportNode(Children.LEAF, imp);
135             }
136             
137             return node;
138         } else if(component instanceof BindingOperation) {
139             return new BindingOperationNode((BindingOperation) component);
140         } else if(component instanceof BindingInput) {
141             return new BindingOperationInputNode((BindingInput) component);
142         } else if(component instanceof BindingOutput) {
143             return new BindingOperationOutputNode((BindingOutput) component);
144         } else if(component instanceof BindingFault) {
145             return new BindingOperationFaultNode((BindingFault) component);
146         } else if(component instanceof Part) {
147             return new PartNode((Part) component);
148         } else if(component instanceof Input) {
149             return new OperationInputNode((Input) component);
150         } else if(component instanceof Output) {
151             return new OperationOutputNode((Output) component);
152         } else if(component instanceof Fault) {
153             return new OperationFaultNode((Fault) component);
154         } else if(component instanceof NotificationOperation) {
155             Operation operation = (Operation) component;
156             return new NotificationOperationNode(operation);
157         } else if (component instanceof OneWayOperation) {
158             Operation operation = (Operation) component;
159             return new OneWayOperationNode(operation);
160         } else if (component instanceof SolicitResponseOperation) {
161             Operation operation = (Operation) component;
162             return new SolicitResponseOperationNode(operation);
163         } else if (component instanceof RequestResponseOperation) {
164             Operation operation = (Operation) component;
165             return new RequestResponseOperationNode(operation);
166         } else if(component instanceof Port) {
167             return new PortNode((Port) component);
168         } else if (component instanceof WSDLSchema) {
169             return createSchemaNode((WSDLSchema) component);
170         } else if(component instanceof Documentation) {
171             return new DocumentationNode((Documentation) component);
172         } else if (component instanceof PartnerLinkType) {
173             return new PartnerLinkTypeNode((PartnerLinkType) component);
174         } else if (component instanceof ExtensibilityElement) {
175             return new ExtensibilityElementNode((ExtensibilityElement) component);
176         }
177         return null;
178     }
179
180     /**
181      * Creates node tree to represent the given WSDL schema.
182      *
183      * @param component WSDL schema.
184      * @return node of WSDL schema.
185      */

186     private Node createSchemaNode(WSDLSchema component) {
187         SchemaModel model = component.getSchemaModel();
188         SchemaNodeFactory factory = new CategorizedSchemaNodeFactory(
189                 model, Lookup.EMPTY);
190         Node node = factory.createRootNode();
191         //To enable save when schema nodes are selected, get the save cookie.
192
InstanceContent content = new InstanceContent();
193         content.add(new SaveCookieDelegate(ActionHelper.getDataObject(component)));
194         Lookup lookup = new AbstractLookup(content);
195         Node schemaRootNode = new EmbeddedSchemaNode(node, component, lookup);
196         return schemaRootNode;
197     }
198
199 }
200
Popular Tags