KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > impl > ImportImpl


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

19
20 package org.netbeans.modules.xml.wsdl.model.impl;
21
22 import org.netbeans.modules.xml.schema.model.SchemaModel;
23 import org.netbeans.modules.xml.schema.model.SchemaModelFactory;
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.model.WSDLModelFactory;
27 import org.netbeans.modules.xml.wsdl.model.spi.WSDLComponentBase;
28 import org.netbeans.modules.xml.wsdl.model.visitor.WSDLVisitor;
29 import org.netbeans.modules.xml.xam.dom.DocumentModel;
30 import org.netbeans.modules.xml.xam.locator.CatalogModelException;
31 import org.netbeans.modules.xml.xam.ModelSource;
32 import org.openide.util.NbBundle;
33 import org.w3c.dom.Element JavaDoc;
34
35 /**
36  *
37  * @author Nam Nguyen
38  */

39 public class ImportImpl extends WSDLComponentBase implements Import {
40     
41     /** Creates a new instance of ImportImpl */
42     public ImportImpl(WSDLModel model, Element JavaDoc e) {
43         super(model, e);
44     }
45     
46     public ImportImpl(WSDLModel model) {
47         this(model, createNewElement(WSDLQNames.IMPORT.getQName(), model));
48     }
49     
50     public void accept(WSDLVisitor visitor) {
51         visitor.visit(this);
52     }
53
54     public void setNamespace(String JavaDoc namespaceURI) {
55         setAttribute(NAMESPACE_URI_PROPERTY, WSDLAttribute.NAMESPACE_URI, namespaceURI);
56     }
57
58     public void setLocation(String JavaDoc locationURI) {
59         setAttribute(LOCATION_PROPERTY, WSDLAttribute.LOCATION, locationURI);
60     }
61
62     public String JavaDoc getNamespace() {
63         return getAttribute(WSDLAttribute.NAMESPACE_URI);
64     }
65
66     public String JavaDoc getLocation() {
67         return getAttribute(WSDLAttribute.LOCATION);
68     }
69
70     public WSDLModel getImportedWSDLModel() throws CatalogModelException {
71         DocumentModel m = resolveImportedModel();
72         if (m instanceof WSDLModel) {
73             return (WSDLModel) m;
74         } else {
75             String JavaDoc msg = NbBundle.getMessage(ImportImpl.class, "MSG_CANNOT_LOAD_WSDL", getLocation());
76             throw new CatalogModelException(msg);
77         }
78     }
79     
80     public WSDLModel resolveToWSDLModel() throws CatalogModelException {
81         DocumentModel m = resolveImportedModel();
82         if (m instanceof WSDLModel) {
83             return (WSDLModel) m;
84         } else {
85             return null;
86         }
87     }
88     
89     public SchemaModel resolveToSchemaModel() throws CatalogModelException {
90         DocumentModel m = resolveImportedModel();
91         if (m instanceof SchemaModel) {
92             return (SchemaModel) m;
93         } else {
94             return null;
95         }
96     }
97     
98     public DocumentModel resolveImportedModel() throws CatalogModelException {
99         ModelSource ms = resolveModel(getLocation());
100         
101         String JavaDoc location = getLocation().toLowerCase();
102         if (location.endsWith(".wsdl")) { //NOI18N
103
return loadAsWSDL(ms);
104         } else if (location.endsWith(".xsd")) { //NOI18N
105
return loadAsSchema(ms);
106         } else {
107             DocumentModel m = loadAsWSDL(ms);
108             if (m == null) {
109                 m = loadAsSchema(ms);
110             }
111             return m;
112         }
113     }
114     
115     private WSDLModel loadAsWSDL(ModelSource ms) {
116         WSDLModel m = WSDLModelFactory.getDefault().getModel(ms);
117         if (m != null && m.getState() == DocumentModel.State.NOT_WELL_FORMED) {
118             return null;
119         }
120         return m;
121     }
122     
123     private SchemaModel loadAsSchema(ModelSource ms) {
124         SchemaModel m = SchemaModelFactory.getDefault().getModel(ms);
125         if (m != null && m.getState() == DocumentModel.State.NOT_WELL_FORMED) {
126             return null;
127         }
128         return m;
129     }
130 }
131
Popular Tags