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: * @(#)ComponentInstallationContext.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.management;
030:
031: import com.sun.jbi.util.StringTranslator;
032:
033: import java.io.File;
034: import java.util.ArrayList;
035: import java.util.Iterator;
036: import java.util.List;
037:
038: /**
039: * Contains information necessary for a component (BC or SE) to perform
040: * special installation/uninstallation processing. This context is provided
041: * to the <CODE>init</CODE> method of the javax.jbi.component.Bootstrap
042: * implementation for the component.
043: *
044: * @author Sun Microsystems, Inc.
045: */
046: public class ComponentInstallationContext implements
047: com.sun.jbi.component.InstallationContext {
048: /**
049: * Flag to determine whether the bootstrap class loader should use an
050: * inverted (self-first) hierarchy or the normal (parent-first) hierarchy.
051: * Set to true for self-first, false for parent-first.
052: */
053: private boolean mBootstrapClassLoaderSelfFirst;
054:
055: /**
056: * Name of the class that implements the javax.jbi.component.Component
057: * interface.
058: */
059: private String mClassName;
060:
061: /**
062: * List of class path elements as relative paths based off of the component
063: * install root (mInstallRoot).
064: */
065: private java.util.List mClassPathElements;
066:
067: /**
068: * Flag to determine whether the component class loader should use an
069: * inverted (self-first) hierarchy or the normal (parent-first) hierarchy.
070: * Set to true for self-first, false for parent-first.
071: */
072: private boolean mComponentClassLoaderSelfFirst;
073:
074: /**
075: * Unique component name.
076: */
077: private String mComponentName;
078:
079: /**
080: * Component type (BINDING or ENGINE).
081: */
082: private int mComponentType;
083:
084: /**
085: * Handle to the ComponentContext.
086: */
087: private javax.jbi.component.ComponentContext mContext;
088:
089: /**
090: * Description of this component.
091: */
092: private String mDescription;
093:
094: /**
095: * Installation root directory for this component.
096: */
097: private String mInstallRoot;
098:
099: /**
100: * Flag set to true for installation or false for uninstallation.
101: */
102: private boolean mIsInstall;
103:
104: /**
105: * StringTranslator for constructing messages.
106: */
107: private StringTranslator mTranslator;
108:
109: /**
110: * Workspace root directory for this component.
111: */
112: private String mWorkspaceRoot;
113:
114: /**
115: * DOM document fragment representing the installation descriptor (jbi.xml)
116: * extension data for the component, if any.
117: */
118: private org.w3c.dom.DocumentFragment mInstallationDescriptorExtension;
119:
120: /**
121: * Public constructor.
122: * @param componentName the unique component name.
123: * @param componentType the type of this component - either BINDING or
124: * ENGINE.
125: * @param className the name of the class the implements the
126: * javax.jbi.component.Component interface for this component.
127: * @param classPathElements the list of elements that comprise the
128: * runtime class path for this component. NOTE: The elements in this list
129: * are relative paths based off the component's install root.
130: * @param extensionData the DOM document fragment representing the contents
131: * of the installation descriptor extension from the jbi.xml file.
132: */
133: public ComponentInstallationContext(String componentName,
134: int componentType, String className,
135: List classPathElements,
136: org.w3c.dom.DocumentFragment extensionData) {
137: mComponentName = componentName;
138: mComponentType = componentType;
139: mClassName = className;
140: mClassPathElements = classPathElements;
141: mInstallationDescriptorExtension = extensionData;
142:
143: // Initialize other attributes
144:
145: mBootstrapClassLoaderSelfFirst = false;
146: mComponentClassLoaderSelfFirst = false;
147: mIsInstall = false;
148: mTranslator = new StringTranslator(this .getClass().getPackage()
149: .getName(), null);
150: }
151:
152: // ----------- Methods from javax.jbi.component.InstallationContext -----------
153:
154: /**
155: * Get a list of elements that comprise the class path for this component.
156: * Each element represents either a directory (containing class files) or a
157: * jar file. The elements are relative paths based off of the component's
158: * install root, and are returned with the File.separator character as their
159: * file separators.
160: * @return a list of String objects containing class path elements.
161: */
162: public List getClassPathElements() {
163: if (File.separator.equals("/")) {
164: return mClassPathElements;
165: } else {
166: List retList = new ArrayList();
167: Iterator i = mClassPathElements.iterator();
168: while (i.hasNext()) {
169: String e = ((String) i.next()).replace('/',
170: File.separatorChar);
171: retList.add(e);
172: }
173: return retList;
174: }
175: }
176:
177: /**
178: * Get the name of the class that implements javax.jbi.component.Component
179: * for this component.
180: * @return the class name.
181: */
182: public String getComponentClassName() {
183: return mClassName;
184: }
185:
186: /**
187: * Get the unique name assigned to this component.
188: * @return the unique component name.
189: */
190: public String getComponentName() {
191: return mComponentName;
192: }
193:
194: /**
195: * Get the component context.
196: * @return the component context.
197: */
198: public javax.jbi.component.ComponentContext getContext() {
199: return mContext;
200: }
201:
202: /**
203: * Return a DOM document fragment representing the installation descriptor
204: * (jbi.xml) extension data for this component, if any is present.
205: * @return the DOM document fragment for the extension data.
206: */
207: public org.w3c.dom.DocumentFragment getInstallationDescriptorExtension() {
208: return mInstallationDescriptorExtension;
209: }
210:
211: /**
212: * Get the installation root directory for this component.
213: * @return the name of the installation root directory, with the levels
214: * separated by the local File.separator character.
215: */
216: public String getInstallRoot() {
217: if (File.separator.equals("/")) {
218: return mInstallRoot;
219: } else {
220: return mInstallRoot.replace('/', File.separatorChar);
221: }
222: }
223:
224: /**
225: * Return an indication as to whether this context is for an install or
226: * an uninstall.
227: * @return true for an install, false for an uninstall.
228: */
229: public boolean isInstall() {
230: return mIsInstall;
231: }
232:
233: /**
234: * Set the list of elements that comprise the class path for this component.
235: * Each element represents either a directory (containing class files) or a
236: * jar file. This method is provided to allow the component's installer to
237: * modify the list of class path elements. Each element must be formatted
238: * using the File.separator character, and must be a relative path based
239: * on the component's install root.
240: * @param classPathElements a list of String objects containing class path
241: * elements.
242: */
243: public void setClassPathElements(List classPathElements) {
244: if (null == classPathElements) {
245: throw new IllegalArgumentException(
246: mTranslator
247: .getString(LocalStringKeys.IC_NULL_CLASS_PATH_ELEMENTS));
248: }
249: if (classPathElements.isEmpty()) {
250: throw new IllegalArgumentException(
251: mTranslator
252: .getString(LocalStringKeys.IC_EMPTY_CLASS_PATH_ELEMENTS));
253: }
254:
255: // Validate each element in the list. No absolute paths are allowed,
256: // and the paths must use the File.separator character in compliance
257: // with the JBI spec.
258:
259: Iterator i = classPathElements.iterator();
260: int index = 0;
261: while (i.hasNext()) {
262: String element = (String) i.next();
263: File f = new File(element);
264: if (f.isAbsolute()) {
265: throw new IllegalArgumentException(
266: mTranslator
267: .getString(
268: LocalStringKeys.IC_ABSOLUTE_PATH_NOT_ALLOWED,
269: new Integer(index), element));
270: }
271: String sep = File.separator.equals("\\") ? "/" : "\\";
272: int offset = element.indexOf(sep);
273: if (offset > -1) {
274: throw new IllegalArgumentException(
275: mTranslator
276: .getString(
277: LocalStringKeys.IC_INCORRECT_FILE_SEPARATOR,
278: sep, new Integer(offset),
279: new Integer(index), element));
280: }
281:
282: // This looks stupid, but inside Appserver all file paths use the
283: // Unix-style file separator.
284:
285: element.replace('\\', '/');
286: index++;
287: }
288:
289: mClassPathElements = classPathElements;
290: }
291:
292: // ---------- Methods from com.sun.jbi.component.InstallationContext ----------
293:
294: /**
295: * Get a list of elements that comprise the class path for this component.
296: * Each element represents either a directory (containing class files) or a
297: * jar file. The elements are absolute paths and are returned with a forward
298: * slash as their file separators.
299: * @return a list of String objects containing class path elements.
300: */
301: public List getAbsoluteClassPathElements() {
302: List retList = new ArrayList();
303: Iterator i = mClassPathElements.iterator();
304: while (i.hasNext()) {
305: String e = mInstallRoot + "/" + (String) i.next();
306: retList.add(e);
307: }
308: return retList;
309: }
310:
311: /**
312: * Return the description of this component.
313: * @return the description of this component.
314: */
315: public String getDescription() {
316: return mDescription;
317: }
318:
319: /**
320: * Return the workspace root directory for the component.
321: * @return the workspace root directory path.
322: */
323: public String getWorkspaceRoot() {
324: return mWorkspaceRoot;
325: }
326:
327: /**
328: * Return an indication as to whether the component being installed is a
329: * Binding Component.
330: * @return true if the component is a BC, false if not.
331: */
332: public boolean isBinding() {
333: return (BINDING == mComponentType);
334: }
335:
336: /**
337: * Return an indication as to whether the bootstrap class loader should
338: * use the normal hierarchy (parent-first) or an inverted hierarchy
339: * (self-first).
340: * @return true if the bootstrap class loader should use the self-first
341: * hierarchy, false if it should use parent-first.
342: */
343: public boolean isBootstrapClassLoaderSelfFirst() {
344: return mBootstrapClassLoaderSelfFirst;
345: }
346:
347: /**
348: * Return an indication as to whether the component class loader should
349: * use the normal hierarchy (parent-first) or an inverted hierarchy
350: * (self-first).
351: * @return true if the component class loader should use the self-first
352: * hierarchy, false if it should use parent-first.
353: */
354: public boolean isComponentClassLoaderSelfFirst() {
355: return mComponentClassLoaderSelfFirst;
356: }
357:
358: /**
359: * Return an indication as to whether the component being installed is a
360: * Service Engine.
361: * @return true if the component is a SE, false if not.
362: */
363: public boolean isEngine() {
364: return (ENGINE == mComponentType);
365: }
366:
367: /**
368: * Set the context for this component. This method is used by the
369: * Component Framework to set the context during installation processing.
370: * @param context the component context.
371: */
372: public void setContext(javax.jbi.component.ComponentContext context) {
373: mContext = context;
374: }
375:
376: // ------------------- Methods local to this implementation -------------------
377:
378: /**
379: * Set a flag to force the bootstrap class loader to use an inverted
380: * hierarchy (self-first).
381: */
382: public void setBootstrapClassLoaderSelfFirst() {
383: mBootstrapClassLoaderSelfFirst = true;
384: }
385:
386: /**
387: * Set a flag to force the component class loader to use an inverted
388: * hierarchy (self-first).
389: */
390: public void setComponentClassLoaderSelfFirst() {
391: mComponentClassLoaderSelfFirst = true;
392: }
393:
394: /**
395: * Set the name of the class that implements javax.jbi.component.Component
396: * for this component.
397: * @param name the component class name of this component.
398: */
399: public void setComponentClassName(String name) {
400: mClassName = name;
401: }
402:
403: /**
404: * Set the name of this component.
405: * @param name the name of this component.
406: */
407: public void setComponentName(String name) {
408: mComponentName = name;
409: }
410:
411: /**
412: * Set the description of this component.
413: * @param description the description of this component.
414: */
415: public void setDescription(String description) {
416: mDescription = description;
417: }
418:
419: /**
420: * Set the installation descriptor extension.
421: * @param extension the extension portion of the component's installation
422: * descriptor.
423: */
424: public void setInstallationDescriptorExtension(
425: org.w3c.dom.DocumentFragment extension) {
426: mInstallationDescriptorExtension = extension;
427: }
428:
429: /**
430: * Set the installation root directory name for this component.
431: * @param installRoot the installation root directory name.
432: */
433: public void setInstallRoot(String installRoot) {
434: mInstallRoot = installRoot;
435: }
436:
437: /**
438: * Set the flag to indicate whether this is an install or an uninstall.
439: * @param isInstall is true for an install, false for an uninstall.
440: */
441: public void setIsInstall(boolean isInstall) {
442: mIsInstall = isInstall;
443: }
444:
445: /**
446: * Set the workspace root directory name for this component.
447: * @param workspaceRoot the workspace root directory name.
448: */
449: public void setWorkspaceRoot(String workspaceRoot) {
450: mWorkspaceRoot = workspaceRoot;
451: }
452: }
|