You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by pc...@apache.org on 2004/06/19 02:31:46 UTC

cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile Both2Bind.java TypeMatcher.java

pcal        2004/06/18 17:31:46

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/bts
                        ParentInstanceFactory.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        Both2Bind.java TypeMatcher.java
  Log:
  add TypeMatcher hook for specifying factory method for bean property objects
  
  Revision  Changes    Path
  1.2       +7 -0      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/ParentInstanceFactory.java
  
  Index: ParentInstanceFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/ParentInstanceFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParentInstanceFactory.java	25 Mar 2004 03:19:28 -0000	1.1
  +++ ParentInstanceFactory.java	19 Jun 2004 00:31:46 -0000	1.2
  @@ -37,6 +37,13 @@
           super();
       }
   
  +    public ParentInstanceFactory(MethodName factoryMethod)
  +    {
  +        super();
  +        setCreateObjectMethod(factoryMethod);
  +    }
  +
  +
       public ParentInstanceFactory(org.apache.xml.xmlbeans.bindingConfig.JavaInstanceFactory node)
       {
           super(node);
  
  
  
  1.14      +8 -0      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2Bind.java
  
  Index: Both2Bind.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2Bind.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Both2Bind.java	16 Apr 2004 18:31:12 -0000	1.13
  +++ Both2Bind.java	19 Jun 2004 00:31:46 -0000	1.14
  @@ -594,6 +594,14 @@
         prop.setGetterName(MethodName.create(jProp.getGetter()));
         JMethod isSetter = matchedProperties[i].getIsSetter();
         if (isSetter != null) prop.setIssetterName(MethodName.create(isSetter));
  +      {
  +        // see if a factory method was specified
  +        JMethod factory = matchedProperties[i].getFactoryMethod();
  +        if (factory != null) {
  +          prop.setJavaInstanceFactory(new ParentInstanceFactory
  +            (MethodName.create(factory)));
  +        }
  +      }
         prop.setCollectionClass(collection);
         prop.setBindingType(bType);
         prop.setNillable(sProp.hasNillable() != SchemaProperty.NEVER);
  
  
  
  1.9       +40 -0     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcher.java
  
  Index: TypeMatcher.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcher.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TypeMatcher.java	16 Apr 2004 18:31:12 -0000	1.8
  +++ TypeMatcher.java	19 Jun 2004 00:31:46 -0000	1.9
  @@ -18,6 +18,7 @@
   import org.apache.xmlbeans.impl.jam.JClass;
   import org.apache.xmlbeans.impl.jam.JProperty;
   import org.apache.xmlbeans.impl.jam.JMethod;
  +import org.apache.xmlbeans.impl.jam.JParameter;
   import org.apache.xmlbeans.SchemaType;
   import org.apache.xmlbeans.SchemaProperty;
   import org.apache.xmlbeans.SchemaTypeSystem;
  @@ -109,6 +110,7 @@
           private JProperty jProperty;
           private SchemaProperty sProperty;
           private JMethod isSetter = null;
  +        private JMethod factoryMethod = null;      
   
           public MatchedProperties(JProperty jProperty, SchemaProperty sProperty)
           {
  @@ -117,6 +119,17 @@
   
           public MatchedProperties(JProperty jProperty,
                                    SchemaProperty sProperty,
  +                                 JMethod isSetter,
  +                                 JMethod factoryMethod)
  +        {
  +          this(jProperty,sProperty,isSetter);
  +          validateFactoryMethod(factoryMethod, jProperty);
  +          this.factoryMethod = factoryMethod;
  +        }
  +
  +      
  +        public MatchedProperties(JProperty jProperty,
  +                                 SchemaProperty sProperty,
                                    JMethod isSetter)
           {
               this.jProperty = jProperty;
  @@ -150,6 +163,33 @@
           public JMethod getIsSetter()
           {
               return isSetter;
  +        }
  +
  +        public JMethod getFactoryMethod()
  +        {
  +            return factoryMethod;
  +        }
  +
  +        // ensure that the given factory is valid a factory factory for
  +        // the given property
  +        private static final void validateFactoryMethod(JMethod factory,
  +                                                        JProperty prop) {
  +          JParameter[] params = factory.getParameters();
  +          if (params.length != 1) {
  +            throw new IllegalArgumentException
  +              (factory.getQualifiedName()+
  +               " not a valid factory factory, must have exactly 1 parameter");
  +          }
  +          if (!params[0].getType().getQualifiedName().equals("java.lang.Class")) {
  +            throw new IllegalArgumentException
  +              (factory.getQualifiedName()+
  +               " must take a java.lang.Class as a parameter");
  +          }
  +          if (!prop.getType().isAssignableFrom(factory.getReturnType())) {
  +            throw new IllegalArgumentException
  +              (factory.getQualifiedName()+
  +               " must return an "+prop.getType().getQualifiedName());
  +          }
           }
   
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org