KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > naming > SerialContextProviderImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.naming;
24
25 import java.util.*;
26 import java.io.*;
27 import java.rmi.*;
28 import javax.naming.*;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31
32 import com.sun.enterprise.connectors.*;
33
34 import java.util.logging.*;
35 import com.sun.logging.*;
36
37 public class SerialContextProviderImpl implements SerialContextProvider {
38
39     static Logger _logger = LogDomains.getLogger(LogDomains.JNDI_LOGGER);
40
41     private TransientContext rootContext;
42
43  
44     protected SerialContextProviderImpl(TransientContext rootContext)
45     throws RemoteException {
46     this.rootContext = rootContext;
47     }
48
49     /**
50      * Lookup the specified name.
51      * @return the object or context bound to the name.
52      * @exception NamingException if there is a naming exception.
53      * @exception if there is an RMI exception.
54      */

55
56     public Object JavaDoc lookup(String JavaDoc name)
57         throws NamingException, RemoteException {
58         try {
59             _logger.fine(" SerialContextProviderImpl :: lookup " + name);
60     
61             Object JavaDoc obj = rootContext.lookup(name);
62             return obj;
63         } catch(NamingException ne) {
64             boolean isLoaded = checkAndLoadResource(name);
65             _logger.fine("CheckAndLoad Resource of " + name + " was " + isLoaded );
66             if ( isLoaded ) {
67                 Object JavaDoc i = rootContext.lookup(name);
68                 return i;
69             }
70             throw ne;
71         } catch(Exception JavaDoc e) {
72         _logger.severe("Exception occurred : " + e.getMessage());
73             RemoteException re = new RemoteException("", e);
74             throw re;
75
76         }
77     }
78
79     private boolean checkAndLoadResource(String JavaDoc name) {
80         boolean res = false;
81         ConnectorRuntime connectorRuntime = ConnectorRuntime.getRuntime();
82         if(connectorRuntime.isServer()) {
83             res = connectorRuntime.checkAndLoadResource(name);
84         }
85         return res;
86     }
87
88
89     /**
90      * Bind the object to the specified name.
91      * @exception NamingException if there is a naming exception.
92      * @exception if there is an RMI exception.
93      */

94
95     public void bind(String JavaDoc name, Object JavaDoc obj)
96         throws NamingException, RemoteException {
97
98         rootContext.bind(name, obj);
99     }
100
101     /**
102      * Rebind the object to the specified name.
103      * @exception NamingException if there is a naming exception.
104      * @exception if there is an RMI exception.
105      */

106
107     public void rebind(String JavaDoc name, Object JavaDoc obj)
108         throws NamingException, RemoteException {
109
110         rootContext.rebind(name, obj);
111     }
112
113     /**
114      * Unbind the specified object.
115      * @exception NamingException if there is a naming exception.
116      * @exception if there is an RMI exception.
117      */

118
119     public void unbind(String JavaDoc name)
120         throws NamingException, RemoteException {
121
122         rootContext.unbind(name);
123     }
124
125     /**
126      * Rename the bound object.
127      * @exception NamingException if there is a naming exception.
128      * @exception if there is an RMI exception.
129      */

130
131     public void rename(String JavaDoc oldname, String JavaDoc newname)
132         throws NamingException, RemoteException {
133
134         rootContext.rename(oldname, newname);
135     }
136
137     public Hashtable list() throws RemoteException {
138
139         return rootContext.list();
140     }
141
142     /**
143      * List the contents of the specified context.
144      * @exception NamingException if there is a naming exception.
145      * @exception if there is an RMI exception.
146      */

147
148     public Hashtable list(String JavaDoc name) throws NamingException, RemoteException {
149     Hashtable ne = rootContext.listContext(name);
150     return ne;
151     }
152
153     /**
154      * Create a subcontext with the specified name.
155      * @return the created subcontext.
156      * @exception NamingException if there is a naming exception.
157      * @exception if there is an RMI exception.
158      */

159
160     public Context createSubcontext(String JavaDoc name)
161     throws NamingException, RemoteException {
162
163     Context ctx = rootContext.createSubcontext(name);
164     return ctx;
165     }
166
167     /**
168      * Destroy the subcontext with the specified name.
169      * @exception NamingException if there is a naming exception.
170      * @exception if there is an RMI exception.
171      */

172
173     public void destroySubcontext(String JavaDoc name)
174     throws NamingException, RemoteException {
175
176     rootContext.destroySubcontext(name);
177     }
178
179 }
180
181
182
183
184
185
186
Popular Tags