001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.core;
021:
022: import java.awt.Image;
023: import java.beans.PropertyChangeListener;
024: import java.io.IOException;
025: import java.util.ArrayList;
026: import java.util.Collection;
027: import java.util.Iterator;
028: import java.util.List;
029:
030: import org.netbeans.modules.bpel.model.api.BpelEntity;
031: import org.netbeans.modules.bpel.model.api.resources.ResourcePackageMarker;
032: import org.netbeans.modules.bpel.model.ext.logging.api.Trace;
033: import org.netbeans.modules.xml.catalog.spi.CatalogDescriptor;
034: import org.netbeans.modules.xml.catalog.spi.CatalogListener;
035: import org.netbeans.modules.xml.catalog.spi.CatalogReader;
036: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.BPELQName;
037: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.schema.resources.ResourceMarker;
038: import org.openide.util.Lookup;
039: import org.openide.util.NbBundle;
040: import org.openide.util.Utilities;
041: import org.openide.util.lookup.Lookups;
042: import org.xml.sax.EntityResolver;
043: import org.xml.sax.InputSource;
044: import org.xml.sax.SAXException;
045:
046: /**
047: * Copied from DDCatalog
048: *
049: * @author ads
050: */
051: public class BPELCatalog implements CatalogReader, CatalogDescriptor,
052: EntityResolver {
053:
054: private static final String URL_BPEL_1_1 = "nbres:/"
055: + ResourcePackageMarker.class.getPackage().getName()
056: .replace('.', '/') + "/"
057: + ResourcePackageMarker.WS_BPEL_1_1_SCHEMA;
058:
059: private static final String URL_BPEL_1_1_DTD = "nbres:/org/netbeans/modules/bpel/core/resources/"
060: + // NOI18N
061: "bpel4ws_1_1.dtd"; // NOI18N
062:
063: private static final String BPEL_1_1 = "http://schemas.xmlsoap.org/ws/2003/03/business-process/"; // NOI18N
064:
065: //TODO r
066: private static final String WS_ADDRESSING = "http://schemas.xmlsoap.org/ws/2004/08/addressing"; // NOI18N
067: private static final String URL_WS_ADDRESSING = "nbres:/org/netbeans/modules/bpel/core/resources/"
068: + // NOI18N
069: "ws-addressing.xsd"; // NOI18N
070:
071: private static final String URL_BPEL_2_0 = "nbres:/" + // NOI18N
072: ResourcePackageMarker.class.getPackage().getName().replace(
073: '.', '/') + "/" + // NOI18N
074: ResourcePackageMarker.WS_BPEL_SCHEMA;
075:
076: private static final String BPEL_2_0 = BpelEntity.BUSINESS_PROCESS_NS_URI;
077:
078: private static final String URL_TRACE_2_0 = "nbres:/" + // NOI18N
079: ResourcePackageMarker.class.getPackage().getName().replace(
080: '.', '/') + "/" + // NOI18N
081: ResourcePackageMarker.TRACE_SCHEMA;
082:
083: private static final String TRACE_2_0 = Trace.LOGGING_NAMESPACE_URI;
084:
085: private static final String WS_BPEL_SERVICE_REF = "http://docs.oasis-open.org/wsbpel/2.0/serviceref"; // NOI18N
086:
087: private static final String URL_WS_BPEL_SERVICE_REF = "nbres:/" + // NOI18N
088: ResourcePackageMarker.class.getPackage().getName().replace(
089: '.', '/') + "/" + // NOI18N
090: ResourcePackageMarker.WS_BPEL_SERVICE_REF_SCHEMA;
091:
092: public static final String SCHEMA = "SCHEMA:"; // NOI18N
093: //
094: // pseudo DTD for code-completion?
095: // MCF - I am not doing pseudo DTD for BPEL 2.0
096: //
097: private static final String BPEL_1_1_ID = SCHEMA + BPEL_1_1;
098: private static final String BPEL_2_0_ID = SCHEMA + BPEL_2_0;
099: private static final String TRACE_2_0_ID = SCHEMA + TRACE_2_0;
100: private static final String WS_BPEL_SERVICE_REF_ID = SCHEMA
101: + WS_BPEL_SERVICE_REF;
102: // TODO r
103: private static final String WS_ADDRESSING_ID = SCHEMA
104: + WS_ADDRESSING;
105:
106: private static final String URL_BPEL_PLT_1_1 = "nbres:/org/netbeans/modules/bpel/core/resources/" // NOI18N
107: + "bpel4ws_1_1_plinkType.xsd"; // NOI18N
108:
109: private static final String BPEL_PLT_1_1 = "http://schemas.xmlsoap.org/ws/2003/05/partner-link/"; // NOI18N
110:
111: private static final String BPEL_PLT_1_1_ID = SCHEMA + BPEL_PLT_1_1;
112:
113: private static final String URL_BPEL_PLT_2_0 = "nbres:/"
114: + ResourceMarker.class.getPackage().getName(). // NOI18N
115: replace('.', '/') + "/"
116: + ResourceMarker.PLNK_SCHEMA;
117:
118: private static final String BPEL_PLT_2_0 = BPELQName.PLNK_NS;
119:
120: private static final String BPEL_PLT_2_0_ID = SCHEMA + BPEL_PLT_2_0;
121:
122: private static final String IMAGE_PATH = "org/netbeans/modules/bpel/core/resources/"
123: + // NOI18N
124: "bpel_catalog.gif"; // NOI18N
125:
126: public BPELCatalog() {
127: }
128:
129: /**
130: *
131: * @return BPELCatalog instance founded in Lookup. Could be null
132: */
133: public static BPELCatalog getDefault() {
134: BPELCatalog bpelCatalog = null;
135:
136: Lookup.Template templ = new Lookup.Template(CatalogReader.class);
137: Lookup userCatalogLookup = Lookups
138: .forPath("Plugins/XML/UserCatalogs"); // NOI18N
139:
140: Lookup.Result res = userCatalogLookup.lookup(templ);
141: Collection impls = res.allInstances();
142:
143: for (Object obj : impls) {
144: if (obj instanceof BPELCatalog) {
145: bpelCatalog = (BPELCatalog) obj;
146: break;
147: }
148: }
149:
150: return bpelCatalog;
151: }
152:
153: /**
154: * Get String iterator representing all public IDs registered in catalog.
155: * @return null if cannot proceed, try later.
156: */
157: public Iterator<String> getPublicIDs() {
158: List<String> list = new ArrayList<String>();
159: list.add(BPEL_1_1_ID);
160: list.add(BPEL_PLT_1_1_ID);
161: list.add(BPEL_2_0_ID);
162: list.add(BPEL_PLT_2_0_ID);
163: list.add(TRACE_2_0_ID);
164: list.add(WS_BPEL_SERVICE_REF_ID);
165: // TODO r
166: list.add(WS_ADDRESSING_ID);
167: return list.listIterator();
168: }
169:
170: /**
171: * Get registered systemid for given public Id or null if not registered.
172: * @return null if not registered
173: */
174: public String getSystemID(String publicId) {
175: if (BPEL_2_0_ID.equals(publicId)) {
176: return URL_BPEL_2_0;
177: // FOR Code Complete? return URL_BPEL_2_0_DTD;
178: } else if (BPEL_PLT_2_0_ID.equals(publicId)) {
179: return URL_BPEL_PLT_2_0;
180: } else if (TRACE_2_0_ID.equals(publicId)) {
181: return URL_TRACE_2_0;
182: } else if (BPEL_1_1_ID.equals(publicId)) {
183: return URL_BPEL_1_1;
184: // FOR Code Complete? return URL_BPEL_1_1_DTD;
185: } else if (BPEL_PLT_1_1_ID.equals(publicId)) {
186: return URL_BPEL_PLT_1_1;
187: } else if (WS_BPEL_SERVICE_REF_ID.equals(publicId)) {
188: return URL_WS_BPEL_SERVICE_REF;
189: } else if (WS_ADDRESSING_ID.equals(publicId)) {
190: return URL_WS_ADDRESSING;
191: } else {
192: return null;
193: }
194: }
195:
196: /**
197: * Refresh content according to content of mounted catalog.
198: */
199: public void refresh() {
200: }
201:
202: /**
203: * Optional operation allowing to listen at catalog for changes.
204: * @throws UnsupportedOpertaionException if not supported by the implementation.
205: */
206: public void addCatalogListener(CatalogListener l) {
207: }
208:
209: /**
210: * Optional operation couled with addCatalogListener.
211: * @throws UnsupportedOpertaionException if not supported by the implementation.
212: */
213: public void removeCatalogListener(CatalogListener l) {
214: }
215:
216: /** Registers new listener. */
217: public void addPropertyChangeListener(PropertyChangeListener l) {
218: }
219:
220: /**
221: * @return I18N display name
222: */
223: public String getDisplayName() {
224: return NbBundle
225: .getMessage(BPELCatalog.class, "LBL_BPELCatalog");
226: }
227:
228: /**
229: * Return visuaized state of given catalog.
230: * @param type of icon defined by JavaBeans specs
231: * @return icon representing current state or null
232: */
233: public Image getIcon(int type) {
234: return Utilities.loadImage(IMAGE_PATH);
235: }
236:
237: /**
238: * @return I18N short description
239: */
240: public String getShortDescription() {
241: return NbBundle.getMessage(BPELCatalog.class,
242: "DESC_BPELCatalog");
243: }
244:
245: /** Unregister the listener. */
246: public void removePropertyChangeListener(PropertyChangeListener l) {
247: }
248:
249: /**
250: * Resolves schema definition file for deployment descriptor (spec.2_4)
251: * @param publicId publicId for resolved entity (null in our case)
252: * @param systemId systemId for resolved entity
253: * @return InputSource for
254: */
255: public InputSource resolveEntity(String publicId, String systemId)
256: throws SAXException, IOException {
257: if (BPEL_2_0.equals(systemId)) {
258: return new org.xml.sax.InputSource(URL_BPEL_2_0);
259: } else if (BPEL_PLT_2_0.equals(systemId)) {
260: return new org.xml.sax.InputSource(URL_BPEL_PLT_2_0);
261: } else if (TRACE_2_0.equals(systemId)) {
262: return new org.xml.sax.InputSource(URL_TRACE_2_0);
263: } else if (BPEL_1_1.equals(systemId)) {
264: return new org.xml.sax.InputSource(URL_BPEL_1_1);
265: } else if (BPEL_PLT_1_1.equals(systemId)) {
266: return new org.xml.sax.InputSource(URL_BPEL_PLT_1_1);
267: } else if (WS_BPEL_SERVICE_REF.equals(systemId)) {
268: return new org.xml.sax.InputSource(URL_WS_BPEL_SERVICE_REF);
269: }
270: // TODO r
271: else if (WS_ADDRESSING.equals(systemId)) {
272: return new org.xml.sax.InputSource(URL_WS_ADDRESSING);
273: } else {
274: return null;
275: }
276: }
277:
278: /**
279: * Get registered URI for the given name or null if not registered.
280: * @return null if not registered
281: */
282: public String resolveURI(String name) {
283: if (BPEL_2_0.equals(name)) {
284: return BPEL_2_0;
285: } else if (BPEL_PLT_2_0.equals(name)) {
286: return BPEL_PLT_2_0;
287: } else if (TRACE_2_0.equals(name)) {
288: return TRACE_2_0;
289: } else if (BPEL_1_1.equals(name)) {
290: return BPEL_1_1;
291: } else if (BPEL_PLT_1_1.equals(name)) {
292: return BPEL_PLT_1_1;
293: } else if (WS_BPEL_SERVICE_REF.equals(name)) {
294: return WS_BPEL_SERVICE_REF;
295: } else if (WS_ADDRESSING.equals(name)) {
296: return WS_ADDRESSING;
297: }
298: return null;
299: }
300:
301: /**
302: * Get registered URI for the given publicId or null if not registered.
303: * @return null if not registered
304: */
305: public String resolvePublic(String publicId) {
306: return null;
307: }
308:
309: }
|