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: * @(#)ConfigurableComponent.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package deploytest;
030:
031: import java.util.logging.Logger;
032:
033: import javax.jbi.component.ComponentContext;
034: import javax.management.ObjectName;
035: import java.io.File;
036:
037: /**
038: * ConfigurableComponent is used to test configuration of a component installer.
039: *
040: * @author Sun Microsystems, Inc.
041: */
042: public class ConfigurableComponent extends BindingComponent implements
043: ConfigurableComponentMBean {
044: private ComponentContext mContext;
045: private ObjectName mConfigMBean;
046: private File mConfigFile;
047:
048: /** If specified, file is created in this directory. */
049: private String mWorkDirectory;
050: /** Name of the file to be created. */
051: private String mFileName;
052:
053: /** ################ ConfigurationMBean methods ################ **/
054:
055: /** Sets the work directory for the config MBean.
056: * @path absolute path to the work directory
057: */
058: public void setWorkDirectory(String path) {
059: mWorkDirectory = path;
060: }
061:
062: /** Returns the absolute path to the installer work directory.
063: * @return absolute path to the work directory, or null if it has not been set.
064: */
065: public String getWorkDirectory() {
066: return mWorkDirectory;
067: }
068:
069: /** Specifies the name of the file to create on install.
070: * @fileName file name
071: */
072: public void setFileName(String fileName) {
073: mFileName = fileName;
074: }
075:
076: /** Returns the name of the file to create on install.
077: * @return file name
078: */
079: public String getFileName() {
080: return mFileName;
081: }
082:
083: /** ###################### 208 SPI methods ###################### **/
084:
085: /** Install the component. Creates a new file with the appropriate
086: */
087: public void onInstall() throws javax.jbi.JBIException {
088: File dir = new File(mWorkDirectory != null ? mWorkDirectory
089: : mContext.getWorkspaceRoot());
090: mConfigFile = new File(dir, mFileName);
091:
092: try {
093: mConfigFile.createNewFile();
094:
095: if (mContext.getMBeanServer().isRegistered(mConfigMBean)) {
096: mContext.getMBeanServer().unregisterMBean(mConfigMBean);
097: }
098: } catch (Exception ex) {
099: throw new javax.jbi.JBIException(ex.toString());
100: }
101: }
102:
103: /** Uninstalls the component. Removes the config file, if present.
104: */
105: public void onUninstall() throws javax.jbi.JBIException {
106: if (mConfigFile != null) {
107: mConfigFile.delete();
108: }
109: }
110:
111: /** Initialize the component installer.
112: */
113: public void init(
114: javax.jbi.component.InstallationContext installationContext)
115: throws javax.jbi.JBIException {
116: mContext = installationContext.getContext();
117: mConfigMBean = mContext.getMBeanNames()
118: .createCustomComponentMBeanName("myconfig");
119:
120: try {
121: // Clean up just in case a prior run did not complete
122: if (mContext.getMBeanServer().isRegistered(mConfigMBean)) {
123: mContext.getMBeanServer().unregisterMBean(mConfigMBean);
124: }
125:
126: mContext.getMBeanServer().registerMBean(this , mConfigMBean);
127: } catch (Exception ex) {
128: throw new javax.jbi.JBIException(ex.toString());
129: }
130: }
131:
132: /**
133: * Get the JMX ObjectName for any additional MBean for this BC. This
134: * implementation always returns null.
135: * @return javax.management.ObjectName is always null.
136: */
137: public javax.management.ObjectName getExtensionMBeanName() {
138: return mConfigMBean;
139: }
140: }
|