1 23 28 29 package com.sun.enterprise.tools.verifier.tests.connector; 30 31 import com.sun.enterprise.tools.verifier.Result; 32 import com.sun.enterprise.tools.verifier.*; 33 import com.sun.enterprise.deployment.ConnectorDescriptor; 34 import com.sun.enterprise.deployment.EnvironmentProperty; 35 import com.sun.enterprise.tools.verifier.tests.*; 36 import java.util.*; 37 import java.beans.*; 38 39 45 public class CheckResourceAdapterJavaBean 46 extends ConnectorTest 47 implements ConnectorCheck 48 { 49 50 58 public Result check(ConnectorDescriptor descriptor) { 59 60 Result result = getInitializedResult(); 61 ComponentNameConstructor compName = 62 getVerifierContext().getComponentNameConstructor(); 63 64 String impl = descriptor.getResourceAdapterClass(); 65 if(impl.equals("")) 66 { 67 if(descriptor.getInBoundDefined()) 68 { 69 result.addErrorDetails(smh.getLocalString 71 ("tests.componentNameConstructor", 72 "For [ {0} ]", 73 new Object [] {compName.toString()})); 74 result.failed(smh.getLocalString 75 (getClass().getName() + ".failed1", 76 "resourceadapter-class cannot be empty if the resource" + 77 " adapter provides inbound communication")); 78 } 79 else 80 { 81 result.addNaDetails(smh.getLocalString 82 ("tests.componentNameConstructor", 83 "For [ {0} ]", 84 new Object [] {compName.toString()})); 85 result.notApplicable(smh.getLocalString 86 ("com.sun.enterprise.tools.verifier.tests.connector.resourceadapter.notApp", 87 "resourceadapter-class is not specified.")); 88 } 89 return result; 90 } 91 Context context = getVerifierContext(); 92 Class implClass = null; 93 try 94 { 95 implClass = Class.forName(impl, false, getVerifierContext().getClassLoader()); 96 } 97 catch(ClassNotFoundException e) 98 { 99 result.addErrorDetails(smh.getLocalString 100 ("tests.componentNameConstructor", 101 "For [ {0} ]", 102 new Object [] {compName.toString()})); 103 result.failed(smh.getLocalString 104 ("com.sun.enterprise.tools.verifier.tests.connector.CheckResourceAdapter.nonexist", 105 "Error: The class [ {0} ] as defined under resourceadapter-class in the deployment descriptor does not exist", 106 new Object [] {impl})); 107 return result; 108 } 109 Set configProps = descriptor.getConfigProperties(); 110 boolean oneFailed = false; 111 Iterator propIter = configProps.iterator(); 112 BeanInfo bi = null; 113 try 114 { 115 bi = Introspector.getBeanInfo(implClass, Object .class); 116 } 117 catch (IntrospectionException ie) { 118 oneFailed = true; 119 result.addErrorDetails(smh.getLocalString 120 ("tests.componentNameConstructor", 121 "For [ {0} ]", 122 new Object [] {compName.toString()})); 123 result.failed(smh.getLocalString 124 (getClass().getName() + ".failed", 125 "Error: The resourceadapter-class [ {0} ] is not JavaBeans compliant", 126 new Object [] {impl} )); 127 return result; 128 } 129 130 PropertyDescriptor[] properties = bi.getPropertyDescriptors(); 131 Hashtable<String , PropertyDescriptor> props = new Hashtable<String , PropertyDescriptor>(); 132 for(int i=0;i<properties.length;i++) 133 { 134 props.put(properties[i].getName(), properties[i]); 135 } 136 while(propIter.hasNext()) 137 { 138 EnvironmentProperty envProp = (EnvironmentProperty) propIter.next(); 139 String name = Introspector.decapitalize(envProp.getName()); 140 String type = envProp.getType(); 141 PropertyDescriptor propDesc = props.get(name); 142 if(propDesc != null) 143 { 144 if (propDesc.getReadMethod()==null || propDesc.getWriteMethod()==null) 145 { 146 oneFailed = true; 147 result.addErrorDetails(smh.getLocalString 148 ("tests.componentNameConstructor", 149 "For [ {0} ]", 150 new Object [] {compName.toString()})); 151 result.failed(smh.getLocalString 152 (getClass().getName() + ".failed1", 153 "Error: The resourceadapter-class [ {0} ] does not provide accessor methods for [ {1} ].", 154 new Object [] {impl, name} )); 155 return result; 156 } 157 } 158 else 159 { 160 oneFailed = true; 161 result.addErrorDetails(smh.getLocalString 162 ("tests.componentNameConstructor", 163 "For [ {0} ]", 164 new Object [] {compName.toString()})); 165 result.failed(smh.getLocalString 166 (getClass().getName() + ".failed1", 167 "Error: The resourceadapter-class [ {0} ] does not provide accessor methods for [ {1} ].", 168 new Object [] {impl, name} )); 169 return result; 170 } 171 } 172 if(!oneFailed) 173 { 174 result.addGoodDetails(smh.getLocalString 175 ("tests.componentNameConstructor", 176 "For [ {0} ]", 177 new Object [] {compName.toString()})); 178 result.passed(smh.getLocalString(getClass().getName() + ".passed", 179 "Success: resourceadapter-class is a Java Bean")); 180 } 181 return result; 182 } 183 } 184 | Popular Tags |