FileDocCategorySizeDatePackage
StaticWeave.javaAPI DocGlassfish v2 API10305Tue May 22 16:54:56 BST 2007oracle.toplink.essentials.weaving

StaticWeave

public class StaticWeave extends Object

Description: This is the static weave command line processing class that verifies command options and invokes StaticWeaveProcessor to statically weave the classes.

Usage:
*  StaticWeave [options] source target
Options:
*  -classpath
*    Set the user class path, use ";" as the delimiter in Window system and ":" in Unix system.
*  -log
*    The path of log file, the standard output will be the default.
*  -loglevel
*    Specify a literal value for toplink log level(OFF,SEVERE,WARNING,INFO,CONFIG,FINE,FINER,FINEST). The default value is OFF.
*  -persistenceinfo
*    The path contains META-INF/persistence.xml. This is ONLY required when the source does not include it. * The classpath must contain all the classes necessary in oder to perform weaving.

* The weaving will be performed in place if source and target point to the same location. Weaving in place is ONLY applicable for directory-based sources.
*Example:
* To weave all entites contained in c:\foo-source.jar with its persistence.xml contained within c:\foo-containing-persistence-xml.jar, and output to c:\\foo-target.jar,
* StaticWeave -persistenceinfo c:\foo-containing-persistencexml.jar -classpath c:\classpath1;c:\classpath2 c:\foo-source.jar c:\foo-target.jar

Fields Summary
private String[]
argv
private String
source
private String
persistenceinfopath
private String
target
private int
loglevel
private Writer
logWriter
private PrintStream
vout
private String[]
classpaths
Constructors Summary
public StaticWeave(String[] argv)

            this.argv = argv;
        
Methods Summary
private java.lang.ClassLoadergetClassLoader()

            if (classpaths!=null){
                URL[] urls= new URL[classpaths.length];
                for(int i=0;i<classpaths.length;i++){
                   urls[i]=(new File(classpaths[i])).toURL();
                }
                return new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
            }else{
                return null;
            }
        
public static voidmain(java.lang.String[] argv)


             

            StaticWeave staticweaver = new StaticWeave(argv);

            try {
                // Verify the command line arguments 
                staticweaver.processCommandLine();
                staticweaver.start();
            } catch (Exception e) {
                throw StaticWeaveException.exceptionPerformWeaving(e);
            }
        
private voidprintUsage()

            PrintStream o = vout;
            o.println(ToStringLocalization.buildMessage("staticweave_commandline_help_message", new Object[]{null}));
        
voidprocessCommandLine()

            if (argv.length < 2 || argv.length>10) {
                printUsage();
                System.exit(1);
            }
            for (int i=0;i<this.argv.length;i++){
                if (argv[i].equalsIgnoreCase("-classpath")) {
                    // Make sure we did not run out of arguments
                    if ((i + 1) >= argv.length ){
                        printUsage();
                        System.exit(1);
                    }
                    classpaths=argv[i+1].split(File.pathSeparator);
                    i++;
                    continue;
                }
                
                if (argv[i].equalsIgnoreCase("-persistenceinfo")) {
                    if ((i + 1) >= argv.length ){
                           printUsage();
                           System.exit(1);
                    }
                    persistenceinfopath=argv[i+1];
                    i++;
                    continue;
                }
                
                if (argv[i].equalsIgnoreCase("-log")) {
                    if ((i + 1) >= argv.length ){
                           printUsage();
                           System.exit(1);
                    }
                    logWriter=new FileWriter(argv[i+1]);
                    i++;
                    continue;
                }

                if (argv[i].equalsIgnoreCase("-loglevel")) {
                    if ((i + 1) >= argv.length ) {
                           printUsage();
                           System.exit(1);
                    }

                   if ( argv[i+1].equalsIgnoreCase("OFF") ||
                        argv[i+1].equalsIgnoreCase("SEVERE") || 
                        argv[i+1].equalsIgnoreCase("WARNING") || 
                        argv[i+1].equalsIgnoreCase("INFO") || 
                        argv[i+1].equalsIgnoreCase("CONFIG") || 
                        argv[i+1].equalsIgnoreCase("FINE") || 
                        argv[i+1].equalsIgnoreCase("FINER") || 
                        argv[i+1].equalsIgnoreCase("FINEST") || 
                        argv[i+1].equalsIgnoreCase("ALL")) {
                       loglevel=AbstractSessionLog.translateStringToLoggingLevel(argv[i+1].toUpperCase());
                    } else{
                        printUsage();
                        System.exit(1);
                    }
                    i++;
                    continue;
                }
                
                if(source!=null){
                    printUsage();
                    System.exit(1);
                }
                
                if(target!=null){
                    printUsage();
                    System.exit(1);
                }

                source=argv[i];
                if((i+1)>=argv.length){
                    printUsage();
                    System.exit(1);
                }
                i++;
                if(i>=argv.length){
                    printUsage();
                    System.exit(1);
                }
                target=argv[i];
                i++;
            }
            
            
           //Ensure source and target have been specified
           if(source==null){
                printUsage();
                throw StaticWeaveException.missingSource();
           } 
           if(target==null){
                printUsage();
                throw StaticWeaveException.missingTarget();
           } 
        
public voidstart()
Invoke StaticWeaveProcessor to perform weaving.


            //perform weaving
            StaticWeaveProcessor staticWeaverProcessor= new StaticWeaveProcessor(this.source,this.target);
            if(persistenceinfopath!=null){
                staticWeaverProcessor.setPersistenceInfo(this.persistenceinfopath);
            }
            if(classpaths!=null){
                staticWeaverProcessor.setClassLoader(getClassLoader());
            }
            if(logWriter!=null){
               staticWeaverProcessor.setLog(logWriter);
            }
            staticWeaverProcessor.setLogLevel(loglevel);
            staticWeaverProcessor.performWeaving();