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: * @(#)SharedLibrary.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.framework;
030:
031: import com.sun.jbi.ComponentState;
032: import com.sun.jbi.ComponentType;
033:
034: import java.net.URLEncoder;
035:
036: import java.util.ArrayList;
037: import java.util.Iterator;
038: import java.util.List;
039:
040: /**
041: * SharedLibrary holds the name and class path for a Shared Library.
042: *
043: * @author Sun Microsystems, Inc.
044: */
045: public class SharedLibrary implements com.sun.jbi.ComponentInfo,
046: java.io.Serializable {
047: /**
048: * Indicator as to whether the shared class loader is to be "inverted".
049: * Its value is true if the search order for the shared class loader is
050: * to be inverted relative to the normal search order - self-first rather
051: * than parent-first. This is persisted across restarts of the JBI framework.
052: */
053: private boolean mClassLoaderSelfFirst;
054:
055: /**
056: * An array that contains all of the elements of the classpath for
057: * this Shared Library.
058: */
059: private ArrayList mClassPathElements;
060:
061: /**
062: * The description of this Shared Library.
063: */
064: private String mDescription;
065:
066: /**
067: * The root directory into which this Shared Library is installed.
068: */
069: private String mInstallRoot;
070:
071: /**
072: * The unique name of this Shared Library.
073: */
074: private String mName;
075:
076: /**
077: * The jbi.xml String
078: */
079: private String mJbiXmlString;
080:
081: /**
082: * The StringTranslator instance to use for messages.
083: */
084: private transient StringTranslator mTranslator;
085:
086: /**
087: * Constructs a SharedLibrary object with the specified name, description,
088: * installation root directory, and list of class path elements.
089: * @param name The unique name of this Shared Library.
090: * @param desc The description of this Shared Library.
091: * @param root The installation root directory for this Shared Library.
092: * @param elementList A list of class path elements comprising this
093: * Shared Library. Each element is a string containing either a directory
094: * path or a jar file path. The elements must be in the order in which
095: * they should appear in the class path.
096: * @throws java.lang.IllegalArgumentException if any arguments are invalid.
097: */
098: SharedLibrary(String name, String desc, String root,
099: List elementList) {
100: this (name, desc, root, false, elementList);
101: }
102:
103: /**
104: * Constructs a SharedLibrary object with the specified component name,
105: * description, component root directory, and list of class path elements.
106: * @param name The unique name of this Shared Library.
107: * @param desc The description of this Shared Library.
108: * @param root The component root directory for this Shared Library.
109: * @param isSelfFirst A flag set to true to force the class loader for
110: * this Shared Library to use a self-first hierarchy, or false to use the
111: * normal parent-first hierarchy.
112: * @param elementList A list of class path elements comprising this
113: * Shared Library. Each element is a string containing either a directory
114: * path or a jar file path. The elements must be in the order in which
115: * they should appear in the class path.
116: * @throws java.lang.IllegalArgumentException if any arguments are invalid.
117: */
118: SharedLibrary(String name, String desc, String root,
119: boolean isSelfFirst, List elementList) {
120: mTranslator = (StringTranslator) EnvironmentContext
121: .getInstance().getStringTranslatorFor(this );
122:
123: if (null == name) {
124: throw new java.lang.IllegalArgumentException(mTranslator
125: .getString(LocalStringKeys.NULL_ARGUMENT, "name"));
126: }
127: if (null == elementList) {
128: throw new java.lang.IllegalArgumentException(mTranslator
129: .getString(LocalStringKeys.NULL_ARGUMENT,
130: "elementList"));
131: }
132: if (0 == elementList.size()) {
133: throw new java.lang.IllegalArgumentException(mTranslator
134: .getString(LocalStringKeys.EMPTY_LIST_ARGUMENT,
135: "elementList"));
136: }
137: mName = name;
138: mDescription = desc;
139: mInstallRoot = root;
140: mClassLoaderSelfFirst = isSelfFirst;
141: mClassPathElements = new ArrayList(elementList);
142: }
143:
144: /**
145: * Constructor for building an instance from a ComponentInfo
146: * @param slInfo - SharedLibrary Info
147: */
148: SharedLibrary(com.sun.jbi.ComponentInfo slInfo) {
149: mName = slInfo.getName();
150: mDescription = slInfo.getDescription();
151: mInstallRoot = slInfo.getInstallRoot();
152: mClassLoaderSelfFirst = slInfo.isClassLoaderSelfFirst();
153: mClassPathElements = new ArrayList(slInfo
154: .getClassPathElements());
155: }
156:
157: /**
158: * Compare another object with this one for equality.
159: * @param object The object to be compared with this one.
160: * @return True if the object is equal to this one, false
161: * if they are not equal.
162: */
163: public boolean equals(Object object) {
164: if (null == object) {
165: return false;
166: }
167: if (!(object instanceof SharedLibrary)) {
168: return false;
169: }
170: SharedLibrary component = (SharedLibrary) object;
171: if (!mName.equals(component.getName())) {
172: return false;
173: }
174: if (ComponentType.SHARED_LIBRARY != component
175: .getComponentType()) {
176: return false;
177: }
178: if (null != component.getComponentClassName()) {
179: return false;
180: }
181: if (null != component.getSharedLibraryNames()) {
182: return false;
183: }
184: if (!mClassPathElements
185: .equals(component.getClassPathElements())) {
186: return false;
187: }
188: return true;
189: }
190:
191: /**
192: * Get the complete classpath for this Shared Library.
193: * @return The list of elements of the classpath for this Shared Library,
194: * in the correct order, as a valid class path string.
195: */
196: public String getClassPathAsString() {
197: String sep = System.getProperty("path.separator");
198: Iterator i = mClassPathElements.iterator();
199: StringBuffer sb = new StringBuffer("");
200: boolean first = true;
201: while (i.hasNext()) {
202: if (!first) {
203: sb.append(sep);
204: } else {
205: first = false;
206: }
207: sb.append((String) i.next());
208: }
209: return new String(sb);
210: }
211:
212: /**
213: * Get the list of elements that comprise the classpath for this
214: * Shared Library.
215: * @return The list of elements of the classpath for this Shared Library,
216: * in the correct search order.
217: */
218: public List getClassPathElements() {
219: return mClassPathElements;
220: }
221:
222: /**
223: * Get the component class name. For a Shared Library, this method always
224: * returns null.
225: * @return Always null.
226: */
227: public String getComponentClassName() {
228: return null;
229: }
230:
231: /**
232: * Get the installation root directory for this Shared Library.
233: * @return The installation root directory path.
234: */
235: public String getInstallRoot() {
236: return mInstallRoot;
237: }
238:
239: /**
240: * Get the component type. This always returns SHARED_LIBRARY.
241: * @return The component type, which is always SHARED_LIBRARY.
242: */
243: public ComponentType getComponentType() {
244: return ComponentType.SHARED_LIBRARY;
245: }
246:
247: /**
248: * Get the component type as a string.
249: * @return The component type as a string ("Shared Library").
250: */
251: public String getComponentTypeAsString() {
252: return mTranslator.getString(LocalStringKeys.SHARED_LIBRARY);
253: }
254:
255: /**
256: * Get the description of this Shared Library.
257: * @return The description of the Shared Library.
258: */
259: public String getDescription() {
260: return mDescription;
261: }
262:
263: /**
264: * Get the unique name of this Shared Library.
265: * @return The unique name of the Shared Library.
266: */
267: public String getName() {
268: return mName;
269: }
270:
271: /**
272: * Get the list of deployed SUs. For a Shared Library, this method always
273: * returns null.
274: * @return Always null.
275: */
276: public List getServiceUnitList() {
277: return null;
278: }
279:
280: /**
281: * Get the list of required Shared Library names. For a Shared Library,
282: * this method call always returns null.
283: * @return Always null.
284: */
285: public List getSharedLibraryNames() {
286: return null;
287: }
288:
289: /**
290: * Get the component status. This always returns SHUTDOWN.
291: * @return The component status, which is always SHUTDOWN.
292: */
293: public ComponentState getStatus() {
294: return ComponentState.SHUTDOWN;
295: }
296:
297: /**
298: * Get the component status as a string. This always returns "Installed".
299: * @return The component status string, which is always "Installed".
300: */
301: public String getStatusAsString() {
302: return ComponentState.SHUTDOWN.toString();
303: }
304:
305: /**
306: * @return the Installation Descriptor [jbi.xml] for the
307: * Shared Library.
308: */
309: public String getInstallationDescriptor() {
310: return mJbiXmlString;
311: }
312:
313: /**
314: * Get the hash code for this Shared Library.
315: * @return The hash code.
316: */
317: public int hashCode() {
318: int hashCode = 0;
319:
320: hashCode += mName.hashCode();
321: hashCode += ComponentType.SHARED_LIBRARY.hashCode();
322: hashCode += mClassPathElements.hashCode();
323:
324: return hashCode;
325: }
326:
327: /**
328: * Check to see if the shared class loader should use the self-first
329: * hierarchy.
330: * @return true if the class loader should use the self-first hierarchy,
331: * false if it should use parent-first.
332: */
333: public boolean isClassLoaderSelfFirst() {
334: return mClassLoaderSelfFirst;
335: }
336:
337: /**
338: * Set the flag that determines the hierarchy for the shared class loader,
339: * which is true for self-first or false for parent-first.
340: * @param isSelfFirst is true for a self-first class loading hierarchy, or
341: * false for a parent-first hierarchy.
342: */
343: public void setClassLoaderSelfFirst(boolean isSelfFirst) {
344: mClassLoaderSelfFirst = isSelfFirst;
345: }
346:
347: /**
348: * @param jbiXml - the string representation of the installation descriptor
349: * for this Shared Library
350: */
351: public void setInstallationDescriptor(String jbiXml) {
352: mJbiXmlString = jbiXml;
353: }
354:
355: /**
356: * Convert to a String.
357: * @return The String representation of this SharedLibrary.
358: */
359: public String toString() {
360: String sep = ",\n";
361: StringBuffer b = new StringBuffer();
362: b.append("Name = " + mName);
363: b.append(sep);
364: b.append("Description = " + mDescription);
365: b.append(sep);
366: b.append("InstallRoot = " + mInstallRoot);
367: b.append(sep);
368: b.append("ClassLoaderSelfFirst = " + mClassLoaderSelfFirst);
369: b.append(sep);
370: b.append("ClassPathElements = " + mClassPathElements);
371: return b.toString();
372: }
373:
374: // The following methods are part of the ComponentInfo interface but are
375: // not applicable to a SharedLibrary. These methods all throw an
376: // UnsupportedOperationException if they are called.
377:
378: /**
379: * Get the class name of the bootstrap implementation.
380: * @return nothing, always throws an exception.
381: * @throws UnsupportedOperationException if called.
382: */
383: public String getBootstrapClassName() {
384: throw new UnsupportedOperationException();
385: }
386:
387: /**
388: * Get the class path elements needed in the bootstrap runtime environment.
389: * @return nothing, always throws an exception.
390: * @throws UnsupportedOperationException if called.
391: */
392: public java.util.List getBootstrapClassPathElements() {
393: throw new UnsupportedOperationException();
394: }
395:
396: /**
397: * Get the installation properties.
398: * @return nothing, always throws exception.
399: * @throws UnsupportedOperationException if called.
400: */
401: public java.util.Map getProperties() {
402: throw new UnsupportedOperationException();
403: }
404:
405: /**
406: * Get the workspace root directory.
407: * @return nothing, always throws exception.
408: * @throws UnsupportedOperationException if called.
409: */
410: public String getWorkspaceRoot() {
411: throw new UnsupportedOperationException();
412: }
413:
414: /**
415: * Check to see if the bootstrap class loader should use a self-first
416: * search hierarchy.
417: * @return nothing, always throws an exception.
418: * @throws UnsupportedOperationException if called.
419: */
420: public boolean isBootstrapClassLoaderSelfFirst() {
421: throw new UnsupportedOperationException();
422: }
423:
424: }
|