StaticWeaveClassTransformerpublic class StaticWeaveClassTransformer extends Object
Description: This class provides the implementation of class transformer by leveraging on the following existing APIs,
- PersistenceUnitProcessor.processORMetadata() - get class descriptor.
- PersistenceUnitProcessor.buildEntityList() - get entity classes lsit.
- TransformerFactory.createTransformerAndModifyProject - get class transformer.
Responsibilities:
- Create the classtransformer for each persistence unit individually and store them into the list.
- Provide class transfom method to perform weaving function.
|
Fields Summary |
---|
private ArrayList | classTransformers | private Writer | logWriter | private int | logLevel | private ClassLoader | aClassLoader |
Constructors Summary |
---|
public StaticWeaveClassTransformer(URL inputArchiveURL, ClassLoader aclassloader)Constructs an instance of StaticWeaveClassTransformer
this(inputArchiveURL,aclassloader,null,SessionLog.OFF);
| public StaticWeaveClassTransformer(URL inputArchiveURL, ClassLoader aclassloader, Writer logWriter, int loglevel)Constructs an instance of StaticWeaveClassTransformer
this.aClassLoader = aclassloader;
this.logWriter=logWriter;
this.logLevel=loglevel;
buildClassTransformers(inputArchiveURL,aclassloader);
|
Methods Summary |
---|
private void | buildClassTransformers(java.net.URL inputArchiveURL, java.lang.ClassLoader aclassloader)INTERNAL:
The method creates classtransformer list corresponding to each persistence unit.
if(classTransformers!=null) {
return ;
} else{
classTransformers = new ArrayList<ClassTransformer>();
}
Archive archive =null;
try{
archive = (new ArchiveFactoryImpl()).createArchive(inputArchiveURL);
}catch(ZipException e){
throw StaticWeaveException.exceptionOpeningArchive(inputArchiveURL,e);
}
List<SEPersistenceUnitInfo> persistenceUnitsList =
PersistenceUnitProcessor.processPersistenceArchive(archive, aclassloader);
if(persistenceUnitsList==null){
throw PersistenceUnitLoadingException.couldNotGetUnitInfoFromUrl(inputArchiveURL);
}
Iterator<SEPersistenceUnitInfo> persistenceUnitsIterator = persistenceUnitsList.iterator();
while (persistenceUnitsIterator.hasNext()){
SEPersistenceUnitInfo unitInfo = (SEPersistenceUnitInfo)persistenceUnitsIterator.next();
unitInfo.setNewTempClassLoader(aclassloader);
//build class transformer.
ClassTransformer transformer = buildTransformer(unitInfo,this.logWriter,this.logLevel);
classTransformers.add(transformer);
}
| private javax.persistence.spi.ClassTransformer | buildTransformer(javax.persistence.spi.PersistenceUnitInfo unitInfo, java.io.Writer logWriter, int logLevel)INTERNAL:
This method builds the classtransformer for the specified perisistence unit.
//persistenceUnitInfo = unitInfo;
ClassLoader privateClassLoader = unitInfo.getNewTempClassLoader();
// create server session (it should be done before initializing ServerPlatform)
ServerSession session = new ServerSession(new Project(new DatabaseLogin()));
session.setLogLevel(logLevel);
if(logWriter!=null){
((DefaultSessionLog)session.getSessionLog()).setWriter(logWriter);
}
session.getPlatform().setConversionManager(new EJB30ConversionManager());
// Create an instance of MetadataProcessor for specified persistence unit info
MetadataProcessor processor = new MetadataProcessor(unitInfo, session, privateClassLoader, true);
// Process the Object/relational metadata from XML and annotations.
PersistenceUnitProcessor.processORMetadata(processor,privateClassLoader, session, false);
//Collection entities = buildEntityList(persistenceUnitInfo, privateClassLoader);
Collection entities = PersistenceUnitProcessor.buildEntityList(processor,privateClassLoader);
// The transformer is capable of altering domain classes to handle a LAZY hint for OneToOne mappings. It will only
// be returned if we we are mean to process these mappings
return TransformerFactory.createTransformerAndModifyProject(session, entities, privateClassLoader);
| public byte[] | transform(java.lang.String originalClassName, java.lang.Class originalClass, byte[] originalClassBytes)INTERNAL:
The method performs weaving function on the given class.
byte[] newClassBytes = null;
for(ClassTransformer transformer : classTransformers){
newClassBytes=transformer.transform(aClassLoader, originalClassName,originalClass, null, originalClassBytes);
if(newClassBytes!=null) {
break;
};
}
return newClassBytes;
|
|