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: * @(#)Engine2Installer.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.ant.test.engine2.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 Engine2Installer 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 Engine2Installer() {
064: mLogger = Logger
065: .getLogger("com.sun.jbi.ui.ant.test.engine2.boot");
066: mLogger.info("Engine2Installer 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("Engine2Installer INIT Called");
091: this .mContext = installContext;
092: // throw JBIException("Test Error on Engine2Installer 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("Engine2Installer 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("Engine2Installer onInstall Called.");
117: // throw new JBIException("*** Test Error Engine2Installer on Install");
118:
119: if (this .mConfigMBean != null) {
120: if (!("chikkala".equalsIgnoreCase(this .mConfigMBean
121: .getUser()))) {
122: throw new JBIException(
123: "user is not chikkala. can not install");
124: }
125:
126: if (!("7777".equalsIgnoreCase(this .mConfigMBean.getPort()))) {
127: throw new JBIException(
128: "Port is not 7777. can not install");
129: }
130:
131: if (this .mConfigMBean.getIntValue() != 1234) {
132: throw new JBIException(
133: "IntValue is not 1234. can not install");
134: }
135:
136: if (this .mConfigMBean.getIntegerValue().intValue() != 9876) {
137: throw new JBIException(
138: "IntegerValue is not 9876. can not install");
139: }
140:
141: } else {
142: throw new JBIException(
143: "Configuration MBean not initialized");
144: }
145: }
146:
147: /**
148: * Called at the beginning of uninstallation of FileEngine . For this
149: * file engine, all the required uninstallation tasks have been taken care
150: * of by the InstallationService
151: * @throws javax.jbi.JBIException when there is an error requiring that
152: * the uninstallation be terminated.
153: */
154: public void onUninstall() throws javax.jbi.JBIException {
155: mLogger.info("*** Engine2Installer onUninstall Called");
156: // throw new JBIException("Test Error Engine2Installer on UnInstall");
157: }
158:
159: /**
160: * fix it
161: * @throws JBIException fix it
162: */
163: public void createConfigMBean() throws JBIException {
164: try {
165: if (this .mConfigMBean == null) {
166: this .mConfigMBean = new ConfigMBeanImpl();
167: }
168:
169: if (this .mConfigMBeanName == null) {
170: MBeanNames mbnHndl = this .mContext.getContext()
171: .getMBeanNames();
172:
173: this .mConfigMBeanName = mbnHndl
174: .createCustomComponentMBeanName("InstallerConfig");
175: }
176: } catch (Exception e) {
177: e.printStackTrace();
178: throw new JBIException(
179: "Ant Test Engine2 Installer ConfigurationMBean Creation Failed",
180: e);
181: }
182: }
183:
184: /**
185: * fix it
186: * @throws JBIException fix it
187: */
188: public void registerConfigMBean() throws JBIException {
189: createConfigMBean(); // make sure it is created.
190:
191: try {
192: MBeanServer mbServer = this .mContext.getContext()
193: .getMBeanServer();
194: StandardMBean configBean = new StandardMBean(
195: this .mConfigMBean, ConfigMBean.class);
196: mbServer.registerMBean(configBean, this .mConfigMBeanName);
197: } catch (Exception e) {
198: e.printStackTrace();
199: throw new JBIException(
200: "Ant Test Engine2 Installer Config MBean Registration Failed",
201: e);
202: }
203:
204: }
205:
206: /**
207: * fix it
208: * @throws JBIException fix it
209: */
210: public void deregisterConfigMBean() throws JBIException {
211: if (this .mConfigMBeanName == null) {
212: this .mLogger
213: .warning("trying to unregister null Installer Config MBean in Ant Test Engine 2 inst");
214: }
215:
216: try {
217: MBeanServer mbServer = this .mContext.getContext()
218: .getMBeanServer();
219: mbServer.unregisterMBean(this .mConfigMBeanName);
220: this .mConfigMBeanName = null;
221: this .mConfigMBean = null;
222: } catch (Exception e) {
223: e.printStackTrace();
224: throw new JBIException("Ant Test Engine2"
225: + "Installer Config MBean Deregistration Failed", e);
226: }
227:
228: }
229:
230: public interface ConfigMBean {
231: public void setUser(String user);
232:
233: public String getUser();
234:
235: public void setPort(String port);
236:
237: public String getPort();
238:
239: public void setIntValue(int intValue);
240:
241: public int getIntValue();
242:
243: public void setIntegerValue(Integer integerValue);
244:
245: public Integer getIntegerValue();
246: }
247:
248: public class ConfigMBeanImpl implements ConfigMBean {
249: private String mUser;
250: private String mPort;
251: private int mIntValue;
252: private Integer mIntegerValue;
253:
254: public String getUser() {
255: return mUser;
256: }
257:
258: public void setUser(String user) {
259: System.out
260: .println("Setting the ConfigMBean attribute \"User\" : "
261: + user);
262: mUser = user;
263: }
264:
265: public String getPort() {
266: return mPort;
267: }
268:
269: public void setPort(String port) {
270: mLogger
271: .info("Setting the ConfigMBean attribute \"Port\" : "
272: + port);
273: mPort = port;
274: }
275:
276: public int getIntValue() {
277: return this .mIntValue;
278: }
279:
280: public void setIntValue(int intValue) {
281: mLogger
282: .info("Setting the ConfigMBean attribute \"IntValue\" : "
283: + intValue);
284: this .mIntValue = intValue;
285: }
286:
287: public Integer getIntegerValue() {
288: return this .mIntegerValue;
289: }
290:
291: public void setIntegerValue(Integer integerValue) {
292: mLogger
293: .info("Setting the ConfigMBean attribute \"IntegerValue\" : "
294: + integerValue);
295: this.mIntegerValue = integerValue;
296: }
297:
298: }
299: }
|