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: * @(#)ComponentDescriptor.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029:
030: package com.sun.jbi.management.descriptor;
031:
032: import java.util.logging.Logger;
033: import java.util.logging.Level;
034:
035: import com.sun.jbi.component.InstallationContext;
036: import com.sun.jbi.management.descriptor.Component;
037: import com.sun.jbi.management.internal.support.DOMUtil;
038: import com.sun.jbi.management.util.StringHelper;
039:
040: import org.w3c.dom.Element;
041:
042: import java.util.List;
043:
044: /**
045: *
046: * This class encapsulates the JAXB model for the Component Descriptor
047: *
048: * @author Sun Microsystems, Inc
049: */
050: public class ComponentDescriptor {
051: /**
052: * The type of the descriptor.
053: */
054: private Component mCompType;
055:
056: /**
057: * Local logger for messages.
058: */
059: private Logger mLog;
060:
061: /**
062: * Element for configuration section of descriptor.
063: */
064: private static final String CONFIGURATION = "Configuration";
065:
066: /**
067: * Element for logging section of descriptor.
068: */
069: private static final String LOGGING = "Logging";
070:
071: /**
072: * Element for observer section of descriptor.
073: */
074: private static final String OBSERVER = "Observer";
075:
076: /**
077: * Constructs a ComponentDescriptor.
078: *
079: * @param jbi the JAXB model for the descriptor.
080: * @throws an IllegalArgumentException if the Jbi passed in not that
081: * for a component
082: */
083: public ComponentDescriptor(Jbi jbi) throws IllegalArgumentException {
084: mCompType = jbi.getComponent();
085: mLog = Logger.getLogger("com.sun.jbi.management");
086:
087: if (mCompType == null) {
088: throw new IllegalArgumentException();
089: }
090: }
091:
092: /**
093: * Get the name of the component.
094: * @return the component name or an empty string if none found.
095: */
096: public String getName() {
097: if (mCompType.getIdentification() != null) {
098: return StringHelper.trim(mCompType.getIdentification()
099: .getName());
100: } else {
101: return "";
102: }
103: }
104:
105: /**
106: * Get the description of the component.
107: * @return the component description or an empty string if none found.
108: */
109: public String getDescription() {
110: if (mCompType.getIdentification() != null) {
111: return StringHelper.trim(mCompType.getIdentification()
112: .getDescription());
113: } else {
114: return "";
115: }
116: }
117:
118: /**
119: * Get the component type (BINDING or ENGINE).
120: * @return the component type or null if none found.
121: */
122: public com.sun.jbi.ComponentType getComponentType() {
123: com.sun.jbi.ComponentType compType = null;
124:
125: String compTypeStr = StringHelper.trim(mCompType.getType());
126: if (compTypeStr.equals("binding-component")) {
127: compType = com.sun.jbi.ComponentType.BINDING;
128: } else if (compTypeStr.equals("service-engine")) {
129: compType = com.sun.jbi.ComponentType.ENGINE;
130: }
131: return compType;
132: }
133:
134: /**
135: * Get the component runtime self-first classloader setting.
136: * @return true if the ComponentClassLoaderDelegation is selfFirst, false
137: * if not.
138: */
139: public boolean isComponentClassLoaderSelfFirst() {
140: return (InstallationContext.SELF_FIRST.equals(StringHelper
141: .trim(mCompType.getComponentClassLoaderDelegation())));
142: }
143:
144: /**
145: * Get the component installer self-first classloader setting.
146: * @return true if the BootstrapClassLoaderDelegation is selfFirst, false
147: * if not.
148: */
149: public boolean isBootstrapClassLoaderSelfFirst() {
150: return (InstallationContext.SELF_FIRST.equals(StringHelper
151: .trim(mCompType.getBootstrapClassLoaderDelegation())));
152: }
153:
154: /**
155: * Get the component class path elements.
156: * @return the component class path elements, with white space removed.
157: */
158: public List<String> getComponentClassPathElements() {
159: if (mCompType.getComponentClassPath() != null) {
160: return StringHelper.trim(mCompType.getComponentClassPath()
161: .getPathElement());
162: } else {
163: return new java.util.ArrayList<String>();
164: }
165: }
166:
167: /**
168: * Get the bootstrap class path elements.
169: * @return the bootstrap class path elements, with white space removed.
170: */
171: public List<String> getBootstrapClassPathElements() {
172: if (mCompType.getBootstrapClassPath() != null) {
173: return StringHelper.trim(mCompType.getBootstrapClassPath()
174: .getPathElement());
175: } else {
176: return new java.util.ArrayList<String>();
177: }
178: }
179:
180: /**
181: * Get the bootstrap class name for the component.
182: * @return the bootstrap class name.
183: */
184: public String getBootstrapClassName() {
185: String bootClassName = StringHelper.trim(mCompType
186: .getBootstrapClassName());
187:
188: return bootClassName;
189: }
190:
191: /**
192: * Get the runtime class name for the component.
193: * @return the runtime class name.
194: */
195: public String getComponentClassName() {
196: String compClassName = "";
197: if (mCompType.getComponentClassName() != null) {
198: compClassName = StringHelper.trim(mCompType
199: .getComponentClassName().getContent());
200: }
201: return compClassName;
202: }
203:
204: /**
205: * Get the list of shared library names for the component.
206: * @return a List of Shared Library names.
207: */
208: public List<String> getSharedLibraryIds() {
209: List<String> sls = new java.util.ArrayList();
210:
211: List<com.sun.jbi.management.descriptor.Component.SharedLibrary> slList = mCompType
212: .getSharedLibraryList();
213:
214: for (com.sun.jbi.management.descriptor.Component.SharedLibrary sl : slList) {
215: String slName = StringHelper
216: .trim(((String) sl.getContent()));
217: if (!"".equals(slName)) {
218: sls.add(slName);
219: }
220: }
221: return sls;
222: }
223:
224: /**
225: * Get the namespace of the "Configuration" element in the jbi.xml, if one
226: * exists. Return an empty string if a "Configuration" element is not
227: * defined.
228: *
229: * @return the configuration element namespace
230: */
231: public String getComponentConfigurationNS() {
232: String ns = "";
233:
234: List<Element> extensions = mCompType.getAnyOrAny();
235:
236: for (Element element : extensions) {
237: if (element.getLocalName().equals(CONFIGURATION)) {
238: ns = element.getNamespaceURI();
239: }
240: }
241:
242: return ns;
243: }
244:
245: /**
246: * Get the the "Configuration" element in the jbi.xml. If the Configuration
247: * element is missing in the jbi.xml a null value is returned
248: *
249: * @return the configuration xml string
250: */
251: public String getComponentConfigurationXml() {
252: String xmlStr = null;
253:
254: List<Element> extensions = mCompType.getAnyOrAny();
255:
256: for (Element element : extensions) {
257: if (element.getLocalName().equals(CONFIGURATION)) {
258: DOMUtil domUtil = new DOMUtil();
259: try {
260: xmlStr = domUtil.elementToString(element);
261: } catch (Throwable ex) {
262: mLog
263: .log(
264: Level.FINE,
265: "Failed to convert configuration element to String",
266: ex);
267: }
268: }
269: }
270:
271: return xmlStr;
272: }
273:
274: /**
275: * Get the the "Logging" element in the jbi.xml. If the Logging
276: * element is missing in the jbi.xml a null value is returned.
277: *
278: * @return the logging element.
279: */
280: public Element getComponentLoggingXml() {
281: Element xml = null;
282:
283: List<Element> extensions = mCompType.getAnyOrAny();
284:
285: for (Element element : extensions) {
286: if (element.getLocalName().equals(LOGGING)) {
287: xml = element;
288: }
289: }
290:
291: return xml;
292: }
293:
294: /**
295: * Get the the "Observer" element in the jbi.xml. If the Observer
296: * element is missing in the jbi.xml a null value is returned.
297: *
298: * @return the observer element.
299: */
300: public Element getComponentObserverXml() {
301: Element xml = null;
302:
303: List<Element> extensions = mCompType.getAnyOrAny();
304:
305: for (Element element : extensions) {
306: if (element.getLocalName().equals(OBSERVER)) {
307: xml = element;
308: }
309: }
310:
311: return xml;
312: }
313:
314: }
|