001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)JBIDescriptor.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.ui.common;
030:
031: import java.io.Reader;
032: import java.io.StringReader;
033: import org.w3c.dom.Document;
034: import org.w3c.dom.Element;
035:
036: /**
037: * This class is the base class for reading the jbi.xml.
038: *
039: * @author Sun Microsystems, Inc.
040: */
041: public abstract class JBIDescriptor {
042: /**
043: * check for shared library descriptor.
044: * @return true if it is shared library desciptor else false.
045: */
046: public abstract boolean isSharedLibraryDescriptor();
047:
048: /**
049: * check for ServiceEngine descriptor.
050: * @return true if it is ServiceEngine desciptor else false.
051: */
052: public abstract boolean isServiceEngineDescriptor();
053:
054: /**
055: * check for BindingComponen descriptor.
056: * @return true if it is BindingComponen desciptor else false.
057: */
058: public abstract boolean isBindingComponentDescriptor();
059:
060: /**
061: * check for service assembly descriptor.
062: * @return true if it is service assembly desciptor else false.
063: */
064: public abstract boolean isServiceAssemblyDescriptor();
065:
066: /**
067: * creates jbi descriptor object .
068: * @param xmlReader Reader object.
069: * @throws java.lang.Exception on error.
070: * @return jbi descriptor object.
071: */
072: public static JBIDescriptor createJBIDescriptor(Reader xmlReader)
073: throws Exception {
074: Document xmlDoc = DOMUtil.UTIL.buildDOMDocument(xmlReader);
075:
076: Element jbiElement = DOMUtil.UTIL.getElement(xmlDoc, "jbi");
077: if (jbiElement == null) {
078: throw new Exception(JBIResultXmlBuilder
079: .createFailedJbiResultXml(Util
080: .getCommonI18NBundle(),
081: "not.a.jbi.descriptor", null));
082: }
083: // get the main element (component, shared-library, service-assembly)
084: Element saEl = DOMUtil.UTIL.getChildElement(jbiElement,
085: "service-assembly");
086: if (saEl != null) {
087: return ServiceAssemblyDD.createServiceAssemblyDD(saEl);
088: }
089:
090: Element slibEl = DOMUtil.UTIL.getChildElement(jbiElement,
091: "shared-library");
092: if (slibEl != null) {
093: return SharedLibraryDD.createSharedLibraryDD(slibEl);
094: }
095:
096: Element compEl = DOMUtil.UTIL.getChildElement(jbiElement,
097: "component");
098: if (compEl != null) {
099: String type = compEl.getAttribute("type");
100: // System.out.println("COMPONENT TYPE: " + type);
101: if ("service-engine".equals(type)) {
102: return ServiceEngineDD.createServiceEngineDD(compEl);
103: } else if ("binding-component".equals(type)) {
104: return BindingComponentDD
105: .createBindingComponentDD(compEl);
106: }
107: }
108:
109: // not a jbi decriptor
110: throw new Exception(JBIResultXmlBuilder
111: .createFailedJbiResultXml(Util.getCommonI18NBundle(),
112: "not.a.jbi.descriptor", null));
113:
114: }
115:
116: /**
117: * creates JBI Descriptor object.
118: * @param xmlText text.
119: * @throws java.lang.Exception on error.
120: * @return object.
121: */
122: public static JBIDescriptor createJBIDescriptor(String xmlText)
123: throws Exception {
124: return createJBIDescriptor(new StringReader(xmlText));
125: }
126:
127: /**
128: * This class represents shared library descriptor.
129: */
130: public static class SharedLibraryDD extends JBIDescriptor {
131: /**
132: * constructor.
133: */
134: protected SharedLibraryDD() {
135: super ();
136: }
137:
138: /**
139: * check for shared library descriptor.
140: * @return true if it is shared library else false.
141: */
142: public boolean isSharedLibraryDescriptor() {
143: return true;
144: }
145:
146: /**
147: * check for ServiceEngine descriptor.
148: * @return true if it is ServiceEngine desciptor else false.
149: */
150: public boolean isServiceEngineDescriptor() {
151: return false;
152: }
153:
154: /**
155: * check for BindingComponent descriptor.
156: * @return true if it is BindingComponent desciptor else false.
157: */
158: public boolean isBindingComponentDescriptor() {
159: return false;
160: }
161:
162: /**
163: * check for ServiceAssembly descriptor.
164: * @return true if it is ServiceAssembly desciptor else false.
165: */
166: public boolean isServiceAssemblyDescriptor() {
167: return false;
168: }
169:
170: /**
171: * creates slib dd.
172: * @param slibEl xml element.
173: * @return object.
174: */
175: public static SharedLibraryDD createSharedLibraryDD(
176: Element slibEl) {
177: return new SharedLibraryDD();
178: }
179: }
180:
181: /**
182: * Common clas for component descriptor
183: */
184: public static abstract class ComponentDD extends JBIDescriptor {
185: /**
186: * constructor.
187: */
188: protected ComponentDD() {
189: super ();
190: }
191: }
192:
193: /**
194: * Service engine descritor.
195: */
196: public static class ServiceEngineDD extends ComponentDD {
197: /**
198: * constructor.
199: */
200: protected ServiceEngineDD() {
201: super ();
202: }
203:
204: /**
205: * check for shared library descriptor.
206: * @return true if it is shared library desciptor else false.
207: */
208: public boolean isSharedLibraryDescriptor() {
209: return false;
210: }
211:
212: /**
213: * check for ServiceEngine descriptor.
214: * @return true if it is ServiceEngine desciptor else false.
215: */
216: public boolean isServiceEngineDescriptor() {
217: return true;
218: }
219:
220: /**
221: * check for BindingComponen descriptor.
222: * @return true if it is BindingComponen desciptor else false.
223: */
224: public boolean isBindingComponentDescriptor() {
225: return false;
226: }
227:
228: /**
229: * check for service assembly descriptor.
230: * @return true if it is service assembly desciptor else false.
231: */
232: public boolean isServiceAssemblyDescriptor() {
233: return false;
234: }
235:
236: /**
237: * cretes service engine dd.
238: * @param compEl xml element.
239: * @return object.
240: */
241: public static ServiceEngineDD createServiceEngineDD(
242: Element compEl) {
243: return new ServiceEngineDD();
244: }
245:
246: }
247:
248: /**
249: * class for bc dd.
250: */
251: public static class BindingComponentDD extends ComponentDD {
252: /**
253: * constructor.
254: */
255: protected BindingComponentDD() {
256: super ();
257: }
258:
259: /**
260: * check for shared library descriptor.
261: * @return true if it is shared library desciptor else false.
262: */
263: public boolean isSharedLibraryDescriptor() {
264: return false;
265: }
266:
267: /**
268: * check for ServiceEngine descriptor.
269: * @return true if it is ServiceEngine desciptor else false.
270: */
271: public boolean isServiceEngineDescriptor() {
272: return false;
273: }
274:
275: /**
276: * check for BindingComponen descriptor.
277: * @return true if it is BindingComponen desciptor else false.
278: */
279: public boolean isBindingComponentDescriptor()
280:
281: {
282: return true;
283: }
284:
285: /**
286: * check for service assembly descriptor.
287: * @return true if it is service assembly desciptor else false.
288: */
289: public boolean isServiceAssemblyDescriptor() {
290: return false;
291: }
292:
293: /**
294: * creates dd.
295: * @param compEl xml element.
296: * @return object.
297: */
298: public static BindingComponentDD createBindingComponentDD(
299: Element compEl) {
300: return new BindingComponentDD();
301: }
302: }
303:
304: }
|