FileDocCategorySizeDatePackage
Resource.javaAPI DocGlassfish v2 API8888Fri May 04 22:35:14 BST 2007com.sun.enterprise.resource

Resource

public class Resource extends Object
Class which represents the Resource.

Fields Summary
protected static final String
CUSTOM_RESOURCE
protected static final String
JDBC_CONNECTION_POOL
protected static final String
CONNECTOR_RESOURCE
protected static final String
ADMIN_OBJECT_RESOURCE
protected static final String
JDBC_RESOURCE
protected static final String
RESOURCE_ADAPTER_CONFIG
protected static final String
MAIL_RESOURCE
protected static final String
EXTERNAL_JNDI_RESOURCE
protected static final String
CONNECTOR_CONNECTION_POOL
protected static final String
PERSISTENCE_MANAGER_FACTORY_RESOURCE
protected static final String
CONNECTOR_SECURITY_MAP
private String
resType
private AttributeList
attrList
private Properties
props
private String
sDescription
Constructors Summary
public Resource(String type)


       
        resType = type;
    
Methods Summary
public booleanequals(java.lang.Object obj)

        if (this == obj) return true;
        if ( !(obj instanceof Resource) ) return false;
        Resource r = (Resource)obj;
        return r.getType().equals(this.getType()) && 
                //No need to compare description for equality
                //r.getDescription().equals(this.getDescription()) &&
                r.getProperties().equals(this.getProperties()) &&
                r.getAttributes().equals(this.getAttributes());
    
private javax.management.AttributegetAttribute(com.sun.enterprise.resource.Resource r, java.lang.String name)
Utility method to get an Attribute of the given name in the specified resource

        for (Iterator<Attribute> iter = r.getAttributes().iterator(); iter.hasNext();) {
            Attribute elt =  iter.next();
            if (elt.getName().equals(name)) return elt;
        }
        return null;
    
public javax.management.AttributeListgetAttributes()

        return attrList;
    
public java.lang.StringgetDescription()

        return sDescription;
    
public java.util.PropertiesgetProperties()

        return props;
    
public java.lang.StringgetType()

        return resType;
    
private booleanhasSameIdentity(com.sun.enterprise.resource.Resource r)
Checks if the specified resource has the same identity as this resource.

        //For two resources to have the same identity, atleast their types should match
        if (r.getType() != this.getType()) {
            return false;
        }
        String rType = r.getType();
        
        //For all resources, their identity is their jndi-name
        if (rType.equals(CUSTOM_RESOURCE)|| rType.equals(EXTERNAL_JNDI_RESOURCE)
             || rType.equals(JDBC_RESOURCE)|| rType.equals(PERSISTENCE_MANAGER_FACTORY_RESOURCE)
             || rType.equals(CONNECTOR_RESOURCE)|| rType.equals(ADMIN_OBJECT_RESOURCE) || rType.equals(MAIL_RESOURCE)) {
            return isEqualAttribute(r, JNDI_NAME);
        }
        
        //For pools the identity is limited to pool name
        if (rType.equals(JDBC_CONNECTION_POOL) || rType.equals(CONNECTOR_CONNECTION_POOL)) {
            return isEqualAttribute(r, CONNECTION_POOL_NAME);
        }
        
        if (rType.equals(RESOURCE_ADAPTER_CONFIG)) {
            return isEqualAttribute(r, RES_ADAPTER_CONFIG);
        }
        
        return false;
    
public inthashCode()

        return this.getAttributes().hashCode() + 
        this.getProperties().hashCode() + 
        this.getType().hashCode();
        //description is not used to generate hashcode
        //this.getDescription().hashCode();
    
public booleanisAConflict(com.sun.enterprise.resource.Resource r)

        //If the two resource have the same identity 
        if (hasSameIdentity(r)) {
            //If the two resources are not equal, then there is no 
            //conflict
            if (!r.equals(this)) 
                return true;
        }
        return false;
    
private booleanisEqualAttribute(com.sun.enterprise.resource.Resource r, java.lang.String name)
Compares the attribute with the specified name in this resource with the passed in resource and checks if they are equal

        return (getAttribute(r, name).equals(getAttribute(this, name)));
    
public voidsetAttribute(java.lang.String name, java.lang.String value)

        attrList.add(new Attribute(name, value));
    
public voidsetAttribute(java.lang.String name, java.lang.String[] value)

        attrList.add(new Attribute(name, value));
    
public voidsetDescription(java.lang.String sDescription)

        this.sDescription = sDescription;
    
public voidsetProperty(java.lang.String name, java.lang.String value)

        props.setProperty(name, value);
    
public java.lang.StringtoString()

        
        String rType = getType();
        String identity = "";
        if (rType.equals(CUSTOM_RESOURCE)|| rType.equals(EXTERNAL_JNDI_RESOURCE)
             || rType.equals(JDBC_RESOURCE)|| rType.equals(PERSISTENCE_MANAGER_FACTORY_RESOURCE)
             || rType.equals(CONNECTOR_RESOURCE)|| rType.equals(ADMIN_OBJECT_RESOURCE) || rType.equals(MAIL_RESOURCE)) {
            identity =  (String) getAttribute(this, JNDI_NAME).getValue();
        }else if (rType.equals(JDBC_CONNECTION_POOL) || rType.equals(CONNECTOR_CONNECTION_POOL)) {
            identity =  (String) getAttribute(this, CONNECTION_POOL_NAME).getValue();
        }else if (rType.equals(RESOURCE_ADAPTER_CONFIG)) {
            identity =  (String) getAttribute(this, RES_ADAPTER_CONFIG).getValue();
        } 
        
        return identity + " of type " + resType;