001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
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: EarManagerWrapper.java 4799 2004-05-25 14:26:36Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ear.deployment.lib.wrapper;
025:
026: import java.lang.reflect.InvocationTargetException;
027: import java.lang.reflect.Method;
028:
029: import org.objectweb.jonas_ear.deployment.api.EarDeploymentDesc;
030: import org.objectweb.jonas_ear.deployment.api.EarDeploymentDescException;
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: *
041: * @author Guillaume Sauthier
042: */
043: public class EarManagerWrapper {
044:
045: /**
046: * EarDeploymentDescManager fully qualified classname
047: */
048: private static final String EAR_MANAGER_CLASSNAME = "org.objectweb.jonas_ear.deployment.lib.EarDeploymentDescManager";
049:
050: /**
051: * logger
052: */
053: private static Logger logger = Log.getLogger(Log.JONAS_EAR_PREFIX);
054:
055: /**
056: * Empty private constructor for utility classes
057: */
058: private EarManagerWrapper() {
059: }
060:
061: /**
062: * Wrap EarDeploymentDescManager.getDeploymentDesc(ear, cl)
063: *
064: * @param ear Ear filename
065: * @param cl Application ClassLoader
066: *
067: * @return the EarDeploymentDesc of the ear filename
068: *
069: * @throws EarDeploymentDescException When Descriptor cannot be instanciated
070: */
071: public static EarDeploymentDesc getDeploymentDesc(String ear,
072: ClassLoader cl) throws EarDeploymentDescException {
073: LoaderManager lm = LoaderManager.getInstance();
074: EarDeploymentDesc earDD = null;
075: try {
076: ClassLoader tools = lm.getToolsLoader();
077: Class manager = tools.loadClass(EAR_MANAGER_CLASSNAME);
078: Method m = manager.getDeclaredMethod("getDeploymentDesc",
079: new Class[] { String.class, ClassLoader.class });
080: earDD = (EarDeploymentDesc) m.invoke(null, new Object[] {
081: ear, cl });
082: } catch (InvocationTargetException ite) {
083: Throwable t = ite.getTargetException();
084: if (EarDeploymentDescException.class.isInstance(t)) {
085: throw (EarDeploymentDescException) ite
086: .getTargetException();
087: } else {
088: throw new EarDeploymentDescException(
089: "EarDeploymentDescManager.getDeploymentDesc fails",
090: t);
091: }
092: } catch (Exception e) {
093: // TODO add i18n here
094: throw new EarDeploymentDescException(
095: "Problems when using reflection on EarDeploymentDescManager",
096: e);
097: }
098:
099: return earDD;
100: }
101:
102: /**
103: * Wrap EarDeploymentDescManager.setParsingWithValidation(b)
104: *
105: * @param b true/false
106: */
107: public static void setParsingWithValidation(boolean b) {
108: LoaderManager lm = LoaderManager.getInstance();
109:
110: try {
111: ClassLoader tools = lm.getToolsLoader();
112: Class manager = tools.loadClass(EAR_MANAGER_CLASSNAME);
113: Method m = manager.getDeclaredMethod(
114: "setParsingWithValidation",
115: new Class[] { boolean.class });
116: m.invoke(null, new Object[] { new Boolean(b) });
117: } catch (Exception e) {
118: // Should never occurs
119: logger.log(BasicLevel.ERROR, e);
120: }
121: }
122:
123: }
|