KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ear > deployment > lib > wrapper > EarManagerWrapper


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EarManagerWrapper.java,v 1.1 2004/05/25 14:26:36 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas_ear.deployment.lib.wrapper;
26
27 import java.lang.reflect.InvocationTargetException JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29
30 import org.objectweb.jonas_ear.deployment.api.EarDeploymentDesc;
31 import org.objectweb.jonas_ear.deployment.api.EarDeploymentDescException;
32
33 import org.objectweb.jonas.common.Log;
34 import org.objectweb.jonas.server.LoaderManager;
35
36 import org.objectweb.util.monolog.api.BasicLevel;
37 import org.objectweb.util.monolog.api.Logger;
38
39
40 /**
41  *
42  *
43  * @author Guillaume Sauthier
44  */

45 public class EarManagerWrapper {
46
47     /**
48      * EarDeploymentDescManager fully qualified classname
49      */

50     private static final String JavaDoc EAR_MANAGER_CLASSNAME = "org.objectweb.jonas_ear.deployment.lib.EarDeploymentDescManager";
51
52     /**
53      * logger
54      */

55     private static Logger logger = Log.getLogger(Log.JONAS_EAR_PREFIX);
56
57     /**
58      * Empty private constructor for utility classes
59      */

60     private EarManagerWrapper() { }
61
62     /**
63      * Wrap EarDeploymentDescManager.getDeploymentDesc(ear, cl)
64      *
65      * @param ear Ear filename
66      * @param cl Application ClassLoader
67      *
68      * @return the EarDeploymentDesc of the ear filename
69      *
70      * @throws EarDeploymentDescException When Descriptor cannot be instanciated
71      */

72     public static EarDeploymentDesc getDeploymentDesc(String JavaDoc ear, ClassLoader JavaDoc cl)
73     throws EarDeploymentDescException {
74         LoaderManager lm = LoaderManager.getInstance();
75         EarDeploymentDesc earDD = null;
76         try {
77             ClassLoader JavaDoc tools = lm.getToolsLoader();
78             Class JavaDoc manager = tools.loadClass(EAR_MANAGER_CLASSNAME);
79             Method JavaDoc m = manager.getDeclaredMethod("getDeploymentDesc", new Class JavaDoc[] {String JavaDoc.class, ClassLoader JavaDoc.class});
80             earDD = (EarDeploymentDesc) m.invoke(null, new Object JavaDoc[] {ear, cl});
81         } catch (InvocationTargetException JavaDoc ite) {
82             Throwable JavaDoc t = ite.getTargetException();
83             if (EarDeploymentDescException.class.isInstance(t)) {
84                 throw (EarDeploymentDescException) ite.getTargetException();
85             } else {
86                 throw new EarDeploymentDescException("EarDeploymentDescManager.getDeploymentDesc fails", t);
87             }
88         } catch (Exception JavaDoc e) {
89             // TODO add i18n here
90
throw new EarDeploymentDescException("Problems when using reflection on EarDeploymentDescManager", e);
91         }
92
93         return earDD;
94     }
95
96     /**
97      * Wrap EarDeploymentDescManager.setParsingWithValidation(b)
98      *
99      * @param b true/false
100      */

101     public static void setParsingWithValidation(boolean b) {
102         LoaderManager lm = LoaderManager.getInstance();
103
104         try {
105             ClassLoader JavaDoc tools = lm.getToolsLoader();
106             Class JavaDoc manager = tools.loadClass(EAR_MANAGER_CLASSNAME);
107             Method JavaDoc m = manager.getDeclaredMethod("setParsingWithValidation", new Class JavaDoc[] {boolean.class});
108             m.invoke(null, new Object JavaDoc[] {new Boolean JavaDoc(b)});
109         } catch (Exception JavaDoc e) {
110             // Should never occurs
111
logger.log(BasicLevel.ERROR, e);
112         }
113     }
114
115 }
116
Popular Tags