1 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 ; 37 import java.security.AccessController ; 38 import java.security.PrivilegedAction ; 39 import java.security.PrivilegedActionException ; 40 import java.util.HashSet ; 41 import java.util.Iterator ; 42 import java.util.Set ; 43 import javax.naming.Reference ; 44 import javax.naming.NamingException ; 45 46 51 public class AdministeredObjectResource extends J2EEResourceBase 52 implements Serializable { 53 54 private String resadapter_; 55 private String adminObjectClass_; 56 private String adminObjectType_; 57 private Set configProperties_; 58 59 60 public AdministeredObjectResource (String name) 61 { 62 super(name); 63 } 64 65 protected J2EEResource doClone(String 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 return 0; 77 } 79 80 public void initialize(AdminObject desc) { 81 configProperties_ = new HashSet (); 82 adminObjectClass_ = desc.getAdminObjectClass(); 83 adminObjectType_ = desc.getAdminObjectInterface(); 84 } 85 86 public String getResourceAdapter() { 87 return resadapter_; 88 } 89 90 public void setResourceAdapter(String resadapter) { 91 resadapter_ = resadapter; 92 } 93 94 public String getAdminObjectType() { 95 return adminObjectType_; 96 } 97 98 public void setAdminObjectType (String adminObjectType) { 99 this.adminObjectType_ = adminObjectType; 100 } 101 102 public void setAdminObjectClass(String name) { 103 this.adminObjectClass_ = name; 104 } 105 106 public String getAdminObjectClass() { 107 return this.adminObjectClass_; 108 } 109 110 113 public void addConfigProperty(EnvironmentProperty configProperty) 114 { 115 this.configProperties_.add(configProperty); 116 } 117 118 121 public void removeConfigProperty(EnvironmentProperty configProperty) 122 { 123 this.configProperties_.remove(configProperty); 124 } 125 126 public Reference createAdminObjectReference() { 127 Reference ref = 128 new Reference (getAdminObjectType(), 129 new SerializableObjectRefAddr("jndiName", this), 130 ConnectorConstants.ADMINISTERED_OBJECT_FACTORY, null); 131 132 return ref; 133 } 134 135 136 public Object createAdministeredObject(ClassLoader jcl) 139 throws PoolingException { 140 141 try { 142 if (jcl == null) { 143 jcl = (ClassLoader ) AccessController.doPrivileged 145 (new PrivilegedAction () { 146 public Object run() { 147 return 148 Thread.currentThread().getContextClassLoader(); 149 } 150 }); 151 } 152 153 154 Object adminObject = 155 jcl.loadClass(adminObjectClass_).newInstance(); 156 157 AccessController.doPrivileged 158 (new SetMethodAction(adminObject, configProperties_)); 159 return adminObject; 160 } catch (PrivilegedActionException ex) { 161 throw (PoolingException) (new PoolingException().initCause(ex)); 162 } catch (Exception ex) { 163 throw (PoolingException) (new PoolingException().initCause(ex)); 164 } 165 166 } 167 168 public String toString() { 169 return "< Administered Object : " + getName() + 170 " , " + getResourceAdapter() + 171 " , " + getAdminObjectType() + " >"; 172 } 173 } 174 | Popular Tags |