xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject cvs commit: xml-xmlbeans/v2/jam/src15/org/apache/xmlbeans/impl/jam/annogen/internal/reflect175 Reflect175ProxyPopulator.java Reflect175AnnotationPopulator.java
Date Thu, 05 Aug 2004 16:29:14 GMT
pcal        2004/08/05 09:29:14

  Modified:    v2/jam/src/org/apache/xmlbeans/impl/jam/annogen
                        AnnotationServiceParams.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal
                        AnnotationServiceParamsImpl.java
                        BaseAnnotationService.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal/joust
                        SourceJavaOutputStream.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/tools
                        Annogen.java AnnogenTask.java
  Added:       v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal
                        AnnotationProxyBase.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/provider
                        AnnotationProxy.java CompositeProxyPopulator.java
                        ProxyPopulator.java
               v2/jam/src15/org/apache/xmlbeans/impl/jam/annogen/internal/reflect175
                        Reflect175ProxyPopulator.java
  Removed:     v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal
                        DefaultValueSetter.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/provider
                        AnnotationPopulator.java
                        CompositeAnnoPopulator.java ValueSetter.java
               v2/jam/src15/org/apache/xmlbeans/impl/jam/annogen/internal/reflect175
                        Reflect175AnnotationPopulator.java
  Log:
  jam: more annotation stuff
  
  Revision  Changes    Path
  1.2       +3 -3      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/AnnotationServiceParams.java
  
  Index: AnnotationServiceParams.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/AnnotationServiceParams.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AnnotationServiceParams.java	4 Aug 2004 16:31:40 -0000	1.1
  +++ AnnotationServiceParams.java	5 Aug 2004 16:29:12 -0000	1.2
  @@ -14,7 +14,7 @@
    */
   package org.apache.xmlbeans.impl.jam.annogen;
   
  -import org.apache.xmlbeans.impl.jam.annogen.provider.AnnotationPopulator;
  +import org.apache.xmlbeans.impl.jam.annogen.provider.ProxyPopulator;
   
   import java.io.File;
   import java.io.FileNotFoundException;
  @@ -32,8 +32,8 @@
   
     public void addXmlOverrides(Reader in);
   
  -  public void insertPopulator(AnnotationPopulator pop);
  +  public void insertPopulator(ProxyPopulator pop);
   
  -  public void appendPopulator(AnnotationPopulator pop);
  +  public void appendPopulator(ProxyPopulator pop);
   
   }
  
  
  
  1.2       +5 -5      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal/AnnotationServiceParamsImpl.java
  
  Index: AnnotationServiceParamsImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal/AnnotationServiceParamsImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AnnotationServiceParamsImpl.java	4 Aug 2004 16:31:40 -0000	1.1
  +++ AnnotationServiceParamsImpl.java	5 Aug 2004 16:29:12 -0000	1.2
  @@ -14,7 +14,7 @@
    */
   package org.apache.xmlbeans.impl.jam.annogen.internal;
   
  -import org.apache.xmlbeans.impl.jam.annogen.provider.AnnotationPopulator;
  +import org.apache.xmlbeans.impl.jam.annogen.provider.ProxyPopulator;
   import org.apache.xmlbeans.impl.jam.annogen.AnnotationServiceParams;
   
   import java.io.Reader;
  @@ -51,19 +51,19 @@
       // addNewPopulator(new XmlPopulator(in));
     }
   
  -  public void insertPopulator(AnnotationPopulator pop) {
  +  public void insertPopulator(ProxyPopulator pop) {
       mPopulators.addFirst(pop);
     }
   
  -  public void appendPopulator(AnnotationPopulator pop) {
  +  public void appendPopulator(ProxyPopulator pop) {
       mPopulators.addLast(pop);
     }
   
     // ========================================================================
     // Pacakge methods
   
  -  /*package*/ AnnotationPopulator[] getPopulators() {
  -    AnnotationPopulator[] out = new AnnotationPopulator[mPopulators.size()];
  +  /*package*/ ProxyPopulator[] getPopulators() {
  +    ProxyPopulator[] out = new ProxyPopulator[mPopulators.size()];
       mPopulators.toArray(out);
       return out;
     }
  
  
  
  1.2       +11 -12    xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal/BaseAnnotationService.java
  
  Index: BaseAnnotationService.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal/BaseAnnotationService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseAnnotationService.java	4 Aug 2004 16:31:40 -0000	1.1
  +++ BaseAnnotationService.java	5 Aug 2004 16:29:12 -0000	1.2
  @@ -17,8 +17,8 @@
   import org.apache.xmlbeans.impl.jam.annogen.tools.Annogen;
   import org.apache.xmlbeans.impl.jam.annogen.AnnotationService;
   import org.apache.xmlbeans.impl.jam.annogen.provider.ElementId;
  -import org.apache.xmlbeans.impl.jam.annogen.provider.AnnotationPopulator;
  -import org.apache.xmlbeans.impl.jam.annogen.provider.ValueSetter;
  +import org.apache.xmlbeans.impl.jam.annogen.provider.ProxyPopulator;
  +import org.apache.xmlbeans.impl.jam.annogen.provider.AnnotationProxy;
   import org.apache.xmlbeans.impl.jam.JAnnotatedElement;
   
   import java.util.HashMap;
  @@ -35,7 +35,7 @@
     // ========================================================================
     // Variables
   
  -  private AnnotationPopulator mPopulator;
  +  private ProxyPopulator mPopulator;
     private Map mCache = new HashMap();
     private ReflectElementIdFactory mReflectIdFactory =
       ReflectElementIdFactory.getInstance();
  @@ -43,7 +43,7 @@
     // ========================================================================
     // Constructors
   
  -  public BaseAnnotationService(AnnotationPopulator pop) {
  +  public BaseAnnotationService(ProxyPopulator pop) {
       if (pop == null) throw new IllegalArgumentException("null pop");
       mPopulator = pop;
     }
  @@ -87,17 +87,16 @@
   
     public Object getAnnotation(Class annoType, ElementId id) {
       if (!mPopulator.hasAnnotation(id,annoType)) return null;
  -    Object out = getCachedAnnotationFor(id,annoType);
  +    AnnotationProxy out = getCachedProxyFor(id,annoType);
       if (out != null) return out;
       try {
  -      out = createAnnotationFor(annoType);
  +      out = createProxyFor(annoType);
       } catch(Exception e) {
         e.printStackTrace(); //FIXME
         return null;
       }
       if (out == null) return null;
  -    ValueSetter vs = new DefaultValueSetter(out);
  -    mPopulator.populateAnnotation(id,annoType,vs);
  +    mPopulator.populateProxy(id,annoType,out);
       return out;
     }
   
  @@ -108,21 +107,21 @@
     // let them extend and override this method, or might be worth exposing
     // an 'AnnotationInstanceFactory' interface for them to implement.
   
  -  protected Object createAnnotationFor(Class annoType)
  +  protected AnnotationProxy createProxyFor(Class annoType)
       throws ClassNotFoundException, InstantiationException,
              IllegalAccessException
     {
       String implName = Annogen.getImplClassFor(annoType);
       Class annoImpl = annoType.getClassLoader().loadClass(implName);
  -    return annoImpl.newInstance();
  +    return (AnnotationProxy)annoImpl.newInstance();
     }
   
   
     // ========================================================================
     // Private methods
   
  -  private Object getCachedAnnotationFor(ElementId id, Class annoType) {
  -    return mCache.get(getCacheKey(id,annoType));
  +  private AnnotationProxy getCachedProxyFor(ElementId id, Class annoType) {
  +    return (AnnotationProxy)mCache.get(getCacheKey(id,annoType));
     }
   
     private String getCacheKey(ElementId id, Class annoType) {
  
  
  
  1.1                  xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal/AnnotationProxyBase.java
  
  Index: AnnotationProxyBase.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.xmlbeans.impl.jam.annogen.internal;
  
  import org.apache.xmlbeans.impl.jam.annogen.provider.AnnotationProxy;
  import org.apache.xmlbeans.impl.jam.annogen.tools.Annogen;
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  
  /**
   * @author Patrick Calahan <email: pcal-at-bea-dot-com>
   */
  public /*abstract*/ class AnnotationProxyBase implements AnnotationProxy {
  
    // ========================================================================
    // AnnotationProxy implementation
  
    /**
     * Just try to set the value via reflection.
     */ 
    public void setValue(String valueName, Object value)
      throws IllegalAccessException, InvocationTargetException
    {
      Class[] sig = new Class[] {value.getClass()};
      Method setter = null;
      try {
        setter = this.getClass().
              getMethod(Annogen.SETTER_PREFIX + valueName, sig);
      } catch (NoSuchMethodException e) {
        e.printStackTrace();  //FIXME log this
        return;
      }
      setter.invoke(this, new Object[]{value});
    }
  }
  
  
  
  1.2       +16 -6     xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal/joust/SourceJavaOutputStream.java
  
  Index: SourceJavaOutputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/internal/joust/SourceJavaOutputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SourceJavaOutputStream.java	4 Aug 2004 16:31:40 -0000	1.1
  +++ SourceJavaOutputStream.java	5 Aug 2004 16:29:13 -0000	1.2
  @@ -98,6 +98,7 @@
     private StringWriter mImportBuffer = null;
     private PrintWriter mCommentPrinter = null;
     private PrintWriter mImportPrinter = null;
  +  private boolean mVerbose = false;
   
     // ========================================================================
     // Constructors
  @@ -123,6 +124,7 @@
     public void setLogger(JamLogger bl) {
       if (bl == null) throw new IllegalArgumentException("null logging");
       mLogger = bl;
  +    mVerbose = bl.isVerbose(this);
     }
   
     // ========================================================================
  @@ -160,7 +162,9 @@
             throws IOException {
       checkStateForWrite();
       printCommentsIfNeeded();
  -    mLogger.verbose("startClass "+mPackageName+"."+mClassOrInterfaceName);
  +    if (mVerbose) {
  +      mLogger.verbose("startClass "+mPackageName+"."+mClassOrInterfaceName);
  +    }
       extendsClassName = makeI18nSafe(extendsClassName);
       mOut.println("package " + mPackageName + ";");
       mOut.println();
  @@ -189,7 +193,9 @@
   
     public void startInterface(String[] extendsInterfaceNames)
             throws IOException {
  -    mLogger.verbose("startInterface "+mPackageName+"."+mClassOrInterfaceName);
  +    if (mVerbose) {
  +      mLogger.verbose("startInterface "+mPackageName+"."+mClassOrInterfaceName);
  +    }
       checkStateForWrite();
       printCommentsIfNeeded();
       mPackageName = makeI18nSafe(mPackageName);
  @@ -216,7 +222,9 @@
                                String typeName,
                                String fieldName,
                                Expression defaultValue) throws IOException {
  -    mLogger.verbose("writeField "+typeName+" "+fieldName);
  +    if (mVerbose) {
  +      mLogger.verbose("writeField "+typeName+" "+fieldName);
  +    }
       checkStateForWrite();
       printCommentsIfNeeded();
       printIndents();
  @@ -252,7 +260,9 @@
                                   String[] paramNames,
                                   String[] exceptionClassNames)
             throws IOException {
  -    mLogger.verbose("startMethod "+methodName);
  +    if (mVerbose) {
  +      mLogger.verbose("startMethod "+methodName);
  +    }
       checkStateForWrite();
       printCommentsIfNeeded();
       methodName = makeI18nSafe(methodName);
  @@ -294,7 +304,7 @@
     }
   
     public void writeComment(String comment) throws IOException {
  -    mLogger.verbose("comment");
  +    if (mVerbose)  mLogger.verbose("comment");
       getCommentPrinter().println(comment);
     }
   
  @@ -334,7 +344,7 @@
     }
   
     public void writeReturnStatement(Expression expression) throws IOException {
  -    mLogger.verbose("return");
  +    if (mVerbose) mLogger.verbose("return");
       checkStateForWrite();
       printCommentsIfNeeded();
       printIndents();
  
  
  
  1.1                  xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/provider/AnnotationProxy.java
  
  Index: AnnotationProxy.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.xmlbeans.impl.jam.annogen.provider;
  
  import java.lang.reflect.InvocationTargetException;
  
  /**
   * <p>Provides a proxied view of some annotation artifact.  JAM calls the
   * public methods on this class to initialize the proxy with annotation
   * values; those methods should not be called by user code.</p>
   *
   * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
   */
  public interface AnnotationProxy {
  
    // ========================================================================
    // Constants
  
    /**
     * <p>Name of the member of annotations which have only a single member.
     * As specified in JSR175, that name is "value", but you should use
     * this constant to prevent typos.</p>
     */
    public static final String SINGLE_MEMBER_NAME = "value";
  
    // ========================================================================
    // Public methods
  
    /**
     */
    public void setValue(String name, Object value)
      throws NoSuchMethodException, IllegalAccessException,
             InvocationTargetException;
  
  
  }
  
  
  
  
  
  
  
  1.1                  xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/provider/CompositeProxyPopulator.java
  
  Index: CompositeProxyPopulator.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.xmlbeans.impl.jam.annogen.provider;
  
  /**
   * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
   */
  public class CompositeProxyPopulator implements ProxyPopulator {
  
    // ========================================================================
    // Variables
  
    private ProxyPopulator[] mPops;
  
    // ========================================================================
    // Constructors
  
    public CompositeProxyPopulator(ProxyPopulator[] pops) {
      if (pops == null) throw new IllegalArgumentException("null pops");
      mPops = pops;
    }
  
    // ========================================================================
    // Annoatation populator implementation
  
    public boolean hasAnnotation(ElementId id, Class annoType) {
      for(int i=0; i<mPops.length; i++) {
        if (mPops[i].hasAnnotation(id,annoType)) return true;
      }
      return false;
    }
  
    public void populateProxy(ElementId id,
                              Class annoType,
                              AnnotationProxy proxy) {
      for(int i=0; i<mPops.length; i++) mPops[i].populateProxy(id,annoType,proxy);
    }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/provider/ProxyPopulator.java
  
  Index: ProxyPopulator.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.xmlbeans.impl.jam.annogen.provider;
  
  
  /**
   * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
   */
  public interface ProxyPopulator {
  
    public boolean hasAnnotation(ElementId id, Class annoType);
  
    public void populateProxy(ElementId id,
                              Class annotationType,
                              AnnotationProxy targetProxy);
  }
  
  
  
  1.2       +56 -7     xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/tools/Annogen.java
  
  Index: Annogen.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/tools/Annogen.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Annogen.java	4 Aug 2004 16:31:41 -0000	1.1
  +++ Annogen.java	5 Aug 2004 16:29:13 -0000	1.2
  @@ -25,6 +25,7 @@
   import org.apache.xmlbeans.impl.jam.annogen.internal.joust.SourceJavaOutputStream;
   import org.apache.xmlbeans.impl.jam.annogen.internal.joust.ExpressionFactory;
   import org.apache.xmlbeans.impl.jam.annogen.internal.joust.Variable;
  +import org.apache.xmlbeans.impl.jam.annogen.internal.AnnotationProxyBase;
   
   import java.util.Arrays;
   import java.util.List;
  @@ -34,6 +35,7 @@
   
   import java.io.File;
   import java.io.IOException;
  +import java.io.StringWriter;
   import java.lang.reflect.Modifier;
   
   /**
  @@ -80,6 +82,8 @@
   
     public static final String SETTER_PREFIX = "set_";
     private static final String FIELD_PREFIX = "_";
  +  private static final String IMPL_SUFFIX = "Impl";
  +  private static final String BASE_CLASS = AnnotationProxyBase.class.getName();
   
     // ========================================================================
     // Variables
  @@ -87,6 +91,7 @@
     private List mClassesTodo = null;
     private Collection mClassesDone = null;
     private JavaOutputStream mJoust = null;
  +  private boolean m14Compatible = true;
   
     // ========================================================================
     // Constructors
  @@ -105,7 +110,7 @@
   
     public void addAnnotationClasses(JClass[] classes) {
       for(int i=0; i<classes.length; i++) {
  -      if (true || classes[i].isAnnotationType()) {
  +      if (true || classes[i].isAnnotationType()) {//FIXME
           mClassesTodo.addAll(Arrays.asList(classes));
         } else {
           warn("Ignoring "+classes[i].getQualifiedName()+
  @@ -132,19 +137,27 @@
       }
     }
   
  +  public void setPre15CompatibilityMode(boolean b) {
  +    m14Compatible = b;
  +  }
  +
     // ========================================================================
     // Private methods
   
     private void doCodegen(JClass clazz) throws IOException {
  -    ExpressionFactory ef = mJoust.getExpressionFactory();
       JMethod[] methods = clazz.getDeclaredMethods();
  -    mJoust.startFile(getPackageFor(clazz),clazz.getSimpleName());
  +    String simpleImplName = getImplSimpleClassnameFor(clazz);
  +    mJoust.startFile(getPackageFor(clazz),simpleImplName);
  +    String[] implementInterface =
  +      (m14Compatible ? null : new String[] {clazz.getQualifiedName()});
       mJoust.startClass(Modifier.PUBLIC,
  -                      null,
  -                      new String[] {clazz.getQualifiedName()});
  +                      BASE_CLASS,
  +                      implementInterface);
       for(int i=0; i<methods.length; i++) {
         String fieldName = FIELD_PREFIX+ methods[i].getSimpleName();
  -      String typeName = methods[i].getReturnType().getQualifiedName();
  +      JClass type = methods[i].getReturnType();
  +      String typeName = (m14Compatible) ?
  +        getImplClassForIfGenerated(type) : type.getQualifiedName();
         Variable fieldVar =
           mJoust.writeField(Modifier.PRIVATE,typeName,fieldName,null);
         { // write the 'getter' implementation
  @@ -188,15 +201,51 @@
       System.out.println("[Warning] "+msg);
     }
   
  +
  +  // THIS IS ALL GROSS.  WE NEED TO SET UP SOME FORMAL MAPPING MACHINERY
  +  // BETWEEN THE EXPOSED TYPES AND THE IMPL TYPES
  +
  +
  +  // ========================================================================
  +  // Private methods
  +
  +  private String getImplClassForIfGenerated(JClass clazz) {
  +    if (clazz.isArrayType()) {
  +      JClass comp = clazz.getArrayComponentType();
  +      if (mClassesTodo.contains(comp) || mClassesDone.contains(comp)) {
  +        StringWriter out = new StringWriter();
  +        out.write(getImplClassFor(comp));
  +        for(int i=0; i<comp.getArrayDimensions(); i++) out.write("[]");
  +        return out.toString();
  +      }
  +    } else if (mClassesTodo.contains(clazz) || mClassesDone.contains(clazz)) {
  +      return getImplClassFor(clazz);
  +    }
  +    return clazz.getQualifiedName();
  +  }
  +
  +  // ========================================================================
  +  // These methods keep the runtime in sync with codegen
  +
     //TODO make this logic pluggable
     private String getPackageFor(JClass clazz) {
       return clazz.getContainingPackage().getQualifiedName()+".impl";
     }
   
  +  private static String getImplSimpleClassnameFor(JClass clazz) {
  +    return clazz.getSimpleName()+IMPL_SUFFIX;
  +  }
  +
     public static String getImplClassFor(Class clazz) {
       String shortName = clazz.getName();
       shortName = shortName.substring(shortName.lastIndexOf('.')+1);
  -    return clazz.getPackage().getName()+".impl."+shortName;
  +    return clazz.getPackage().getName()+".impl."+shortName+IMPL_SUFFIX;
  +  }
  +
  +  private static String getImplClassFor(JClass clazz) {
  +    String shortName = clazz.getQualifiedName();
  +    shortName = shortName.substring(shortName.lastIndexOf('.')+1);
  +    return clazz.getContainingPackage().getQualifiedName()+".impl."+shortName+IMPL_SUFFIX;
     }
   
   
  
  
  
  1.2       +95 -0     xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/tools/AnnogenTask.java
  
  Index: AnnogenTask.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annogen/tools/AnnogenTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AnnogenTask.java	4 Aug 2004 16:31:41 -0000	1.1
  +++ AnnogenTask.java	5 Aug 2004 16:29:13 -0000	1.2
  @@ -15,9 +15,104 @@
   package org.apache.xmlbeans.impl.jam.annogen.tools;
   
   import org.apache.tools.ant.Task;
  +import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.types.Path;
  +import org.apache.xmlbeans.impl.jam.JamServiceFactory;
  +import org.apache.xmlbeans.impl.jam.JamServiceParams;
  +import org.apache.xmlbeans.impl.jam.JamService;
  +import org.apache.xmlbeans.impl.jam.JClass;
  +
  +import java.io.File;
  +import java.io.IOException;
   
   /**
    * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
    */
   public class AnnogenTask extends Task {
  +
  +  // ========================================================================
  +  // Variables
  +
  +  private Annogen mAnnogen = new Annogen();
  +  private Path mSrcDir = null;
  +  private String mIncludes = "**/*.java";
  +
  +  // ========================================================================
  +  // Constructors
  +
  +  public AnnogenTask() {}
  +
  +  // ========================================================================
  +  // Public methods
  +
  +  /**
  +   * Sets the directory into which source files should be generated.
  +   * @param f
  +   */
  +  public void setOutputDir(File f) {
  +    mAnnogen.setOutputDir(f);
  +  }
  +
  +  /**
  +   * Set the source directories to find the source Java files.
  +   */
  +  public void setSrcdir(Path srcDir) {
  +    if (mSrcDir == null) {
  +      mSrcDir = srcDir;
  +    } else {
  +      mSrcDir.append(srcDir);
  +    }
  +  }
  +
  +  /**
  +   * Includes source files matching the given patten.  Pattern is relative
  +   * to srcDir.
  +   */
  +  public void setIncludes(String includes) {
  +    if (includes == null) throw new IllegalArgumentException("null includes");
  +    mIncludes = includes;
  +  }
  +
  +  public void setPre15CompatibilityMode(boolean b) {
  +    mAnnogen.setPre15CompatibilityMode(b);
  +  }
  +
  +
  +  // ========================================================================
  +  // Task implementation
  +
  +  public void execute() throws BuildException {
  +    if (mSrcDir == null) {
  +      throw new BuildException("'srcDir' must be specified");
  +    }
  +    JamServiceFactory jsf = JamServiceFactory.getInstance();
  +    JamServiceParams p = jsf.createServiceParams();
  +    p.includeSourcePattern(path2files(mSrcDir),mIncludes);
  +    try {
  +      JamService js = jsf.createService(p);
  +      JClass[] classes = js.getAllClasses();
  +      mAnnogen.addAnnotationClasses(classes);
  +      log("Generating annotation impls for the following classes:");
  +      for(int i=0; i<classes.length; i++) {
  +        log("  "+classes[i].getQualifiedName());
  +      }
  +      mAnnogen.doCodegen();
  +      log("...done.");
  +    } catch(IOException ioe) {
  +      throw new BuildException(ioe);
  +    }
  +  }
  +
  +  // ========================================================================
  +  // Private methods
  +
  +  private File[] path2files(Path path) {
  +    String[] list = path.list();
  +    File[] out = new File[list.length];
  +    for(int i=0; i<out.length; i++) {
  +      out[i] = new File(list[i]).getAbsoluteFile();
  +    }
  +    return out;
  +  }
  +
   }
  
  
  
  1.1                  xml-xmlbeans/v2/jam/src15/org/apache/xmlbeans/impl/jam/annogen/internal/reflect175/Reflect175ProxyPopulator.java
  
  Index: Reflect175ProxyPopulator.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.xmlbeans.impl.jam.annogen.internal.reflect175;
  
  import org.apache.xmlbeans.impl.jam.annogen.provider.ProxyPopulator;
  import org.apache.xmlbeans.impl.jam.annogen.provider.ElementId;
  import org.apache.xmlbeans.impl.jam.annogen.provider.AnnotationProxy;
  import org.apache.xmlbeans.impl.jam.annogen.internal.ReflectElementId;
  import org.apache.xmlbeans.impl.jam.annogen.tools.Annogen;
  
  import java.lang.reflect.AnnotatedElement;
  import java.lang.reflect.Method;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.annotation.Annotation;
  
  /**
   * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
   */
  public class Reflect175ProxyPopulator implements ProxyPopulator {
  
    // ========================================================================
    // Variables
  
    private ClassLoader mClassLoader = ClassLoader.getSystemClassLoader();
  
    // ========================================================================
    // AnnotationPopulator implementation
  
    public boolean hasAnnotation(ElementId id, Class annoType) {
      if (!(id instanceof ReflectElementId)) {
        throw new IllegalArgumentException("This case is NYI");
      }
      AnnotatedElement element =
        (AnnotatedElement)((ReflectElementId)id).getAnnotatedElement();
      return (element.getAnnotation(annoType) != null);
    }
  
    public void populateProxy(ElementId id,
                              Class annoType,
                              AnnotationProxy targetInstance)
    {
      if (!(id instanceof ReflectElementId)) {
        throw new IllegalArgumentException("This case is NYI");
      }
      AnnotatedElement element =
        (AnnotatedElement)((ReflectElementId)id).getAnnotatedElement();
      Annotation ann = element.getAnnotation(annoType);
      if (ann == null) return; // nothing there, nothing to do
      Method[] methods = annoType.getDeclaredMethods();
      for(int i=0; i<methods.length; i++) {
        Class returnType = methods[i].getReturnType();
        if (returnType.isArray()) throw new IllegalStateException("array members are NYI");//FIXME
        if (returnType == null || returnType == void.class) continue;
        if (methods[i].getParameterTypes().length > 0) continue;
        try {
          Object value = methods[i].invoke(ann,(Object[])null);
          targetInstance.setValue(methods[i].getName(),value);
        } catch(IllegalAccessException iae) {
          iae.printStackTrace();//FIXME log this
        } catch(InvocationTargetException ite) {
          ite.printStackTrace();//FIXME log this
        } catch(NoSuchMethodException nsme) {
          nsme.printStackTrace();//FIXME log this
        }
      }
    }
  }
  
  
  

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


Mime
View raw message