geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel MockGBean.java
Date Thu, 22 Jan 2004 20:10:33 GMT
dain        2004/01/22 12:10:33

  Modified:    modules/kernel/src/java/org/apache/geronimo/gbean
                        GBeanInfoFactory.java
               modules/kernel/src/test/org/apache/geronimo/kernel
                        MockGBean.java
  Log:
  Added addInterface to GBeanInfoFactory
  
  Revision  Changes    Path
  1.5       +47 -4     incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoFactory.java
  
  Index: GBeanInfoFactory.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GBeanInfoFactory.java	16 Jan 2004 23:31:21 -0000	1.4
  +++ GBeanInfoFactory.java	22 Jan 2004 20:10:33 -0000	1.5
  @@ -55,11 +55,14 @@
    */
   package org.apache.geronimo.gbean;
   
  +import java.lang.reflect.Method;
  +import java.util.ArrayList;
  +import java.util.HashMap;
   import java.util.HashSet;
  +import java.util.List;
  +import java.util.Map;
   import java.util.Set;
  -
  -import org.apache.geronimo.gbean.GAttributeInfo;
  -import org.apache.geronimo.gbean.GBeanInfo;
  +import java.util.Arrays;
   
   /**
    *
  @@ -98,6 +101,46 @@
           notifications.addAll(source.getNotificationsSet());
           //in case subclass constructor has same parameters as superclass.
           constructor = source.getConstructor();
  +    }
  +
  +    public void addInterface(Class intf) {
  +        addInterface(intf, new String[0]);
  +    }
  +
  +    public void addInterface(Class intf, String[] persistentAttriubtes) {
  +        Set persistentName = new HashSet(Arrays.asList(persistentAttriubtes));
  +        Map tempAttributes = new HashMap();
  +
  +        Method[] methods = intf.getMethods();
  +        for (int i = 0; i < methods.length; i++) {
  +            Method method = methods[i];
  +            String name = method.getName();
  +            if (name.startsWith("get") || name.startsWith("is")) {
  +                String attributeName = (name.startsWith("get")) ? name.substring(3) : name.substring(2);
  +                GAttributeInfo attribute = (GAttributeInfo) tempAttributes.get(attributeName);
  +                if (attribute == null) {
  +                    tempAttributes.put(attributeName, new GAttributeInfo(attributeName,
persistentName.contains(attributeName), name, null));
  +                } else {
  +                    tempAttributes.put(attributeName, new GAttributeInfo(attributeName,
persistentName.contains(attributeName), name, attribute.getSetterName()));
  +                }
  +            } else if (name.startsWith("set")) {
  +                String attributeName = name.substring(3);
  +                GAttributeInfo attribute = (GAttributeInfo) tempAttributes.get(attributeName);
  +                if (attribute == null) {
  +                    tempAttributes.put(attributeName, new GAttributeInfo(attributeName,
persistentName.contains(attributeName), null, name));
  +                } else {
  +                    tempAttributes.put(attributeName, new GAttributeInfo(attributeName,
persistentName.contains(attributeName), attribute.getSetterName(), name));
  +                }
  +            } else {
  +                Class[] parameterTypes = method.getParameterTypes();
  +                List parameters = new ArrayList(parameterTypes.length);
  +                for (int j = 0; j < parameterTypes.length; j++) {
  +                    parameters.add(parameterTypes[j].getName());
  +                }
  +                operations.add(new GOperationInfo(name, name, parameters));
  +            }
  +        }
  +        attributes.addAll(tempAttributes.values());
       }
   
       public void addAttribute(GAttributeInfo info) {
  
  
  
  1.9       +2 -3      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MockGBean.java	22 Jan 2004 18:34:13 -0000	1.8
  +++ MockGBean.java	22 Jan 2004 20:10:33 -0000	1.9
  @@ -91,13 +91,12 @@
           infoFactory.addAttribute(new GAttributeInfo("Name", true));
           infoFactory.addAttribute(new GAttributeInfo("Value", true));
           infoFactory.addAttribute(new GAttributeInfo("FinalInt", true));
  -        infoFactory.addAttribute(new GAttributeInfo("MutableInt", true));
           infoFactory.addAttribute(new GAttributeInfo("EndpointMutableInt"));
           infoFactory.addOperation(new GOperationInfo("checkResource", new String[]{"java.lang.String"}));
           infoFactory.addOperation(new GOperationInfo("checkEndpoint"));
           infoFactory.addOperation(new GOperationInfo("checkEndpointCollection"));
           infoFactory.addOperation(new GOperationInfo("doSomething", new String[]{"java.lang.String"}));
  -        infoFactory.addOperation(new GOperationInfo("doSetMutableInt", new String[] {"int"}));
  +        infoFactory.addInterface(MockEndpoint.class, new String[] {"MutableInt"});
           infoFactory.addEndpoint(new GEndpointInfo("MockEndpoint", MockEndpoint.class.getName()));
           infoFactory.addEndpoint(new GEndpointInfo("EndpointCollection", MockEndpoint.class.getName()));
           infoFactory.setConstructor(new GConstructorInfo(new String[]{"Name", "FinalInt"},
new Class[]{String.class, Integer.TYPE}));
  
  
  

Mime
View raw message