001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: /*
037: * JBIConfigBean.java
038: */
039: package com.sun.jbi.jsf.bean;
040:
041: import java.util.logging.Level;
042: import java.util.logging.Logger;
043: import javax.faces.context.FacesContext;
044: import com.sun.jbi.jsf.util.ConnectionUtilities;
045: import com.sun.jbi.jsf.util.JBILogger;
046: import com.sun.jbi.jsf.util.JBITreeExtension;
047: import com.sun.jbi.ui.common.JBIAdminCommands;
048:
049: /**
050: * JavaServer Faces managed bean that loads the other (psuedo) managed beans
051: * and checks for JBI runtime and JBI admin-gui extensions.
052: *
053: * @author Sun Microsystems Inc.
054: */
055: public class JBIConfigBean {
056:
057: /**
058: * Gets the JBI common client, checks for JBI runtime availability, and
059: * checks-for/initializes any (optional) JBI admin-gui navigation tree
060: * extension (such as one added by a Java CAPS installation).
061: */
062: public JBIConfigBean() {
063: boolean isJbiRuntimeEnabled = false;
064:
065: try {
066: mCachedClient = (new ConnectionUtilities()).getClient();
067: isJbiRuntimeEnabled = mCachedClient.isJBIRuntimeEnabled();
068: sLog.fine("JBIConfigBean.<init>(): isJbiRuntimeEnabled="
069: + isJbiRuntimeEnabled + ", mCachedClient="
070: + mCachedClient);
071: if (isJbiRuntimeEnabled) {
072: boolean isExtensionInitialized = initExtensionManagedBeans();
073: if (isExtensionInitialized) {
074: mIsJbiEnabled = true;
075:
076: // check for any JBI extension subtree
077: initJBITreeExtension();
078: }
079: }
080: } catch (Exception ex) {
081: sLog
082: .log(
083: Level.FINE,
084: "JBIConfigBean.isJbiEnabled() caught exception",
085: ex);
086: }
087: sLog.fine("JBIConfigBean.<init>(): mIsJbiEnabled="
088: + mIsJbiEnabled);
089: }
090:
091: /**
092: * get the common client for JBI administration queries and operations
093: *
094: * @return the JBI Administration common client
095: */
096: public JBIAdminCommands getClient() {
097: sLog.fine("JBIConfigBean.getClient() result=" + mCachedClient);
098: return mCachedClient;
099: }
100:
101: /**
102: * checks for a usable JBI runtime (JBI's JSF tags use this to
103: * conditionally render JBI views; no runtime (or any missing required jar
104: * files) results in no JBI tree node or tabs in the console
105: *
106: * @return true if the JBI console implementation, common client, and
107: * runtime are all available
108: */
109: public boolean isJbiEnabled() {
110: boolean result = mIsJbiEnabled;
111: sLog.fine("JBIConfigBean.isJbiEnabled(): result=" + result);
112: return result;
113: }
114:
115: /**
116: * returns the admin-gui navigation tree extension, if any.
117: *
118: * @return the extension or null
119: */
120: public JBITreeExtension getJBITreeExtension() {
121: JBITreeExtension result = mJBITreeExtension;
122: sLog.fine("JBIConfigBean.getJBITreeExtension(), result="
123: + result);
124: return result;
125: }
126:
127: //Get Logger to log fine mesages for debugging
128: private static Logger sLog = JBILogger.getInstance();
129:
130: private static final String[][] EXTENSION_MANAGED_BEANS = {
131: { "ArchiveBean", "com.sun.jbi.jsf.bean.ArchiveBean" },
132: { "AlertBean", "com.sun.jbi.jsf.bean.AlertBean" },
133: { "CompConfigBean", "com.sun.jbi.jsf.bean.CompConfigBean" },
134: { "DeletionBean", "com.sun.jbi.jsf.bean.DeletionBean" },
135: { "InstallationBean",
136: "com.sun.jbi.jsf.bean.InstallationBean" },
137: { "JBIComponentConfigBean",
138: "com.sun.jbi.jsf.bean.JBIComponentConfigBean" },
139: { "ListBean", "com.sun.jbi.jsf.bean.ListBean" },
140: { "LoggingBean", "com.sun.jbi.jsf.bean.LoggingBean" },
141: { "OperationBean", "com.sun.jbi.jsf.bean.OperationBean" },
142: { "RuntimeConfigurationBean",
143: "com.sun.jbi.jsf.bean.RuntimeConfigurationBean" },
144: { "RuntimeStatsBean",
145: "com.sun.jbi.jsf.bean.RuntimeStatsBean" },
146: { "ServiceUnitBean", "com.sun.jbi.jsf.bean.ServiceUnitBean" },
147: { "ShowBean", "com.sun.jbi.jsf.bean.ShowBean" },
148: { "TargetBean", "com.sun.jbi.jsf.bean.TargetBean" },
149: { "UploadCopyRadioBean",
150: "com.sun.jbi.jsf.bean.UploadCopyRadioBean" }, };
151: private static final int INDEX_BEAN_NAME = 0;
152: private static final int INDEX_CLASS_NAME = 1;
153:
154: private static final String TREE_EXTENSION_CLASS_NAME = "com.sun.jbi.jsf.util.JBITreeExtensionImpl";
155:
156: /**
157: * loads extension-managed (formerly JavaServer Faces managed) beans.
158: *
159: * @return true if no exceptions occur
160: */
161: private boolean initExtensionManagedBeans() {
162: boolean result = true;
163: // assume success
164: try {
165: for (int i = 0; i < EXTENSION_MANAGED_BEANS.length; ++i) {
166: String beanName = EXTENSION_MANAGED_BEANS[i][INDEX_BEAN_NAME];
167: String className = EXTENSION_MANAGED_BEANS[i][INDEX_CLASS_NAME];
168: Class beanClass = Class.forName(className);
169: Object bean = beanClass.newInstance();
170: sLog
171: .fine("JBIConfigBean.initExensionManagedBeans() beanName="
172: + beanName
173: + ", className="
174: + className
175: + ", bean=" + bean);
176: FacesContext facesContext = FacesContext
177: .getCurrentInstance();
178: facesContext.getExternalContext().getSessionMap().put(
179: beanName, bean);
180: }
181: } catch (Exception ex) {
182: result = false;
183: // indicate failure
184: sLog
185: .log(
186: Level.FINE,
187: "JBIConfigBean.initExtensionManagedBeans() caught Exception",
188: ex);
189: }
190: sLog.fine("JBIConfigBean.initExensionManagedBeans() result="
191: + result);
192: return result;
193: }
194:
195: /**
196: * initializes the (optional) admin-gui navigation tree extension, if any.
197: * A ClassNotFoundException is expected if there is no tree extension
198: * class found in the classpath (when Java CAPS is installed this would be
199: * in the optional glassfish/jbi/lib/jbi-gui-ext.jar file).
200: */
201: private void initJBITreeExtension() {
202: sLog.fine("JBIConfigBean.initJBITreeExtension()");
203:
204: mJBITreeExtension = null;
205:
206: try {
207: Class treeExtensionClass = Class
208: .forName(TREE_EXTENSION_CLASS_NAME);
209: mJBITreeExtension = (JBITreeExtension) treeExtensionClass
210: .newInstance();
211: } catch (Exception ex) {
212: sLog
213: .fine("JBIConfigBean.initJBITreeExtension() no CAPS extension tree found");
214: sLog
215: .log(
216: Level.FINEST,
217: ("JBIConfigBean.initJBITreeExtension() caught ex=" + ex),
218: ex);
219: }
220:
221: sLog
222: .fine("JBIConfigBean.initJBITreeExtension(), mJBITreeExtension="
223: + mJBITreeExtension);
224: }
225:
226: /**
227: * cached JBI client and its JMX connection (prevents garbage collection
228: * during life of web console)
229: */
230: private JBIAdminCommands mCachedClient;
231:
232: /**
233: * JBI is enabled when the jbi-admin-gui and jbi-admin-common jar files
234: * are both present
235: */
236: private boolean mIsJbiEnabled = false;
237:
238: /**
239: * JBI tree extension is non-null if an implementation is found in the
240: * classpath
241: */
242: private JBITreeExtension mJBITreeExtension = null;
243:
244: }
|