FileDocCategorySizeDatePackage
CheckResourceAdapterJavaBean.javaAPI DocGlassfish v2 API7484Fri May 04 22:33:28 BST 2007com.sun.enterprise.tools.verifier.tests.connector

CheckResourceAdapterJavaBean

public class CheckResourceAdapterJavaBean extends ConnectorTest implements ConnectorCheck
Test that "resourceadapter-class" is a Java Bean.
author
Anisha Malhotra
version

Fields Summary
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.ConnectorDescriptor descriptor)

Test that "resourceadapter-class" is a Java Bean.

param
descriptor deployment descriptor for the rar file
return
result object containing the result of the individual test performed


    Result result = getInitializedResult();
    ComponentNameConstructor compName = 
      getVerifierContext().getComponentNameConstructor();

    String impl = descriptor.getResourceAdapterClass();
    if(impl.equals(""))
    {
      if(descriptor.getInBoundDefined())
      {
        // resourceadapter-class cannot be null
        result.addErrorDetails(smh.getLocalString
            ("tests.componentNameConstructor",
             "For [ {0} ]",
             new Object[] {compName.toString()}));
        result.failed(smh.getLocalString
            (getClass().getName() + ".failed1",
             "resourceadapter-class cannot be empty if the resource" + 
             " adapter provides inbound communication"));
      }
      else
      {
          result.addNaDetails(smh.getLocalString
              ("tests.componentNameConstructor",
               "For [ {0} ]",
               new Object[] {compName.toString()}));
          result.notApplicable(smh.getLocalString
              ("com.sun.enterprise.tools.verifier.tests.connector.resourceadapter.notApp",
               "resourceadapter-class is not specified."));
      }
      return result;
    }
    Context context = getVerifierContext();
    Class implClass = null;
    try
    {
      implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
    }
    catch(ClassNotFoundException e)
    {
      result.addErrorDetails(smh.getLocalString
          ("tests.componentNameConstructor",
           "For [ {0} ]",
           new Object[] {compName.toString()}));
      result.failed(smh.getLocalString
          ("com.sun.enterprise.tools.verifier.tests.connector.CheckResourceAdapter.nonexist",
           "Error: The class [ {0} ] as defined under resourceadapter-class in the deployment descriptor does not exist",
           new Object[] {impl}));
      return result;
    }
    Set configProps = descriptor.getConfigProperties();
    boolean oneFailed = false;
    Iterator propIter = configProps.iterator();
    BeanInfo bi = null;
    try
    {
      bi = Introspector.getBeanInfo(implClass, Object.class);
    } 
    catch (IntrospectionException ie) {
      oneFailed = true;
      result.addErrorDetails(smh.getLocalString
          ("tests.componentNameConstructor",
           "For [ {0} ]",
           new Object[] {compName.toString()}));
      result.failed(smh.getLocalString
          (getClass().getName() + ".failed",
           "Error: The resourceadapter-class [ {0} ] is not JavaBeans compliant",
           new Object[] {impl} ));
      return result;
    }

    PropertyDescriptor[] properties = bi.getPropertyDescriptors();
    Hashtable<String, PropertyDescriptor> props = new Hashtable<String, PropertyDescriptor>();
    for(int i=0;i<properties.length;i++)
    {
      props.put(properties[i].getName(), properties[i]);
    }
    while(propIter.hasNext()) 
    {
      EnvironmentProperty envProp = (EnvironmentProperty) propIter.next();
      String name = Introspector.decapitalize(envProp.getName());
      String type = envProp.getType();
      PropertyDescriptor propDesc = props.get(name);
      if(propDesc != null)
      {
        if (propDesc.getReadMethod()==null || propDesc.getWriteMethod()==null)
        {
          oneFailed = true;
          result.addErrorDetails(smh.getLocalString
              ("tests.componentNameConstructor",
               "For [ {0} ]",
               new Object[] {compName.toString()}));
          result.failed(smh.getLocalString
              (getClass().getName() + ".failed1",
               "Error: The resourceadapter-class [ {0} ] does not provide accessor methods for [ {1} ].",
               new Object[] {impl, name} ));
          return result;
        }
      }
      else
      {
        oneFailed = true;
        result.addErrorDetails(smh.getLocalString
            ("tests.componentNameConstructor",
             "For [ {0} ]",
             new Object[] {compName.toString()}));
        result.failed(smh.getLocalString
            (getClass().getName() + ".failed1",
             "Error: The resourceadapter-class [ {0} ] does not provide accessor methods for [ {1} ].",
             new Object[] {impl, name} ));
        return result;
      }
    }
    if(!oneFailed)
    {
      result.addGoodDetails(smh.getLocalString
          ("tests.componentNameConstructor",
           "For [ {0} ]",
           new Object[] {compName.toString()}));	
      result.passed(smh.getLocalString(getClass().getName() + ".passed",
            "Success: resourceadapter-class is a Java Bean"));                     
    }
    return result;