Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.objectstyle.cayenne.gen
Class DefaultClassGenerator

    java.lang.Object
      org.objectstyle.cayenne.gen.MapClassGenerator
          org.objectstyle.cayenne.gen.DefaultClassGenerator

Direct Known Subclasses:
  AntClassGenerator

    public class DefaultClassGenerator

extends MapClassGenerator

Extends MapClassGenerator to allow target-specific filesystem locations where the files should go. Adds "execute" method that performs class generation based on the internal state of this object.

Author:
  Andrei Adamchik

Field Summary
`protected java.io.File` | `destDir`
`protected java.lang.String` | `encoding` Stores the encoding of the generated file.
`protected boolean` | `makePairs`
`protected java.lang.String` | `outputPattern`
`protected boolean` | `overwrite`
`protected java.lang.String` | `superTemplate`
`protected java.lang.String` | `template`
`protected long` | `timestamp`
`protected boolean` | `usePkgPath`

Fields inherited from class org.objectstyle.cayenne.gen.MapClassGenerator
`client, CLIENT_SUBCLASS_TEMPLATE_1_2, CLIENT_SUPERCLASS_TEMPLATE_1_2, dataMap, DEFAULT_VERSION, mode, MODE_DATAMAP, MODE_ENTITY, objEntities, SINGLE_CLASS_TEMPLATE, SINGLE_CLASS_TEMPLATE_1_1, SINGLE_CLASS_TEMPLATE_1_2, SUBCLASS_TEMPLATE, SUBCLASS_TEMPLATE_1_1, SUBCLASS_TEMPLATE_1_2, SUPERCLASS_PREFIX, SUPERCLASS_TEMPLATE, SUPERCLASS_TEMPLATE_1_1, SUPERCLASS_TEMPLATE_1_2, superPkg, VERSION_1_1, VERSION_1_2, versionString, vppConfig`

Constructor Summary
`DefaultClassGenerator()`
`DefaultClassGenerator(DataMap dataMap)` Creates class generator and initializes it with DataMap.
`DefaultClassGenerator(DataMap dataMap, java.util.List selectedObjEntities)` Creates class generator and initializes it with the list of ObjEntities that will be used in class generation.
`DefaultClassGenerator(java.util.List selectedObjEntities)` Deprecated. Use DefaultClassGenerator(DataMap, List) to provide support for v1.2 templates.

Method Summary
`void` | `closeWriter(java.io.Writer out)` Closes writer after class code has been successfully written by ClassGenerationInfo.
`void` | `execute()` Runs class generation.
`protected java.io.File` | `fileForClass(java.lang.String pkgName, java.lang.String className)` Returns a target file where a generated class must be saved.
`protected java.io.File` | `fileForSuperclass(java.lang.String pkgName, java.lang.String className)` Returns a target file where a generated superclass must be saved.
`java.lang.String` | `getEncoding()` Returns file encoding for the generated files.
`protected java.lang.String` | `getSupertemplateForPairs()` Returns template file path for Java superclass when generating class pairs.
`protected java.lang.String` | `getTemplateForPairs()` Returns template file path for Java subclass when generating class pairs.
`protected java.lang.String` | `getTemplateForSingles()` Returns template file path for Java class when generating single classes.
`long` | `getTimestamp()` Returns internal timestamp of this generator used to make decisions about overwriting individual files.
`protected boolean` | `isOld(java.io.File file)` Returns true if `file` parameter is older than internal timestamp of this class generator.
`protected java.io.File` | `mkpath(java.io.File dest, java.lang.String pkgName)` Returns a File object corresponding to a directory where files that belong to `pkgName` package should reside.
`java.io.Writer` | `openWriter(ObjEntity entity, java.lang.String pkgName, java.lang.String className)` Opens a Writer to write generated output.
`void` | `setDestDir(java.io.File destDir)` Sets the destDir.
`void` | `setEncoding(java.lang.String encoding)` Sets file encoding.
`void` | `setMakePairs(boolean makePairs)` Sets `makepairs` property.
`void` | `setOutputPattern(java.lang.String outputPattern)` Sets `outputPattern` property.
`void` | `setOverwrite(boolean overwrite)` Sets `overwrite` property.
`void` | `setSuperTemplate(java.io.File superTemplate)` Deprecated. since 1.2 use `setSuperTemplate(String)` as custom template can also be looked up in CLASSPATH.
`void` | `setSuperTemplate(java.lang.String superTemplate)` Sets `superTemplate` property.
`void` | `setTemplate(java.io.File template)` Deprecated. since 1.2 use `setTemplate(String)` as custom template can also be looked up in CLASSPATH.
`void` | `setTemplate(java.lang.String template)` Sets `template` property.
`void` | `setTimestamp(long timestamp)`
`void` | `setUsePkgPath(boolean usePkgPath)` Sets `usepkgpath` property.
`void` | `validateAttributes()` Validates the state of this class generator.

Methods inherited from class org.objectstyle.cayenne.gen.MapClassGenerator
`defaultSingleClassTemplate, defaultSubclassTemplate, defaultSuperclassTemplate, generateClassPairs, generateClassPairs, generateSingleClasses, generateSingleClasses, generateSingleClasses, getDataMap, getObjEntities, getSuperPkg, getVersionString, getVppConfig, initClassGenerator_1_1, isClient, setClient, setDataMap, setMode, setObjEntities, setSuperPkg, setVersionString, setVppConfig`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### destDir

    protected java.io.File destDir

### overwrite

    protected boolean overwrite

### usePkgPath

    protected boolean usePkgPath

### makePairs

    protected boolean makePairs

### template

    protected java.lang.String template

### superTemplate

    protected java.lang.String superTemplate

### timestamp

    protected long timestamp

### outputPattern

    protected java.lang.String outputPattern

### encoding

    protected java.lang.String encoding

  Stores the encoding of the generated file.

  Since:
    1.2

Constructor Detail

### DefaultClassGenerator

    public DefaultClassGenerator()

### DefaultClassGenerator

    public DefaultClassGenerator(DataMap dataMap)

  Creates class generator and initializes it with DataMap. This will ensure generation of classes for all ObjEntities in the DataMap.

### DefaultClassGenerator

    public DefaultClassGenerator(DataMap dataMap,
                                 java.util.List selectedObjEntities)

  Creates class generator and initializes it with the list of ObjEntities that will be used in class generation.

### DefaultClassGenerator

    public DefaultClassGenerator(java.util.List selectedObjEntities)

  Deprecated. Use DefaultClassGenerator(DataMap, List) to provide support for v1.2 templates.

  Creates class generator and initializes it with the list of ObjEntities that will be used in class generation.

Method Detail

### execute

    public void execute()
                 throws java.lang.Exception

  Runs class generation.

  Throws:
    `java.lang.Exception`

### validateAttributes

    public void validateAttributes()
                            throws java.lang.Exception

  Validates the state of this class generator. Throws exception if it is in inconsistent state. Called internally from "execute".

  Throws:
    `java.lang.Exception`

### setDestDir

    public void setDestDir(java.io.File destDir)

  Sets the destDir.

### setOverwrite

    public void setOverwrite(boolean overwrite)

  Sets `overwrite` property.

### setMakePairs

    public void setMakePairs(boolean makePairs)

  Sets `makepairs` property.

### setTemplate

    public void setTemplate(java.io.File template)

  Deprecated. since 1.2 use `setTemplate(String)` as custom template can also be looked up in CLASSPATH.

  Sets `template` property.

### setSuperTemplate

    public void setSuperTemplate(java.io.File superTemplate)

  Deprecated. since 1.2 use `setSuperTemplate(String)` as custom template can also be looked up in CLASSPATH.

  Sets `superTemplate` property.

### setTemplate

    public void setTemplate(java.lang.String template)

  Sets `template` property.

### setSuperTemplate

    public void setSuperTemplate(java.lang.String superTemplate)

  Sets `superTemplate` property.

### setUsePkgPath

    public void setUsePkgPath(boolean usePkgPath)

  Sets `usepkgpath` property.

### setOutputPattern

    public void setOutputPattern(java.lang.String outputPattern)

  Sets `outputPattern` property.

### closeWriter

    public void closeWriter(java.io.Writer out)
                     throws java.lang.Exception

  Description copied from class: `MapClassGenerator`
  Closes writer after class code has been successfully written by ClassGenerationInfo.

  Specified by:
    `closeWriter` in class `MapClassGenerator`
  Throws:
    `java.lang.Exception`

### openWriter

    public java.io.Writer openWriter(ObjEntity entity,
                                     java.lang.String pkgName,
                                     java.lang.String className)
                              throws java.lang.Exception

  Opens a Writer to write generated output. Writer encoding is determined from the value of the "encoding" property.

  Specified by:
    `openWriter` in class `MapClassGenerator`
  Returns:
    Writer to store generated class source code or null if this class generation should be skipped.
  Throws:
    `java.lang.Exception`

### fileForSuperclass

    protected java.io.File fileForSuperclass(java.lang.String pkgName,
                                             java.lang.String className)
                                      throws java.lang.Exception

  Returns a target file where a generated superclass must be saved. If null is returned, class shouldn't be generated.

  Throws:
    `java.lang.Exception`

### fileForClass

    protected java.io.File fileForClass(java.lang.String pkgName,
                                        java.lang.String className)
                                 throws java.lang.Exception

  Returns a target file where a generated class must be saved. If null is returned, class shouldn't be generated.

  Throws:
    `java.lang.Exception`

### isOld

    protected boolean isOld(java.io.File file)

  Returns true if `file` parameter is older than internal timestamp of this class generator.

### mkpath

    protected java.io.File mkpath(java.io.File dest,
                                  java.lang.String pkgName)
                           throws java.lang.Exception

  Returns a File object corresponding to a directory where files that belong to `pkgName` package should reside. Creates any missing diectories below `dest`.

  Throws:
    `java.lang.Exception`

### getTemplateForSingles

    protected java.lang.String getTemplateForSingles()
                                              throws java.io.IOException

  Returns template file path for Java class when generating single classes.

  Throws:
    `java.io.IOException`

### getTemplateForPairs

    protected java.lang.String getTemplateForPairs()
                                            throws java.io.IOException

  Returns template file path for Java subclass when generating class pairs.

  Throws:
    `java.io.IOException`

### getSupertemplateForPairs

    protected java.lang.String getSupertemplateForPairs()
                                                 throws java.io.IOException

  Returns template file path for Java superclass when generating class pairs.

  Throws:
    `java.io.IOException`

### getTimestamp

    public long getTimestamp()

  Returns internal timestamp of this generator used to make decisions about overwriting individual files.

### setTimestamp

    public void setTimestamp(long timestamp)

### getEncoding

    public java.lang.String getEncoding()

  Returns file encoding for the generated files.

  Since:
    1.2

### setEncoding

    public void setEncoding(java.lang.String encoding)

  Sets file encoding. If set to null, default system encoding will be used.

  Since:
    1.2

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2006 ObjectStyle.org All Rights Reserved.