KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > naming > factory > AdministeredObjectFactory


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.factory;
24
25 import com.sun.enterprise.ComponentInvocation;
26 import com.sun.enterprise.InvocationManager;
27 import com.sun.enterprise.Switch;
28 import com.sun.enterprise.connectors.*;
29 import com.sun.enterprise.deployment.ConnectorDescriptor;
30 import com.sun.enterprise.resource.ResourceInstaller;
31 import com.sun.logging.LogDomains;
32 import java.util.Hashtable JavaDoc;
33 import java.util.logging.Level JavaDoc;
34 import java.util.logging.Logger JavaDoc;
35 import javax.naming.ConfigurationException JavaDoc;
36 import javax.naming.Context JavaDoc;
37 import javax.naming.InitialContext JavaDoc;
38 import javax.naming.Name JavaDoc;
39 import javax.naming.NamingException JavaDoc;
40 import javax.naming.Reference JavaDoc;
41 import javax.naming.spi.ObjectFactory JavaDoc;
42
43 /**
44  * An object factory to handle creation of administered object
45  *
46  * @author Qingqing Ouyang
47  *
48  */

49 public class AdministeredObjectFactory implements ObjectFactory JavaDoc {
50
51     private static Logger JavaDoc logger =
52     LogDomains.getLogger(LogDomains.RSR_LOGGER);
53
54     //required by ObjectFactory
55
public AdministeredObjectFactory() {}
56
57     public Object JavaDoc getObjectInstance(Object JavaDoc obj,
58                     Name JavaDoc name,
59                     Context JavaDoc nameCtx,
60                     Hashtable JavaDoc env) throws Exception JavaDoc {
61
62     Reference JavaDoc ref = (Reference JavaDoc) obj;
63     logger.fine("AdministeredObjectFactory: " + ref +
64             " Name:" + name);
65
66         //String jndiName = (String) ref.get(0).getContent();
67
AdministeredObjectResource aor =
68             (AdministeredObjectResource) ref.get(0).getContent();
69         String JavaDoc jndiName = aor.getName();
70         String JavaDoc moduleName = aor.getResourceAdapter();
71     
72     ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
73     
74         //If call fom application client, start resource adapter lazily.
75
//todo: Similar code in ConnectorObjectFactory - to refactor.
76
if(runtime.getEnviron() == ConnectorRuntime.CLIENT) {
77             ConnectorDescriptor connectorDescriptor = null;
78             try {
79                 Context JavaDoc ic = new InitialContext JavaDoc();
80                 String JavaDoc descriptorJNDIName = ConnectorAdminServiceUtils.
81                     getReservePrefixedJNDINameForDescriptor(moduleName);
82                 connectorDescriptor = (ConnectorDescriptor)ic.lookup(descriptorJNDIName);
83             } catch(NamingException JavaDoc ne) {
84                 logger.log(Level.FINE, "Failed to look up ConnectorDescriptor " +
85                                             "from JNDI", moduleName);
86                 throw new ConnectorRuntimeException("Failed to look up " +
87                                                 "ConnectorDescriptor from JNDI");
88             }
89             runtime.createActiveResourceAdapter(connectorDescriptor, moduleName,
90                             null,false);
91         }
92     
93         ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
94         if (runtime.checkAccessibility(moduleName, loader) == false) {
95         throw new NamingException JavaDoc("Only the application that has the embedded resource" +
96                                    "adapter can access the resource adapter");
97     }
98
99     logger.fine("[AdministeredObjectFactory] ==> Got AdministeredObjectResource = " + aor);
100
101     return aor.createAdministeredObject(null);
102     }
103
104 }
105
Popular Tags