Package oracle.toplink.essentials.internal.weaving

Examples of oracle.toplink.essentials.internal.weaving.StaticWeaveClassTransformer


        //Instantiate classloader
        this.classLoader = (this.classLoader == null)? Thread.currentThread().getContextClassLoader():this.classLoader;
        this.classLoader = new URLClassLoader(getURLs(), this.classLoader);
       
        //Instantiate the classtransformer, we check if the persistenceinfo URL has been specified.
        StaticWeaveClassTransformer classTransformer=null;
        if(persistenceInfo!=null){
            classTransformer = new StaticWeaveClassTransformer(persistenceInfo, this.classLoader,this.logWriter,this.logLevel);
        } else{
            classTransformer = new StaticWeaveClassTransformer(source, this.classLoader,this.logWriter,this.logLevel);
        }

        //Starting process...
        Archive sourceArchive =(new ArchiveFactoryImpl()).createArchive(source);
        Iterator entries = sourceArchive.getEntries();
        while (entries.hasNext()){
            String entryName = (String)entries.next();
            InputStream entryInputStream = sourceArchive.getEntry(entryName);
            String className = PersistenceUnitProcessor.buildClassNameFromEntryString(entryName) ;
           
            //Add a directory entry
            swoh.addDirEntry(getDirectoryFromEntryName(entryName));
           
            //Add a regular entry
            JarEntry newEntry = new JarEntry(entryName);
           
            byte[] originalClassBytes=null;
            byte[] transferredClassBytes=null;
            try {
                Class thisClass = this.classLoader.loadClass(className);
                //if the class is not in the classpath, we simply copy the entry
                //to the target(no weaving).
                if (thisClass == null){
                    swoh.addEntry(entryInputStream, newEntry);
                    continue;
                }
               
                //Try to read the loaded class bytes, the class bytes is required for
                //classtransformer to perform transfer. Simply copy entry to the target(no weaving)
                //if the class bytes can't be read.
                InputStream is = this.classLoader.getResourceAsStream(entryName);
                if (is!=null){
                    originalClassBytes = new byte[is.available()];
                    is.read(originalClassBytes);
                }else{
                    swoh.addEntry(entryInputStream, newEntry);
                    continue;
                }
               
                //If everything is OK so far, we perform the weaving. we need three paramteres in order to
                //class to perform weaving for that class, the class name,the class object and class bytes.
                transferredClassBytes = classTransformer.transform(className.replace('.', '/'), thisClass, originalClassBytes);
               
                //if transferredClassBytes is null means the class dose not get woven.
                if(transferredClassBytes!=null){
                    swoh.addEntry(newEntry, transferredClassBytes);
                } else{
View Full Code Here

TOP

Related Classes of oracle.toplink.essentials.internal.weaving.StaticWeaveClassTransformer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.