FileDocCategorySizeDatePackage
Environment.javaAPI DocGlassfish v2 API26890Fri May 04 22:34:38 BST 2007com.sun.jdo.api.persistence.enhancer.impl

Environment

public final class Environment extends com.sun.jdo.api.persistence.enhancer.util.Support
Environment serves as a central collection for the options and working environment of the filter tool.

Fields Summary
private PrintWriter
out
private PrintWriter
err
private boolean
timingOption
private boolean
verboseOption
private boolean
quietOption
private boolean
noWriteOption
private boolean
disableThisHookHoisting
private boolean
disableInitializerAnnotationSuppression
private boolean
forceOverwriteOption
private boolean
updateInPlaceOption
private int
errorsEncountered
private File
destinationDirectory
private Hashtable
classMap
private HashMap
missingClasses
private com.sun.jdo.api.persistence.enhancer.util.ClassPath
classPathOption
private com.sun.jdo.api.persistence.enhancer.util.ClassPath
destClassPath
private Hashtable
fieldSuppressions
private Hashtable
classSuppressions
private com.sun.jdo.api.persistence.enhancer.meta.JDOMetaData
jdoMetaData
private String
lastErrorMessage
Constructors Summary
public Environment()
The constructor

    
Methods Summary
public voidaddClass(ClassControl cc)
Add the class to the class mapping table. Check that it does not conflict with earlier settings.

        String className = cc.className();
        ClassControl existCC = getClass(className);

        if (existCC != null) {

            if (!existCC.source().sameAs(cc.source())) {
                //@olsen: support for I18N
                error(getI18N("enhancer.class_already_entered",//NOI18N
                              cc.userClassName(),
                              cc.sourceName(),
                              existCC.sourceName()));
                return;
            }

            // the two files are from the same source - select the higher
            // level of persistence capability and discard the other
            if (cc.persistType() == ClassControl.PersistUnknown ||
                existCC.persistType() == ClassControl.PersistCapable ||
                (existCC.persistType() == ClassControl.PersistAware &&
                 cc.persistType() != ClassControl.PersistCapable))
                return;

        }

        if (existCC == null && cc.sourceName() != null)
            message("adding class " + cc.userClassName() +//NOI18N
                    " from " + cc.sourceName());//NOI18N

        classMap.put(className, cc);
    
public booleancanFindClass(java.lang.String className)
Look for the specified class in the class map. If not there, use the class path to find the class. If still not found, return false.

        return findClass(className) != null;
    
private booleanclassWarningsSuppressed(java.lang.String classname)
Check whether the named class should have warnings suppressed.

        return classSuppressions.get(classname) != null;
    
public java.util.ArrayListcollectClasses(int persistType)
Return a ArrayList of ClassControl objects which have the specified persistence type

        ArrayList v = new ArrayList();
        for (Iterator e = classMap.values().iterator(); e.hasNext();) {
            ClassControl cc = (ClassControl)e.next();
            if (cc.persistType() == persistType)
                v.add(cc);
        }
        return v;
    
public java.util.ArrayListcollectClasses()
Return an ArrayList of the ClassControls in classMap. This is useful in that it provides a stable base for enumeration.

        ArrayList v = new ArrayList();
        for (Iterator e = classMap.values().iterator(); e.hasNext(); )
            v.add(e.next());
        return v;
    
public java.io.FiledestinationDirectory()

        return destinationDirectory;
    
public booleandoInitializerOptimization()

        return disableInitializerAnnotationSuppression == false;
    
public booleandoThisOptimization()

        return disableThisHookHoisting == false;
    
public booleandoTimingStatistics()

        return timingOption;
    
public voiderror(java.lang.String error)

        errorsEncountered++;
        //@olsen: support for I18N
        //@olsen: redirected output
        //System.out.print("Error: ");
        //System.out.println(err);
        err.println(lastErrorMessage = getI18N("enhancer.enumerated_error",
                                               errorsEncountered,
                                               error));
    
public interrorCount()

        return errorsEncountered;
    
public voidexcludeDestinationDirectory()
Update the class path to remove the destination directory if it is found in the class path.

        if (destinationDirectory != null)
            classPathOption.remove(destinationDirectory);
    
private booleanfieldWarningsSuppressed(java.lang.String classname, java.lang.String fieldName)
Check whether the named field in the named class should have warnings suppressed.

        return fieldSuppressions.get(classname + "." + fieldName) != null;//NOI18N
    
public ClassControlfindClass(java.lang.String className)
Look for the specified class in the class map. If not there, use the class path to find the class. If still not found, return false.

        ClassControl cc = (ClassControl) classMap.get(className);

        if ((cc == null) && (missingClasses.get(className) == null)) {

            // Not already known - try looking up in class path
            cc = lookupClass(className);
            if (cc != null) {
                message("Reading class " + cc.userClassName() +//NOI18N
                        " from " + cc.sourceName());//NOI18N
                classMap.put(className, cc);
            } else {
                missingClasses.put(className, className);
            }
        }

        return cc;
    
public booleanforceOverwrite()

        return forceOverwriteOption;
    
public ClassControlgetClass(java.lang.String className)
Look for the specified class in the class map. No other class lookup is performed. Use this only if you are certain that the class will have been found.

        return (ClassControl)classMap.get(className);
    
public java.util.IteratorgetClasses()

        return classMap.values().iterator();
    
public java.io.PrintWritergetErrorWriter()

        return err;
    
public com.sun.jdo.api.persistence.enhancer.meta.JDOMetaDatagetJDOMetaData()
Is the class a well known persistent capable class? These are normally the java primitives.

        return jdoMetaData;
    
public final java.lang.StringgetLastErrorMessage()

        return this.lastErrorMessage;
    
public java.io.PrintWritergetOutputWriter()

        return out;
    
public booleanisVerbose()

        return this.verboseOption;
    
public ClassControllookupClass(java.lang.String className)
Look up the specified class in the class search path. Callers should normally consult the classmap prior to calling this function. The class is not entered into the classmap

        ClassFileSource source = classPathOption.findClass(className);

        while (true) {
            if (source == null)
                return null;

            //@olsen: cosmetics
            try {
                ClassControl cc = new ClassControl(source, this);
                if (cc.className() != null &&
                    cc.className().equals(className))
                    return cc;
            } catch (ClassFormatError e) {
            }

            // Try to find an alternate source for the class
            source = source.nextSource(className);
        }
    
public com.sun.jdo.api.persistence.enhancer.util.ClassFileSourcelookupDestClass(java.lang.String className)
Look for a class source using the destination directory as a root directory for the lookup which represents the annotated output for the class specified. Return null if not found.

        if (destClassPath == null && destinationDirectory != null)
            destClassPath = new ClassPath(destinationDirectory.getPath());
        return (destClassPath == null
                ? null : destClassPath.findClass(className));
    
public voidmessage(java.lang.String mess)

        if (verboseOption) {
            //@olsen: redirected output
            //System.out.println(mess);
            out.println("JDO ENHANCER: " + mess);//NOI18N
        }
    
public voidmessageNL(java.lang.String mess)

        if (verboseOption) {
            //@olsen: redirected output
            //System.out.println(mess);
            out.println();
            out.println("JDO ENHANCER: " + mess);//NOI18N
        }
    
public voidmoveDestinationDirectoryToEnd()
Update the class path to move the destination directory to the end of the class path if it is found in the class path.

        if (destinationDirectory != null &&
            classPathOption.remove(destinationDirectory))
            classPathOption.append(destinationDirectory);
    
public voidreset()
Reset the environment.

/*
        jdoMetaData = null;

        verboseOption = false;
        quietOption = false;
        dumpLevel = 0;

        disableThisHookHoisting = false;
        disableInitializerAnnotationSuppression = false;
        disableArrayHookCaching = false;
        disableArrayElementFetch = false;

        noWriteOption = false;
        forceOverwriteOption = false;
        updateInPlaceOption = false;
        classPathOption = null;
        destinationDirectory = null;
        destClassPath = null;

        renamedMap.clear();
        translations.clear();
*/
        errorsEncountered = 0;

        classMap.clear();
        missingClasses.clear();

        fieldSuppressions.clear();
        classSuppressions.clear();
    
public voidsetDestinationDirectory(java.lang.String dir)

        final File dest = new File(dir);
        if (destinationDirectory != null) {
            //@olsen: support for I18N
            error(getI18N("destination_directory_already_set",//NOI18N
                          dir,
                          destinationDirectory.getPath()));
            return;
        }
        if (!dest.isDirectory()) {
            error(getI18N("enhancer.destination_directory_not_exist",//NOI18N
                          dir));
            return;
        }
        destinationDirectory = dest;
    
public voidsetDoTimingStatistics(boolean dontOpt)


    // public accessors

        
        timingOption = dontOpt;
    
public voidsetErrorWriter(java.io.PrintWriter err)

        this.err = err;
    
public voidsetForceOverwrite(boolean forceOverwrite)

        forceOverwriteOption = forceOverwrite;
    
public voidsetJDOMetaData(com.sun.jdo.api.persistence.enhancer.meta.JDOMetaData jdoMetaData)

        this.jdoMetaData = jdoMetaData;
    
public voidsetNoInitializerOptimization(boolean dontOpt)

        disableInitializerAnnotationSuppression = dontOpt;
    
public voidsetNoOptimization(boolean dontOpt)

//@olsen: disabled feature
/*
        disableArrayHookCaching = dontOpt;
*/
        disableThisHookHoisting = dontOpt;
        disableInitializerAnnotationSuppression = dontOpt;
//@olsen: disabled feature
/*
        disableArrayElementFetch = dontOpt;
*/
    
public voidsetNoThisOptimization(boolean dontOpt)

        disableThisHookHoisting = dontOpt;
    
public voidsetNoWrite(boolean dontWrite)

        noWriteOption = dontWrite;
    
public voidsetOutputWriter(java.io.PrintWriter out)

        this.out = out;
    
public voidsetQuiet(boolean beQuiet)

        quietOption = beQuiet;
    
public voidsetVerbose(boolean beVerbose)

        verboseOption = beVerbose;
    
public voidsuppressClassWarnings(java.lang.String className)
Add a suppression entry for a class

        classSuppressions.put(className, className);
    
public voidsuppressFieldWarnings(java.lang.String fullFieldName)
Add a suppression entry for a field of a class

        fieldSuppressions.put(fullFieldName, fullFieldName);
    
public booleanupdateInPlace()

        return updateInPlaceOption;
    
static java.lang.StringvalidVMPackage(java.lang.String pkg)
Convert a user package name to a VM package name. If the package name isn't valid, return null instead.

        StringBuffer buf = new StringBuffer();

        int i=0;
        while (i<pkg.length()) {
            if (i != 0) {
                // each package component must be preceded by a '.'
                if (pkg.charAt(i) != '.")
                    return null;

                // translate '.' to '/'
                buf.append("/");//NOI18N

                // there must be more characters for the next package component
                i++;
                if (i == pkg.length())
                    return null;
            }

            if (!Character.isJavaIdentifierStart(pkg.charAt(i)))
                return null;
            buf.append(pkg.charAt(i++));

            while (i < pkg.length() &&
                   Character.isJavaIdentifierPart(pkg.charAt(i)))
                buf.append(pkg.charAt(i++));
        }

        return buf.toString();
    
public voidwarning(java.lang.String warn)

        if (!quietOption) {
            //@olsen: support for I18N
            //@olsen: redirected output
            //System.out.print("Warning: ");
            //System.out.println(warn);
            out.println(getI18N("enhancer.warning", warn));//NOI18N
        }
    
public voidwarning(java.lang.String warn, java.lang.String classname)

        if (!quietOption &&
            !classWarningsSuppressed(classname)) {
            //@olsen: support for I18N
            //@olsen: redirected output
            //System.out.print("Warning: ");
            //System.out.println(warn);
            out.println(getI18N("enhancer.warning", warn));//NOI18N
        }
    
public voidwarning(java.lang.String warn, java.lang.String classname, java.lang.String fieldname)

        if (!quietOption &&
            !classWarningsSuppressed(classname) &&
            !fieldWarningsSuppressed(classname, fieldname)) {
            //@olsen: support for I18N
            //@olsen: redirected output
            //System.out.print("Warning: ");
            //System.out.println(warn);
            out.print(getI18N("enhancer.warning", warn));//NOI18N
        }
    
public booleanwriteClasses()
Expected dump levels are 0, 1, 2, 3 dump level 0 is always on.

        return (noWriteOption == false && errorsEncountered == 0);