01: /*
02: *
03: * JOnAS: Java(TM) Open Application Server
04: * Copyright (C) 1999 Bull S.A.
05: * Contact: jonas-team@objectweb.org
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20: * USA
21: *
22: * --------------------------------------------------------------------------
23: * $Id: javaURLContextFactory.java 2588 2003-06-13 11:19:49Z benoitf $
24: * --------------------------------------------------------------------------
25: */
26:
27: package org.objectweb.jonas.naming.java;
28:
29: import java.util.Hashtable;
30: import javax.naming.Context;
31: import javax.naming.Name;
32: import javax.naming.spi.ObjectFactory;
33: import org.objectweb.util.monolog.api.Logger;
34: import org.objectweb.util.monolog.api.BasicLevel;
35:
36: /**
37: * Context factory for javaURLContext objects.
38: * This factory will be used for all "java:..." urls provided as Name objects
39: * for all JNDI operations.
40: *
41: * @author Philippe Durieux
42: * Contributor(s):
43: * Philippe Coq Monolog
44: */
45: public class javaURLContextFactory implements ObjectFactory {
46:
47: /**
48: * Logger used by JOnAS
49: */
50: private static Logger logger = null;
51:
52: /**
53: * Returns an instance of javaURLContext for a java URL.
54: *
55: * If url is null, the result is a context for resolving java URLs.
56: * If url is a URL, the result is a context named by the URL.
57: *
58: * @param url String with a "java:" prefix or null.
59: * @param name Name of context, relative to ctx, or null.
60: * @param ctx Context relative to which 'name' is named.
61: * @param env Environment to use when creating the context
62: * @return new created object.
63: * @throws Exception if it fails.
64: */
65: public Object getObjectInstance(Object url, Name name, Context ctx,
66: Hashtable env) throws Exception {
67: if (url == null) {
68: // All naming operations with "java:..." comes here
69: // Users are encouraged to used intermediate contexts:
70: // ctx = ic.lookup("java:comp/env") called only once (perfs)
71: return new javaURLContext(env);
72: }
73: if (url instanceof String) {
74: // Don't know what to do here
75: logger.log(BasicLevel.WARN,
76: "javaURLContextFactory.getObjectInstance(" + url
77: + ")");
78: return null;
79: } else if (url instanceof String[]) {
80: // Don't know what to do here
81: logger
82: .log(BasicLevel.WARN,
83: "javaURLContextFactory.getObjectInstance(String[])");
84: return null;
85: } else {
86: // invalid argument
87: throw (new IllegalArgumentException("javaURLContextFactory"));
88: }
89: }
90: }
|