Commit 0554ac3f authored by Philippe Merle's avatar Philippe Merle

Added new public methods to class FraSCAti and interface CompositeManager in...

Added new public methods to class FraSCAti and interface CompositeManager in order to simplify integration with other frameworks like OSGi, Nuxeo, Kerovee:
- FraSCAti newFraSCAti(ClassLoader classLoader) to instantiate a new FraSCAti instance in the context of a given class loader.
- Component getComposite(String composite, ClassLoader classLoader) to load a composite from a given class loader.
- ProcessingContext newProcessingContext(ClassLoader classLoader) to create a new processing context related to a given class loader.
parent 5314f431
/**
* OW2 FraSCAti Assembly Factory
* Copyright (C) 2008-2010 INRIA, University of Lille 1
* Copyright (C) 2008-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -44,7 +44,6 @@ import org.ow2.frascati.assembly.factory.api.ClassLoaderManager;
import org.ow2.frascati.assembly.factory.api.CompositeManager;
import org.ow2.frascati.assembly.factory.api.ProcessingContext;
import org.ow2.frascati.assembly.factory.api.ProcessingMode;
import org.ow2.frascati.assembly.factory.processor.ProcessingContextImpl;
import org.ow2.frascati.component.factory.api.MembraneGeneration;
import org.ow2.frascati.tinfi.TinfiDomain;
import org.ow2.frascati.util.AbstractFractalLoggeable;
......@@ -133,10 +132,10 @@ public class FraSCAti
* Load and instantiate a Java class.
*/
@SuppressWarnings("unchecked")
protected static <T> T loadAndInstantiate(String classname)
protected static <T> T loadAndInstantiate(String classname, ClassLoader classLoader)
throws ClassNotFoundException, InstantiationException, IllegalAccessException
{
Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(classname);
Class<?> clazz = classLoader.loadClass(classname);
return (T)clazz.newInstance();
}
......@@ -146,13 +145,14 @@ public class FraSCAti
* @return The assembly factory component
* @throws FrascatiException
*/
protected final void initFrascatiComposite() throws FrascatiException
protected final void initFrascatiComposite(ClassLoader classLoader) throws FrascatiException
{
// Instantiate the OW2 FraSCAti bootstrap factory.
Factory bootstrapFactory;
try {
bootstrapFactory = loadAndInstantiate(
System.getProperty(FRASCATI_BOOTSTRAP_PROPERTY_NAME, FRASCATI_BOOTSTRAP_DEFAULT_VALUE));
System.getProperty(FRASCATI_BOOTSTRAP_PROPERTY_NAME, FRASCATI_BOOTSTRAP_DEFAULT_VALUE),
classLoader);
} catch (Exception exc) {
severe(new FrascatiException("Cannot instantiate the OW2 FraSCAti bootstrap class", exc));
return;
......@@ -211,15 +211,21 @@ public class FraSCAti
// --------------------------------------------------------------------------
public static FraSCAti newFraSCAti() throws FrascatiException
{
return newFraSCAti(Thread.currentThread().getContextClassLoader());
}
public static FraSCAti newFraSCAti(ClassLoader classLoader) throws FrascatiException
{
FraSCAti frascati;
try {
frascati = loadAndInstantiate(
System.getProperty(FRASCATI_CLASS_PROPERTY_NAME, FRASCATI_CLASS_DEFAULT_VALUE));
System.getProperty(FRASCATI_CLASS_PROPERTY_NAME, FRASCATI_CLASS_DEFAULT_VALUE),
classLoader);
} catch (Exception exc) {
throw new FrascatiException("Cannot instantiate the OW2 FraSCAti class", exc);
}
frascati.initFrascatiComposite();
frascati.initFrascatiComposite(classLoader);
return frascati;
}
......@@ -273,6 +279,24 @@ public class FraSCAti
return getCompositeManager().getComposite(composite, libs);
}
/**
* Load and create an SCA assembly instance from composite file
*
* @param composite
* - The composite file located into the current class path, on the
* local file system, or at an URL
* @param classLoader
* - the class loader to use
*
* @return the SCA composite component
* @throws FrascatiException
*/
public final Component getComposite(String composite, ClassLoader classLoader)
throws FrascatiException
{
return getCompositeManager().getComposite(composite, classLoader);
}
/**
*
*/
......@@ -297,11 +321,20 @@ public class FraSCAti
public final ProcessingContext newProcessingContext(ProcessingMode processingMode)
throws FrascatiException
{
ProcessingContext processingContext = new ProcessingContextImpl(getClassLoader());
ProcessingContext processingContext = newProcessingContext(getClassLoader());
processingContext.setProcessingMode(processingMode);
return processingContext;
}
/**
*
*/
public final ProcessingContext newProcessingContext(ClassLoader classLoader)
throws FrascatiException
{
return getCompositeManager().newProcessingContext(classLoader);
}
/**
*
*/
......
/**
* OW2 FraSCAti Assembly Factory
* Copyright (C) 2009-2010 INRIA, University of Lille 1
* Copyright (C) 2009-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -52,6 +52,15 @@ public interface CompositeManager {
*/
ProcessingContext newProcessingContext(URL ... urls);
/**
* Create a new processing context instance.
*
* @param classLoader the class loader of the processing context.
* @return a new processing context instance.
* @since 1.5
*/
ProcessingContext newProcessingContext(ClassLoader classLoader);
/**
* Load a contribution ZIP archive.
*
......@@ -95,6 +104,19 @@ public interface CompositeManager {
*/
Component getComposite(String composite, URL[] libs) throws ManagerException;
/**
* Load an SCA composite and create the FraSCAti composite instance.
*
* @param composite
* name of the composite file to load, can be a resource for the
* current class path, a local file or an URL.
* @param classLoader the class loader to use.
* @return the resulting FraSCAti composite instance.
* @throws ManagerException thrown when a problem occurs.
* @since 1.5
*/
Component getComposite(String composite, ClassLoader classLoader) throws ManagerException;
/**
* Load an SCA composite and create the associate FraSCAti composite instance.
*
......
/**
* OW2 FraSCAti Assembly Factory
* Copyright (C) 2008-2011 INRIA, University of Lille 1
* Copyright (C) 2008-2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -236,7 +236,15 @@ public class AssemblyFactoryManager
public final ProcessingContext newProcessingContext(URL ... urls)
{
FrascatiClassLoader fcl = new FrascatiClassLoader(urls, this.mainClassLoader);
return new ProcessingContextImpl(fcl);
return newProcessingContext(fcl);
}
/**
* @see org.ow2.frascati.assembly.factory.api.newProcessingContext(ClassLoader)
*/
public final ProcessingContext newProcessingContext(ClassLoader classLoader)
{
return new ProcessingContextImpl(classLoader);
}
/**
......@@ -384,6 +392,15 @@ public class AssemblyFactoryManager
return processComposite(new QName(composite), newProcessingContext(libs == null ? new URL[0] : libs));
}
/**
* @see org.ow2.frascati.assembly.factory.api.CompositeManager#getComposite(String)
*/
public final Component getComposite(String composite, ClassLoader classLoader)
throws ManagerException
{
return processComposite(new QName(composite), newProcessingContext(classLoader));
}
/**
* @see org.ow2.frascati.assembly.factory.api.processComposite(QName, ProcessingContext)
*
......
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