001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ClusterDaemonConfigurationManagerWrapper.java 8696 2006-06-28 16:09:49Z pelletib $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_clusterd.lib.wrapper;
025:
026: import java.lang.reflect.InvocationTargetException;
027: import java.lang.reflect.Method;
028:
029: import org.objectweb.jonas_clusterd.api.ClusterDaemonConfiguration;
030: import org.objectweb.jonas_clusterd.api.ClusterDaemonConfigurationException;
031:
032: import org.objectweb.jonas.common.Log;
033: import org.objectweb.jonas.server.LoaderManager;
034:
035: import org.objectweb.util.monolog.api.BasicLevel;
036: import org.objectweb.util.monolog.api.Logger;
037:
038: /**
039: *
040: * Wrapper for accessing to the Digester tool
041: * @author Benoit Pelletier
042: */
043: public class ClusterDaemonConfigurationManagerWrapper {
044:
045: /**
046: * ClusterDaemonManager fully qualified classname
047: */
048: private static final String CLUSTER_DAEMON_MANAGER_CLASSNAME = "org.objectweb.jonas_clusterd.lib.ClusterDaemonConfigurationManager";
049:
050: /**
051: * logger
052: */
053: private static Logger logger = Log
054: .getLogger(Log.JONAS_CLUSTER_DAEMON);
055:
056: /**
057: * Empty private constructor for utility classes
058: */
059: private ClusterDaemonConfigurationManagerWrapper() {
060: }
061:
062: /**
063: * Wrap ClusterDaemonManager.getClusterDaemonConfiguration(fileName, cl)
064: *
065: * @param fileName name of the file containing the cluster daemon configuration
066: * @param cl ClassLoader
067: *
068: * @return the cluster daemon configuration
069: *
070: * @throws ClusterDaemonConfigurationException When ClusterDaemonConfiguration can't be created
071: */
072: public static ClusterDaemonConfiguration getClusterDaemonConfiguration(
073: String fileName, ClassLoader cl)
074: throws ClusterDaemonConfigurationException {
075: LoaderManager lm = LoaderManager.getInstance();
076: ClusterDaemonConfiguration conf = null;
077: try {
078: ClassLoader tools = lm.getToolsLoader();
079: Class manager = tools
080: .loadClass(CLUSTER_DAEMON_MANAGER_CLASSNAME);
081: Method m = manager.getDeclaredMethod(
082: "getClusterDaemonConfiguration", new Class[] {
083: String.class, ClassLoader.class });
084: conf = (ClusterDaemonConfiguration) m.invoke(null,
085: new Object[] { fileName, cl });
086: } catch (InvocationTargetException ite) {
087: Throwable t = ite.getTargetException();
088: if (ClusterDaemonConfigurationException.class.isInstance(t)) {
089: throw (ClusterDaemonConfigurationException) ite
090: .getTargetException();
091: } else {
092: throw new ClusterDaemonConfigurationException(
093: "ClusterDaemonManager.getClusterDaemonConfiguration fails",
094: t);
095: }
096: } catch (Exception e) {
097: // TODO add i18n here
098: throw new ClusterDaemonConfigurationException(
099: "Problems when using reflection on ClusterDaemonManager",
100: e);
101: }
102:
103: return conf;
104: }
105:
106: /**
107: * Wrap ClusterDaemonConfigurationManager.setParsingWithValidation(b)
108: *
109: * @param b true/false
110: */
111: public static void setParsingWithValidation(boolean b) {
112: LoaderManager lm = LoaderManager.getInstance();
113:
114: try {
115: ClassLoader tools = lm.getToolsLoader();
116: Class manager = tools
117: .loadClass(CLUSTER_DAEMON_MANAGER_CLASSNAME);
118: Method m = manager.getDeclaredMethod(
119: "setParsingWithValidation",
120: new Class[] { boolean.class });
121: m.invoke(null, new Object[] { new Boolean(b) });
122: } catch (Exception e) {
123: // Should never occurs
124: logger.log(BasicLevel.ERROR, e);
125: }
126: }
127:
128: }
|