FileDocCategorySizeDatePackage
EnvironmentProperty.javaAPI DocGlassfish v2 API15237Fri May 04 22:31:22 BST 2007None

EnvironmentProperty

public class EnvironmentProperty extends Descriptor implements com.sun.enterprise.deployment.web.EnvironmentEntry, InjectionCapable, com.sun.enterprise.deployment.web.WebDescriptor, com.sun.enterprise.deployment.web.ContextParameter, com.sun.enterprise.deployment.web.InitializationParameter
The EnvironmentProperty class hold the data about a single environment entry for J2EE components.
author
Danny Coward

Fields Summary
private String
value
private String
type
private Object
valueObject
private boolean
setValueCalled
private Set
injectionTargets
private static Class[]
allowedTypes
private static com.sun.enterprise.util.LocalStringManagerImpl
localStrings
protected String
mappedName
Constructors Summary
public EnvironmentProperty(EnvironmentProperty other)
copy constructor.

						    
           

       
	super(other);
	value = other.value;
	type = other.type;
	valueObject = other.valueObject;
    
public EnvironmentProperty()
Construct an environment property if type String and empty string value and no description.

    
public EnvironmentProperty(String name, String value, String description)
Construct an environment property of given name value and description.

	this(name, value, description, null);
    
public EnvironmentProperty(String name, String value, String description, String type)
Construct an environment property of given name value and description and type. Throws an IllegalArgumentException if bounds checking is true and the value cannot be reconciled with the given type.

	super(name, description);
	this.value = value;
	checkType(type);
	this.type = type;
    
Methods Summary
public voidaddInjectionTarget(InjectionTarget target)

        if (injectionTargets==null) {
            injectionTargets = new HashSet<InjectionTarget>();
        }
        boolean found = false;
        for (InjectionTarget injTarget : injectionTargets) {
            if (injTarget.equals(target)) {
                found = true;
                break;
            }
        }
        if (!found) {
            injectionTargets.add(target);
        }
    
private voidcheckType(java.lang.String type)
checks the given class type. throws an IllegalArgumentException if bounds checking if the type is not allowed.

	if (type != null) {
	    Class typeClass = null;
	    // is it loadable ?
	    try {
		typeClass = Class.forName(type);
	    } catch (Throwable t) {
		if (this.isBoundsChecking()) {
		    throw new IllegalArgumentException(localStrings.getLocalString(
										   "enterprise.deployment..exceptiontypenotallowedpropertytype",
										   "{0} is not an allowed property value type", new Object[] {type}));
		} else {
		    return;
		}
	    }
	    boolean allowedType = false;
	    for (int i = 0; i < allowedTypes.length; i++) {
		if (allowedTypes[i].equals(typeClass)) {
		    allowedType = true;
		    break;
		}
	    }
	    if (this.isBoundsChecking() && !allowedType) {
		throw new IllegalArgumentException(localStrings.getLocalString(
										   "enterprise.deployment.exceptiontypenotallowedprprtytype",
										   "{0} is not an allowed property value type", new Object[] {type}));
	    }
	}
    
private java.lang.StringconvertPrimitiveTypes(java.lang.String type)

        if (type == null) {
            return type;
        }

        if (type.equals("int")) {
            return "java.lang.Integer";
        } else if (type.equals("boolean")) {
            return "java.lang.Boolean";
        } else if (type.equals("double")) {
            return "java.lang.Double";
        } else if (type.equals("float")) {
            return "java.lang.Float";
        } else if (type.equals("long")) {
            return "java.lang.Long";
        } else if (type.equals("short")) {
            return "java.lang.Short";
        } else if (type.equals("byte")) {
            return "java.lang.Byte";
        } else if (type.equals("char")) {
            return "java.lang.Character";
        }
        return type;
    
public booleanequals(java.lang.Object other)
Returns true if the argument is an environment property of the same name, false else.

	if (other instanceof EnvironmentProperty &&
	    this.getName().equals( ((EnvironmentProperty) other).getName() )) {
		return true;
	}
	return false;
    
public java.lang.StringgetComponentEnvName()

        return getName();
    
public java.lang.StringgetInjectResourceType()

        return type;
    
public java.util.SetgetInjectionTargets()

        return injectionTargets;
    
public java.lang.StringgetMappedName()

        return (mappedName != null)? mappedName : "";
    
private java.lang.ObjectgetObjectFromString(java.lang.String string, java.lang.Class type)

        if (type == null && !this.isBoundsChecking()) {
            Object obj = getValueObjectUsingAllowedTypes(string);
            if (obj != null) return obj;
        }
	if (string == null || ("".equals(string) && !type.equals(String.class))) {
	    return null;
	}
	try {
            if (String.class.equals(type)) {
		return string;
            } else if (Boolean.class.equals(type)) {
		return Boolean.valueOf(string);
	    } else if (Integer.class.equals(type)) {
		return Integer.valueOf(string);
	    } else if (Double.class.equals(type)) {
		return new Double(string);
	    } else if (Float.class.equals(type)) {
		return new Float(string);
	    } else if (Short.class.equals(type)) {
		return Short.valueOf(string);
	    } else if (Byte.class.equals(type)) {
		return Byte.valueOf(string);
	    } else if (Long.class.equals(type)) {
		return Long.valueOf(string);
	    } else if (Character.class.equals(type)) {
                if (string.length() != 1) {
                    throw new IllegalArgumentException();
                } else {
                    return Character.valueOf(string.charAt(0));
                }
            }
	} catch (Throwable t) {
	    throw new IllegalArgumentException(localStrings.getLocalString(
									   "enterprise.deployment.exceptioncouldnotcreateinstancetype",
									   "Could not create instance of {0} from {1}\n reason: {2}" + t, new Object[] {type, string, t}));
	}
	throw new IllegalArgumentException(localStrings.getLocalString(
								       "enterprise.deployment.exceptionillegaltypeenvproperty",
								       "Illegal type for environment properties: {0}", new Object[] {type}));
    
public java.lang.StringgetResolvedValue()
Returns a resolved value of this environment property

    	return RelativePathResolver.resolvePath(getValue());
    
public java.lang.ObjectgetResolvedValueObject()
Returns the typed value object of this environment property. Throws an IllegalArgumentException if bounds checking is true and the value cannot be reconciled with the given type.

 	if (this.valueObject == null) {
 	    this.valueObject = "";
 	}
 	return getObjectFromString(this.getResolvedValue(), this.getValueType()); 
     
public java.lang.StringgetType()
Returns value type of this environment property as a classname.

	if (type == null && this.isBoundsChecking()) {
            return String.class.getName();
	} else {
            return type;
        }
    
public java.lang.StringgetValue()
Returns the String value of this environment property

	if (this.value == null) {
	    this.value = "";
	}
	return value;
    
public java.lang.ObjectgetValueObject()
Returns the typed value object of this environment property. Throws an IllegalArgumentException if bounds checking is true and the value cannot be reconciled with the given type.

	if (this.valueObject == null) {
	    this.valueObject = "";
	}
	return getObjectFromString(this.getValue(), this.getValueType()); 
    
private java.lang.ObjectgetValueObjectUsingAllowedTypes(java.lang.String string)

        if (this.type.equals(int.class.getName())) {
            return Integer.valueOf(string);
        } else if (this.type.equals(long.class.getName())) {
            return Long.valueOf(string);
        } else if (this.type.equals(short.class.getName())) {
            return Short.valueOf(string);
        } else if (this.type.equals(boolean.class.getName())) {
            return Boolean.valueOf(string);
        } else if (this.type.equals(float.class.getName())) {
            return new Float(string);
        } else if (this.type.equals(double.class.getName())) {
            return new Double(string);
        } else if (this.type.equals(byte.class.getName())) {
            return Byte.valueOf(string);
        } else if (this.type.equals(char.class.getName())) {
            if (string.length() != 1) {
                throw new IllegalArgumentException();
            } else {
                return Character.valueOf(string.charAt(0));
            }
        } 
        return null;
    
public java.lang.ClassgetValueType()
Returns value type of this environment property.

	if (this.type == null) {
	    return String.class;
	} else {
	    try {
		return Class.forName(this.type);
	    } catch (Throwable t) {
		return null;
	    }
	}
    
public booleanhasAValue()

        return setValueCalled;
    
public inthashCode()
The hashCode of an environment property is the same as that of the name String.

	return this.getName().hashCode();
    
public booleanisInjectable()

        return (injectionTargets!=null && injectionTargets.size()>0);
        //return (getInjectTargetName() != null);
    
public voidprint(java.lang.StringBuffer toStringBuffer)
Returns a String representation of this environment property.

	toStringBuffer.append("Env-Prop: ").append(super.getName()).append("@");
        printInjectableResourceInfo(toStringBuffer);
        toStringBuffer.append("@").append(this.getType()).append("@").append(this.getValue()).append("@").append("@").append(super.getDescription());
    
public java.lang.StringBufferprintInjectableResourceInfo(java.lang.StringBuffer toStringBuffer)

        
        if( isInjectable() ) {
            for (InjectionTarget target : getInjectionTargets()) {
                if( target.isFieldInjectable() ) {
                    toStringBuffer.append("Field-Injectable Resource. Class name = ").
                            append(target.getClassName()).append(" Field name=").
                            append(target.getFieldName());
                } else {
                    toStringBuffer.append("Method-Injectable Resource. Class name =").
                            append(target.getClassName()).append(" Method =").                            
                            append(target.getMethodName());
                }
            }
        } else {
            toStringBuffer.append("Non-Injectable Resource");
        }

        return toStringBuffer;
    
public voidsetInjectResourceType(java.lang.String resourceType)

        type = convertPrimitiveTypes(resourceType);
    
public voidsetMappedName(java.lang.String mName)

        mappedName = mName;
    
public voidsetType(java.lang.String type)
Returns value type of this environment property. Throws Illegal argument exception if this is not an allowed type and bounds checking.

	checkType(type);
	this.type = type;
    
public voidsetValue(java.lang.String value)
Sets the value of the environment property to the given string.

	this.value = value;
        this.setValueCalled = true;
	super.changed();