1 /*
 2  * Copyright (c) 2003 Peter Antman, Teknik i Media  <peter.antman@tim.se>
 3  *
 4  * $Id: JacorbUtil.java 14827 2006-03-05 17:22:24Z laghi $
 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 of the License, or (at your option) 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  USA
19  */
20 package org.xmlBlaster.j2ee.util;
21 import java.util.Properties;
22 import java.io.InputStream;
23 
24 import java.util.logging.Logger;
25 import org.xmlBlaster.util.Global;
26 import org.xmlBlaster.util.XmlBlasterException;
27 import org.xmlBlaster.util.def.ErrorCode;
28 import org.xmlBlaster.util.property.Property;
29 /**
30  * Helpers class to work with Jacorb in embedded J2EE environment.
31  *
32  * @author <a href="mailto:pra@tim.se">Peter Antman</a>
33  * @version $Revision: 1.2 $
34  */
35 
36 public class JacorbUtil {
37    private static Logger log = Logger.getLogger(JacorbUtil.class.getName());
38    private static final String ME = "JacorbUtil";
39    /**
40     * Load the given jacorb properties file from the context classloader and
41     * put it into the given global.
42     * Jacorb is not capable of finding its jacorb.properties in the
43     * context classpath (actually it uses the system classloader.)
44     * Remember that jacorb.properties is in xmlBlaster.jar.
45     */
46    public static void loadJacorbProperties(String fileName, Global glob) throws XmlBlasterException {
47       if ( fileName == null) {
48          throw new XmlBlasterException(glob,ErrorCode.RESOURCE_CONFIGURATION,
49                                         ME,"jacorb property filename not allowed to be null");
50       } // end of if ()
51       
52       Properties props = new Properties();
53       try {
54          // Read orb properties file into props
55          ClassLoader cl = Thread.currentThread().getContextClassLoader();
56          InputStream is = cl.getResourceAsStream(fileName);
57          if (is != null) {
58             props.load(is);
59             // Ad to global
60             Property p = glob.getProperty();
61             p.addArgs2Props( props );
62          } else {
63 
64             log.warning("No "+fileName+" found in context classpath");
65          }
66       } catch (Exception e) {
67          throw new XmlBlasterException(glob,ErrorCode.RESOURCE_CONFIGURATION,
68                                         ME,"could not load jacorb properties "+e);
69       } // end of try-catch
70 
71    }
72 }// JacorbUtil


syntax highlighted by Code2HTML, v. 0.9.1