KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > jndi > enc > java > javaURLContextFactory


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2005 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: javaURLContextFactory.java,v 1.5 2005/03/15 17:54:52 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.carol.jndi.enc.java;
27
28 import java.util.Hashtable JavaDoc;
29
30 import javax.naming.Context JavaDoc;
31 import javax.naming.Name JavaDoc;
32 import javax.naming.spi.ObjectFactory JavaDoc;
33
34 import org.objectweb.carol.util.configuration.TraceCarol;
35
36 /**
37  * Context factory for javaURLContext objects. This factory will be used for all
38  * "java:..." urls provided as Name objects for all JNDI operations.
39  * @author Philippe Durieux Contributor(s): Philippe Coq Monolog
40  */

41 public class javaURLContextFactory implements ObjectFactory JavaDoc {
42
43     /**
44      * @return an instance of javaURLContext for a java URL. If url is null, the
45      * result is a context for resolving java URLs. If url is a URL, the
46      * result is a context named by the URL.
47      * @param url String with a "java:" prefix or null.
48      * @param name Name of context, relative to ctx, or null.
49      * @param ctx Context relative to which 'name' is named.
50      * @param env Environment to use when creating the context *
51      * @throws Exception if this object factory encountered an exception while
52      * attempting to create an object, and no other object factories are
53      * to be tried.
54      */

55     public Object JavaDoc getObjectInstance(Object JavaDoc url, Name JavaDoc name, Context JavaDoc ctx, Hashtable JavaDoc env) throws Exception JavaDoc {
56         if (TraceCarol.isDebugjndiEncCarol()) {
57             TraceCarol.debugjndiEncCarol("url = '" + url + "'.");
58         }
59
60         if (url == null) {
61             // All naming operations with "java:..." comes here
62
// Users are encouraged to used intermediate contexts:
63
// ctx = ic.lookup("java:comp/env") called only once (perfs)
64
return new JavaURLContext(env);
65         }
66         if (url instanceof String JavaDoc) {
67             // Don't know what to do here
68
if (TraceCarol.isDebugjndiEncCarol()) {
69                 TraceCarol.debugjndiEncCarol("javaURLContextFactory.getObjectInstance(" + url + ")");
70             }
71             return null;
72         } else if (url instanceof String JavaDoc[]) {
73             // Don't know what to do here
74
if (TraceCarol.isDebugjndiEncCarol()) {
75                 TraceCarol.debugjndiEncCarol("javaURLContextFactory.getObjectInstance(String[])");
76             }
77             return null;
78         } else {
79             // invalid argument
80
throw (new IllegalArgumentException JavaDoc("javaURLContextFactory"));
81         }
82     }
83 }
Popular Tags