geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlaskow...@apache.org
Subject cvs commit: incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx GBeanMBeanAttribute.java
Date Sat, 13 Mar 2004 23:46:30 GMT
jlaskowski    2004/03/13 15:46:30

  Modified:    modules/kernel/src/test/org/apache/geronimo/kernel
                        MockGBean.java
               modules/kernel/src/java/org/apache/geronimo/gbean/jmx
                        GBeanMBeanAttribute.java
  Added:       modules/kernel/src/test/org/apache/geronimo/gbean/jmx
                        GBeanMBeanAttributeTest.java
  Log:
    o GBeanMBeanAttribute junit tests
    o additional ExceptionMutableInt attribute and respective access methods
    o additional ctor's input arguments checks
  
  Revision  Changes    Path
  1.14      +41 -13    incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java
  
  Index: MockGBean.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- MockGBean.java	10 Mar 2004 09:59:02 -0000	1.13
  +++ MockGBean.java	13 Mar 2004 23:46:30 -0000	1.14
  @@ -17,26 +17,29 @@
   
   package org.apache.geronimo.kernel;
   
  +import java.lang.reflect.InvocationTargetException;
   import java.util.Collection;
   import java.util.Collections;
   import java.util.Iterator;
   
   import org.apache.geronimo.gbean.GBeanInfo;
   import org.apache.geronimo.gbean.GBeanInfoFactory;
  -import org.apache.geronimo.gbean.GConstructorInfo;
  -import org.apache.geronimo.gbean.GOperationInfo;
  -import org.apache.geronimo.gbean.GReferenceInfo;
   
   /**
  - *
  - *
    * @version $Revision$ $Date$
    */
   public class MockGBean implements MockEndpoint {
  +
       private static final GBeanInfo GBEAN_INFO;
  +
       private final String name;
  +
       private final int finalInt;
  +
       private int mutableInt;
  +
  +    private int exceptionMutableInt;
  +
       private String value;
   
       private MockEndpoint endpoint;
  @@ -52,18 +55,17 @@
           infoFactory.addAttribute("Name", true);
           infoFactory.addAttribute("Value", true);
           infoFactory.addAttribute("FinalInt", true);
  +        infoFactory.addAttribute("MutableInt", false);
  +        infoFactory.addAttribute("ExceptionMutableInt", true);
           infoFactory.addAttribute("EndpointMutableInt", false);
  -        infoFactory.addOperation("checkResource", new Class[] {String.class});
  +        infoFactory.addOperation("checkResource", new Class[] { String.class});
           infoFactory.addOperation("checkEndpoint");
           infoFactory.addOperation("checkEndpointCollection");
  -        infoFactory.addOperation("doSomething", new Class[] {String.class});
  -        infoFactory.addInterface(MockEndpoint.class, new String[] {"MutableInt"});
  +        infoFactory.addOperation("doSomething", new Class[] { String.class});
  +        infoFactory.addInterface(MockEndpoint.class, new String[] { "MutableInt"});
           infoFactory.addReference("MockEndpoint", MockEndpoint.class);
           infoFactory.addReference("EndpointCollection", MockEndpoint.class);
  -        infoFactory.setConstructor(
  -                new String[]{"Name", "FinalInt"},
  -                new Class[]{String.class, Integer.TYPE}
  -        );
  +        infoFactory.setConstructor(new String[] { "Name", "FinalInt"}, new Class[] { String.class,
Integer.TYPE});
           GBEAN_INFO = infoFactory.getBeanInfo();
       }
   
  @@ -98,6 +100,32 @@
   
       public void setValue(String value) {
           this.value = value;
  +    }
  +
  +    public void setExceptionMutableInt(int exceptionMutableInt) throws InvocationTargetException
{
  +        this.exceptionMutableInt = exceptionMutableInt;
  +        if (exceptionMutableInt == -1) {
  +            throw new InvocationTargetException(new Exception("Thrown when -1"));
  +        }
  +        if (exceptionMutableInt == -2) {
  +            throw new InvocationTargetException(new Error("Thrown when -2"));
  +        }
  +        if (exceptionMutableInt == -3) {
  +            throw new InvocationTargetException(new Throwable("Thrown when -3"));
  +        }
  +    }
  +
  +    public int getExceptionMutableInt() throws InvocationTargetException {
  +        if (this.exceptionMutableInt == -1) {
  +            throw new InvocationTargetException(new Exception("Thrown when -1"));
  +        }
  +        if (this.exceptionMutableInt == -2) {
  +            throw new InvocationTargetException(new Error("Thrown when -2"));
  +        }
  +        if (exceptionMutableInt == -3) {
  +            throw new InvocationTargetException(new Throwable("Thrown when -3"));
  +        }
  +        return this.exceptionMutableInt;
       }
   
       public MockEndpoint getMockEndpoint() {
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/gbean/jmx/GBeanMBeanAttributeTest.java
  
  Index: GBeanMBeanAttributeTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.gbean.jmx;
  
  import javax.management.MalformedObjectNameException;
  import javax.management.ObjectName;
  
  import junit.framework.TestCase;
  
  import org.apache.geronimo.gbean.GAttributeInfo;
  import org.apache.geronimo.gbean.InvalidConfigurationException;
  import org.apache.geronimo.kernel.Kernel;
  import org.apache.geronimo.kernel.MockGBean;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/03/13 23:46:30 $
   */
  public class GBeanMBeanAttributeTest extends TestCase {
  
      private static final String attributeName = "Name";
  
      private static final String persistentPrimitiveAttributeName = "MutableInt";
  
      private static final String attributeValue = "Value";
  
      private static ObjectName name;
      static {
          try {
              name = new ObjectName("test:name=MyMockGBean");
          } catch (MalformedObjectNameException ignored) {
          }
      }
  
      private GBeanMBean gmbean = null;
  
      private MethodInvoker getInvoker = null;
  
      private MethodInvoker setInvoker = null;
  
      private GAttributeInfo persistentPrimitiveAttributeInfo = null, attributeInfo = null,
              throwingExceptionAttributeInfo = null;
  
      public final void testGBeanMBeanAttributeGBeanMBeanStringClassMethodInvokerMethodInvoker()
{
          try {
              new GBeanMBeanAttribute(null, null, null, null, null);
              fail("IllegalArgumentException expected");
          } catch (IllegalArgumentException expected) {
          }
          try {
              new GBeanMBeanAttribute(gmbean, attributeName, String.class, null, null);
              fail("InvalidConfigurationException expected");
          } catch (InvalidConfigurationException expected) {
          }
          GBeanMBeanAttribute attribute;
          attribute = new GBeanMBeanAttribute(gmbean, attributeName, String.class, getInvoker,
null);
          assertEquals(String.class, attribute.getType());
          assertEquals(attributeName, attribute.getName());
          assertTrue(attribute.isReadable());
          assertFalse(attribute.isWritable());
          assertFalse(attribute.isPersistent());
          attribute = new GBeanMBeanAttribute(gmbean, attributeName, String.class, null, setInvoker);
          assertEquals(String.class, attribute.getType());
          assertEquals(attributeName, attribute.getName());
          assertFalse(attribute.isReadable());
          assertTrue(attribute.isWritable());
          assertFalse(attribute.isPersistent());
          attribute = new GBeanMBeanAttribute(gmbean, attributeName, String.class, getInvoker,
setInvoker);
          assertEquals(String.class, attribute.getType());
          assertEquals(attributeName, attribute.getName());
          assertTrue(attribute.isReadable());
          assertTrue(attribute.isWritable());
          assertFalse(attribute.isPersistent());
      }
  
      public final void testGBeanMBeanAttributeGBeanMBeanGAttributeInfoClass() {
          try {
              new GBeanMBeanAttribute(null, null, null);
              fail("IllegalArgumentException expected");
          } catch (IllegalArgumentException expected) {
          }
  
          // 2. @todo BUG An attribute must be readable, writable, or persistent
          // GBeanMBeanAttribute ctor doesn't check if readable/writable are
          // null's
          try {
              new GBeanMBeanAttribute(gmbean, attributeInfo, null);
              // till Dain sorts out the question of ctor
              // fail("InvalidConfigurationException expected");
          } catch (InvalidConfigurationException expected) {
          }
  
          try {
              GAttributeInfo invalidAttributeInfo = new GAttributeInfo(attributeName, false,
null, null);
  
              new GBeanMBeanAttribute(gmbean, invalidAttributeInfo, null);
              fail("InvalidConfigurationException expected");
          } catch (InvalidConfigurationException expected) {
          }
      }
  
      public final void testOnline() throws Exception {
  
          // 1. setValue throws Exception
          {
              final Integer valueThatCausesException = new Integer(-1);
  
              final GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, throwingExceptionAttributeInfo,
null);
              attribute.setValue(valueThatCausesException);
  
              final Kernel kernel = new Kernel("test.kernel", "test");
              try {
                  kernel.boot();
                  kernel.loadGBean(name, gmbean);
                  attribute.online();
                  fail("Setter upon call with " + valueThatCausesException + " should have
thrown exception");
              } catch (/* IllegalArgument */Exception expected) {
              } finally {
                  // @todo possible BUG: gmbean holds information on being online although
kernel is shutdown
                  // explicit unloading GBean
                  kernel.unloadGBean(name);
                  kernel.shutdown();
              }
          }
  
          // 2. setValue throws Error
          {
              final Integer valueThatCausesError = new Integer(-2);
  
              final GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, throwingExceptionAttributeInfo,
null);
              attribute.setValue(valueThatCausesError);
  
              final Kernel kernel = new Kernel("test.kernel", "test");
              try {
                  kernel.boot();
                  kernel.loadGBean(name, gmbean);
                  attribute.online();
                  fail("Setter upon call with " + valueThatCausesError + " should have thrown
error");
              } catch (Error expected) {
              } finally {
                  // @todo possible BUG: see the above finally block
                  kernel.unloadGBean(name);
                  kernel.shutdown();
              }
          }
  
          // 3. setValue throws Throwable
          {
              final Integer valueThatCausesThrowable = new Integer(-3);
  
              final GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, throwingExceptionAttributeInfo,
null);
              attribute.setValue(valueThatCausesThrowable);
  
              final Kernel kernel = new Kernel("test.kernel", "test");
              try {
                  kernel.boot();
                  kernel.loadGBean(name, gmbean);
                  attribute.online();
                  fail("Setter upon call with " + valueThatCausesThrowable + " should have
thrown throwable");
              } catch (Throwable expected) {
              } finally {
                  kernel.shutdown();
              }
          }
  
          {
              try {
                  GBeanMBean gmbean2 = new GBeanMBean(MockGBean.getGBeanInfo());
                  GBeanMBeanAttribute attribute2 = new GBeanMBeanAttribute(gmbean2, throwingExceptionAttributeInfo,
null);
                  attribute2.online();
                  fail("AssertionError or NullPointerException expected");
              } catch (Exception expected) {
              }
          }
      }
  
      public final void testOffline() {
          //TODO Implement offline().
      }
  
      public final void testGetValue() throws Exception {
          // attribute that isn't readable and persistent
          final GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, attributeName,
String.class, null,
                  setInvoker);
          try {
              attribute.getValue();
              fail("Only persistent attributes can be accessed while offline; exception expected");
          } catch (/* IllegalState */Exception expected) {
          }
  
          final ObjectName name = new ObjectName("test:name=MyMockGBean");
  
          final Kernel kernel = new Kernel("test.kernel", "test");
          try {
              kernel.boot();
              kernel.loadGBean(name, gmbean);
              kernel.startGBean(name);
  
              attribute.getValue();
              fail("This attribute is not readable; exception expected");
          } catch (/* IllegalArgument */Exception expected) {
          } finally {
              kernel.shutdown();
          }
      }
  
      public final void testSetValue() throws Exception {
  
          // 1. (offline) attribute that isn't readable and persistent
          {
              final GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, attributeName,
String.class, null,
                      setInvoker);
              try {
                  attribute.setValue(null);
                  fail("Only persistent attributes can be modified while offline; exception
expected");
              } catch (/* IllegalState */Exception expected) {
              }
          }
  
          // 2. (offline) attribute that is of primitive type, writable and
          // persistent, but not readable
          {
              final GBeanMBeanAttribute persistentAttribute = new GBeanMBeanAttribute(gmbean,
                      persistentPrimitiveAttributeInfo, int.class);
              try {
                  persistentAttribute.setValue(null);
                  fail("Cannot assign null to a primitive attribute; exception expected");
              } catch (/* IllegalArgument */Exception expected) {
              }
          }
  
          // 3. (online) attribute that is immutable and not persistent
          {
              final GBeanMBeanAttribute immutableAttribute = new GBeanMBeanAttribute(gmbean,
attributeName, String.class,
                      getInvoker, null);
  
              final Kernel kernel = new Kernel("test.kernel", "test");
              try {
                  kernel.boot();
                  kernel.loadGBean(name, gmbean);
                  kernel.startGBean(name);
  
                  immutableAttribute.setValue(null);
                  fail("This attribute is not writable; exception expected");
              } catch (/* IllegalArgument */Exception expected) {
              } finally {
                  kernel.shutdown();
              }
          }
  
          // 4. (online) attribute that is mutable and of primitive type
          {
              final GBeanMBeanAttribute mutablePersistentAttribute = new GBeanMBeanAttribute(gmbean,
                      persistentPrimitiveAttributeInfo, null);
  
              final Kernel kernel = new Kernel("test.kernel", "test");
              try {
                  kernel.boot();
                  kernel.loadGBean(name, gmbean);
                  kernel.startGBean(name);
  
                  mutablePersistentAttribute.setValue(null);
                  fail("Cannot assign null to a primitive attribute; exception expected");
              } catch (/* IllegalArgument */Exception expected) {
              } finally {
                  kernel.shutdown();
              }
          }
  
          // 4a. @todo BUG: It's possible to set a value to a persistent
          // attribute while online; IllegalStateException expected
          {
              final GBeanMBeanAttribute mutablePersistentAttribute = new GBeanMBeanAttribute(gmbean,
                      persistentPrimitiveAttributeInfo, null);
  
              final Kernel kernel = new Kernel("test.kernel", "test");
              try {
                  kernel.boot();
                  kernel.loadGBean(name, gmbean);
                  kernel.startGBean(name);
  
                  mutablePersistentAttribute.setValue(new Integer(4));
                  //fail("Cannot assign a value to a persistent attribute while
                  // online; exception expected");
              } catch (/* IllegalState */Exception expected) {
              } finally {
                  kernel.shutdown();
              }
          }
  
          // 5. Invoke setValue so that exception is thrown
          {
              final GBeanMBeanAttribute attribute = new GBeanMBeanAttribute(gmbean, attributeName,
int.class, null,
                      setInvoker);
  
              final Kernel kernel = new Kernel("test.kernel", "test");
              try {
                  kernel.boot();
                  kernel.loadGBean(name, gmbean);
                  kernel.startGBean(name);
  
                  attribute.setValue(new Integer(4));
                  fail("Exception expected upon setValue's call");
              } catch (/* IllegalState */Exception expected) {
              } finally {
                  kernel.shutdown();
              }
          }
      }
  
      protected void setUp() throws Exception {
          gmbean = new GBeanMBean(MockGBean.getGBeanInfo());
          getInvoker = new MethodInvoker() {
  
              public Object invoke(Object target, Object[] arguments) throws Exception {
                  throw new UnsupportedOperationException("Throws exception to rise test coverage");
              }
          };
          setInvoker = new MethodInvoker() {
  
              public Object invoke(Object target, Object[] arguments) throws Exception {
                  throw new UnsupportedOperationException("Throws exception to rise test coverage");
              }
          };
          attributeInfo = new GAttributeInfo(attributeName, false);
          throwingExceptionAttributeInfo = new GAttributeInfo("ExceptionMutableInt", true);
          persistentPrimitiveAttributeInfo = new GAttributeInfo(persistentPrimitiveAttributeName,
true);
      }
  
      protected void tearDown() throws Exception {
          gmbean = null;
      }
  }
  
  
  
  1.9       +101 -82   incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java
  
  Index: GBeanMBeanAttribute.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- GBeanMBeanAttribute.java	10 Mar 2004 09:59:00 -0000	1.8
  +++ GBeanMBeanAttribute.java	13 Mar 2004 23:46:30 -0000	1.9
  @@ -30,26 +30,43 @@
   import org.apache.geronimo.gbean.InvalidConfigurationException;
   
   /**
  - *
  - *
    * @version $Revision$ $Date$
    */
   public class GBeanMBeanAttribute {
  +
       private static final Log log = LogFactory.getLog(GBeanMBeanAttribute.class);
  +
       private final GBeanMBean gmbean;
  +
       private final String name;
  +
       private final Class type;
  +
       private final boolean readable;
  +
       private final MethodInvoker getInvoker;
  +
       private final boolean writable;
  +
       private final MethodInvoker setInvoker;
  +
       private final boolean isConstructorArg;
  +
       private final boolean persistent;
  +
       private final MBeanAttributeInfo mbeanAttributeInfo;
   
       private Object persistentValue;
   
  -    public GBeanMBeanAttribute(GBeanMBean gmbean, String name, Class type, MethodInvoker
getInvoker, MethodInvoker setInvoker) {
  +    public GBeanMBeanAttribute(GBeanMBean gmbean, String name, Class type, MethodInvoker
getInvoker,
  +            MethodInvoker setInvoker) {
  +        if (gmbean == null || name == null || type == null) {
  +            throw new IllegalArgumentException("null param(s) supplied");
  +        }
  +        if (getInvoker == null && setInvoker == null) {
  +            throw new InvalidConfigurationException("An attribute must be readable, writable,
or persistent: +"
  +                    + " name=" + name + " targetClass=" + gmbean.getType().getName());
  +        }
           this.gmbean = gmbean;
           this.name = name;
           this.type = type;
  @@ -59,30 +76,35 @@
           this.setInvoker = setInvoker;
           this.isConstructorArg = false;
           this.persistent = false;
  -        mbeanAttributeInfo = new MBeanAttributeInfo(name, type.getName(), null, readable,
writable, type == Boolean.TYPE);
  +        this.mbeanAttributeInfo = new MBeanAttributeInfo(name, type.getName(), null, readable,
writable,
  +                type == Boolean.TYPE);
       }
   
  -    public GBeanMBeanAttribute(GBeanMBean gMBean, GAttributeInfo attributeInfo, Class constructorType)
throws InvalidConfigurationException {
  -        if (attributeInfo.isReadable() == Boolean.FALSE &&
  -                attributeInfo.isWritable() == Boolean.FALSE &&
  -                !attributeInfo.isPersistent()) {
  -            throw new InvalidConfigurationException("An attribute must be readable, writable,
or persistent: +" +
  -                    " name=" + attributeInfo.getName() +
  -                    " targetClass=" + gMBean.getType().getName());
  +    public GBeanMBeanAttribute(GBeanMBean gmbean, GAttributeInfo attributeInfo, Class constructorType)
  +            throws InvalidConfigurationException {
  +        if (gmbean == null || attributeInfo == null) {
  +            throw new IllegalArgumentException("null param(s) supplied");
           }
  -        this.gmbean = gMBean;
  +        if (attributeInfo.isReadable() == Boolean.FALSE && attributeInfo.isWritable()
== Boolean.FALSE
  +                && !attributeInfo.isPersistent()) {
  +            throw new InvalidConfigurationException("An attribute must be readable, writable,
or persistent: +"
  +                    + " name=" + attributeInfo.getName() + " targetClass=" + gmbean.getType().getName());
  +        }
  +        this.gmbean = gmbean;
           this.name = attributeInfo.getName();
           this.persistent = attributeInfo.isPersistent();
           this.isConstructorArg = (constructorType != null);
   
           boolean isIs;
   
  -        // If attribute is persistent or not tagged as unreadable, search for a getter
method
  +        // If attribute is persistent or not tagged as unreadable, search for a
  +        // getter method
           if (attributeInfo instanceof DynamicGAttributeInfo) {
               type = Object.class;
               readable = attributeInfo.isReadable().booleanValue();
               if (readable) {
                   getInvoker = new MethodInvoker() {
  +
                       public Object invoke(Object target, Object[] arguments) throws Exception
{
                           DynamicGBean dynamicGBean = (DynamicGBean) GBeanMBeanAttribute.this.gmbean.getTarget();
                           return dynamicGBean.getAttribute(name);
  @@ -94,6 +116,7 @@
               writable = attributeInfo.isWritable().booleanValue();
               if (writable) {
                   setInvoker = new MethodInvoker() {
  +
                       public Object invoke(Object target, Object[] arguments) throws Exception
{
                           DynamicGBean dynamicGBean = (DynamicGBean) GBeanMBeanAttribute.this.gmbean.getTarget();
                           dynamicGBean.setAttribute(name, arguments[0]);
  @@ -107,27 +130,30 @@
           } else {
               Method getterMethod = null;
               if (attributeInfo.isPersistent() || attributeInfo.isReadable() != Boolean.FALSE)
{
  -                getterMethod = searchForGetter(gMBean, attributeInfo);
  +                getterMethod = searchForGetter(gmbean, attributeInfo);
               }
               if (getterMethod != null) {
                   getInvoker = new FastMethodInvoker(getterMethod);
   
  -                // this attribute is readable as long as it was not explicitly tagged as
unreadable
  +                // this attribute is readable as long as it was not explicitly
  +                // tagged as unreadable
                   readable = attributeInfo.isReadable() != Boolean.FALSE;
               } else {
                   getInvoker = null;
                   readable = false;
               }
   
  -            // If attribute is persistent or not tagged as unwritable, search for a setter
method
  +            // If attribute is persistent or not tagged as unwritable, search
  +            // for a setter method
               Method setterMethod = null;
               if (attributeInfo.isPersistent() || attributeInfo.isWritable() != Boolean.FALSE)
{
  -                setterMethod = searchForSetter(gMBean, attributeInfo);
  +                setterMethod = searchForSetter(gmbean, attributeInfo);
               }
               if (setterMethod != null) {
                   setInvoker = new FastMethodInvoker(setterMethod);
   
  -                // this attribute is writable as long as it was not explicitly tagged as
unwritable
  +                // this attribute is writable as long as it was not explicitly
  +                // tagged as unwritable
                   writable = attributeInfo.isWritable() != Boolean.FALSE;
                   isIs = setterMethod.getName().startsWith("is");
               } else {
  @@ -137,35 +163,31 @@
               }
   
               // getter and setter types are consistent
  -            if (getInvoker != null && setInvoker != null &&
  -                    getterMethod.getReturnType() != setterMethod.getParameterTypes()[0])
{
  -                throw new InvalidConfigurationException("Getter and setter methods do not
have the same types:" +
  -                        " name=" + attributeInfo.getName() +
  -                        " getterMethod=" + getterMethod.getName() +
  -                        " setterMethod=" + setterMethod.getName() +
  -                        " targetClass=" + gMBean.getType().getName());
  +            if (getInvoker != null && setInvoker != null
  +                    && getterMethod.getReturnType() != setterMethod.getParameterTypes()[0])
{
  +                throw new InvalidConfigurationException("Getter and setter methods do not
have the same types:"
  +                        + " name=" + attributeInfo.getName() + " getterMethod=" + getterMethod.getName()
  +                        + " setterMethod=" + setterMethod.getName() + " targetClass=" +
gmbean.getType().getName());
               }
   
               // getter and constructor types are consistent
  -            if (constructorType != null && getterMethod != null &&
  -                    constructorType != getterMethod.getReturnType()) {
  -                throw new InvalidConfigurationException("Constructor argument and getter
method do not have the same type:" +
  -                        " name=" + attributeInfo.getName() +
  -                        " constructorType=" + constructorType.getName() +
  -                        " getterMethod=" + getterMethod.getName() +
  -                        " getterMethod type=" + getterMethod.getReturnType().getName()
+
  -                        " targetClass=" + gMBean.getType().getName());
  +            if (constructorType != null && getterMethod != null && constructorType
!= getterMethod.getReturnType()) {
  +                throw new InvalidConfigurationException(
  +                        "Constructor argument and getter method do not have the same type:"
+ " name="
  +                                + attributeInfo.getName() + " constructorType=" + constructorType.getName()
  +                                + " getterMethod=" + getterMethod.getName() + " getterMethod
type="
  +                                + getterMethod.getReturnType().getName() + " targetClass="
+ gmbean.getType().getName());
               }
   
               // setter and constructor types are consistent
  -            if (constructorType != null && setterMethod != null &&
  -                    constructorType != setterMethod.getParameterTypes()[0]) {
  -                throw new InvalidConfigurationException("Constructor argument and setter
method do not have the same type:" +
  -                        " name=" + attributeInfo.getName() +
  -                        " constructorType=" + constructorType.getName() +
  -                        " setterMethod=" + setterMethod.getName() +
  -                        " getterMethod type=" + setterMethod.getParameterTypes()[0].getName()
+
  -                        " targetClass=" + gMBean.getType().getName());
  +            if (constructorType != null && setterMethod != null
  +                    && constructorType != setterMethod.getParameterTypes()[0])
{
  +                throw new InvalidConfigurationException(
  +                        "Constructor argument and setter method do not have the same type:"
+ " name="
  +                                + attributeInfo.getName() + " constructorType=" + constructorType.getName()
  +                                + " setterMethod=" + setterMethod.getName() + " getterMethod
type="
  +                                + setterMethod.getParameterTypes()[0].getName() + " targetClass="
  +                                + gmbean.getType().getName());
               }
   
               // set the attribute type
  @@ -181,15 +203,10 @@
               }
           }
   
  -        mbeanAttributeInfo = new MBeanAttributeInfo(
  -                attributeInfo.getName(),
  -                type.getName(),
  -                null,
  -                readable,
  -                writable,
  +        mbeanAttributeInfo = new MBeanAttributeInfo(attributeInfo.getName(), type.getName(),
null, readable, writable,
                   isIs);
   
  -        if(persistent && type.isPrimitive()) {
  +        if (persistent && type.isPrimitive()) {
               if (type == Boolean.TYPE) {
                   persistentValue = Boolean.FALSE;
               } else if (type == Character.TYPE) {
  @@ -241,13 +258,15 @@
               ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
               try {
                   Thread.currentThread().setContextClassLoader(gmbean.getClassLoader());
  -                setInvoker.invoke(gmbean.getTarget(), new Object[]{persistentValue});
  +                assert gmbean.getTarget() == null : "online() invoked, however the corresponding
GBeanMBean is " +
  +                    "not fully initialized (perhaps online() has been called directly instead
by a Kernel)";
  +                setInvoker.invoke(gmbean.getTarget(), new Object[] { persistentValue});
               } catch (InvocationTargetException e) {
                   Throwable targetException = e.getTargetException();
  -                if(targetException instanceof Exception) {
  -                    throw (Exception)targetException;
  +                if (targetException instanceof Exception) {
  +                    throw (Exception) targetException;
                   } else if (targetException instanceof Error) {
  -                    throw (Error)targetException;
  +                    throw (Error) targetException;
                   }
                   throw e;
               } finally {
  @@ -263,8 +282,8 @@
                   Thread.currentThread().setContextClassLoader(gmbean.getClassLoader());
                   persistentValue = getInvoker.invoke(gmbean.getTarget(), null);
               } catch (Throwable throwable) {
  -                log.error("Could not get the current value of persistent attribute while
going offline.  The " +
  -                        "persistent attribute will not reflect the current state attribute:
name=" + name, throwable);
  +                log.error("Could not get the current value of persistent attribute while
going offline.  The "
  +                        + "persistent attribute will not reflect the current state attribute:
name=" + name, throwable);
               } finally {
                   Thread.currentThread().setContextClassLoader(oldClassLoader);
               }
  @@ -302,8 +321,8 @@
       public void setValue(Object value) throws ReflectionException {
           if (gmbean.isOffline()) {
               if (persistent) {
  -                if(value == null && type.isPrimitive()) {
  -                    throw new IllegalArgumentException("Can not assign null to a primitive
attribute");
  +                if (value == null && type.isPrimitive()) {
  +                    throw new IllegalArgumentException("Cannot assign null to a primitive
attribute");
                   }
                   // @todo actually check type
                   this.persistentValue = value;
  @@ -318,14 +337,14 @@
                       throw new IllegalArgumentException("This attribute is not writable");
                   }
               }
  -            if(value == null && type.isPrimitive()) {
  -                throw new IllegalArgumentException("Can not assign null to a primitive
attribute");
  +            if (value == null && type.isPrimitive()) {
  +                throw new IllegalArgumentException("Cannot assign null to a primitive attribute");
               }
               // @todo actually check type
               ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
               try {
                   Thread.currentThread().setContextClassLoader(gmbean.getClassLoader());
  -                setInvoker.invoke(gmbean.getTarget(), new Object[]{value});
  +                setInvoker.invoke(gmbean.getTarget(), new Object[] { value});
               } catch (Throwable throwable) {
                   throw new ReflectionException(new InvocationTargetException(throwable));
               } finally {
  @@ -334,7 +353,8 @@
           }
       }
   
  -    private static Method searchForGetter(GBeanMBean gMBean, GAttributeInfo attributeInfo)
throws InvalidConfigurationException {
  +    private static Method searchForGetter(GBeanMBean gMBean, GAttributeInfo attributeInfo)
  +                                                                                      
   throws InvalidConfigurationException {
           if (attributeInfo.getGetterName() == null) {
               // no explicit name give so we must search for a name
               String getterName = "get" + attributeInfo.getName();
  @@ -342,10 +362,8 @@
               Method[] methods = gMBean.getType().getMethods();
               for (int i = 0; i < methods.length; i++) {
                   Method method = methods[i];
  -                if (method.getParameterTypes().length == 0 &&
  -                        method.getReturnType() != Void.TYPE &&
  -                        (getterName.equalsIgnoreCase(method.getName()) ||
  -                        isName.equalsIgnoreCase(method.getName()))) {
  +                if (method.getParameterTypes().length == 0 && method.getReturnType()
!= Void.TYPE
  +                        && (getterName.equalsIgnoreCase(method.getName()) || isName.equalsIgnoreCase(method.getName())))
{
   
                       return method;
                   }
  @@ -362,53 +380,54 @@
               }
           }
   
  -        // if this attribute was explicity tagged as being readable but there is not getter
  +        // if this attribute was explicity tagged as being readable but there
  +        // is not getter
           if (attributeInfo.isReadable() == Boolean.TRUE) {
  -            throw new InvalidConfigurationException("Getter method not found on target:"
+
  -                    " name=" + attributeInfo.getName() +
  -                    " targetClass=" + gMBean.getType().getName());
  +            throw new InvalidConfigurationException("Getter method not found on target:"
+ " name="
  +                    + attributeInfo.getName() + " targetClass=" + gMBean.getType().getName());
           }
   
           // a getter is not necessary for this attribute
           return null;
       }
   
  -    private static Method searchForSetter(GBeanMBean gMBean, GAttributeInfo attributeInfo)
throws InvalidConfigurationException {
  +    private static Method searchForSetter(GBeanMBean gMBean, GAttributeInfo attributeInfo)
  +                                                                                      
   throws InvalidConfigurationException {
           if (attributeInfo.getSetterName() == null) {
               // no explicit name give so we must search for a name
               String setterName = "set" + attributeInfo.getName();
               Method[] methods = gMBean.getType().getMethods();
               for (int i = 0; i < methods.length; i++) {
                   Method method = methods[i];
  -                if (method.getParameterTypes().length == 1 &&
  -                        method.getReturnType() == Void.TYPE &&
  -                        setterName.equalsIgnoreCase(method.getName())) {
  +                if (method.getParameterTypes().length == 1 && method.getReturnType()
== Void.TYPE
  +                        && setterName.equalsIgnoreCase(method.getName())) {
   
                       return method;
                   }
               }
           } else {
  -            // even though we have an exact name we need to search the methods becaus we
don't know the parameter type
  +            // even though we have an exact name we need to search the methods
  +            // becaus we don't know the parameter type
               Method[] methods = gMBean.getType().getMethods();
               String setterName = attributeInfo.getSetterName();
               for (int i = 0; i < methods.length; i++) {
                   Method method = methods[i];
  -                if (method.getParameterTypes().length == 1 &&
  -                        method.getReturnType() == Void.TYPE &&
  -                        setterName.equals(method.getName())) {
  +                if (method.getParameterTypes().length == 1 && method.getReturnType()
== Void.TYPE
  +                        && setterName.equals(method.getName())) {
   
                       return method;
                   }
               }
           }
   
  -        // An attribute must have a setter if it was explicitly tagged as writable or
  -        // if it is persistent and it is not a constructor arg (if it is persistent we
must have
  +        // An attribute must have a setter if it was explicitly tagged as
  +        // writable or
  +        // if it is persistent and it is not a constructor arg (if it is
  +        // persistent we must have
           // a way toget the data into the instance)
           if (attributeInfo.isWritable() == Boolean.TRUE) {
  -            throw new InvalidConfigurationException("Setter method not found on target:"
+
  -                    " name=" + attributeInfo.getName() +
  -                    " targetClass=" + gMBean.getType().getName());
  +            throw new InvalidConfigurationException("Setter method not found on target:"
+ " name="
  +                    + attributeInfo.getName() + " targetClass=" + gMBean.getType().getName());
           }
   
           // a setter is not necessary for this attribute
  
  
  

Mime
View raw message