0001: /*
0002: * BEGIN_HEADER - DO NOT EDIT
0003: *
0004: * The contents of this file are subject to the terms
0005: * of the Common Development and Distribution License
0006: * (the "License"). You may not use this file except
0007: * in compliance with the License.
0008: *
0009: * You can obtain a copy of the license at
0010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0011: * See the License for the specific language governing
0012: * permissions and limitations under the License.
0013: *
0014: * When distributing Covered Code, include this CDDL
0015: * HEADER in each file and include the License file at
0016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0017: * If applicable add the following below this CDDL HEADER,
0018: * with the fields enclosed by brackets "[]" replaced with
0019: * your own identifying information: Portions Copyright
0020: * [year] [name of copyright owner]
0021: */
0022:
0023: /*
0024: * @(#)Component.java
0025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
0026: *
0027: * END_HEADER - DO NOT EDIT
0028: */
0029: package com.sun.jbi.framework;
0030:
0031: import com.sun.jbi.ComponentState;
0032: import com.sun.jbi.ComponentType;
0033:
0034: import java.io.File;
0035: import java.io.FileInputStream;
0036: import java.io.FileOutputStream;
0037:
0038: import java.net.URLEncoder;
0039:
0040: import java.util.ArrayList;
0041: import java.util.HashMap;
0042: import java.util.Hashtable;
0043: import java.util.Iterator;
0044: import java.util.List;
0045: import java.util.Map;
0046: import java.util.Properties;
0047: import java.util.TreeMap;
0048: import java.util.logging.Level;
0049: import java.util.logging.Logger;
0050:
0051: /**
0052: * This class holds information about a Binding Component (BC) or a Service
0053: * Engine (SE). This information is used by the JBI framework to install and
0054: * manage BCs and SEs. Some of the information is permanent, and is persisted
0055: * by the Component Registry across restarts of the JBI framework. Other
0056: * information is only relevant for the duration of a JBI framework lifecycle.
0057: * All attributes that are not persisted are marked <CODE>transient</CODE>.
0058: *
0059: * @author Sun Microsystems, Inc.
0060: */
0061: public class Component implements com.sun.jbi.ComponentInfo {
0062: //
0063: // Data items that are persisted across JBI restarts.
0064: //
0065:
0066: /**
0067: * Indicator as to whether the bootstrap class loader is to be "inverted".
0068: * Its value is true if the search order for the bootstrap class loader is
0069: * to be inverted relative to the normal search order - self-first rather
0070: * than parent-first. This is persisted across restarts of the JBI framework.
0071: */
0072: private boolean mBootstrapClassLoaderSelfFirst;
0073:
0074: /**
0075: * The name of the class that implements the
0076: * <CODE>javax.jbi.component.Bootstrap</CODE> interface
0077: * for this BC or SE. This is persisted across restarts of the JBI framework.
0078: */
0079: private String mBootstrapClassName;
0080:
0081: /**
0082: * The class path that the bootstrap implementation needs in its runtime
0083: * environment, stored as an array of elements. Each element is a
0084: * <CODE>String</CODE>
0085: * containing an absolute path to a jar file or a directory that contains
0086: * class files. This is persisted across restarts of the JBI framework.
0087: */
0088: private ArrayList mBootstrapClassPathElements;
0089:
0090: /**
0091: * Indicator as to whether the component class loader is to be "inverted".
0092: * Its value is true if the search order for the component class loader is
0093: * to be inverted relative to the normal search order - self-first rather
0094: * than parent-first. This is persisted across restarts of the JBI framework.
0095: */
0096: private boolean mComponentClassLoaderSelfFirst;
0097:
0098: /**
0099: * The name of the class that implements the
0100: * <CODE>javax.jbi.component.Component</CODE>
0101: * interface for this BC or SE. This is persisted across restarts of the
0102: * JBI framework.
0103: */
0104: private String mComponentClassName;
0105:
0106: /**
0107: * The class path that the component implementation needs in its
0108: * runtime environment, stored as an array of elements. Each element
0109: * represents either an absolute path to a jar file or a directory
0110: * that contains class files. This is persisted across restarts of
0111: * the JBI framework.
0112: */
0113: private ArrayList mComponentClassPathElements;
0114:
0115: /**
0116: * The current state of this BC or SE. This is persisted across restarts
0117: * of the JBI framework. Valid states are:
0118: * <UL>
0119: * <LI><CODE>LOADED</CODE> - the component's installer has been loaded
0120: * but the installation has not yet completed</LI>
0121: * <LI><CODE>SHUTDOWN</CODE> - the component is installed but is not
0122: * currently initialized (this is what the JBI specification refers to as
0123: * <CODE>SHUTDOWN</CODE> state)</LI>
0124: * <LI><CODE>STOPPED</CODE> - the component has been initialized but either
0125: * has not yet been started or has been stopped after a previous start</LI>
0126: * <LI><CODE>STARTED</CODE> - the component has been started and is able
0127: * to process requests</LI>
0128: * </UL>
0129: * <BR>
0130: * The state changes that are allowed are:
0131: * <UL>
0132: * <LI><CODE>LOADED</CODE> --> <CODE>SHUTDOWN<CODE/></LI>
0133: * <LI><CODE>SHUTDOWN</CODE> --> <CODE>STOPPED</CODE></LI>
0134: * <LI><CODE>STOPPED</CODE> --> <CODE>STARTED</CODE></LI>
0135: * <LI><CODE>STARTED</CODE> --> <CODE>STOPPED</CODE></LI>
0136: * <LI><CODE>STOPPED</CODE> --> <CODE>SHUTDOWN</CODE></LI>
0137: * </UL>
0138: * <BR>
0139: * Note that the <CODE>LOADED</CODE> state is a transient state during the
0140: * installation of a component, and it is never persisted. When a component
0141: * is in this state, it has not yet been stored in the registry. Once it is
0142: * stored in the registry, it is in <CODE>SHUTDOWN</CODE> state until it is
0143: * initialized.
0144: */
0145: private ComponentState mComponentState;
0146:
0147: /**
0148: * The type of this component (BC or SE). This is persisted across restarts
0149: * of the JBI framework.
0150: */
0151: private ComponentType mComponentType;
0152:
0153: /**
0154: * The description of this BC or SE. This is persisted across restarts of the
0155: * JBI framework.
0156: */
0157: private String mDescription;
0158:
0159: /**
0160: * The desired state of this BC or SE. This is persisted across restarts of
0161: * the JBI framework. This state is set when a request to change the state
0162: * is received from an administrator in the form of a start, stop, or shut
0163: * down command.
0164: */
0165: private ComponentState mDesiredState;
0166:
0167: /**
0168: * The root installation directory path for this BC or SE. This is
0169: * persisted across restarts of the JBI framework.
0170: */
0171: private String mInstallRoot;
0172:
0173: /**
0174: * The name for this BC or SE. This is persisted across restarts of the
0175: * JBI framework.
0176: */
0177: private String mName;
0178:
0179: /**
0180: * The list of ServiceUnit objects representing the Service Units that are
0181: * deployed to this BC or SE. This is persisted across restarts of the JBI
0182: * framework.
0183: */
0184: private Hashtable mServiceUnitList;
0185:
0186: /**
0187: * The list of names of Shared Libraries that are required by this
0188: * BC or SE. This is persisted across restarts of the JBI framework.
0189: */
0190: private ArrayList mSharedLibraryNames;
0191:
0192: /**
0193: * The workspace root directory path for this BC or SE. This is persisted
0194: * across restarts of the JBI framework.
0195: */
0196: private String mWorkspaceRoot;
0197:
0198: //
0199: // Data items that are NOT persisted across JBI restarts.
0200: //
0201:
0202: /**
0203: * The bootstrap class loader for this BC or SE. This is NOT persisted.
0204: */
0205: private transient ClassLoader mBootstrapClassLoader;
0206:
0207: /**
0208: * When true, indicates that the bootstrap cleanUp() method needs to be
0209: * called by unloadBootstrap(). This is NOT persisted.
0210: */
0211: private transient boolean mBootstrapCleanUpNeeded;
0212:
0213: /**
0214: * The instance of the class that implements the
0215: * <CODE>javax.jbi.component.Bootstrap</CODE>
0216: * interface for this BC or SE. This is NOT persisted.
0217: */
0218: private transient javax.jbi.component.Bootstrap mBootstrapInstance;
0219:
0220: /**
0221: * A flag that indicates that a life cycle request is currently active.
0222: * This is NOT persisted.
0223: */
0224: private transient boolean mBusy;
0225:
0226: /**
0227: * The instance of the class that implements the
0228: * <CODE>javax.jbi.component.Component</CODE>
0229: * interface for this BC or SE. This is NOT persisted.
0230: */
0231: private transient javax.jbi.component.Component mComponentInstance;
0232:
0233: /**
0234: * The instance of the ComponentContext for this BC or SE. This is NOT
0235: * persisted.
0236: */
0237: private transient ComponentContext mContext;
0238:
0239: /**
0240: * The instance of the Deployer for this BC or SE. This is NOT persisted.
0241: */
0242: private transient Deployer mDeployerInstance;
0243:
0244: /**
0245: * The JMX ObjectName of the DeployerMBean for this BC or SE. This is NOT
0246: * persisted.
0247: */
0248: private transient javax.management.ObjectName mDeployerMBeanName;
0249:
0250: /**
0251: * The JMX ObjectName of the bootstrap ExtensionMBean for this BC or SE.
0252: * This is NOT persisted.
0253: */
0254: private transient javax.management.ObjectName mExtensionMBeanName;
0255:
0256: /**
0257: * The JMX ObjectName of the InstallerMBean for this BC or SE. This is NOT
0258: * persisted.
0259: */
0260: private transient javax.management.ObjectName mInstallerMBeanName;
0261:
0262: /**
0263: * The JMX ObjectName of the Configuration for this BC or SE. This is NOT
0264: * persisted.
0265: */
0266: private transient javax.management.ObjectName mConfigMBeanName;
0267:
0268: /**
0269: * The jbi.xml descriptor string. This is NOT persisted.
0270: */
0271: private transient String mJbiXmlString;
0272:
0273: /**
0274: * The jbi.xml JAXB model wrapper. This is NOT persisted.
0275: */
0276: private transient com.sun.jbi.management.descriptor.ComponentDescriptor mJbiXmlModel;
0277:
0278: /**
0279: * The instance of the class that implements the
0280: * <CODE>javax.jbi.component.ComponentLifeCycle</CODE>
0281: * interface for this BC or SE. This is NOT persisted.
0282: */
0283: private transient javax.jbi.component.ComponentLifeCycle mLifeCycleInstance;
0284:
0285: /**
0286: * The JMX ObjectName of the LifeCycleMBean for this BC or SE. This is NOT
0287: * persisted.
0288: */
0289: private transient javax.management.ObjectName mLifeCycleMBeanName;
0290:
0291: /**
0292: * The logger for logging errors.
0293: */
0294: private transient Logger mLog;
0295:
0296: /**
0297: * The instance of the logger MBean class for this BC or SE. This is NOT
0298: * persisted.
0299: */
0300: private transient ComponentLogger mLoggerInstance;
0301:
0302: /**
0303: * The JMX ObjectName of the LoggerMBean for this BC or SE. This is NOT
0304: * persisted.
0305: */
0306: private transient javax.management.ObjectName mLoggerMBeanName;
0307:
0308: /**
0309: * Flag to indicate that this component is an NMR observer. This is NOT
0310: * persisted.
0311: */
0312: private transient Boolean mObserver;
0313:
0314: /**
0315: * The instance of the class that implements the
0316: * <CODE>javax.jbi.component.ServiceUnitManager</CODE>
0317: * interface for this BC or SE. This is NOT persisted.
0318: */
0319: private transient javax.jbi.component.ServiceUnitManager mSUManagerInstance;
0320:
0321: /**
0322: * The instance of the statistics class for this BC or SE. This is NOT
0323: * persisted.
0324: */
0325: private transient ComponentStatistics mStatisticsInstance;
0326:
0327: /**
0328: * The JMX ObjectName of the ComponentStatisticsMBean for this BC or SE.
0329: * This is NOT persisted.
0330: */
0331: private transient javax.management.ObjectName mStatisticsMBeanName;
0332:
0333: /**
0334: * The StringTranslator to be used for constructing messages. This is NOT
0335: * persisted.
0336: */
0337: private transient StringTranslator mTranslator;
0338:
0339: /**
0340: * A flag that indicates that the component is being updated.
0341: * This is NOT persisted.
0342: */
0343: private transient boolean mUpdating;
0344:
0345: /**
0346: * XML namespace URI for the NMR observer element in the installation
0347: * descriptor extension in jbi.xml for this component.
0348: */
0349: private static String OBSERVER_NS = "http://www.sun.com/jbi/observer";
0350:
0351: /**
0352: * XML tag for the NMR observer element in the installation descriptor
0353: * extension in jbi.xml for this component.
0354: */
0355: private static String OBSERVER_TAG = "Observer";
0356:
0357: /**
0358: * Create a new Component instance.
0359: */
0360: public Component() {
0361: mServiceUnitList = new Hashtable();
0362: mTranslator = (StringTranslator) EnvironmentContext
0363: .getInstance().getStringTranslatorFor(this );
0364: mLog = EnvironmentContext.getInstance().getLogger();
0365: mComponentState = ComponentState.UNKNOWN;
0366: mDesiredState = ComponentState.UNKNOWN;
0367: mObserver = null;
0368: }
0369:
0370: /**
0371: * Constructor for building an instance from a ComponentInfo instance
0372: * @param compInfo - the ComponentInfo instance
0373: */
0374: public Component(com.sun.jbi.ComponentInfo compInfo) {
0375: mServiceUnitList = new Hashtable();
0376: mTranslator = (StringTranslator) EnvironmentContext
0377: .getInstance().getStringTranslatorFor(this );
0378: mLog = EnvironmentContext.getInstance().getLogger();
0379:
0380: mComponentType = compInfo.getComponentType();
0381: mName = compInfo.getName();
0382: mDescription = compInfo.getDescription();
0383: mInstallRoot = compInfo.getInstallRoot();
0384: mWorkspaceRoot = compInfo.getWorkspaceRoot();
0385: mComponentState = ComponentState.SHUTDOWN;
0386: mDesiredState = compInfo.getStatus();
0387: mObserver = null;
0388:
0389: mBootstrapClassLoaderSelfFirst = compInfo
0390: .isBootstrapClassLoaderSelfFirst();
0391: mBootstrapClassName = compInfo.getBootstrapClassName();
0392: mBootstrapClassPathElements = new ArrayList(compInfo
0393: .getBootstrapClassPathElements());
0394:
0395: mComponentClassName = compInfo.getComponentClassName();
0396: mComponentClassPathElements = new ArrayList(compInfo
0397: .getClassPathElements());
0398: mComponentClassLoaderSelfFirst = compInfo
0399: .isClassLoaderSelfFirst();
0400: List<com.sun.jbi.ServiceUnitInfo> suList = compInfo
0401: .getServiceUnitList();
0402: for (com.sun.jbi.ServiceUnitInfo suInfo : suList) {
0403: ServiceUnit su = new ServiceUnit(suInfo);
0404: mServiceUnitList.put(suInfo.getName(), su);
0405: }
0406: mSharedLibraryNames = new ArrayList(compInfo
0407: .getSharedLibraryNames());
0408: }
0409:
0410: /**
0411: * Add a ServiceUnit object to the list of Service Units deployed to this
0412: * BC or SE.
0413: * @param serviceUnit The ServiceUnit object representing the Service Unit.
0414: * @throws javax.jbi.JBIException if the Service Unit is already in the list.
0415: */
0416: public void addServiceUnit(ServiceUnit serviceUnit)
0417: throws javax.jbi.JBIException {
0418: if (null == serviceUnit) {
0419: throw new java.lang.IllegalArgumentException(mTranslator
0420: .getString(LocalStringKeys.NULL_ARGUMENT,
0421: "serviceUnit"));
0422: }
0423: if (!mServiceUnitList.containsKey(serviceUnit.getName())) {
0424: mServiceUnitList.put(serviceUnit.getName(), serviceUnit);
0425: } else {
0426: String msg = mTranslator.getString(
0427: LocalStringKeys.SU_ALREADY_EXISTS, serviceUnit
0428: .getName(), getComponentTypeAsString(),
0429: getName());
0430: throw new javax.jbi.JBIException(msg);
0431: }
0432: }
0433:
0434: /**
0435: * Clear the instance reference for the <CODE>Bootstrap</CODE> implementation
0436: * for this BC or SE.
0437: */
0438: public void clearBootstrapInstance() {
0439: mBootstrapInstance = null;
0440:
0441: // Destroy the class loader.
0442: ((CustomClassLoader) mBootstrapClassLoader).releaseResources();
0443: mBootstrapClassLoader = null;
0444: }
0445:
0446: /**
0447: * Clear the "busy" flag.
0448: */
0449: public void clearBusy() {
0450: mBusy = false;
0451: }
0452:
0453: /**
0454: * Clear the instance reference for the <CODE>Component</CODE> implementation
0455: * for this BC or SE. Also remove the class loader if it exists.
0456: */
0457: public void clearLifeCycleInstance() {
0458: // Clear the class instance references.
0459: mComponentInstance = null;
0460: mLifeCycleInstance = null;
0461: mSUManagerInstance = null;
0462:
0463: // Destroy the class loader. The only reason for an exception here
0464: // is that the class loader did not exist, and that is not treated
0465: // as an error.
0466: try {
0467: ClassLoaderFactory.getInstance()
0468: .removeComponentClassLoader(mName);
0469: } catch (javax.jbi.JBIException ex) {
0470: ;
0471: }
0472: }
0473:
0474: /**
0475: * Clear the reference to the <CODE>ComponentStatistics</CODE> instance
0476: * for this BC or SE.
0477: */
0478: public void clearStatisticsInstance() {
0479: mStatisticsInstance = null;
0480: }
0481:
0482: /**
0483: * Clear the <code>Updating</code> flag. This also clears the <code>Busy
0484: * </code> flag.
0485: */
0486: public void clearUpdating() {
0487: mUpdating = false;
0488: clearBusy();
0489: }
0490:
0491: /**
0492: * Compare another Object with this one for equality.
0493: * @param object The object to be compared with this one.
0494: * @return True if the object is equal to this Component, false
0495: * if they are not equal.
0496: */
0497: public boolean equals(Object object) {
0498: if (null == object || !(object instanceof Component)) {
0499: return false;
0500: }
0501: Component component = (Component) object;
0502: if (!mName.equals(component.getName())) {
0503: return false;
0504: }
0505: if (mComponentType != component.getComponentType()) {
0506: return false;
0507: }
0508: if (null == mDescription) {
0509: if (null != component.getDescription()) {
0510: return false;
0511: }
0512: } else {
0513: if (!mDescription.equals(component.getDescription())) {
0514: return false;
0515: }
0516: }
0517: if (null == mBootstrapClassName) {
0518: if (null != component.getBootstrapClassName()) {
0519: return false;
0520: }
0521: } else {
0522: if (!mBootstrapClassName.equals(component
0523: .getBootstrapClassName())) {
0524: return false;
0525: }
0526: }
0527: if (null == mBootstrapClassPathElements) {
0528: if (null != component.getBootstrapClassPathElements()) {
0529: return false;
0530: }
0531: } else {
0532: if (!mBootstrapClassPathElements.equals(component
0533: .getBootstrapClassPathElements())) {
0534: return false;
0535: }
0536: }
0537: if (null == mComponentClassName) {
0538: if (null != component.getComponentClassName()) {
0539: return false;
0540: }
0541: } else {
0542: if (!mComponentClassName.equals(component
0543: .getComponentClassName())) {
0544: return false;
0545: }
0546: }
0547: if (null == mComponentClassPathElements) {
0548: if (null != component.getComponentClassPathElements()) {
0549: return false;
0550: }
0551: } else {
0552: if (!mComponentClassPathElements.equals(component
0553: .getComponentClassPathElements())) {
0554: return false;
0555: }
0556: }
0557: if (null == mInstallRoot) {
0558: if (null != component.getInstallRoot()) {
0559: return false;
0560: }
0561: } else {
0562: if (!mInstallRoot.equals(component.getInstallRoot())) {
0563: return false;
0564: }
0565: }
0566: if (null == mWorkspaceRoot) {
0567: if (null != component.getWorkspaceRoot()) {
0568: return false;
0569: }
0570: } else {
0571: if (!mWorkspaceRoot.equals(component.getWorkspaceRoot())) {
0572: return false;
0573: }
0574: }
0575: if (null == mSharedLibraryNames) {
0576: if (null != component.getSharedLibraryNames()
0577: && !component.getSharedLibraryNames().isEmpty()) {
0578: return false;
0579: }
0580: } else {
0581: if (!mSharedLibraryNames.equals(component
0582: .getSharedLibraryNames())) {
0583: return false;
0584: }
0585: }
0586: if (null == mServiceUnitList) {
0587: if (null != component.getServiceUnitList()
0588: && !component.getServiceUnitList().isEmpty()) {
0589: return false;
0590: }
0591: } else {
0592: if (!getServiceUnitList().equals(
0593: component.getServiceUnitList())) {
0594: return false;
0595: }
0596: }
0597: return true;
0598: }
0599:
0600: /**
0601: * Get the class name of the bootstrap implementation for this BC or SE.
0602: * @return The bootstrap class name.
0603: */
0604: public String getBootstrapClassName() {
0605: return mBootstrapClassName;
0606: }
0607:
0608: /**
0609: * Get the class path elements that this BC or SE needs in its bootstrap
0610: * runtime environment.
0611: * @return A list of the elements of the bootstrap class path as strings.
0612: */
0613: public java.util.List<String> getBootstrapClassPathElements() {
0614: return mBootstrapClassPathElements;
0615: }
0616:
0617: /**
0618: * Get an instance of the bootstrap class for this BC or SE. This method
0619: * can create a new instance if necessary. This is controlled by the
0620: * <CODE>canCreate</CODE> parameter. If the value of <CODE>canCreate</CODE>
0621: * is <code>true</CODE>, then if there is no instance of the bootstrap
0622: * class a new one is created. In this case, the return value is guaranteed
0623: * to be non-null. If the value of <CODE>canCreate</CODE> is <CODE>false</CODE>,
0624: * then a new instance of the bootstrap class is never created. In this
0625: * case, the return value can be null if there is no bootstrap instance.
0626: * @param canCreate Is true if a new instance of the bootstrap class can
0627: * be created if one does not already exist, and false if no new instance
0628: * can be created.
0629: * @return The bootstrap class instance.
0630: * @throws javax.jbi.JBIException if the class cannot be loaded.
0631: */
0632: public javax.jbi.component.Bootstrap getBootstrapInstance(
0633: boolean canCreate) throws javax.jbi.JBIException {
0634: if (canCreate) {
0635: // Create a new instance if one is not already present.
0636: if (null == mBootstrapInstance) {
0637: ClassLoader cl;
0638: Object o;
0639: try {
0640: cl = ClassLoaderFactory.getInstance()
0641: .createBootstrapClassLoader(this );
0642: mBootstrapClassLoader = cl;
0643: o = cl.loadClass(mBootstrapClassName).newInstance();
0644: if (o instanceof javax.jbi.component.Bootstrap) {
0645: mBootstrapInstance = (javax.jbi.component.Bootstrap) o;
0646: } else {
0647: String msg = mTranslator.getString(
0648: LocalStringKeys.COMP_CLASS_NOT_VALID,
0649: mBootstrapClassName,
0650: "javax.jbi.component.Bootstrap");
0651: throw new javax.jbi.JBIException(msg);
0652: }
0653: } catch (javax.jbi.JBIException jbiEx) {
0654: throw new javax.jbi.JBIException(
0655: mTranslator
0656: .getString(
0657: LocalStringKeys.COMP_BOOTSTRAP_LOAD_FAILED,
0658: mName, jbiEx.getMessage()));
0659: } catch (ClassNotFoundException cnfEx) {
0660: String msg = mTranslator.getString(
0661: LocalStringKeys.COMP_CLASS_NOT_FOUND, cnfEx
0662: .getMessage());
0663: if (null != cnfEx.getCause()) {
0664: mLog.log(Level.WARNING, msg, cnfEx.getCause());
0665: throw new javax.jbi.JBIException(
0666: mTranslator
0667: .getString(
0668: LocalStringKeys.COMP_BOOTSTRAP_LOAD_FAILED,
0669: mName, msg), cnfEx
0670: .getCause());
0671: } else {
0672: throw new javax.jbi.JBIException(
0673: mTranslator
0674: .getString(
0675: LocalStringKeys.COMP_BOOTSTRAP_LOAD_FAILED,
0676: mName, msg));
0677: }
0678: } catch (Throwable ex) {
0679: String msg = mTranslator.getString(
0680: LocalStringKeys.COMP_EXCEPTION, ex
0681: .getClass().getName());
0682: mLog.log(Level.WARNING, msg, ex);
0683: throw new javax.jbi.JBIException(
0684: mTranslator
0685: .getString(
0686: LocalStringKeys.COMP_BOOTSTRAP_LOAD_FAILED,
0687: mName, msg), ex);
0688: }
0689: }
0690: }
0691: return mBootstrapInstance;
0692: }
0693:
0694: /**
0695: * Get the class path elements that this BC or SE needs in its runtime
0696: * environment.
0697: * @return A list of the elements of the component's class path as strings.
0698: */
0699: public List<String> getClassPathElements() {
0700: return mComponentClassPathElements;
0701: }
0702:
0703: /**
0704: * Get the class name of the component implementation for this
0705: * BC or SE.
0706: * @return The component class name.
0707: */
0708: public String getComponentClassName() {
0709: return mComponentClassName;
0710: }
0711:
0712: /**
0713: * Get the complete classpath for this component as a String.
0714: * @return The full classpath value.
0715: */
0716: public String getComponentClassPathAsString() {
0717: String sep = System.getProperty("path.separator");
0718: Iterator i = mComponentClassPathElements.iterator();
0719: StringBuffer sb = new StringBuffer("");
0720: boolean first = true;
0721: while (i.hasNext()) {
0722: if (!first) {
0723: sb.append(sep);
0724: } else {
0725: first = false;
0726: }
0727: sb.append((String) i.next());
0728: }
0729: return new String(sb);
0730: }
0731:
0732: /**
0733: * Get the class path elements that this BC or SE needs in its runtime
0734: * environment.
0735: * @return A list of the elements of the component's class path as strings.
0736: */
0737: public List<String> getComponentClassPathElements() {
0738: return mComponentClassPathElements;
0739: }
0740:
0741: /**
0742: * Get the javax.jbi.component.Component instance for the BC or SE. If none
0743: * is available, returns null.
0744: * @return The instance of javax.jbi.component.Component or null if no
0745: * instance is currently available.
0746: */
0747: public javax.jbi.component.Component getComponentInstance() {
0748: return mComponentInstance;
0749: }
0750:
0751: /**
0752: * Get the component type for this BC or SE.
0753: * @return The component type (BINDING or ENGINE).
0754: */
0755: public ComponentType getComponentType() {
0756: return mComponentType;
0757: }
0758:
0759: /**
0760: * Get the component type for this BC or SE as a string.
0761: * @return The component type as a string ("binding" or "engine").
0762: */
0763: public String getComponentTypeAsString() {
0764: if (isBinding()) {
0765: return mTranslator.getString(LocalStringKeys.BINDING);
0766: }
0767: if (isEngine()) {
0768: return mTranslator.getString(LocalStringKeys.ENGINE);
0769: }
0770: return mTranslator.getString(LocalStringKeys.UNKNOWN);
0771: }
0772:
0773: /**
0774: * Get the ComponentContext for this BC or SE.
0775: * @return The context for the component.
0776: */
0777: public ComponentContext getContext() {
0778: return mContext;
0779: }
0780:
0781: /**
0782: * Get the JMX ObjectName for the component configuration Dynamic MBean.
0783: * @return the objectName The JMX ObjectName of the component configuration
0784: * Dynamic MBean.
0785: */
0786: public javax.management.ObjectName getConfigurationMBeanName() {
0787: return mConfigMBeanName;
0788: }
0789:
0790: /**
0791: * Get the Deployer instance for the BC or SE.
0792: * If none is available, returns null.
0793: * @return The instance of Deployer or null if no instance is currently
0794: * available.
0795: */
0796: public Deployer getDeployerInstance() {
0797: return mDeployerInstance;
0798: }
0799:
0800: /**
0801: * Get the JMX ObjectName for the Deployer MBean.
0802: * @return The ObjectName if the MBean is registered, null if not.
0803: */
0804: public javax.management.ObjectName getDeployerMBeanName() {
0805: return mDeployerMBeanName;
0806: }
0807:
0808: /**
0809: * Get the description for this BC or SE.
0810: * @return The component description.
0811: */
0812: public String getDescription() {
0813: return mDescription;
0814: }
0815:
0816: /**
0817: * Get the desired state of this component.
0818: * @return The state, either, <CODE>SHUTDOWN</CODE>, <CODE>STARTED</CODE>,
0819: * or <CODE>STOPPED</CODE>.
0820: */
0821: public ComponentState getDesiredState() {
0822: return mDesiredState;
0823: }
0824:
0825: /**
0826: * Get the JMX ObjectName for the bootstrap extension MBean.
0827: * @return The ObjectName if the MBean is registered, null if not.
0828: */
0829: public javax.management.ObjectName getExtensionMBeanName() {
0830: return mExtensionMBeanName;
0831: }
0832:
0833: /**
0834: * Get the JMX ObjectName for the Installer MBean.
0835: * @return The ObjectName if the MBean is registered, null if not.
0836: */
0837: public javax.management.ObjectName getInstallerMBeanName() {
0838: return mInstallerMBeanName;
0839: }
0840:
0841: /**
0842: * Get the root installation directory for this BC or SE.
0843: * @return The component installation root directory.
0844: */
0845: public String getInstallRoot() {
0846: return mInstallRoot;
0847: }
0848:
0849: /**
0850: * Get an instance of the life cycle class for this BC or SE. This method
0851: * can create a new instance if necessary. This is controlled by the
0852: * <CODE>canCreate</CODE> parameter. If the value of <CODE>canCreate</CODE>
0853: * is <code>true</CODE>, then if there is no instance of the life cycle
0854: * class a new one is created. In this case, the return value is guaranteed
0855: * to be non-null. If the value of <CODE>canCreate</CODE> is <CODE>false</CODE>,
0856: * then a new instance of the life cycle class is never created. In this
0857: * case, the return value can be null if there is no life cycle instance.
0858: * @param canCreate is true if a new instance of the life cycle class can
0859: * be created if one does not already exist, and false if no new instance
0860: * can be created.
0861: * @return The life cycle class instance.
0862: * @throws javax.jbi.JBIException if the class cannot be loaded.
0863: */
0864: public javax.jbi.component.ComponentLifeCycle getLifeCycleInstance(
0865: boolean canCreate) throws javax.jbi.JBIException {
0866: if (canCreate) {
0867: // Create a new instance if one is not already present.
0868: if (null == mComponentInstance) {
0869: ClassLoader cl;
0870: Object o;
0871: try {
0872: cl = ClassLoaderFactory.getInstance()
0873: .createComponentClassLoader(this );
0874: o = cl.loadClass(mComponentClassName).newInstance();
0875: if (o instanceof javax.jbi.component.Component) {
0876: mComponentInstance = (javax.jbi.component.Component) o;
0877: } else {
0878: String msg = mTranslator.getString(
0879: LocalStringKeys.COMP_CLASS_NOT_VALID,
0880: mComponentClassName,
0881: "javax.jbi.component.Component");
0882: throw new javax.jbi.JBIException(msg);
0883: }
0884: mLifeCycleInstance = mComponentInstance
0885: .getLifeCycle();
0886: if (null == mLifeCycleInstance) {
0887: String msg = mTranslator
0888: .getString(
0889: LocalStringKeys.COMP_INSTANCE_NOT_PROVIDED,
0890: "getLifeCycle()",
0891: "javax.jbi.component.ComponentLifeCycle");
0892: throw new javax.jbi.JBIException(msg);
0893: }
0894: } catch (javax.jbi.JBIException jbiEx) {
0895: throw new javax.jbi.JBIException(
0896: mTranslator
0897: .getString(
0898: LocalStringKeys.COMP_LIFECYCLE_LOAD_FAILED,
0899: mName, jbiEx.getMessage()));
0900: } catch (ClassNotFoundException cnfEx) {
0901: String msg = mTranslator.getString(
0902: LocalStringKeys.COMP_CLASS_NOT_FOUND, cnfEx
0903: .getMessage());
0904: if (null != cnfEx.getCause()) {
0905: mLog.log(Level.WARNING, msg, cnfEx.getCause());
0906: throw new javax.jbi.JBIException(
0907: mTranslator
0908: .getString(
0909: LocalStringKeys.COMP_LIFECYCLE_LOAD_FAILED,
0910: mName, msg), cnfEx
0911: .getCause());
0912:
0913: } else {
0914: throw new javax.jbi.JBIException(
0915: mTranslator
0916: .getString(
0917: LocalStringKeys.COMP_LIFECYCLE_LOAD_FAILED,
0918: mName, msg));
0919: }
0920: } catch (NoClassDefFoundError ncdfEx) {
0921: String msg = mTranslator.getString(
0922: LocalStringKeys.COMP_CLASS_NOT_FOUND,
0923: ncdfEx.getMessage());
0924: if (null != ncdfEx.getCause()) {
0925: mLog.log(Level.WARNING, msg, ncdfEx.getCause());
0926: throw new javax.jbi.JBIException(
0927: mTranslator
0928: .getString(
0929: LocalStringKeys.COMP_LIFECYCLE_LOAD_FAILED,
0930: mName, msg), ncdfEx
0931: .getCause());
0932: } else {
0933: throw new javax.jbi.JBIException(
0934: mTranslator
0935: .getString(
0936: LocalStringKeys.COMP_LIFECYCLE_LOAD_FAILED,
0937: mName, msg));
0938: }
0939: } catch (Throwable ex) {
0940: String msg = mTranslator.getString(
0941: LocalStringKeys.COMP_EXCEPTION, ex
0942: .getClass().getName());
0943: mLog.log(Level.WARNING, msg, ex);
0944: throw new javax.jbi.JBIException(
0945: mTranslator
0946: .getString(
0947: LocalStringKeys.COMP_LIFECYCLE_LOAD_FAILED,
0948: mName, msg), ex);
0949: }
0950: }
0951: }
0952: if (null != mComponentInstance) {
0953: return mLifeCycleInstance;
0954: } else {
0955: return null;
0956: }
0957: }
0958:
0959: /**
0960: * Get the JMX ObjectName for the LifeCycle MBean.
0961: * @return The ObjectName if the MBean is registered, null if not.
0962: */
0963: public javax.management.ObjectName getLifeCycleMBeanName() {
0964: return mLifeCycleMBeanName;
0965: }
0966:
0967: /**
0968: * Get the logger MBean instance.
0969: * @return the ComponentLogger object.
0970: */
0971: public ComponentLogger getLoggerInstance() {
0972: return mLoggerInstance;
0973: }
0974:
0975: /**
0976: * Get the JMX ObjectNames for the logger MBean.
0977: * @return the LoggerMBean object name.
0978: */
0979: public javax.management.ObjectName getLoggerMBeanName() {
0980: return mLoggerMBeanName;
0981: }
0982:
0983: /**
0984: * Get the unique name for this BC or SE.
0985: * @return The name.
0986: */
0987: public String getName() {
0988: return mName;
0989: }
0990:
0991: /**
0992: * Get the ServiceUnit object for a specified Service Unit name. If none
0993: * is found, return null.
0994: * @param serviceUnitName The unique name of the Service Unit.
0995: * @return The Service Unit or null if not found.
0996: */
0997: public ServiceUnit getServiceUnit(String serviceUnitName) {
0998: return (ServiceUnit) mServiceUnitList.get(serviceUnitName);
0999: }
1000:
1001: /**
1002: * Get the list of ServiceUnit objects representing all Service Units
1003: * currently deployed to this BC or SE.
1004: * @return A list of the ServiceUnit objects.
1005: */
1006: public List<com.sun.jbi.ServiceUnitInfo> getServiceUnitList() {
1007: return new ArrayList(mServiceUnitList.values());
1008: }
1009:
1010: /**
1011: * Get the ServiceUnitManager instance for this component, if one is
1012: * available.
1013: * @return the Service Unit Manager or null if there is none.
1014: */
1015: public javax.jbi.component.ServiceUnitManager getServiceUnitManager() {
1016: if (null == mSUManagerInstance) {
1017: if (null != mComponentInstance) {
1018: mSUManagerInstance = mComponentInstance
1019: .getServiceUnitManager();
1020: }
1021: }
1022: return mSUManagerInstance;
1023: }
1024:
1025: /**
1026: * Get the list of Shared Library names required by this BC or SE.
1027: * @return A list of the Shared Library names as strings.
1028: */
1029: public List<String> getSharedLibraryNames() {
1030: return mSharedLibraryNames;
1031: }
1032:
1033: /**
1034: * Get the instance of the statistics MBean. If there is none, return null.
1035: * @return Instance of com.sun.jbi.monitoring.ComponentStatisticsBase
1036: * or null if no instance is currently available.
1037: */
1038: public ComponentStatistics getStatisticsInstance() {
1039: return mStatisticsInstance;
1040: }
1041:
1042: /**
1043: * Get the JMX ObjectName for the statistics MBean.
1044: * @return The ObjectName if the MBean is registered, null if not.
1045: */
1046: public javax.management.ObjectName getStatisticsMBeanName() {
1047: return mStatisticsMBeanName;
1048: }
1049:
1050: /**
1051: * Get the status of this component.
1052: * @return The status, either <CODE>LOADED</CODE>, <CODE>SHUTDOWN</CODE>,
1053: * <CODE>STARTED</CODE>, or <CODE>STOPPED</CODE>.
1054: */
1055: public ComponentState getStatus() {
1056: return mComponentState;
1057: }
1058:
1059: /**
1060: * Get the status of this component as a string value.
1061: * @return The status as a string, either "loaded", "installed", "started",
1062: * or "stopped".
1063: */
1064: public String getStatusAsString() {
1065: return mComponentState.toString();
1066: }
1067:
1068: /**
1069: * Get a component state as a string value.
1070: * @param status A state, either <CODE>LOADED</CODE>, <CODE>SHUTDOWN</CODE>,
1071: * <CODE>STARTED</CODE>, or <CODE>STOPPED</CODE>.
1072: * @return The status as a string, either "loaded", "installed", "started",
1073: * or "stopped".
1074: */
1075: public String getStatusAsString(ComponentState status) {
1076: if (status == ComponentState.SHUTDOWN) {
1077: return mTranslator
1078: .getString(LocalStringKeys.COMP_STATE_SHUTDOWN);
1079: }
1080: if (status == ComponentState.LOADED) {
1081: return mTranslator
1082: .getString(LocalStringKeys.COMP_STATE_LOADED);
1083: }
1084: if (status == ComponentState.STARTED) {
1085: return mTranslator
1086: .getString(LocalStringKeys.COMP_STATE_STARTED);
1087: }
1088: if (status == ComponentState.STOPPED) {
1089: return mTranslator
1090: .getString(LocalStringKeys.COMP_STATE_STOPPED);
1091: }
1092: return mTranslator.getString(LocalStringKeys.UNKNOWN);
1093: }
1094:
1095: /**
1096: * Get the workspace root directory for this BC or SE.
1097: * @return The workspace root directory.
1098: */
1099: public String getWorkspaceRoot() {
1100: return mWorkspaceRoot;
1101: }
1102:
1103: /**
1104: * Get the installation descriptor (jbi.xml) for the component as a String.
1105: * @return the Installation Descriptor for the component.
1106: */
1107: public String getInstallationDescriptor() {
1108: return mJbiXmlString;
1109: }
1110:
1111: /**
1112: * Get the wrapped JAXB model for the installation descriptor (jbi.xml) for
1113: * the component.
1114: * @return the wrapped JAXB model for the installation descriptor.
1115: */
1116: public com.sun.jbi.management.descriptor.ComponentDescriptor getInstallationDescriptorModel() {
1117: if (null == mJbiXmlModel) {
1118: com.sun.jbi.management.registry.Registry reg = (com.sun.jbi.management.registry.Registry) EnvironmentContext
1119: .getInstance().getRegistry();
1120: if (null != reg) {
1121: try {
1122: mJbiXmlModel = reg.getGenericQuery()
1123: .getComponentDescriptor(mName);
1124: } catch (Throwable ex) {
1125: mLog.log(Level.FINE,
1126: "Unable to get installation descriptor for "
1127: + mName, ex);
1128: }
1129: }
1130: }
1131: return mJbiXmlModel;
1132: }
1133:
1134: /**
1135: * Get the hash code for this Component instance.
1136: * @return The hash code.
1137: */
1138: public int hashCode() {
1139: int hashCode = 0;
1140:
1141: hashCode += mName.hashCode();
1142: hashCode += mComponentType.hashCode();
1143: hashCode += mBootstrapClassName.hashCode();
1144: hashCode += mBootstrapClassPathElements.hashCode();
1145: hashCode += mComponentClassName.hashCode();
1146: hashCode += mComponentClassPathElements.hashCode();
1147: if (null != mSharedLibraryNames) {
1148: hashCode += mSharedLibraryNames.hashCode();
1149: }
1150:
1151: return hashCode;
1152: }
1153:
1154: /**
1155: * Check to see if this component is a BC.
1156: * @return True if the component is a BC, false if not.
1157: */
1158: public boolean isBinding() {
1159: return (mComponentType == ComponentType.BINDING);
1160: }
1161:
1162: /**
1163: * Check to see if this component is processing a life cycle request.
1164: * @return True if the component busy, false if not.
1165: */
1166: public boolean isBusy() {
1167: return mBusy;
1168: }
1169:
1170: /**
1171: * Check to see if the bootstrap cleanUp() method needs to be called.
1172: * @return true if the bootstrap cleanUp() method should be called, or
1173: * false if it has already been called.
1174: */
1175: public boolean isBootstrapCleanUpNeeded() {
1176: return mBootstrapCleanUpNeeded;
1177: }
1178:
1179: /**
1180: * Check to see if the bootstrap class loader should use a self-first
1181: * search hierarchy.
1182: * @return True if the bootstrap class loader should use a self-first
1183: * search hierarchy, false if it should use parent-first.
1184: */
1185: public boolean isBootstrapClassLoaderSelfFirst() {
1186: return mBootstrapClassLoaderSelfFirst;
1187: }
1188:
1189: /**
1190: * Check to see if the component class loader should use a self-first
1191: * search hierarchy.
1192: * @return True if the component class loader should use a self-first
1193: * search hierarchy, false if it should use parent-first.
1194: */
1195: public boolean isComponentClassLoaderSelfFirst() {
1196: return mComponentClassLoaderSelfFirst;
1197: }
1198:
1199: /**
1200: * Check to see if this component is a SE.
1201: * @return True if the component is a SE, false if not.
1202: */
1203: public boolean isEngine() {
1204: return (ComponentType.ENGINE == mComponentType);
1205: }
1206:
1207: /**
1208: * Check to see if this component is initialized.
1209: * @return True if the component is initialized, false if not.
1210: */
1211: public boolean isInitialized() {
1212: return (ComponentState.STOPPED == mComponentState);
1213: }
1214:
1215: /**
1216: * Check to see if this component is installed.
1217: * @return True if the component is installed, false if not.
1218: */
1219: public boolean isInstalled() {
1220: return (ComponentState.SHUTDOWN == mComponentState);
1221: }
1222:
1223: /**
1224: * Check to see if this component is loaded.
1225: * @return True if the component is loaded, false if not.
1226: */
1227: public boolean isLoaded() {
1228: return (ComponentState.LOADED == mComponentState);
1229: }
1230:
1231: /**
1232: * Check to see if this component is an NMR observer.
1233: * @return <code>true</code> if the component is an observer,
1234: * <code>false</code> if not.
1235: */
1236: public boolean isObserver() {
1237: if (null == mObserver) {
1238: setObserver(false);
1239: com.sun.jbi.management.descriptor.ComponentDescriptor cd = getInstallationDescriptorModel();
1240: if (null != cd) {
1241: org.w3c.dom.Element obs = cd.getComponentObserverXml();
1242: if (null != obs) {
1243: if (null != obs.getElementsByTagNameNS(OBSERVER_NS,
1244: OBSERVER_TAG)) {
1245: mLog.fine(mName + " is an NMR Observer");
1246: setObserver(true);
1247: }
1248: }
1249: }
1250: }
1251: return mObserver.booleanValue();
1252: }
1253:
1254: /**
1255: * Check to see if a Service Unit is registered to this component.
1256: * @param serviceUnitName the unique name of the Service Unit.
1257: * @return true if the Service Unit is registered, false if not.
1258: */
1259: public boolean isServiceUnitRegistered(String serviceUnitName) {
1260: return mServiceUnitList.containsKey(serviceUnitName);
1261: }
1262:
1263: /**
1264: * Check to see if this component is shut down.
1265: * @return True if the component is shut down, false if not.
1266: */
1267: public boolean isShutDown() {
1268: return (ComponentState.SHUTDOWN == mComponentState);
1269: }
1270:
1271: /**
1272: * Check to see if this component is started.
1273: * @return True if the component is started, false if not.
1274: */
1275: public boolean isStarted() {
1276: return (ComponentState.STARTED == mComponentState);
1277: }
1278:
1279: /**
1280: * Check to see if this component is in the process of starting.
1281: * @return True if the component is starting, false if not.
1282: public boolean isStarting()
1283: {
1284: return (ComponentState.STARTING == mComponentState);
1285: }
1286: */
1287:
1288: /**
1289: * Check to see if this component is stopped.
1290: * @return True if the component is stopped, false if not.
1291: */
1292: public boolean isStopped() {
1293: return (ComponentState.STOPPED == mComponentState);
1294: }
1295:
1296: /**
1297: * Check to see if this component is in the process of stopping.
1298: * @return True if the component is stopping, false if not.
1299: public boolean isStopping()
1300: {
1301: return (ComponentState.STOPPING == mComponentState);
1302: }
1303: */
1304:
1305: /**
1306: * Check to see if this component is being updated.
1307: * @return True if the component is being updated, false if not.
1308: */
1309: public boolean isUpdating() {
1310: return mUpdating;
1311: }
1312:
1313: /**
1314: * Remove a ServiceUnit object from the list of Service Units deployed to
1315: * this BC or SE.
1316: * @param serviceUnitName The name of the Service Unit.
1317: * @throws javax.jbi.JBIException if no service unit is found by the
1318: * specified name.
1319: */
1320: public void removeServiceUnit(String serviceUnitName)
1321: throws javax.jbi.JBIException {
1322: if (mServiceUnitList.containsKey(serviceUnitName)) {
1323: mServiceUnitList.remove(serviceUnitName);
1324: } else {
1325: String msg = mTranslator.getString(
1326: LocalStringKeys.SU_NOT_FOUND, serviceUnitName,
1327: getComponentTypeAsString(), getName());
1328: throw new javax.jbi.JBIException(msg);
1329: }
1330: }
1331:
1332: /**
1333: * Set the flag that indicates whether the bootstrap cleanUp() method needs
1334: * to be called.
1335: * @param isCleanUpNeeded true if the bootstrap cleanUp() method should be
1336: * called, or false if it has already been called.
1337: */
1338: public void setBootstrapCleanUpNeeded(boolean isCleanUpNeeded) {
1339: mBootstrapCleanUpNeeded = isCleanUpNeeded;
1340: }
1341:
1342: /**
1343: * Set the flag that determines the hierarchy for the bootstrap class loader
1344: * which is true for self-first or false for parent-first.
1345: * @param isSelfFirst is true for a self-first class loading hierarchy, or
1346: * false for a parent-first hierarchy.
1347: */
1348: public void setBootstrapClassLoaderSelfFirst(boolean isSelfFirst) {
1349: mBootstrapClassLoaderSelfFirst = isSelfFirst;
1350: }
1351:
1352: /**
1353: * Set the class name of the bootstrap implementation for this
1354: * BC or SE.
1355: * @param className The bootstrap class name.
1356: */
1357: public void setBootstrapClassName(String className) {
1358: mBootstrapClassName = className;
1359: }
1360:
1361: /**
1362: * Set the class path elements for the bootstrap implementation for this
1363: * BC or SE.
1364: * @param classPathElements The list of class path elements as strings.
1365: */
1366: public void setBootstrapClassPathElements(List classPathElements) {
1367: mBootstrapClassPathElements = new ArrayList(classPathElements);
1368: }
1369:
1370: /**
1371: * Set the flag indicating the component is busy processing a life cycle
1372: * operation. This method is synchronized so that the flag can be set by
1373: * only one caller at any time. If the flag is already set, an exception
1374: * is thrown indicating that an operation is already in progress on the
1375: * component.
1376: *
1377: * @throws javax.jbi.JBIException when the component is already busy.
1378: */
1379: public synchronized void setBusy() throws javax.jbi.JBIException {
1380: if (mBusy) {
1381: throw new javax.jbi.JBIException(mTranslator.getString(
1382: LocalStringKeys.COMP_BUSY, mName));
1383: }
1384: mBusy = true;
1385: }
1386:
1387: /**
1388: * Set the flag indicating the component is busy processing a life cycle
1389: * operation. This method is used only when processing a forced shutdown
1390: * of the component. No checking is done for the busy flag already being
1391: * set. Do NOT use this method for any purpose other than during a forced
1392: * shutdown of the component, or the results will be unpredictable.
1393: */
1394: public void setBusyForce() {
1395: mBusy = true;
1396: }
1397:
1398: /**
1399: * Set the flag that determines the hierarchy for the component class loader
1400: * which is true for self-first or false for parent-first.
1401: * @param isSelfFirst is true for a self-first class loading hierarchy, or
1402: * false for a parent-first hierarchy.
1403: */
1404: public void setComponentClassLoaderSelfFirst(boolean isSelfFirst) {
1405: mComponentClassLoaderSelfFirst = isSelfFirst;
1406: }
1407:
1408: /**
1409: * Set the root installation directory for this BC or SE.
1410: * @param installRoot The component's install root directory.
1411: */
1412: public void setInstallRoot(String installRoot) {
1413: if (null != installRoot) {
1414: mInstallRoot = installRoot.replace('\\', '/');
1415: } else {
1416: mInstallRoot = installRoot;
1417: }
1418: }
1419:
1420: /**
1421: * Set the component type.
1422: * @param type The component type.
1423: */
1424: public void setComponentType(ComponentType type) {
1425: mComponentType = type;
1426: }
1427:
1428: /**
1429: * Set the component type for a BC.
1430: */
1431: public void setComponentTypeBinding() {
1432: mComponentType = ComponentType.BINDING;
1433: }
1434:
1435: /**
1436: * Set the component type for a SE.
1437: */
1438: public void setComponentTypeEngine() {
1439: mComponentType = ComponentType.ENGINE;
1440: }
1441:
1442: /**
1443: * Set the component's Deployer instance.
1444: * @param deployer the instance of Deployer for the component.
1445: */
1446: public void setDeployerInstance(Deployer deployer) {
1447: mDeployerInstance = deployer;
1448: }
1449:
1450: /**
1451: * Set the desired state of a component.
1452: * @param state The desired state to be set.
1453: * Valid states are <CODE>SHUTDOWN</CODE>, <CODE>STOPPED</CODE>, and
1454: * <CODE>STARTED</CODE>.
1455: */
1456: public void setDesiredState(ComponentState state) {
1457: if (ComponentState.SHUTDOWN != state
1458: && ComponentState.STOPPED != state
1459: && ComponentState.STARTED != state) {
1460: throw new java.lang.IllegalArgumentException(mTranslator
1461: .getString(LocalStringKeys.INVALID_ARGUMENT,
1462: "state", state.toString()));
1463: }
1464: mDesiredState = state;
1465: }
1466:
1467: /**
1468: * Set the component state. This method is used ONLY by startup and unit
1469: * test code. It does no validation of the state.
1470: * @param status The ComponentState to be set.
1471: * Valid states are <CODE>LOADED</CODE>, <CODE>SHUTDOWN</CODE>,
1472: * <CODE>STOPPED</CODE>, and <CODE>STARTED</CODE>.
1473: */
1474: public void setStatus(ComponentState status) {
1475: mComponentState = status;
1476: }
1477:
1478: /**
1479: * Set the component state to loaded. The only time a component can be in
1480: * this state is when its bootstrap class is loaded for an install or an
1481: * uninstall that has not yet completed.
1482: */
1483: public void setLoaded() {
1484: if (isStopped()) {
1485: throw new java.lang.IllegalStateException(
1486: mTranslator
1487: .getString(
1488: LocalStringKeys.COMP_INVALID_STATE_CHANGE,
1489: mTranslator
1490: .getString(LocalStringKeys.COMP_STATE_STOPPED),
1491: mTranslator
1492: .getString(LocalStringKeys.COMP_STATE_LOADED)));
1493: }
1494: if (isStarted()) {
1495: throw new java.lang.IllegalStateException(
1496: mTranslator
1497: .getString(
1498: LocalStringKeys.COMP_INVALID_STATE_CHANGE,
1499: mTranslator
1500: .getString(LocalStringKeys.COMP_STATE_STARTED),
1501: mTranslator
1502: .getString(LocalStringKeys.COMP_STATE_LOADED)));
1503: }
1504:
1505: mComponentState = ComponentState.LOADED;
1506: }
1507:
1508: /**
1509: * Set the class name of the Component implementation for this component.
1510: * @param className The life cycle class name.
1511: */
1512: public void setComponentClassName(String className) {
1513: if (null != className) {
1514: mComponentClassName = className;
1515: }
1516: }
1517:
1518: /**
1519: * Set the class instance of the Component implementation for this BC or SE.
1520: * @param classInstance The Component class instance.
1521: */
1522: public void setComponentInstance(
1523: javax.jbi.component.Component classInstance) {
1524: if (null != classInstance) {
1525: mComponentInstance = classInstance;
1526: mLifeCycleInstance = classInstance.getLifeCycle();
1527: }
1528: }
1529:
1530: /**
1531: * Set the class path elements that this BC or SE needs in its runtime
1532: * environment.
1533: * @param classPathElements A list containing the class path elements as
1534: * strings.
1535: */
1536: public void setComponentClassPathElements(List classPathElements) {
1537: if (null != classPathElements) {
1538: mComponentClassPathElements = new ArrayList(
1539: classPathElements);
1540: }
1541: }
1542:
1543: /**
1544: * Set the JMX ObjectName for the component configuration Dynamic MBean.
1545: * @param objectName The JMX ObjectName of the component configuration
1546: * Dynamic MBean.
1547: */
1548: public void setConfigurationMBeanName(
1549: javax.management.ObjectName objectName) {
1550: mConfigMBeanName = objectName;
1551: }
1552:
1553: /**
1554: * Set the ComponentContext for this BC or SE.
1555: * @param context The componet's context.
1556: */
1557: public void setContext(ComponentContext context) {
1558: mContext = context;
1559: }
1560:
1561: /**
1562: * Set the description of this BC or SE.
1563: * @param description The description.
1564: */
1565: public void setDescription(String description) {
1566: mDescription = description;
1567: }
1568:
1569: /**
1570: * Set the JMX ObjectName for the DeployerMBean.
1571: * @param objectName The JMX ObjectName of the DeployerMBean.
1572: */
1573: public void setDeployerMBeanName(
1574: javax.management.ObjectName objectName) {
1575: mDeployerMBeanName = objectName;
1576: }
1577:
1578: /**
1579: * Set the JMX ObjectName for the bootstrap ExtensionMBean.
1580: * @param objectName The JMX ObjectName of the ExtensionMBean.
1581: */
1582: public void setExtensionMBeanName(
1583: javax.management.ObjectName objectName) {
1584: mExtensionMBeanName = objectName;
1585: }
1586:
1587: /**
1588: * Set the JMX ObjectName for the InstallerMBean.
1589: * @param objectName The JMX ObjectName of the InstallerMBean.
1590: */
1591: public void setInstallerMBeanName(
1592: javax.management.ObjectName objectName) {
1593: mInstallerMBeanName = objectName;
1594: }
1595:
1596: /**
1597: * Set the JMX ObjectName for the LifeCycleMBean.
1598: * @param objectName The JMX ObjectName of the LifeCycleMBean.
1599: */
1600: public void setLifeCycleMBeanName(
1601: javax.management.ObjectName objectName) {
1602: mLifeCycleMBeanName = objectName;
1603: }
1604:
1605: /**
1606: * Set the ComponentLoggerMBean instance for this component.
1607: * @param instance The ComponentLogger instance.
1608: */
1609: public void setLoggerInstance(ComponentLogger instance) {
1610: mLoggerInstance = instance;
1611: }
1612:
1613: /**
1614: * Set the LoggerMBean ObjectName for this component.
1615: * @param objectName The ObjectName for the logger MBean.
1616: */
1617: public void setLoggerMBeanName(
1618: javax.management.ObjectName objectName) {
1619: mLoggerMBeanName = objectName;
1620: }
1621:
1622: /**
1623: * Set the name for this BC or SE.
1624: * @param name The name.
1625: */
1626: public void setName(String name) {
1627: mName = name;
1628: }
1629:
1630: /**
1631: * Set the observer flag for this component. This flag indicates whether
1632: * the component is an NMR observer.
1633: * @param isObserver <code>true</code> indicates that the component is an
1634: * NMR observer, <code>false</code> indicates that it is not.
1635: */
1636: public void setObserver(boolean isObserver) {
1637: mObserver = Boolean.valueOf(isObserver);
1638: }
1639:
1640: /**
1641: * Set the list of Shared Library names required by this BC or SE.
1642: * The names must be in the list in the order in which the Shared
1643: * Libraries should appear in the class path.
1644: * @param nameList A list containing the names as Strings.
1645: */
1646: public void setSharedLibraryNames(List<String> nameList) {
1647: if (null != nameList) {
1648: mSharedLibraryNames = new ArrayList(nameList);
1649: }
1650: }
1651:
1652: /**
1653: * Set the component state to shutdown (installed but not active).
1654: */
1655: public void setShutdown() {
1656: // If this is an install, clear the reference to the bootstrap
1657: // instance so that it can be garbage-collected.
1658:
1659: if (isLoaded()) {
1660: mBootstrapInstance = null;
1661: }
1662:
1663: // If the component is running it cannot be set to shutdown, only
1664: // to stopped.
1665:
1666: else if (isStarted()) {
1667: throw new java.lang.IllegalStateException(
1668: mTranslator
1669: .getString(
1670: LocalStringKeys.COMP_INVALID_STATE_CHANGE,
1671: mTranslator
1672: .getString(LocalStringKeys.COMP_STATE_STARTED),
1673: mTranslator
1674: .getString(LocalStringKeys.COMP_STATE_SHUTDOWN)));
1675: }
1676:
1677: // If this is a shutdown of a component, clear the reference to the
1678: // life cycle instance so that it can be garbage-collected.
1679:
1680: else if (isStopped()) {
1681: mComponentInstance = null;
1682: }
1683:
1684: mComponentState = ComponentState.SHUTDOWN;
1685: }
1686:
1687: /**
1688: * Set the component state to shutting down.
1689: public void setShuttingDown()
1690: {
1691: mComponentState = ComponentState.SHUTTINGDOWN;
1692: }
1693: */
1694:
1695: /**
1696: * Set the component state to started.
1697: */
1698: public void setStarted() {
1699: if (isLoaded()) {
1700: throw new java.lang.IllegalStateException(
1701: mTranslator
1702: .getString(
1703: LocalStringKeys.COMP_INVALID_STATE_CHANGE,
1704: mTranslator
1705: .getString(LocalStringKeys.COMP_STATE_LOADED),
1706: mTranslator
1707: .getString(LocalStringKeys.COMP_STATE_STARTED)));
1708: }
1709: if (isShutDown()) {
1710: throw new java.lang.IllegalStateException(
1711: mTranslator
1712: .getString(
1713: LocalStringKeys.COMP_INVALID_STATE_CHANGE,
1714: mTranslator
1715: .getString(LocalStringKeys.COMP_STATE_SHUTDOWN),
1716: mTranslator
1717: .getString(LocalStringKeys.COMP_STATE_STARTED)));
1718: }
1719:
1720: mComponentState = ComponentState.STARTED;
1721: }
1722:
1723: /**
1724: * Set the component state to starting.
1725: public void setStarting()
1726: {
1727: mComponentState = ComponentState.STARTING;
1728: }
1729: */
1730:
1731: /**
1732: * Set the instance of ComponentStatistics for this BC or SE.
1733: * @param classInstance The ComponentStatistics instance.
1734: */
1735: public void setStatisticsInstance(ComponentStatistics classInstance) {
1736: if (null != classInstance) {
1737: mStatisticsInstance = classInstance;
1738: }
1739: }
1740:
1741: /**
1742: * Set the JMX ObjectName for the StatisticsMBean.
1743: * @param objectName The JMX ObjectName of the StatisticsMBean.
1744: */
1745: public void setStatisticsMBeanName(
1746: javax.management.ObjectName objectName) {
1747: mStatisticsMBeanName = objectName;
1748: }
1749:
1750: /**
1751: * Set the component state to stopped.
1752: */
1753: public void setStopped() {
1754: if (isLoaded()) {
1755: throw new java.lang.IllegalStateException(
1756: mTranslator
1757: .getString(
1758: LocalStringKeys.COMP_INVALID_STATE_CHANGE,
1759: mTranslator
1760: .getString(LocalStringKeys.COMP_STATE_LOADED),
1761: mTranslator
1762: .getString(LocalStringKeys.COMP_STATE_STOPPED)));
1763: }
1764:
1765: mComponentState = ComponentState.STOPPED;
1766: }
1767:
1768: /**
1769: * Set the component state to stopping.
1770: public void setStopping()
1771: {
1772: mComponentState = ComponentState.STOPPING;
1773: }
1774: */
1775:
1776: /**
1777: * Set the <code>Updating</code> flag indicating the component is being
1778: * updated. This requires first setting the <code>Busy</code> flag to prevent
1779: * any life cycle operations from being processed for the component while
1780: * it is being updated. If the <code>Busy</code> flag is already set, this
1781: * means that a life cycle operation is in progress and the update cannot
1782: * proceed. In this case an exception is thrown.
1783: */
1784: public void setUpdating() throws javax.jbi.JBIException {
1785: setBusy(); // throws exception if already busy
1786: mUpdating = true;
1787: }
1788:
1789: /**
1790: * Set the workspace root directory for this BC or SE.
1791: * @param workspaceRoot The component workspace root directory.
1792: */
1793: public void setWorkspaceRoot(String workspaceRoot) {
1794: if (null != workspaceRoot) {
1795: mWorkspaceRoot = workspaceRoot.replace('\\', '/');
1796: } else {
1797: mWorkspaceRoot = workspaceRoot;
1798: }
1799: }
1800:
1801: /**
1802: * Set the installation descriptor for this component.
1803: * @param jbiXml - the string representation of the installation descriptor
1804: * for this Component
1805: */
1806: public void setInstallationDescriptor(String jbiXml) {
1807: mJbiXmlString = jbiXml;
1808: }
1809:
1810: /**
1811: * Convert to a String.
1812: * @return The String representation of this Component.
1813: */
1814: public String toString() {
1815: String sep = ",\n";
1816: StringBuffer b = new StringBuffer();
1817: b.append("Component Name = " + mName);
1818: b.append(sep);
1819: b.append("ComponentType = " + mComponentType.toString());
1820: b.append(" (" + getComponentTypeAsString() + ")");
1821: b.append(sep);
1822: b.append("Description = "
1823: + (null != mDescription ? mDescription : ""));
1824: b.append(sep);
1825: b.append("State = " + mComponentState);
1826: b.append(" (" + getStatusAsString(mComponentState) + ")");
1827: b.append(sep);
1828: b.append("Desired State = " + mDesiredState.toString());
1829: b.append(" (" + mDesiredState.toString() + ")");
1830: b.append(sep);
1831: b.append("InstallRoot = "
1832: + (null != mInstallRoot ? mInstallRoot : ""));
1833: b.append(sep);
1834: b.append("WorkspaceRoot = "
1835: + (null != mWorkspaceRoot ? mWorkspaceRoot : ""));
1836: b.append(sep);
1837: b.append("BootstrapClassName = "
1838: + (null != mBootstrapClassName ? mBootstrapClassName
1839: : ""));
1840: b.append(sep);
1841: b
1842: .append("BootstrapClassPathElements = "
1843: + (null != mBootstrapClassPathElements ? mBootstrapClassPathElements
1844: : new ArrayList()));
1845: b.append(sep);
1846: b.append("BootstrapClassLoaderSelfFirst = "
1847: + mBootstrapClassLoaderSelfFirst);
1848: b.append(sep);
1849: b.append("ComponentClassName = "
1850: + (null != mComponentClassName ? mComponentClassName
1851: : ""));
1852: b.append(sep);
1853: b
1854: .append("ComponentClassPathElements = "
1855: + (null != mComponentClassPathElements ? mComponentClassPathElements
1856: : new ArrayList()));
1857: b.append(sep);
1858: b.append("ComponentClassLoaderSelfFirst = "
1859: + mComponentClassLoaderSelfFirst);
1860: b.append(sep);
1861: b.append("ServiceUnitList = "
1862: + (null != mServiceUnitList ? mServiceUnitList
1863: : new Hashtable()));
1864: b.append(sep);
1865: b.append("SharedLibraryNames = "
1866: + (null != mSharedLibraryNames ? mSharedLibraryNames
1867: : new ArrayList()));
1868: return b.toString();
1869: }
1870:
1871: /**
1872: * Return an indication of whether the class loaders for this component
1873: * should use the self-first hierarchy.
1874: * @return true/false depending on the value of the ClassLoaderSelfFirst
1875: * attribute.
1876: */
1877: public boolean isClassLoaderSelfFirst() {
1878: return mComponentClassLoaderSelfFirst;
1879: }
1880:
1881: /**
1882: * Get the component properties. TODO
1883: * @return the component properties
1884: */
1885: public Map getProperties() {
1886: return new HashMap();
1887: }
1888: }
|