Commit 1d23f653 authored by Gwenael Cattez's avatar Gwenael Cattez

ProcessingContext : store all the processed composite not just a rootComposite...

ProcessingContext : store all the processed composite not just a rootComposite (useful for contribution with multiple deployable)
CompositeManager : add a method to get the ProcessingContext used to process a composite
parent 106ceec8
......@@ -60,7 +60,15 @@ public interface CompositeManager {
* @since 1.5
*/
ProcessingContext newProcessingContext(ClassLoader classLoader);
/**
* Get the ProcessingContext used to process the composite
*
* @param compositeName the name of the composite
* @return the ProcessingContext related to the composite or null if not found
*/
ProcessingContext getProcessingContext(String compositeName);
/**
* Load a contribution ZIP archive.
*
......
......@@ -26,44 +26,68 @@
package org.ow2.frascati.assembly.factory.api;
import java.util.List;
import org.eclipse.stp.sca.Composite;
import org.ow2.frascati.parser.api.ParsingContext;
/**
* OW2 FraSCAti Assembly Factory SCA processing context interface.
*
*
* @author <a href="mailto:philippe.merle@inria.fr">Philippe Merle</a>
* @version 1.3
*/
public interface ProcessingContext extends ParsingContext {
public interface ProcessingContext extends ParsingContext
{
/**
* Get the current processing mode for this processing context.
*
* @return the current processing mode for this processing context.
*/
ProcessingMode getProcessingMode();
/**
* Set the current processing mode for this processing context.
*
* @param processingMode the current processing mode for this processing context.
*/
void setProcessingMode(ProcessingMode processingMode);
/**
* Get the processed root SCA composite.
*
* @return the processed root SCA composite.
*/
Composite getRootComposite();
/**
* Get the current processing mode for this processing context.
*
* @return the current processing mode for this processing context.
*/
ProcessingMode getProcessingMode();
/**
* Set the processed root SCA composite.
*
* @param composite the processed root SCA composite.
*/
void setRootComposite(Composite composite);
/**
* Set the current processing mode for this processing context.
*
* @param processingMode the current processing mode for this processing context.
*/
void setProcessingMode(ProcessingMode processingMode);
/**
* Add a processed SCA composite to the processed composites
*
* @param processedComposite the composite to store
*/
void addProcessedComposite(Composite processedComposite);
/**
* Get the processed root SCA composite.
*
* @return the processed root SCA composite.
*/
Composite getRootComposite();
/**
* Get a list of all Composite processed in this ProcessingContext
*
* @return a list of all Composite processed in this ProcessingContext
*/
List<Composite> getProcessedComposite();
/**
* Set the processed root SCA composite.
*
* @param composite the processed root SCA composite.
*/
void setRootComposite(Composite composite);
/**
* Get a processed Composite named compositeName
*
* @param compositeName the name of the searched composite
* @return the processed composite named compositeName or null if not found
*/
Composite getProcessedComposite(String compositeName);
}
......@@ -52,6 +52,7 @@ import org.eclipse.stp.sca.Composite;
import org.eclipse.stp.sca.ContributionType;
import org.eclipse.stp.sca.DeployableType;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.util.Fractal;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
......@@ -123,6 +124,18 @@ public class AssemblyFactoryManager
@Reference(name = "composite-processor")
private Processor<Composite> compositeProcessor;
/**
* Processor for SCA imports
*/
@Reference(name = "sca-import-processor")
private ImportExportProcessor<BaseImportType> scaImportProcessor;
/**
* Processor for SCA exports
*/
@Reference(name = "sca-export-processor")
private ImportExportProcessor<BaseExportType> scaExportProcessor;
/**
* The main class loader used by the OW2 FraSCAti Assembly Factory.
*/
......@@ -133,20 +146,24 @@ public class AssemblyFactoryManager
*/
private Component topLevelDomainComposite;
/**
* Map of the ImportExportFrascatiClassLoader
* Used to share resources between composite deployed at runtime
*/
private List<ImportExportFrascatiClassLoader> exportFrascatiClassLoaders=new ArrayList<ImportExportFrascatiClassLoader>();
/**
* Map of all processingContext used to process composite (entry composite's name)
*/
private Map<String, ProcessingContext> mapOfProcessingContext=new HashMap<String, ProcessingContext>();
/**
* Map of loaded composites.
*/
// TODO: Use QName instead of String
private Map<String, Component> loadedComposites = new HashMap<String, Component>();
@Reference(name = "sca-import-processor")
private ImportExportProcessor<BaseImportType> scaImportProcessor;
@Reference(name = "sca-export-processor")
private ImportExportProcessor<BaseExportType> scaExportProcessor;
private List<ImportExportFrascatiClassLoader> exportFrascatiClassLoaders=new ArrayList<ImportExportFrascatiClassLoader>();
//---------------------------------------------------------------------------
// Internal methods.
......@@ -235,7 +252,16 @@ public class AssemblyFactoryManager
fcl.addParent(this.mainClassLoader);
return new ProcessingContextImpl(fcl);
}
/**
* @see org.ow2.frascati.assembly.factory.api.CompositeManager#getProcessingContext(java.lang.String)
*/
public ProcessingContext getProcessingContext(String rootCompositeName)
{
return this.mapOfProcessingContext.get(rootCompositeName);
}
/**
* @see org.ow2.frascati.assembly.factory.api.CompositeManager#getContribution(String)
*/
......@@ -251,6 +277,7 @@ public class AssemblyFactoryManager
public final Component[] processContribution(String contribution, ProcessingContext processingContext)
throws ManagerException
{
// Get the processing context class loader.
FrascatiClassLoader frascatiClassLoader = (FrascatiClassLoader)processingContext.getClassLoader();
......@@ -469,7 +496,8 @@ public class AssemblyFactoryManager
// Iterate over 'Deployable' defined in contribution descriptor
ArrayList<Component> components = new ArrayList<Component>();
for (DeployableType deployable : contributionType.getDeployable()) {
for (DeployableType deployable : contributionType.getDeployable())
{
try {
Component c = processComposite(deployable.getComposite(), processingContext);
components.add(c);
......@@ -557,10 +585,11 @@ public class AssemblyFactoryManager
}
// If composite is the first loaded, then put it in the processing context as the root composite.
if(processingContext.getRootComposite() == null) {
if(processingContext.getRootComposite() == null)
{
processingContext.setRootComposite(composite);
}
// Are errors detected during the parsing phase.
// if(processingContext.getErrors() > 0) {
// warning(new ManagerException("Errors detected during the parsing phase of composite '" + qname + "'"));
......@@ -670,8 +699,14 @@ public class AssemblyFactoryManager
severe(new ManagerException("Could not start the SCA composite '" + qname + "'", e));
return null;
}
/*Store the processing Context and the processed composite for further uses*/
processingContext.addProcessedComposite(composite);
this.mapOfProcessingContext.put(composite.getName(), processingContext);
log.info("Save processing context for composite : "+composite.getName());
if(processingMode == ProcessingMode.start) {
if(processingMode == ProcessingMode.start)
{
return component;
}
......@@ -749,6 +784,10 @@ public class AssemblyFactoryManager
// Remove component from loaded composites.
this.loadedComposites.remove(name);
// // Remove the processingContext from the saved processingContext
// this.mapOfProcessingContext.remove(name);
// log.info("Remove ProcessingContext realed to "+name+" comoposite");
// Stop the SCA component.
stopFractalComponent(component);
}
......
......@@ -27,102 +27,144 @@
package org.ow2.frascati.assembly.factory.processor;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.stp.sca.Composite;
import org.ow2.frascati.assembly.factory.api.ProcessingContext;
import org.ow2.frascati.assembly.factory.api.ProcessingMode;
import org.ow2.frascati.parser.core.ParsingContextImpl;
/**
* OW2 FraSCAti Assembly Factory SCA processing context class.
*
*
* @author <a href="mailto:philippe.merle@inria.fr">Philippe Merle</a>
* @version 1.3
*/
public class ProcessingContextImpl
extends ParsingContextImpl
implements ProcessingContext {
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
/**
* The current processing mode.
*/
private ProcessingMode processingMode = ProcessingMode.all;
/**
* The processed root SCA composite.
*/
private Composite rootComposite;
//---------------------------------------------------------------------------
// Internal methods.
// --------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Public methods.
// --------------------------------------------------------------------------
/**
* Construct with the current thread context class loader.
*/
public ProcessingContextImpl() {
super();
}
/**
* Construct with a class loader.
*
* @param classLoader the class loader of the parser context.
*/
public ProcessingContextImpl(ClassLoader classLoader) {
super(classLoader);
}
/**
* @see ParsingContextImpl#loadClass(String)
*/
@Override
public final <T> Class<T> loadClass(String className) throws ClassNotFoundException {
try {
return super.loadClass(className);
} catch(ClassNotFoundException cnfe) {
if(getResource(className.replace(".", File.separator) + ".java") != null) {
return null;
}
throw cnfe;
}
}
/**
* @see ProcessingContext.getProcessingMode()
*/
public final ProcessingMode getProcessingMode() {
return this.processingMode;
}
/**
* @see ProcessingContext.setProcessingMode(ProcessingMode)
*/
public final void setProcessingMode(ProcessingMode processingMode) {
this.processingMode = processingMode;
}
/**
* @see ProcessingContext.getRootComposite()
*/
public final Composite getRootComposite() {
return this.rootComposite;
}
/**
* @see ProcessingContext.setRootComposite(Composite)
*/
public final void setRootComposite(Composite composite) {
this.rootComposite = composite;
}
public class ProcessingContextImpl extends ParsingContextImpl implements ProcessingContext
{
// ---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
/**
* The current processing mode.
*/
private ProcessingMode processingMode = ProcessingMode.all;
private List<Composite> processedComposites = new ArrayList<Composite>();
/**
* The processed root SCA composite.
*/
private Composite rootComposite;
// ---------------------------------------------------------------------------
// Internal methods.
// --------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Public methods.
// --------------------------------------------------------------------------
/**
* Construct with the current thread context class loader.
*/
public ProcessingContextImpl()
{
super();
}
/**
* Construct with a class loader.
*
* @param classLoader the class loader of the parser context.
*/
public ProcessingContextImpl(ClassLoader classLoader)
{
super(classLoader);
}
/**
* @see ParsingContextImpl#loadClass(String)
*/
@Override
public final <T> Class<T> loadClass(String className) throws ClassNotFoundException
{
try
{
return super.loadClass(className);
} catch (ClassNotFoundException cnfe)
{
if (getResource(className.replace(".", File.separator) + ".java") != null)
{
return null;
}
throw cnfe;
}
}
/**
* @see ProcessingContext.getProcessingMode()
*/
public final ProcessingMode getProcessingMode()
{
return this.processingMode;
}
/**
* @see ProcessingContext.setProcessingMode(ProcessingMode)
*/
public final void setProcessingMode(ProcessingMode processingMode)
{
this.processingMode = processingMode;
}
/**
* @see ProcessingContext.getRootComposite()
*/
public final Composite getRootComposite()
{
return this.rootComposite;
}
/**
* @see ProcessingContext.setRootComposite(Composite)
*/
public final void setRootComposite(Composite composite)
{
this.rootComposite = composite;
}
/**
* @see org.ow2.frascati.assembly.factory.api.ProcessingContext#addProcessedComposite(org.eclipse.stp.sca.Composite)
*/
public final void addProcessedComposite(Composite processedComposite)
{
this.processedComposites.add(processedComposite);
}
/**
* @see org.ow2.frascati.assembly.factory.api.ProcessingContext#getProcessedComposite()
*/
public final List<Composite> getProcessedComposite()
{
return this.processedComposites;
}
/**
* @see org.ow2.frascati.assembly.factory.api.ProcessingContext#getProcessedComposite(java.lang.String)
*/
public Composite getProcessedComposite(String compositeName)
{
for (Composite processedComposite : this.processedComposites)
{
if (processedComposite.getName().equals(compositeName))
{
return processedComposite;
}
}
return null;
}
}
......@@ -29,9 +29,12 @@
package org.ow2.frascati.assembly.factory.processor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Handler for Java.Proxy that acting as a SCA Binding
* Because SCA binding is not support by the binding factory we use java Proxy to act as stub
*
*/
public class ScaBindingScaInvocationHandler implements InvocationHandler
......@@ -41,6 +44,9 @@ public class ScaBindingScaInvocationHandler implements InvocationHandler
*/
private Object delegate;
/**
* The path of the delegate service
*/
private String bindingURI;
/**
......@@ -66,6 +72,13 @@ public class ScaBindingScaInvocationHandler implements InvocationHandler
*/
public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
return method.invoke(this.delegate, args);
try
{
return method.invoke(this.delegate, args);
}
catch(InvocationTargetException e)
{
throw e.getCause();
}
}
}
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