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

StaticWeaveAntTask

public class StaticWeaveAntTask extends org.apache.tools.ant.Task

Description: This is the static weave ant task definition class that verifies the value of specified attributes and invokes StaticWeaveProcessor to weave classes.

Usage:

  • Ensure the classpath contains all the classes necessary to load the classes in the source.
  • The lib containing this weaving Ant task must be added into the classpath by using the -lib option on Ant command line instead of using the classpath attribute of the taskdef Ant task.
  • Define weaving Ant task and Ant target by using following attributes: source - specify source location. In the default configuration StaticWeaveAntTask assumes the source contains the persistence.xml,if this is not the case, the location containing the persistence.xml must be explicitly identified by the attribute 'persistenceinfo'. target - specify the output location (either a directory or a jar). persistenceinfo - specify the location containing the persistence.xml. This is optional and should only be specified if the source does not contain the persistence.xml. log - specify a logging file. This is optional loglevel - specify a literal value of toplink logging level(OFF,SEVERE,WARNING,INFO,CONFIG,FINE,FINER,FINEST) The default value is OFF(8). This is optional.
  • 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: * *<target name="define.task" description="New task definition for toplink static weaving"/>
*  <taskdef name="weave" classname="oracle.toplink.essentials.weaving.StaticWeaverAntTask"/>
*</target>
*<target name="weaving" description="perform weaving." depends="define.task">
*  <weave source= "c:\foo.jar" target = "c:\wovenfoo.jar" persistenceinfo="c:\foo-containing-persistenceinfo.jar">
*    <classpath>
*      <pathelement path="c:\foo-dependent.jar"/>
*    </classpath>
*  </weave>
*</target> *

Fields Summary
private String
source
private String
persistenceinfo
private String
target
private Vector
classPaths
private int
logLevel
private Writer
logWriter
Constructors Summary
Methods Summary
public voidaddClasspath(org.apache.tools.ant.types.Path path)
Add the dependent classpath in order to load classes from the specified input jar.

param
path

        classPaths.add(path);
    
public voidexecute()
Execute ant task

       verifyOptions();
       start();
    
private java.util.VectorgetPathElement()

        Vector pathElements = new Vector();
        for(int i=0;i<classPaths.size();i++){
            String thisPath = ((Path)classPaths.get(i)).toString();
            if(thisPath!=null){
               String[] thisSplitedPath=thisPath.split(File.pathSeparator);
               if(thisSplitedPath!=null){
                   for(int j=0;j<thisSplitedPath.length;j++){
                     pathElements.add(thisSplitedPath[j]);
                   }
               }
            }
        }
        return pathElements;
    
private java.net.URL[]getURLs()

        Vector pathElements = getPathElement();
        URL[] urls = new URL[pathElements.size()];
        for(int i=0;i<pathElements.size();i++){
           try {
               urls[i] = (new File((String)pathElements.get(i))).toURI().toURL();
           } catch (MalformedURLException e) {
               throw StaticWeaveException.exceptionPerformWeaving(e);
           }
        }
        return urls;
    
public voidsetLog(java.lang.String logFile)
Set the archive containing persistence.xml while input archive does not contain it.

param
inputMainJarFile

        try{
           this.logWriter = new FileWriter(logFile);
        }catch(Exception e){
            throw StaticWeaveException.openLoggingFileException(logFile,e);
        }
    
public voidsetLogLevel(java.lang.String logLevel)

        if (logLevel.equalsIgnoreCase("OFF") ||
            logLevel.equalsIgnoreCase("SEVERE") || 
            logLevel.equalsIgnoreCase("WARNING") || 
            logLevel.equalsIgnoreCase("INFO") || 
            logLevel.equalsIgnoreCase("CONFIG") || 
            logLevel.equalsIgnoreCase("FINE") || 
            logLevel.equalsIgnoreCase("FINER") || 
            logLevel.equalsIgnoreCase("FINEST") || 
            logLevel.equalsIgnoreCase("ALL")) {
            this.logLevel=AbstractSessionLog.translateStringToLoggingLevel(logLevel.toUpperCase());
        } else{
            throw StaticWeaveException.illegalLoggingLevel(logLevel);
        }
    
public voidsetPersistenceinfo(java.lang.String persistenceinfo)

        this.persistenceinfo = persistenceinfo;
    
public voidsetSource(java.lang.String source)
Set the input archive to be used to weave.

param
inputJarFile

    
    
                    
        
           this.source = source;
    
public voidsetTarget(java.lang.String target)
Set output archive to be used to weave to

param
outputJarFile

           this.target = target;
    
private voidstart()
Invoke weaving process..

       try{
           StaticWeaveProcessor weave = new StaticWeaveProcessor(source, target);
           URL[] urls = getURLs();
           if(urls!=null){
               URLClassLoader classLoader = new URLClassLoader(getURLs(), Thread.currentThread().getContextClassLoader());
               weave.setClassLoader(classLoader);
           }
           if(persistenceinfo!=null){
               weave.setPersistenceInfo(persistenceinfo);
           }
           if(logWriter!=null){
               weave.setLog(logWriter);
           }
           weave.setLogLevel(this.logLevel);
           weave.performWeaving();
       }catch(Exception e){
           throw StaticWeaveException.exceptionPerformWeaving(e);
       }
    
private voidverifyOptions()
Verify the value of attributes.

throws
BuildException

       if(source==null) {
           throw StaticWeaveException.missingSource();
       }
       
       if(target==null) {
           throw StaticWeaveException.missingTarget();
       }