001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 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: DomainManagerWrapper.java 8433 2006-06-06 08:12:47Z pelletib $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_domain.lib.wrapper;
025:
026: import java.lang.reflect.InvocationTargetException;
027: import java.lang.reflect.Method;
028:
029: import org.objectweb.jonas.common.Log;
030: import org.objectweb.jonas.server.LoaderManager;
031:
032: import org.objectweb.jonas_domain.api.DomainMap;
033: import org.objectweb.jonas_domain.api.DomainMapException;
034:
035: import org.objectweb.util.monolog.api.BasicLevel;
036: import org.objectweb.util.monolog.api.Logger;
037:
038: /**
039: *
040: *
041: * @author Adriana Danes
042: */
043: public class DomainManagerWrapper {
044:
045: /**
046: * DomainMapManager fully qualified classname
047: */
048: private static final String DOMAIN_MANAGER_CLASSNAME = "org.objectweb.jonas_domain.lib.DomainMapManager";
049:
050: /**
051: * logger
052: */
053: private static Logger logger = Log
054: .getLogger(Log.JONAS_DOMAIN_MANAGEMENT_PREFIX);
055:
056: /**
057: * Empty private constructor for utility classes
058: */
059: private DomainManagerWrapper() {
060: }
061:
062: /**
063: * Wrap DomainMapManager.getDeploymentDesc(domainFileName, cl)
064: *
065: * @param domainFileName name of the file containing the domain map
066: * @param cl Domain ClassLoader
067: *
068: * @return the DomainMap containing the map description
069: *
070: * @throws DomainMapException When DomainMap can't be created
071: */
072: public static DomainMap getDomainMap(String domainFileName,
073: ClassLoader cl) throws DomainMapException {
074: LoaderManager lm = LoaderManager.getInstance();
075: DomainMap map = null;
076: try {
077: ClassLoader tools = lm.getToolsLoader();
078: Class manager = tools.loadClass(DOMAIN_MANAGER_CLASSNAME);
079: Method m = manager.getDeclaredMethod("getDomainMap",
080: new Class[] { String.class, ClassLoader.class });
081: map = (DomainMap) m.invoke(null, new Object[] {
082: domainFileName, cl });
083: } catch (InvocationTargetException ite) {
084: Throwable t = ite.getTargetException();
085: if (DomainMapException.class.isInstance(t)) {
086: throw (DomainMapException) ite.getTargetException();
087: } else {
088: throw new DomainMapException(
089: "DomainMapManager.getDomainMap fails", t);
090: }
091: } catch (Exception e) {
092: // TODO add i18n here
093: throw new DomainMapException(
094: "Problems when using reflection on DomainMapManager",
095: e);
096: }
097:
098: return map;
099: }
100:
101: /**
102: * Wrap DomainMapManager.setParsingWithValidation(b)
103: *
104: * @param b true/false
105: */
106: public static void setParsingWithValidation(boolean b) {
107: LoaderManager lm = LoaderManager.getInstance();
108:
109: try {
110: ClassLoader tools = lm.getToolsLoader();
111: Class manager = tools.loadClass(DOMAIN_MANAGER_CLASSNAME);
112: Method m = manager.getDeclaredMethod(
113: "setParsingWithValidation",
114: new Class[] { boolean.class });
115: m.invoke(null, new Object[] { new Boolean(b) });
116: } catch (Exception e) {
117: // Should never occurs
118: logger.log(BasicLevel.ERROR, e);
119: }
120: }
121:
122: }
|