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: * @(#)ServiceAssemblyDD.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.PrintStream;
032: import java.util.ArrayList;
033: import java.util.Collections;
034: import java.util.Iterator;
035: import java.util.List;
036: import org.w3c.dom.Element;
037: import org.w3c.dom.NodeList;
038:
039: /**
040: * This class is reads the jbi.xml as a service assembly descriptor.
041: *
042: * @author Sun Microsystems, Inc.
043: */
044: public class ServiceAssemblyDD extends JBIDescriptor {
045: /**
046: * id info
047: */
048: Identification mIdInfo;
049: /**
050: * list of su dds
051: */
052: private List mServiceUnitDDList;
053:
054: /**
055: * Creates a new instance of JBIDescriptor
056: * @param idInfo id info.
057: * @param suDDList list.
058: */
059: protected ServiceAssemblyDD(Identification idInfo, List suDDList) {
060: this .mIdInfo = idInfo;
061: if (suDDList != null) {
062:
063: this .mServiceUnitDDList = Collections
064: .unmodifiableList(suDDList);
065: } else {
066: this .mServiceUnitDDList = new ArrayList();
067: }
068: }
069:
070: /**
071: * attribute
072: * @return value
073: */
074: public String getName() {
075: return this .mIdInfo.getName();
076: }
077:
078: /**
079: * attribute
080: * @return value
081: */
082: public String getDescription() {
083: return this .mIdInfo.getDescription();
084: }
085:
086: /**
087: * returns su list
088: * @return list
089: */
090: public List getServiceUnitDDList() {
091: return this .mServiceUnitDDList;
092: }
093:
094: /**
095: * check for shared library descriptor.
096: * @return true if it is shared library desciptor else false.
097: */
098: public boolean isSharedLibraryDescriptor() {
099: return false;
100: }
101:
102: /**
103: * check for ServiceEngine descriptor.
104: * @return true if it is ServiceEngine desciptor else false.
105: */
106: public boolean isServiceEngineDescriptor() {
107: return false;
108: }
109:
110: /**
111: * check for BindingComponen descriptor.
112: * @return true if it is BindingComponen desciptor else false.
113: */
114: public boolean isBindingComponentDescriptor() {
115: return false;
116: }
117:
118: /**
119: * check for service assembly descriptor.
120: * @return true if it is service assembly desciptor else false.
121: */
122: public boolean isServiceAssemblyDescriptor() {
123: return true;
124: }
125:
126: /**
127: * object as string
128: * @return string
129: */
130: public String toString() {
131: // if ( this.mIdInfo == null )
132: // {
133: // return "Identification object is null in ServiceAssemblyDD";
134: // }
135: // if( this.mServiceUnitDDList == null )
136: // {
137: // return "ServiceUnitDDList is null in ServiceAssemblyDD";
138: // }
139:
140: return "Name : " + getName() + "\n" + "Description : "
141: + getDescription() + "\n" + "Service Units : "
142: + getServiceUnitDDList().size();
143: }
144:
145: /**
146: * object as string
147: * @param out print stream.
148: */
149: public void printServiceAssembly(PrintStream out) {
150: out.println(this );
151: List list = this .getServiceUnitDDList();
152: for (Iterator itr = list.iterator(); itr.hasNext();) {
153: out.println(itr.next());
154: }
155: }
156:
157: /**
158: * create sa dd.
159: * @param idInfo id info.
160: * @param suDDList list.
161: * @return sa dd .
162: */
163: public static ServiceAssemblyDD createServiceAssemblyDD(
164: Identification idInfo, List suDDList) {
165: return new ServiceAssemblyDD(idInfo, suDDList);
166: }
167:
168: /**
169: * creates sa dd.
170: * @param saEl xml element.
171: * @return sa dd.
172: */
173: public static ServiceAssemblyDD createServiceAssemblyDD(Element saEl) {
174: Identification idInfo = null;
175: List suDDList = null;
176:
177: Element idInfoEl = DOMUtil.UTIL.getChildElement(saEl,
178: "identification");
179: if (idInfoEl != null) {
180: idInfo = Identification.createIdentification(idInfoEl);
181: }
182: suDDList = new ArrayList();
183: NodeList suNodeList = DOMUtil.UTIL.getChildElements(saEl,
184: "service-unit");
185: int size = suNodeList.getLength();
186: for (int i = 0; i < size; ++i) {
187: Element suEl = (Element) suNodeList.item(i);
188: if (suEl != null) {
189: ServiceUnitDD suDD = ServiceUnitDD
190: .createServiceUnitDD(suEl);
191: suDDList.add(suDD);
192: }
193: }
194: return createServiceAssemblyDD(idInfo, suDDList);
195: }
196:
197: /**
198: * Service Unit Deployment Descriptor model
199: */
200: public static class ServiceUnitDD {
201: /**
202: * id info
203: */
204: Identification mIdInfo;
205: /**
206: * target name
207: */
208: private String mTargetName;
209:
210: /**
211: * SU Zip name
212: */
213: private String mZipName;
214:
215: /**
216: * constructor
217: * @param idInfo id info.
218: * @param targetName target name.
219: */
220: protected ServiceUnitDD(Identification idInfo,
221: String targetName, String suZipName) {
222: this .mIdInfo = idInfo;
223: this .mTargetName = targetName;
224: this .mZipName = suZipName;
225: }
226:
227: /**
228: * attribute
229: * @return value
230: */
231: public String getName() {
232: return this .mIdInfo.getName();
233: }
234:
235: /**
236: * attribute
237: * @return value
238: */
239: public String getDescription() {
240: return this .mIdInfo.getDescription();
241: }
242:
243: /**
244: * attribute
245: * @return value
246: */
247: public String getTargetName() {
248: return this .mTargetName;
249: }
250:
251: /**
252: * Getter for the SU zip name
253: * @return String the zip name for the SU
254: */
255: public String getArtifactZipName() {
256: return this .mZipName;
257: }
258:
259: /**
260: * string value of the object
261: * @return value
262: */
263: public String toString() {
264: return "Name : " + getName() + "\n" + "Description : "
265: + getDescription() + "\n" + "TargetName : "
266: + getTargetName();
267: }
268:
269: /**
270: * create su dd.
271: * @param idInfo id info.
272: * @param targetName target name.
273: * @return su dd.
274: */
275: public static ServiceUnitDD createServiceUnitDD(
276: Identification idInfo, String targetName,
277: String suZipName) {
278: return new ServiceUnitDD(idInfo, targetName, suZipName);
279: }
280:
281: /**
282: * creates su dd
283: * @param suEl xml element.
284: * @return su dd.
285: */
286: public static ServiceUnitDD createServiceUnitDD(Element suEl) {
287: Identification idInfo = null;
288: String targetName = null;
289: String suZipName = null;
290:
291: Element idInfoEl = DOMUtil.UTIL.getElement(suEl,
292: "identification");
293: if (idInfoEl != null) {
294: idInfo = Identification.createIdentification(idInfoEl);
295: }
296:
297: Element targetNameEl = DOMUtil.UTIL.getElement(suEl,
298: "component-name");
299: if (targetNameEl != null) {
300: targetName = DOMUtil.UTIL.getTextData(targetNameEl);
301:
302: }
303:
304: Element zipEl = DOMUtil.UTIL.getElement(suEl,
305: "artifacts-zip");
306: if (zipEl != null) {
307: suZipName = DOMUtil.UTIL.getTextData(zipEl);
308: }
309: return createServiceUnitDD(idInfo, targetName, suZipName);
310: }
311:
312: }
313:
314: /**
315: * Identification model
316: */
317: public static class Identification {
318: /**
319: * name
320: */
321: private String mName;
322: /**
323: * descritpion
324: */
325: private String mDesc;
326:
327: /**
328: * constructor
329: * @param name name
330: * @param desc description
331: */
332: protected Identification(String name, String desc) {
333: this .mName = name;
334: this .mDesc = desc;
335: }
336:
337: /**
338: * attribute
339: * @return value
340: */
341: public String getName() {
342: return this .mName;
343: }
344:
345: /**
346: * attribute
347: * @return value
348: */
349: public String getDescription() {
350: return this .mDesc;
351: }
352:
353: /**
354: * string value of the object
355: * @return value
356: */
357: public String toString() {
358: return "Name : " + getName() + "\n" + "Description : "
359: + getDescription();
360: }
361:
362: /**
363: * creates identification object.
364: * @param name name.
365: * @param desc descritpion.
366: * @return id object.
367: */
368: public static Identification createIdentification(String name,
369: String desc) {
370: return new Identification(name, desc);
371: }
372:
373: /**
374: * creates id object
375: * @param idInfoEl xml element
376: * @return id object
377: */
378: public static Identification createIdentification(
379: Element idInfoEl) {
380: String name = null;
381: String desc = null;
382:
383: Element nameEl = DOMUtil.UTIL.getElement(idInfoEl, "name");
384: if (nameEl != null) {
385: name = DOMUtil.UTIL.getTextData(nameEl);
386: }
387:
388: Element descEl = DOMUtil.UTIL.getElement(idInfoEl,
389: "description");
390: if (descEl != null) {
391: desc = DOMUtil.UTIL.getTextData(descEl);
392: }
393: return createIdentification(name, desc);
394: }
395:
396: }
397:
398: }
|