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

## org.apache.cayenne.gen
Class DefaultClassGenerator

    java.lang.Object
      org.apache.cayenne.gen.MapClassGenerator
          org.apache.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:
  Andrus Adamchik

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

Fields inherited from class org.apache.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, List selectedObjEntities)` Creates class generator and initializes it with the list of ObjEntities that will be used in class generation.

Method Summary
`void` | `closeWriter(Writer out)` Closes writer after class code has been successfully written by ClassGenerationInfo.
`void` | `execute()` Runs class generation.
`protected File` | `fileForClass(String pkgName, String className)` Returns a target file where a generated class must be saved.
`protected File` | `fileForSuperclass(String pkgName, String className)` Returns a target file where a generated superclass must be saved.
`String` | `getEncoding()` Returns file encoding for the generated files.
`protected String` | `getSupertemplateForPairs()` Returns template file path for Java superclass when generating class pairs.
`protected String` | `getTemplateForPairs()` Returns template file path for Java subclass when generating class pairs.
`protected 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(File file)` Returns true if `file` parameter is older than internal timestamp of this class generator.
`protected File` | `mkpath(File dest, String pkgName)` Returns a File object corresponding to a directory where files that belong to `pkgName` package should reside.
`Writer` | `openWriter(ObjEntity entity, String pkgName, String className)` Opens a Writer to write generated output.
`void` | `setDestDir(File destDir)` Sets the destDir.
`void` | `setEncoding(String encoding)` Sets file encoding.
`void` | `setMakePairs(boolean makePairs)` Sets `makepairs` property.
`void` | `setOutputPattern(String outputPattern)` Sets `outputPattern` property.
`void` | `setOverwrite(boolean overwrite)` Sets `overwrite` property.
`void` | `setSuperTemplate(String superTemplate)` Sets `superTemplate` property.
`void` | `setTemplate(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.apache.cayenne.gen.MapClassGenerator
`defaultSingleClassTemplate, defaultSubclassTemplate, defaultSuperclassTemplate, generateClassPairs, generateClassPairs, 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 File destDir

### overwrite

    protected boolean overwrite

### usePkgPath

    protected boolean usePkgPath

### makePairs

    protected boolean makePairs

### template

    protected String template

### superTemplate

    protected String superTemplate

### timestamp

    protected long timestamp

### outputPattern

    protected String outputPattern

### encoding

    protected 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,
                                 List selectedObjEntities)

  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 Exception

  Runs class generation.

  Throws:
    `Exception`

### validateAttributes

    public void validateAttributes()
                            throws Exception

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

  Throws:
    `Exception`

### setDestDir

    public void setDestDir(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(String template)

  Sets `template` property.

### setSuperTemplate

    public void setSuperTemplate(String superTemplate)

  Sets `superTemplate` property.

### setUsePkgPath

    public void setUsePkgPath(boolean usePkgPath)

  Sets `usepkgpath` property.

### setOutputPattern

    public void setOutputPattern(String outputPattern)

  Sets `outputPattern` property.

### closeWriter

    public void closeWriter(Writer out)
                     throws Exception

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

  Specified by:
    `closeWriter` in class `MapClassGenerator`
  Throws:
    `Exception`

### openWriter

    public Writer openWriter(ObjEntity entity,
                             String pkgName,
                             String className)
                      throws 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:
    `Exception`

### fileForSuperclass

    protected File fileForSuperclass(String pkgName,
                                     String className)
                              throws Exception

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

  Throws:
    `Exception`

### fileForClass

    protected File fileForClass(String pkgName,
                                String className)
                         throws Exception

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

  Throws:
    `Exception`

### isOld

    protected boolean isOld(File file)

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

### mkpath

    protected File mkpath(File dest,
                          String pkgName)
                   throws 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:
    `Exception`

### getTemplateForSingles

    protected String getTemplateForSingles()
                                    throws IOException

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

  Throws:
    `IOException`

### getTemplateForPairs

    protected String getTemplateForPairs()
                                  throws IOException

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

  Throws:
    `IOException`

### getSupertemplateForPairs

    protected String getSupertemplateForPairs()
                                       throws IOException

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

  Throws:
    `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 String getEncoding()

  Returns file encoding for the generated files.

  Since:
    1.2

### setEncoding

    public void setEncoding(String encoding)

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

  Since:
    1.2

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

Copyright © 2001-2007 Apache Cayenne. All Rights Reserved.