Commit 5c3676ae authored by seinturier's avatar seinturier

Provide a factory method for the ContentClassMetaData class with a custom...

Provide a factory method for the ContentClassMetaData class with a custom classloader transmitted as parameter. Issue raised by Damien.
parent 1562d767
Tinfi 0.3
---------
* new controller for handling policy sets and intents
* API for setting and retrieving custom metadata and annotations
Tinfi 0.2.1
-----------
......
......@@ -32,6 +32,7 @@ import java.util.HashMap;
import java.util.Map;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.osoa.sca.ComponentContext;
import org.osoa.sca.annotations.Callback;
import org.osoa.sca.annotations.ComponentName;
......@@ -64,16 +65,49 @@ public class ContentClassMetaData extends ClassMetaData {
* Retrieve the SCA related metadata for the specified component class name.
*
* @param fcContentDesc the component class name (so called content class)
* @throws IllegalContentClassMetaData
* @return the corresponding metadata
* @throws IllegalContentClassMetaData
* if an error occurs while retrieving metadata
*/
public static ContentClassMetaData get( String fcContentDesc )
throws IllegalContentClassMetaData {
ClassLoaderItf cl = null;
try {
Component boot = new Tinfi().newFcInstance();
cl = (ClassLoaderItf) boot.getFcInterface(ClassLoaderFcItf.NAME);
}
catch( NoSuchInterfaceException nsie ) {
/*
* Shouldn't occur since Tinfi provides a classloader interface.
*/
throw new RuntimeException(nsie);
}
ContentClassMetaData ccmd = ccmds.get(fcContentDesc);
if( ccmd == null ) {
ccmd = new ContentClassMetaData(fcContentDesc);
ccmd = new ContentClassMetaData(fcContentDesc,cl);
ccmds.put(fcContentDesc,ccmd);
}
return ccmd;
}
/**
* Retrieve the SCA related metadata for the specified component class name.
*
* @param fcContentDesc the component class name (so called content class)
* @param cl the class loader for loading the component class
* @return the corresponding metadata
* @throws IllegalContentClassMetaData
* if an error occurs while retrieving metadata
*/
public static ContentClassMetaData get( String fcContentDesc, ClassLoader cl )
throws IllegalContentClassMetaData {
ContentClassMetaData ccmd = ccmds.get(fcContentDesc);
if( ccmd == null ) {
ccmd = new ContentClassMetaData(fcContentDesc,cl);
ccmds.put(fcContentDesc,ccmd);
}
......@@ -142,23 +176,38 @@ public class ContentClassMetaData extends ClassMetaData {
* Retrieve the SCA related metadata for the specified component class name.
*
* @param fcContentDesc the component class name (so called content class)
* @param cl the class loader for loading the component class
* @throws IllegalContentClassMetaData
* if an error occurs while retrieving metadata
*/
private ContentClassMetaData( String fcContentDesc, ClassLoader cl )
throws IllegalContentClassMetaData {
this( loadClass(fcContentDesc,cl) );
}
/**
* Retrieve the SCA related metadata for the specified component class name.
*
* @param fcContentDesc the component class name (so called content class)
* @param cl the class loader for loading the component class
* @throws IllegalContentClassMetaData
* if an error occurs while retrieving metadata
*/
private ContentClassMetaData( String fcContentDesc, ClassLoaderItf cl )
throws IllegalContentClassMetaData {
this( loadClass(fcContentDesc,cl) );
}
/**
* Retrieve the SCA related metadata for the specified component class name.
*
* @throws IllegalContentClassMetaData
* if an error occurs while retrieving metadata
*/
private ContentClassMetaData( String fcContentDesc )
private ContentClassMetaData( Class<?> fcContentClass )
throws IllegalContentClassMetaData {
/*
* Load the component class.
*/
try {
Component boot = new Tinfi().newFcInstance();
ClassLoaderItf cl = (ClassLoaderItf) boot.getFcInterface(ClassLoaderFcItf.NAME);
fcContentClass = cl.loadClass(fcContentDesc);
}
catch( Exception e ) {
throw new IllegalContentClassMetaData(e);
}
this.fcContentClass = fcContentClass;
setSupportClass(fcContentClass);
/*
......@@ -288,6 +337,34 @@ public class ContentClassMetaData extends ClassMetaData {
// -------------------------------------------------------------------------
// Implementation specific
// -------------------------------------------------------------------------
/**
* Load, with the specified classloader, the class whose name is specified.
*/
private static Class<?> loadClass( String name, ClassLoader cl )
throws IllegalContentClassMetaData {
try {
Class<?> c = cl.loadClass(name);
return c;
}
catch( ClassNotFoundException e ) {
throw new IllegalContentClassMetaData(e);
}
}
/**
* Load, with the specified classloader, the class whose name is specified.
*/
private static Class<?> loadClass( String name, ClassLoaderItf cl )
throws IllegalContentClassMetaData {
try {
Class<?> c = cl.loadClass(name);
return c;
}
catch( ClassNotFoundException e ) {
throw new IllegalContentClassMetaData(e);
}
}
/**
* Check that at most one element, method or field, is annotated with the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment