You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by da...@apache.org on 2003/11/11 17:00:59 UTC

cvs commit: incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service GeronimoAttributeInfo.java GeronimoMBean.java GeronimoMBeanInfo.java ParserUtil.java

dain        2003/11/11 08:00:59

  Modified:    modules/kernel/src/java/org/apache/geronimo/kernel/service
                        GeronimoAttributeInfo.java GeronimoMBean.java
                        GeronimoMBeanInfo.java ParserUtil.java
  Log:
  Added support for initial value of attributes.
  
  Revision  Changes    Path
  1.6       +56 -20    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoAttributeInfo.java
  
  Index: GeronimoAttributeInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoAttributeInfo.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- GeronimoAttributeInfo.java	10 Nov 2003 20:38:31 -0000	1.5
  +++ GeronimoAttributeInfo.java	11 Nov 2003 16:00:59 -0000	1.6
  @@ -127,6 +127,11 @@
        */
       long cacheTimeLimit;
   
  +    /**
  +     * The initial value that will be set into the attribute.
  +     */
  +    private Object initialValue;
  +
       //
       // Runtime information -- this is not exposed to clients
       //
  @@ -174,26 +179,39 @@
        * Creates a mutable GeronimoAttributeInfo with the specified name
        */
       public GeronimoAttributeInfo(String name) {
  -        this(name, true, true);
  +        this(name, true, true, null, null, null);
  +    }
  +
  +    public GeronimoAttributeInfo(String name, Object initialValue) {
  +        this(name, true, true, null, null, initialValue);
  +    }
  +
  +    public GeronimoAttributeInfo(String name, boolean readable, boolean writable) {
  +        this(name, readable, writable, null, null, null);
       }
   
  -	public GeronimoAttributeInfo(String name, boolean readable, boolean writable) {
  -	    this(name, readable, writable, null, null);
  -	}
  -
  -	public GeronimoAttributeInfo(String name, boolean readable, boolean writable, String description, String targetName) {
  -		super("Ignore", "Ignore", null, true, true, false);
  -		this.name = name;
  -		this.readable = readable;
  -		this.writable = writable;
  -		this.description = description;
  -		this.targetName = targetName;
  -
  -		immutable = false;
  -		getterMethod = null;
  -		setterMethod = null;
  -		type = null;
  -	}
  +    public GeronimoAttributeInfo(String name, boolean readable, boolean writable, Object initialValue) {
  +        this(name, readable, writable, null, null, initialValue);
  +    }
  +
  +    public GeronimoAttributeInfo(String name, boolean readable, boolean writable, String description, String targetName) {
  +        this(name, readable, writable, description, targetName, null);
  +    }
  +
  +    public GeronimoAttributeInfo(String name, boolean readable, boolean writable, String description, String targetName, Object initialValue) {
  +        super("Ignore", "Ignore", null, true, true, false);
  +        this.name = name;
  +        this.readable = readable;
  +        this.writable = writable;
  +        this.description = description;
  +        this.targetName = targetName;
  +        this.initialValue = initialValue;
  +
  +        immutable = false;
  +        getterMethod = null;
  +        setterMethod = null;
  +        type = null;
  +    }
   
   
       /**
  @@ -201,7 +219,7 @@
        * @param source the source GeronimoAttributeInfo to copy
        * @param parent the GeronimoMBeanInfo that will contain this attribute
        */
  -    GeronimoAttributeInfo(GeronimoAttributeInfo source, GeronimoMBeanInfo parent) {
  +    GeronimoAttributeInfo(GeronimoAttributeInfo source, GeronimoMBeanInfo parent) throws Exception {
           super("Ignore", "Ignore", null, true, true, false);
           immutable = true;
   
  @@ -224,6 +242,7 @@
           //
           description = source.description;
           cacheTimeLimit = source.cacheTimeLimit;
  +        initialValue = source.initialValue;
   
           //
           // Optional (derived)
  @@ -322,6 +341,15 @@
               setterMethod = null;
           }
           type = attributeType.getName();
  +
  +        if(initialValue != null) {
  +            if (attributeType != String.class && initialValue instanceof String) {
  +                initialValue = ParserUtil.getValue(attributeType, (String) initialValue);
  +            }
  +            if (setterMethod != null) {
  +                setterMethod.invoke(target, new Object[]{initialValue});
  +            }
  +        }
       }
   
       public String getName() {
  @@ -446,6 +474,14 @@
           } else {
               this.cacheTimeLimit = Long.parseLong(cacheTimeLimit);
           }
  +    }
  +
  +    public Object getInitialValue() {
  +        return initialValue;
  +    }
  +
  +    public void setInitialValue(Object initialValue) {
  +        this.initialValue = initialValue;
       }
   
       public int hashCode() {
  
  
  
  1.6       +23 -10    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBean.java
  
  Index: GeronimoMBean.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBean.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- GeronimoMBean.java	9 Nov 2003 20:00:05 -0000	1.5
  +++ GeronimoMBean.java	11 Nov 2003 16:00:59 -0000	1.6
  @@ -119,6 +119,17 @@
   
           classLoader = ClassSpaceUtil.getClassLoader(server, classSpace);
           context = new GeronimoMBeanContext(server, this, name);
  +        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
  +        try {
  +            // Set the class loader
  +            Thread.currentThread().setContextClassLoader(classLoader);
  +
  +            // @todo there is an issue here with restarted deployments
  +            addManagedObjectMBeanInfo();
  +            mbeanInfo = new GeronimoMBeanInfo(mbeanInfo);
  +        } finally {
  +            Thread.currentThread().setContextClassLoader(oldClassLoader);
  +        }
           return this.objectName;
       }
   
  @@ -133,8 +144,7 @@
               // Set the class loader
               Thread.currentThread().setContextClassLoader(classLoader);
   
  -            addManagedObjectMBeanInfo();
  -            mbeanInfo = new GeronimoMBeanInfo(mbeanInfo);
  +            // build the attribute map
               Set attributes = mbeanInfo.getAttributeSet();
               for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
                   GeronimoAttributeInfo attributeInfo = (GeronimoAttributeInfo) iterator.next();
  @@ -151,12 +161,15 @@
                       operationInfoMap.put(new MBeanOperationSignature(setterName, new String[]{attributeInfo.getType()}), attributeInfo);
                   }
               }
  +
  +            // build the operation map
               Set operations = mbeanInfo.getOperationsSet();
               for (Iterator iterator = operations.iterator(); iterator.hasNext();) {
                   GeronimoOperationInfo operationInfo = (GeronimoOperationInfo) iterator.next();
                   operationInfoMap.put(new MBeanOperationSignature(operationInfo.getName(), operationInfo.getParameterTypes()), operationInfo);
               }
   
  +            // set the context
               for (Iterator i = mbeanInfo.targets.values().iterator(); i.hasNext();) {
                   Object target = i.next();
                   if (target instanceof GeronimoMBeanTarget) {
  @@ -230,8 +243,8 @@
   
       protected boolean canStart() {
           for (Iterator i = mbeanInfo.getEndpointsSet().iterator(); i.hasNext();) {
  -            GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint)i.next();
  -            if(!endpoint.canStart()) {
  +            GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint) i.next();
  +            if (!endpoint.canStart()) {
                   return false;
               }
           }
  @@ -248,7 +261,7 @@
   
       protected void doStart() throws Exception {
           for (Iterator i = mbeanInfo.getEndpointsSet().iterator(); i.hasNext();) {
  -            GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint)i.next();
  +            GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint) i.next();
               endpoint.doStart();
           }
           for (Iterator i = mbeanInfo.targets.values().iterator(); i.hasNext();) {
  @@ -261,8 +274,8 @@
   
       protected boolean canStop() {
           for (Iterator i = mbeanInfo.getEndpointsSet().iterator(); i.hasNext();) {
  -            GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint)i.next();
  -            if(!endpoint.canStop()) {
  +            GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint) i.next();
  +            if (!endpoint.canStop()) {
                   return false;
               }
           }
  @@ -279,7 +292,7 @@
   
       protected void doStop() throws Exception {
           for (Iterator i = mbeanInfo.getEndpointsSet().iterator(); i.hasNext();) {
  -            GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint)i.next();
  +            GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint) i.next();
               endpoint.doStop();
           }
           for (Iterator i = mbeanInfo.targets.values().iterator(); i.hasNext();) {
  @@ -292,7 +305,7 @@
   
       protected void doFail() {
           for (Iterator i = mbeanInfo.getEndpointsSet().iterator(); i.hasNext();) {
  -            GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint)i.next();
  +            GeronimoMBeanEndpoint endpoint = (GeronimoMBeanEndpoint) i.next();
               endpoint.doFail();
           }
           for (Iterator i = mbeanInfo.targets.values().iterator(); i.hasNext();) {
  
  
  
  1.5       +2 -2      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBeanInfo.java
  
  Index: GeronimoMBeanInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBeanInfo.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GeronimoMBeanInfo.java	9 Nov 2003 20:04:45 -0000	1.4
  +++ GeronimoMBeanInfo.java	11 Nov 2003 16:00:59 -0000	1.5
  @@ -117,7 +117,7 @@
           immutable = false;
       }
   
  -    GeronimoMBeanInfo(GeronimoMBeanInfo source) {
  +    GeronimoMBeanInfo(GeronimoMBeanInfo source) throws Exception {
           super("Ignore", null, null, null, null, null);
           immutable = true;
   
  
  
  
  1.4       +18 -12    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/ParserUtil.java
  
  Index: ParserUtil.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/ParserUtil.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ParserUtil.java	24 Oct 2003 22:35:42 -0000	1.3
  +++ ParserUtil.java	11 Nov 2003 16:00:59 -0000	1.4
  @@ -314,21 +314,27 @@
           return getValue(type, value, baseURI);
       }
   
  +    public static Object getValue(Class type, String value) {
  +        return getValue(type, value, null);
  +    }
  +
       public static Object getValue(Class type, String value, URI baseURI) {
           value = parse(value);
   
  -        if (URI.class.equals(type)) {
  -            return baseURI.resolve(value);
  -        }
  -        if (URL.class.equals(type)) {
  -            try {
  -                return baseURI.resolve(value).toURL();
  -            } catch (MalformedURLException e) {
  -                throw new IllegalArgumentException("Value is not a valid URI: value=" + value);
  +        if(baseURI != null) {
  +            if (URI.class.equals(type)) {
  +                return baseURI.resolve(value);
  +            }
  +            if (URL.class.equals(type)) {
  +                try {
  +                    return baseURI.resolve(value).toURL();
  +                } catch (MalformedURLException e) {
  +                    throw new IllegalArgumentException("Value is not a valid URI: value=" + value);
  +                }
  +            }
  +            if (File.class.equals(type)) {
  +                return new File(baseURI.resolve(value));
               }
  -        }
  -        if (File.class.equals(type)) {
  -            return new File(baseURI.resolve(value));
           }
   
           // try a property editor