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: * @(#)JMXConnectionFactory.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.client;
030:
031: import com.sun.jbi.ui.common.JBIResultXmlBuilder;
032: import com.sun.jbi.ui.common.JMXConnectionException;
033: import com.sun.jbi.ui.common.I18NBundle;
034:
035: import java.util.Properties;
036:
037: /**
038: * Abstract facoty implementation.
039: *
040: * @author Sun Microsystems, Inc.
041: */
042: public abstract class JMXConnectionFactory {
043: /**
044: * property name for class to load.
045: */
046: public static final String FACTORY_IMPL_CLASS_PROP = "com.sun.jbi.tools.jmx.connection.factory";
047:
048: /**
049: * if no property set, try load this impl class.
050: */
051: public static final String FACTORY_IMPL_CLASS = "com.sun.jbi.ui.client.jmxremote.RemoteJMXConnectionFactory";
052: /** i18n */
053: private static I18NBundle sI18NBundle = null;
054:
055: /**
056: * The full path/name of the property file.
057: */
058: private static String sFullPropertyFileName = null;
059:
060: /** gives the I18N bundle.
061: *@return I18NBundle object
062: */
063: protected static I18NBundle getI18NBundle() {
064: // lazzy initialize the JBI Client
065: if (sI18NBundle == null) {
066: sI18NBundle = new I18NBundle("com.sun.jbi.ui.client");
067: }
068: return sI18NBundle;
069: }
070:
071: /**
072: *
073: *
074: * @param conprops
075: *
076: * @return
077: */
078: public abstract JMXConnection getConnection(Properties conprops)
079: throws JMXConnectionException;
080:
081: /**
082: * creates jmx connection.
083: *
084: * @param provprops
085: * @param host host name
086: * @param port port number
087: * @param username username
088: * @param password password
089: *
090: * @return jmx connection
091: */
092: public static Properties getConnectionProperties(
093: Properties provprops, String host, String port,
094: String username, String password) {
095: Properties props = JMXConnectionProperties
096: .getJMXConnectionPropertyMap(provprops, null, host,
097: port, username, password);
098:
099: return props;
100: }
101:
102: /**
103: *
104: *
105: * @param factoryImplName
106: *
107: * @return
108: */
109: public static JMXConnectionFactory newInstance(
110: String factoryImplName) throws JMXConnectionException {
111: if ((factoryImplName == null)
112: || (factoryImplName.trim().equals(""))) {
113: return newInstance();
114: }
115:
116: try {
117: Class cl = Class.forName(factoryImplName);
118:
119: return (JMXConnectionFactory) cl.newInstance();
120: } catch (Exception ex) {
121: // pass null to the cause as you have already serialized the cause to jbi mgmt xml
122: throw new JMXConnectionException(JBIResultXmlBuilder
123: .createJbiResultXml(getI18NBundle(),
124: "jbi.ui.client.connection.factory.error",
125: new Object[] { factoryImplName }, ex), null);
126: }
127: }
128:
129: /**
130: *
131: *
132: * @param factoryImplName
133: *
134: * @return
135: */
136: public static JMXConnectionFactory newInstance(Properties props)
137: throws JMXConnectionException {
138: String facImplname = null;
139:
140: if (props != null) {
141: facImplname = (String) props
142: .getProperty(FACTORY_IMPL_CLASS_PROP);
143: }
144:
145: return newInstance(facImplname);
146: }
147:
148: /**
149: *
150: *
151: * @return
152: */
153: public static JMXConnectionFactory newInstance()
154: throws JMXConnectionException {
155: String factoryImplClass = JMXConnectionProperties.getInstance()
156: .getDefaultConnectionFactory();
157:
158: if (factoryImplClass == null) {
159: factoryImplClass = FACTORY_IMPL_CLASS;
160: }
161:
162: JMXConnectionFactory impl = null;
163:
164: try {
165: impl = (JMXConnectionFactory) Class.forName(
166: factoryImplClass).newInstance();
167: } catch (Exception ex) {
168: // any exception, just load the default class?
169: // pass null to the cause as you have already serialized the cause to jbi mgmt xml
170: throw new JMXConnectionException(JBIResultXmlBuilder
171: .createJbiResultXml(getI18NBundle(),
172: "jbi.ui.client.connection.factory.error",
173: new Object[] { factoryImplClass }, ex),
174: null);
175:
176: }
177:
178: return impl;
179: }
180: }
|