Re: Why not WOGen? [Was: Eclipse 3.0 and EOGenerator

From: Pierre Frisch (pierre.frisc..pearway.com)
Date: Fri Jul 23 2004 - 18:41:42 EDT

  • Next message: Brendan Duddridge: "Unable to locate entity and missing components from frameworks"

    Andus,

    We make extensive use of EOGenerator. Here is our template and the ant
    task that we use. I would love to get rid of the dependance on
    EOGenerator.

    Thanks

    Pierre

         <!-- Generate EOs -->
         <target name="generate.eos">
             <exec dir="${project.dir}"
    executable="/Developer/Tools/eogenerator" vmlauncher="false"
    outputproperty="eogen.log" logError="true" newenvironment="true">
                 <arg value="-model" />
                 <arg file="${project.dir}/Resources/Catalog.eomodeld" />
                 <arg value="-refmodel" />
                 <arg
    file="${project.dir}/../sPearWayAccess/Resources/Prototypes.eomodeld"
    />
                 <arg value="-templatedir" />
                 <arg file="${project.dir}/../sPearWayAccess/Templates" />
                 <arg value="-destination" />
                 <arg file="${project.dir}/Sources/" />
                 <arg value="-packagedirs" />
                 <arg value="-verbose" />
                 <arg value="-java" />
                 <arg value="-define-copyrightYear" />
                 <arg value="1997-2004" />
                 <arg value="-define-copyrightBy" />
                 <arg value="sPearWay Ltd." />
             </exec>
             <echo message="EOGenerator ${eogen.log}" />
         </target>

    <$comment
    EO Template for use by "eogenerator" based upon MiscMerge engine.
    You may customize this file to modify the templates generated
    by this tool. See the MiscMerge documentation for a description
    of the parsing language. The engine gets passed this file and an
    EOEntity to process, so the methods used must be ones that an
    EOEntity can respond to.

    BE SURE NOT TO INCLUDE DATES IN THIS FILE. Since the "eogenerator"
    tool tries to compare the newly generated file with the old file,
    adding dates to this file will guarantee the old file gets
    overridden by the new file, forcing a recompilation of your EO.$>
    //
    // <$GEN_PREFIX$><$classNameWithoutPackage$>.java
    //
    // Created by eogenerator
    // DO NOT EDIT. Make changes to <$classNameWithoutPackage$>.java
    instead.
    // copyright <$copyrightYear$> <$copyrightBy$>

    <$foreach package classPackage do$>package <$package$>;

    <$endforeach do$>
    import com.webobjects.foundation.*;
    import com.webobjects.eocontrol.*;
    import java.math.BigDecimal;
    import java.util.*;

    public abstract class <$GEN_PREFIX$><$classNameWithoutPackage$> extends
    <$if
    hasParentEntity$><$javaParentClassName$><$else$>EOGenericRecord<$endif$>
      {
         private static org.apache.log4j.Logger logger =
    org.apache.log4j.Logger.getLogger(<$GEN_PREFIX$><$classNameWithoutPackag
    e$>.class);

    <$foreach attribute classAttributes..ortedNameArray do$>
         public static final String
    <$attribute.name.initialCapitalString$>Key =
    "<$attribute.name$>";<$endforeach$>
    <$foreach rel classToOneRelationships..ortedNameArray do$>
         public static final String <$rel.name.initialCapitalString$>Key =
    "<$rel.name$>";<$endforeach$>
    <$foreach rel classToManyRelationships..ortedNameArray do$>
         public static final String <$rel.name.initialCapitalString$>Key =
    "<$rel.name$>";<$endforeach$>

         public <$GEN_PREFIX$><$classNameWithoutPackage$>() {
             super();
         }

    /*
         // If you add instance variables to store property values you
         // should add empty implementions of the Serialization methods
         // to avoid unnecessary overhead (the properties will be
         // serialized for you in the superclass).
         private void writeObject(java.io.ObjectOutputStream out) throws
    java.io.IOException {
         }

         private void readObject(java.io.ObjectInputStream in) throws
    java.io.IOException, java.lang.ClassNotFoundException {
         }
    */
    <$foreach FetchSpec
    javaBeautifiedFetchSpecificationDictionaries..ortedNameArray do$>
         public static NSArray
    objectsFor<$FetchSpec.niceName$>(EOEditingContext context<$foreach
    Binding FetchSpec.bindings do2$>,
    <$Binding.codeType$><$Binding.name$>Binding<$endforeach do2$>) {
             EOFetchSpecification spec =
    EOFetchSpecification.fetchSpecificationNamed("<$FetchSpec.fetchName$>",
    "<$name$>");
    <$if FetchSpec.bindings.count > 0$>
             NSMutableDictionary bindings = new NSMutableDictionary();
    <$foreach Binding FetchSpec.bindings do2$>
             if (<$Binding.name$>Binding != null)
                 bindings.setObjectForKey(<$Binding.name$>Binding,
    "<$Binding.name$>");<$endforeach do2$>
             spec = spec.fetchSpecificationWithQualifierBindings(bindings);
    <$endif$>
             return context.objectsWithFetchSpecification(spec);
         }
    <$endforeach do$>
    <$foreach Attribute classAttributes..ortedNameArray do$>
         public <$Attribute.javaValueClassName$> <$Attribute.name$>() {
             return
    (<$Attribute.javaValueClassName$>)this.storedValueForKey("<$Attribute.na
    me$>");
         }

         public void
    set<$Attribute.name.initialCapitalString$>(<$Attribute.javaValueClassNam
    e$> value) {
             this.takeStoredValueForKey(value, "<$Attribute.name$>");
         }

         public void
    initialize<$Attribute.name.initialCapitalString$>(<$Attribute.javaValueC
    lassName$> value) {
             this.set<$Attribute.name.initialCapitalString$>(value);
         }
    <$endforeach do$>
    <$foreach ToOneRelationship classToOneRelationships..ortedNameArray
    do$>
         public
    <$ToOneRelationship.destinationEntity.referenceJavaClassName$>
    <$ToOneRelationship.name$>() {
             return
    (<$ToOneRelationship.destinationEntity.referenceJavaClassName$>)this.sto
    redValueForKey("<$ToOneRelationship.name$>");
         }

         public void
    set<$ToOneRelationship.name.initialCapitalString$>(<$ToOneRelationship.d
    estinationEntity.referenceJavaClassName$> value) {
             this.takeStoredValueForKey(value, "<$ToOneRelationship.name$>");
         }

         public
    <$ToOneRelationship.destinationEntity.referenceJavaClassName$>
    <$ToOneRelationship.name$>Relationship() {
             return
    (<$ToOneRelationship.destinationEntity.referenceJavaClassName$>)this.sto
    redValueForKey("<$ToOneRelationship.name$>");
         }

         public void
    set<$ToOneRelationship.name.initialCapitalString$>Relationship(<$ToOneRe
    lationship.destinationEntity.referenceJavaClassName$> value) {
             if (value == null) {
                  
    <$ToOneRelationship.destinationEntity.referenceJavaClassName$> object =
    this.<$ToOneRelationship.name$>();
                 if (object != null)
                      
    this.removeObjectFromBothSidesOfRelationshipWithKey(object,
    "<$ToOneRelationship.name$>");
             } else {
                 this.addObjectToBothSidesOfRelationshipWithKey(value,
    "<$ToOneRelationship.name$>");
             }
         }

         public void
    initialize<$ToOneRelationship.name.initialCapitalString$>(<$ToOneRelatio
    nship.destinationEntity.referenceJavaClassName$> value) {
              
    this.set<$ToOneRelationship.name.initialCapitalString$>Relationship(valu
    e);
         }
    <$endforeach do$>
    <$foreach ToManyRelationship classToManyRelationships..ortedNameArray
    do$>
         public NSArray <$ToManyRelationship.name$>() {
             return
    (NSArray)this.storedValueForKey("<$ToManyRelationship.name$>");
         }

         public void
    set<$ToManyRelationship.name.initialCapitalString$>(NSArray value) {
             this.takeStoredValueForKey(value,
    "<$ToManyRelationship.name$>");
         }

         public void
    addTo<$ToManyRelationship.name.initialCapitalString$>(<$ToManyRelationsh
    ip.destinationEntity.referenceJavaClassName$> object) {
             if (logger.isDebugEnabled()) {
                 if ( (this.editingContext() != null) && (object != null) &&
    ( ! this.editingContext().equals(object.editingContext()) ) ) {
                     try {
                         throw new Exception("WrongEdidtingContext");
                     } catch(Exception exception) {
                          
    logger.warn("addTo<$ToManyRelationship.name.initialCapitalString$>
    exception " , exception);
                     }
                 }
             }
             this.includeObjectIntoPropertyWithKey(object,
    "<$ToManyRelationship.name$>");
         }

         public void
    removeFrom<$ToManyRelationship.name.initialCapitalString$>(<$ToManyRelat
    ionship.destinationEntity.referenceJavaClassName$> object) {
             this.excludeObjectFromPropertyWithKey(object,
    "<$ToManyRelationship.name$>");
         }

         public void
    addTo<$ToManyRelationship.name.initialCapitalString$>Relationship(<$ToMa
    nyRelationship.destinationEntity.referenceJavaClassName$> object) {
             this.addObjectToBothSidesOfRelationshipWithKey(object,
    "<$ToManyRelationship.name$>");
         }

         public void
    removeFrom<$ToManyRelationship.name.initialCapitalString$>Relationship(<
    $ToManyRelationship.destinationEntity.referenceJavaClassName$> object)
    {
             this.removeObjectFromBothSidesOfRelationshipWithKey(object,
    "<$ToManyRelationship.name$>");
         }

         public
    <$ToManyRelationship.destinationEntity.referenceJavaClassName$>
    create<$ToManyRelationship.name.initialCapitalString$>Relationship() {
             EOClassDescription classDescription =
    EOClassDescription.classDescriptionForEntityName("<$ToManyRelationship.d
    estinationEntity.name$>");
             EOEnterpriseObject object =
    classDescription.createInstanceWithEditingContext(this.editingContext(),
      null);
             this.editingContext().insertObject(object);
             this.addObjectToBothSidesOfRelationshipWithKey(object,
    "<$ToManyRelationship.name$>");
             return
    (<$ToManyRelationship.destinationEntity.referenceJavaClassName$>)object;
         }

         public void
    delete<$ToManyRelationship.name.initialCapitalString$>Relationship(<$ToM
    anyRelationship.destinationEntity.referenceJavaClassName$> object) {
             // DeleteRuleNullify = 0;
             // DeleteRuleCascade = 1;
             // DeleteRuleDeny = 2;
             // DeleteRuleNoAction = 3;
             <$if ToManyRelationship.deleteRule != 2$>
             this.removeObjectFromBothSidesOfRelationshipWithKey(object,
    "<$ToManyRelationship.name$>");<$if ToManyRelationship.deleteRule ==
    1$>
             // Cascade delete rule
             this.editingContext().deleteObject(object);<$else$><$if
    ToManyRelationship.ownsDestination$>
             // Own destination delete rule
             this.editingContext().deleteObject(object);<$endif$><$endif$>
             <$else$>
             // Deny delete rule
             <$endif$>
         }

         public void
    deleteAll<$ToManyRelationship.name.initialCapitalString$>Relationships()
      {
             for ( Iterator objects =
    this.<$ToManyRelationship.name$>().vector().iterator();
    objects.hasNext(); )
                  
    this.delete<$ToManyRelationship.name.initialCapitalString$>Relationship(
    (<$ToManyRelationship.destinationEntity.referenceJavaClassName$>)objects
    .next());
         }

         public void
    initialize<$ToManyRelationship.name.initialCapitalString$>(NSArray
    value) {
             this.set<$ToManyRelationship.name.initialCapitalString$>(value);
         }

         public void
    initialize<$ToManyRelationship.name.initialCapitalString$>(<$ToManyRelat
    ionship.destinationEntity.referenceJavaClassName$> value) {
              
    this.addTo<$ToManyRelationship.name.initialCapitalString$>Relationship(v
    alue);
         }
    <$endforeach do$>}

    On Jul 23, 2004, at 15:22, Andrus Adamchik wrote:

    > Hi Pierre,
    >
    > On Jul 23, 2004, at 5:40 PM, Pierre Frisch wrote:
    >> The last time I looked at WOGen it was a lot less flexible than
    >> EOGenerator.
    >
    >> Can you parse the same template files?
    >
    > The same - no, but it is based on Velocity templates that are very
    > flexible. Basically they are as flexible and dynamic as the API
    > provided by Java objects that sit in the template "context" during
    > parsing. "Context" objects usually limit what you can and can't
    > access, otherwise Velocity scripting language is generic, powerful and
    > rather well documented.
    >
    > BTW, if you have any specifics on what's missing, please open a
    > feature request via JIRA. Ulrich, please assign any such issues to me.
    >
    > Andrus
    >
    >





    This archive was generated by hypermail 2.0.0 : Fri Jul 23 2004 - 18:41:48 EDT