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: * @(#)Engine4Installer.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.ui.cli.test.engine4.boot;
030:
031: import javax.jbi.component.Bootstrap;
032: import javax.jbi.component.InstallationContext;
033: import java.util.logging.Logger;
034: import javax.jbi.JBIException;
035: import javax.jbi.management.MBeanNames;
036: import javax.management.MBeanServer;
037: import javax.management.ObjectName;
038: import javax.management.StandardMBean;
039:
040: /**
041: * Class to install the engine.
042: *
043: * @author Sun Microsystems, Inc.
044: */
045: public class Engine4Installer implements Bootstrap {
046:
047: /**
048: * Internal handle to the logger instance
049: */
050: private Logger mLogger;
051: /** fix it */
052: private ObjectName mConfigMBeanName;
053: /** fix it */
054: private ConfigMBean mConfigMBean;
055: /**
056: * fix it
057: */
058: private InstallationContext mContext;
059:
060: /**
061: * Creates a new instance of StockQuoteEngineBootstrap
062: */
063: public Engine4Installer() {
064: mLogger = Logger
065: .getLogger("com.sun.jbi.ui.cli.test.engine4.boot");
066: mLogger.info("Engine4Installer Constructor called");
067: }
068:
069: /**
070: * Cleans up any resources allocated by the bootstrap implementation,
071: * including deregistration of the extension MBean, if applicable.
072: * This method will be called after the onInstall() or onUninstall() method
073: * is called, whether it succeeds or fails.
074: * @throws javax.jbi.JBIException when cleanup processing fails to complete
075: * successfully.
076: */
077: public void cleanUp() throws javax.jbi.JBIException {
078: deregisterConfigMBean();
079: }
080:
081: /**
082: * Called to initialize the BC bootstrap.
083: * @param installContext is the context containing information
084: * from the install command and from the BC jar file.
085: * @throws javax.jbi.JBIException when there is an error requiring that
086: * the installation be terminated.
087: */
088: public void init(InstallationContext installContext)
089: throws javax.jbi.JBIException {
090: mLogger.info("Engine4Installer INIT Called");
091: this .mContext = installContext;
092: // throw JBIException("Test Error on Engine4Installer init");
093: registerConfigMBean();
094: return;
095: }
096:
097: /**
098: * Get the JMX ObjectName for the optional installation configuration MBean
099: * for this BC. If there is none, the value is null.
100: * @return ObjectName the JMX object name of the installation configuration
101: * MBean or null if there is no MBean.
102: */
103: public javax.management.ObjectName getExtensionMBeanName() {
104: mLogger.info("Engine4Installer getExtensionMBeanName Called");
105: return this .mConfigMBeanName;
106: }
107:
108: /**
109: * Called at the beginning of installation of BPEL Engine. For this
110: * Engine, all the required installation tasks have been taken care
111: * by the InstallationService.
112: * @throws javax.jbi.JBIException when there is an error requiring that
113: * the installation be terminated.
114: */
115: public void onInstall() throws javax.jbi.JBIException {
116: mLogger.info("Engine4Installer onInstall Called.");
117:
118: }
119:
120: /**
121: * Called at the beginning of uninstallation of FileEngine . For this
122: * file engine, all the required uninstallation tasks have been taken care
123: * of by the InstallationService
124: * @throws javax.jbi.JBIException when there is an error requiring that
125: * the uninstallation be terminated.
126: */
127: public void onUninstall() throws javax.jbi.JBIException {
128: mLogger.info("*** Engine4Installer onUninstall Called");
129: // throw new JBIException("Test Error Engine4Installer on UnInstall");
130: }
131:
132: /**
133: * fix it
134: * @throws JBIException fix it
135: */
136: public void createConfigMBean() throws JBIException {
137: try {
138: if (this .mConfigMBean == null) {
139: this .mConfigMBean = new ConfigMBeanImpl();
140: }
141:
142: if (this .mConfigMBeanName == null) {
143: MBeanNames mbnHndl = this .mContext.getContext()
144: .getMBeanNames();
145:
146: this .mConfigMBeanName = mbnHndl
147: .createCustomComponentMBeanName("InstallerConfig");
148: }
149: } catch (Exception e) {
150: e.printStackTrace();
151: throw new JBIException(
152: "cli Test Engine4 Installer ConfigurationMBean Creation Failed",
153: e);
154: }
155: }
156:
157: /**
158: * fix it
159: * @throws JBIException fix it
160: */
161: public void registerConfigMBean() throws JBIException {
162: createConfigMBean(); // make sure it is created.
163:
164: try {
165: MBeanServer mbServer = this .mContext.getContext()
166: .getMBeanServer();
167: StandardMBean configBean = new StandardMBean(
168: this .mConfigMBean, ConfigMBean.class);
169: mbServer.registerMBean(configBean, this .mConfigMBeanName);
170: } catch (Exception e) {
171: e.printStackTrace();
172: throw new JBIException(
173: "cli Test Engine4 Installer Config MBean Registration Failed",
174: e);
175: }
176:
177: }
178:
179: /**
180: * fix it
181: * @throws JBIException fix it
182: */
183: public void deregisterConfigMBean() throws JBIException {
184: if (this .mConfigMBeanName == null) {
185: this .mLogger
186: .warning("trying to unregister null Installer Config MBean in cli Test Engine 2 inst");
187: }
188:
189: try {
190: MBeanServer mbServer = this .mContext.getContext()
191: .getMBeanServer();
192: mbServer.unregisterMBean(this .mConfigMBeanName);
193: this .mConfigMBeanName = null;
194: this .mConfigMBean = null;
195: } catch (Exception e) {
196: e.printStackTrace();
197: throw new JBIException("cli Test Engine4"
198: + "Installer Config MBean Deregistration Failed", e);
199: }
200:
201: }
202:
203: public interface ConfigMBean {
204: public void setUser(String user);
205:
206: public String getUser();
207:
208: public void setPort(String port);
209:
210: public String getPort();
211:
212: public void setIntValue(int intValue);
213:
214: public int getIntValue();
215:
216: public void setIntegerValue(Integer integerValue);
217:
218: public Integer getIntegerValue();
219: }
220:
221: public class ConfigMBeanImpl implements ConfigMBean {
222: private String mUser;
223: private String mPort;
224: private int mIntValue;
225: private Integer mIntegerValue;
226:
227: public String getUser() {
228: return mUser;
229: }
230:
231: public void setUser(String user) {
232: System.out
233: .println("Setting the ConfigMBean attribute \"User\" : "
234: + user);
235: mUser = user;
236: }
237:
238: public String getPort() {
239: return mPort;
240: }
241:
242: public void setPort(String port) {
243: mLogger
244: .info("Setting the ConfigMBean attribute \"Port\" : "
245: + port);
246: mPort = port;
247: }
248:
249: public int getIntValue() {
250: return this .mIntValue;
251: }
252:
253: public void setIntValue(int intValue) {
254: mLogger
255: .info("Setting the ConfigMBean attribute \"IntValue\" : "
256: + intValue);
257: this .mIntValue = intValue;
258: }
259:
260: public Integer getIntegerValue() {
261: return this .mIntegerValue;
262: }
263:
264: public void setIntegerValue(Integer integerValue) {
265: mLogger
266: .info("Setting the ConfigMBean attribute \"IntegerValue\" : "
267: + integerValue);
268: this.mIntegerValue = integerValue;
269: }
270:
271: }
272: }
|