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: * @(#)CalculatorServiceInstaller.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.abc.jbi.calculator.installer;
030:
031: import java.util.logging.Logger;
032: import javax.management.ObjectName;
033: import javax.management.StandardMBean;
034: import javax.jbi.component.ComponentContext;
035: import javax.jbi.component.InstallationContext;
036: import javax.jbi.management.MBeanNames;
037:
038: /**
039: * The CalculatorServiceInstaller class uses the functionality of the model
040: * Component Installer to do all its work.
041: */
042: public class CalculatorServiceInstaller extends
043: com.sun.jbi.management.engine.ModelEngineInstaller
044: implements
045: com.abc.jbi.calculator.installer.CalculatorServiceInstallerConfigMBean {
046: /**
047: * Store the InstallationContext
048: */
049: private InstallationContext mContext;
050:
051: private ComponentContext mEnv;
052:
053: /** handle to our MBean Namer: */
054: protected com.sun.jbi.management.MBeanNames mMBeanNames;
055:
056: /**
057: * Store the proxy host -- CalculatorServiceInstallerConfigMBean
058: */
059: private String mProxyHost = "unspecified";
060:
061: /**
062: * Store the proxy port -- CalculatorServiceInstallerConfigMBean
063: */
064: private int mProxyPort = -1;
065:
066: private Logger mLog;
067:
068: /**
069: * Initializes the installation environment for a SE. This method is
070: * expected to save any information from the installation context that
071: * may be needed by other methods.
072: * @param installContext is the context containing information from the
073: * install command and from the SE jar file.
074: * @throws javax.jbi.JBIException when there is an error requiring that the
075: * installation be terminated.
076: */
077: public void init(InstallationContext installContext)
078: throws javax.jbi.JBIException {
079: StandardMBean mbean = null;
080: ObjectName mbname = null;
081: mContext = installContext;
082:
083: try {
084: //why doesn't this work for model components????
085: //mMBeanNames = (com.sun.jbi.management.MBeanNames) mEnv.getMBeanNames();
086:
087: //work-around for above:
088: //com.sun.jbi.management.support.MBeanNamesImpl mbnamesImpl = new com.sun.jbi.management.support.MBeanNamesImpl(mEnv.getMBeanNames().getJmxDomainName());
089: com.sun.jbi.management.support.MBeanNamesImpl mbnamesImpl = new com.sun.jbi.management.support.MBeanNamesImpl(
090: "com.sun.jbi", System
091: .getProperty("com.sun.jbi.instanceName"));
092: mMBeanNames = (com.sun.jbi.management.MBeanNames) mbnamesImpl;
093:
094: mbname = this .getExtensionMBeanName();
095: mEnv = mContext.getContext();
096:
097: mLog = Logger.getLogger(this .getClass().getPackage()
098: .getName());
099:
100: mLog.info("Calculator Installer init() called.");
101: mLog.info("my getExtensionMBeanName is : " + mbname);
102: mLog.info("Here's where I register the mbean...");
103: } catch (Exception e) {
104: e.printStackTrace();
105: }
106:
107: try {
108: mbean = new StandardMBean(
109: this ,
110: com.abc.jbi.calculator.installer.CalculatorServiceInstallerConfigMBean.class);
111: mEnv.getMBeanServer().registerMBean(mbean, mbname);
112: } catch (Exception e) {
113: e.printStackTrace();
114: }
115: }
116:
117: /**
118: * Obtains the optional installer configuration MBean ObjectName. If none
119: * is provided by this SE, returns null.
120: * @return ObjectName which represents the MBean registered by the init()
121: * method. If none was registered, returns null.
122: */
123: public ObjectName getExtensionMBeanName() {
124: ObjectName aname = null;
125:
126: try {
127: aname = mMBeanNames.getCustomEngineMBeanName(
128: "InstallerExtensionMBean", mContext
129: .getComponentName());
130: } catch (Exception e) {
131: e.printStackTrace();
132: }
133:
134: return aname;
135: }
136:
137: /**
138: * Called at the beginning of installation of a SE to perform any special
139: * installation tasks required by the SE.
140: * @throws javax.jbi.JBIException when there is an error requiring that the
141: * installation be terminated.
142: */
143: public void onInstall() throws javax.jbi.JBIException {
144: super .onInstall();
145: Logger mLog = Logger.getLogger(this .getClass().getPackage()
146: .getName());
147: ObjectName mbname = this .getExtensionMBeanName();
148:
149: mLog.info("Calculator Installer onInstall() called.");
150: mLog.info("Proxy Host is " + this .getProxyHost());
151: mLog.info("Proxy Port is " + this .getProxyPort());
152: mLog.info("Here's where I unregister the " + mbname
153: + " MBean...");
154: try {
155: mEnv.getMBeanServer().unregisterMBean(mbname);
156: mLog.info("unregistration successful.");
157: } catch (javax.management.InstanceNotFoundException infe) {
158: mLog.warning("InstanceNotFoundException: "
159: + infe.getMessage());
160: infe.printStackTrace();
161: } catch (javax.management.MBeanRegistrationException mre) {
162: mLog.warning("MBeanRegistrationException: "
163: + mre.getMessage());
164: mre.printStackTrace();
165: }
166: }
167:
168: /**
169: * Called at the beginning of uninstallation of a SE to perform any special
170: * installation tasks required by the SE.
171: * @throws javax.jbi.JBIException when there is an error requiring that
172: * the uninstallation be terminated.
173: */
174: public void onUninstall() throws javax.jbi.JBIException {
175: super .onUninstall();
176: Logger mLog = Logger.getLogger(this .getClass().getPackage()
177: .getName());
178: ObjectName mbname = this .getExtensionMBeanName();
179:
180: mLog.info("Calculator Installer onunInstall() called.");
181: mLog.info("Proxy Host is " + this .getProxyHost());
182: mLog.info("Proxy Port is " + this .getProxyPort());
183: mLog.info("Here's where I unregister the " + mbname
184: + " MBean...");
185: try {
186: mEnv.getMBeanServer().unregisterMBean(mbname);
187: mLog.info("unregistration successful.");
188: } catch (javax.management.InstanceNotFoundException infe) {
189: mLog.warning("InstanceNotFoundException: "
190: + infe.getMessage());
191: infe.printStackTrace();
192: } catch (javax.management.MBeanRegistrationException mre) {
193: mLog.warning("MBeanRegistrationException: "
194: + mre.getMessage());
195: mre.printStackTrace();
196: }
197: }
198:
199: /* methods from CalculatorServiceInstallerConfigMBean */
200: /**
201: * Return the proxy host.
202: *
203: * @return - the proxy host.
204: */
205: public String getProxyHost() {
206: return mProxyHost;
207: }
208:
209: /**
210: * Return the proxy port.
211: *
212: * @return - the proxy port.
213: */
214: public int getProxyPort() {
215: return mProxyPort;
216: }
217:
218: /**
219: * Specify the proxy host.
220: *
221: * @param aHost - the proxy host.
222: */
223: public void setProxyHost(String aHost) {
224: mProxyHost = aHost;
225: }
226:
227: /**
228: * Specify the proxy port.
229: *
230: * @param aPort - the proxy port.
231: */
232: public void setProxyPort(int aPort) {
233: mProxyPort = aPort;
234: }
235:
236: }
|