KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > AdministeredObjectResource


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
24 package com.sun.enterprise.connectors;
25
26 import com.sun.enterprise.Switch;
27 import com.sun.enterprise.deployment.AdminObject;
28 import com.sun.enterprise.deployment.ConnectorDescriptor;
29 import com.sun.enterprise.deployment.EnvironmentProperty;
30 import com.sun.enterprise.resource.PoolingException;
31 import com.sun.enterprise.resource.ResourceInstaller;
32 import com.sun.enterprise.connectors.util.SetMethodAction;
33 import com.sun.enterprise.repository.J2EEResourceBase;
34 import com.sun.enterprise.repository.J2EEResource;
35 import com.sun.enterprise.repository.SerializableObjectRefAddr;
36 import java.io.Serializable JavaDoc;
37 import java.security.AccessController JavaDoc;
38 import java.security.PrivilegedAction JavaDoc;
39 import java.security.PrivilegedActionException JavaDoc;
40 import java.util.HashSet JavaDoc;
41 import java.util.Iterator JavaDoc;
42 import java.util.Set JavaDoc;
43 import javax.naming.Reference JavaDoc;
44 import javax.naming.NamingException JavaDoc;
45
46 /**
47  * Resource infor for Connector administered objects
48  *
49  * @author Qingqing Ouyang
50  */

51 public class AdministeredObjectResource extends J2EEResourceBase
52     implements Serializable JavaDoc {
53
54     private String JavaDoc resadapter_;
55     private String JavaDoc adminObjectClass_;
56     private String JavaDoc adminObjectType_;
57     private Set JavaDoc configProperties_;
58
59     
60     public AdministeredObjectResource (String JavaDoc name)
61     {
62         super(name);
63     }
64
65     protected J2EEResource doClone(String JavaDoc name) {
66         AdministeredObjectResource clone =
67             new AdministeredObjectResource(name);
68         clone.setResourceAdapter(getResourceAdapter());
69         clone.setAdminObjectType(getAdminObjectType());
70         return clone;
71     }
72
73
74     public int getType() {
75         // FIX ME
76
return 0;
77         //return J2EEResource.ADMINISTERED_OBJECT;
78
}
79
80     public void initialize(AdminObject desc) {
81         configProperties_ = new HashSet JavaDoc();
82         adminObjectClass_ = desc.getAdminObjectClass();
83         adminObjectType_ = desc.getAdminObjectInterface();
84     }
85
86     public String JavaDoc getResourceAdapter() {
87         return resadapter_;
88     }
89
90     public void setResourceAdapter(String JavaDoc resadapter) {
91         resadapter_ = resadapter;
92     }
93
94     public String JavaDoc getAdminObjectType() {
95         return adminObjectType_;
96     }
97     
98     public void setAdminObjectType (String JavaDoc adminObjectType) {
99         this.adminObjectType_ = adminObjectType;
100     }
101
102     public void setAdminObjectClass(String JavaDoc name) {
103         this.adminObjectClass_ = name;
104     }
105
106     public String JavaDoc getAdminObjectClass() {
107         return this.adminObjectClass_;
108     }
109     
110     /*
111      * Add a configProperty to the set
112      */

113     public void addConfigProperty(EnvironmentProperty configProperty)
114     {
115         this.configProperties_.add(configProperty);
116     }
117
118     /**
119      * Add a configProperty to the set
120      */

121     public void removeConfigProperty(EnvironmentProperty configProperty)
122     {
123         this.configProperties_.remove(configProperty);
124     }
125
126     public Reference JavaDoc createAdminObjectReference() {
127         Reference JavaDoc ref =
128             new Reference JavaDoc(getAdminObjectType(),
129                     new SerializableObjectRefAddr("jndiName", this),
130                     ConnectorConstants.ADMINISTERED_OBJECT_FACTORY, null);
131         
132         return ref;
133     }
134
135
136     // called by com.sun.enterprise.naming.factory.AdministeredObjectFactory
137
// FIXME. embedded??
138
public Object JavaDoc createAdministeredObject(ClassLoader JavaDoc jcl)
139         throws PoolingException {
140
141         try {
142             if (jcl == null) {
143                 // use context class loader
144
jcl = (ClassLoader JavaDoc) AccessController.doPrivileged
145                     (new PrivilegedAction JavaDoc() {
146                             public Object JavaDoc run() {
147                                 return
148                                     Thread.currentThread().getContextClassLoader();
149                             }
150                         });
151             }
152                 
153             
154             Object JavaDoc adminObject =
155                 jcl.loadClass(adminObjectClass_).newInstance();
156             
157             AccessController.doPrivileged
158                 (new SetMethodAction(adminObject, configProperties_));
159             return adminObject;
160         } catch (PrivilegedActionException JavaDoc ex) {
161             throw (PoolingException) (new PoolingException().initCause(ex));
162         } catch (Exception JavaDoc ex) {
163             throw (PoolingException) (new PoolingException().initCause(ex));
164         }
165
166     }
167
168     public String JavaDoc toString() {
169         return "< Administered Object : " + getName() +
170             " , " + getResourceAdapter() +
171             " , " + getAdminObjectType() + " >";
172     }
173 }
174
Popular Tags