Commit a3852172 authored by Philippe Merle's avatar Philippe Merle

* Improved the code quality according to checking rules of Sonar.

* Cosmetic updates.
parent bad64af8
/***
/**
* OW2 FraSCAti Contribution Maven Plugin
* Copyright (C) 2008-2010 INRIA, University of Lille 1
*
......@@ -113,23 +113,24 @@ public class FrascatiContributionMojo
ouputFile.createNewFile();
FileOutputStream outputStream = new FileOutputStream(ouputFile);
try {
String begin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\">\n";
String end = "</contribution>";
String begin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\">\n";
String end = "</contribution>";
String body = "";
String body = "";
for (String deployable : deployables) {
body = body + " <deployable composite=\"" + deployable
for (String deployable : deployables) {
body = body + " <deployable composite=\"" + deployable
+ "\"/>\n";
getLog().info("Added deployable composite : " + deployable);
}
// write contribution file
outputStream.write((begin + body + end).getBytes());
outputStream.flush();
outputStream.close();
getLog().info("Added deployable composite : " + deployable);
}
// write contribution file
outputStream.write((begin + body + end).getBytes());
outputStream.flush();
} finally {
outputStream.close();
}
} catch (IOException e) {
getLog().error("Could not create contribution descriptor");
}
......@@ -193,20 +194,21 @@ public class FrascatiContributionMojo
* @throws IOException
*/
private void copy(File inFile, File outFile) throws IOException {
private void copy(File inFile, File outFile) throws IOException
{
FileReader in = new FileReader(inFile);
FileWriter out = new FileWriter(outFile);
int c;
try {
int c;
// TODO: Could be speedup by using a buffer.
while ((c = in.read()) != -1) {
out.write(c);
// TODO: Could be speedup by using a buffer.
while ((c = in.read()) != -1) {
out.write(c);
}
} finally {
in.close();
out.close();
}
in.close();
out.close();
}
/**
......@@ -217,35 +219,38 @@ public class FrascatiContributionMojo
* @throws IOException
*/
private void zip(File inFile, File outFile) throws IOException {
private void zip(File inFile, File outFile) throws IOException
{
final int buffer = 2048;
BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream(outFile);
ZipOutputStream out = new ZipOutputStream(
new BufferedOutputStream(dest));
byte data[] = new byte[buffer];
List<String> list = visitFiles(inFile, new ArrayList<String>(), "");
for (String f : list) {
FileInputStream fi = new FileInputStream(new File(inFile, f));
origin = new BufferedInputStream(fi, buffer);
ZipEntry entry = new ZipEntry(f);
out.putNextEntry(entry);
int count;
while ((count = origin.read(data, 0, buffer)) != -1) {
out.write(data, 0, count);
try {
byte data[] = new byte[buffer];
List<String> list = visitFiles(inFile, new ArrayList<String>(), "");
for (String f : list) {
FileInputStream fi = new FileInputStream(new File(inFile, f));
BufferedInputStream origin = new BufferedInputStream(fi, buffer);
ZipEntry entry = new ZipEntry(f);
out.putNextEntry(entry);
try {
int count;
while ((count = origin.read(data, 0, buffer)) != -1) {
out.write(data, 0, count);
}
} finally {
origin.close();
fi.close();
}
}
origin.close();
} finally {
out.close();
dest.close();
}
out.close();
}
private List<String> visitFiles(File dir, List<String> files, String currentDir)
......
......@@ -45,8 +45,9 @@ import org.ow2.frascati.util.FrascatiException;
*
* @author Nicolas Dolet
*/
public class Launcher extends AbstractLoggeable {
public class Launcher
extends AbstractLoggeable
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
......@@ -68,7 +69,8 @@ public class Launcher extends AbstractLoggeable {
/**
* Default constructor.
*/
public Launcher() {
public Launcher()
{
scaComposite = null;
}
......@@ -79,7 +81,8 @@ public class Launcher extends AbstractLoggeable {
* @throws FrascatiException
*/
public Launcher(String compositeName)
throws FrascatiException {
throws FrascatiException
{
try {
scaComposite = FraSCAti.newFraSCAti().getComposite(compositeName);
this.compositeName = compositeName;
......@@ -96,7 +99,8 @@ public class Launcher extends AbstractLoggeable {
* @throws FrascatiException
*/
public Launcher(String compositeName, FraSCAti f)
throws FrascatiException {
throws FrascatiException
{
try {
scaComposite = f.getComposite(compositeName);
this.compositeName = compositeName;
......@@ -115,7 +119,8 @@ public class Launcher extends AbstractLoggeable {
* @throws FrascatiException
*/
public Launcher(String compositeName, FraSCAti f, URL[] urls)
throws FrascatiException {
throws FrascatiException
{
try {
scaComposite = f.getComposite(compositeName,urls);
this.compositeName = compositeName;
......@@ -147,7 +152,8 @@ public class Launcher extends AbstractLoggeable {
* Launch the composite
* @throws FrascatiException
*/
public final void launch() throws FrascatiException {
public final void launch() throws FrascatiException
{
if (compositeName != null) {
try {
scaComposite = FraSCAti.newFraSCAti().getComposite(compositeName);
......@@ -166,7 +172,8 @@ public class Launcher extends AbstractLoggeable {
* @throws FrascatiException
*/
public final void launch(String compositeName)
throws FrascatiException {
throws FrascatiException
{
this.compositeName = compositeName;
launch();
}
......@@ -187,13 +194,14 @@ public class Launcher extends AbstractLoggeable {
*/
@SuppressWarnings("unchecked")
public final <T> T call(String serviceName, String methodName,
Class<T> responseType, Object... params) throws FrascatiException {
Class<T> responseType, Object... params) throws FrascatiException
{
StringBuffer paramList = new StringBuffer();
try {
Object o = TinfiDomain
.getService(scaComposite, Object.class, serviceName);
Class<?> c = o.getClass();
Class<?>[] paramTypes;
String paramList = "";
boolean withParams;
if (params == null) {
paramTypes = new Class[0];
......@@ -202,7 +210,7 @@ public class Launcher extends AbstractLoggeable {
paramTypes = new Class[params.length];
for (int i = 0; i < params.length; ++i) {
paramTypes[i] = params[i].getClass();
paramList += params[i] + " ";
paramList.append(params[i]).append(' ');
}
withParams = true;
}
......@@ -220,7 +228,7 @@ public class Launcher extends AbstractLoggeable {
return null;
} catch (NoSuchMethodException e) {
warning(new FrascatiException("The service '" + serviceName
+ "' does not provide the method " + methodName + params, e));
+ "' does not provide the method " + methodName + '(' + paramList.toString() + ')', e));
return null;
} catch (IllegalArgumentException e) {
warning(new FrascatiException(e));
......
/**
* OW2 FraSCAti Assembly Factory
* Copyright (C) 2009 INRIA, SARDES
* Copyright (C) 2009-2010 INRIA, SARDES
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -20,7 +20,8 @@
*
* Author: Valerio Schiavoni
*
* Contributor(s):
* Contributor(s): Philippe Merle
*
*/
package org.ow2.frascati.assembly.factory;
......@@ -69,12 +70,15 @@ import org.ow2.frascati.util.FrascatiException;
* @see http://maven.apache.org/plugins/maven-assembly-plugin/
* @see http://ant.apache.org/manual/CoreTasks/jar.html
*/
public class ManifestLauncher {
public class ManifestLauncher
{
protected ManifestLauncher() {
private ManifestLauncher()
{
}
public static void main(String[] args) throws IOException {
public static void main(String[] args) throws IOException
{
// mainComposite : the name of the main composite file
// mainService: the name of the main service
// mainMethod: the name of the method to call
......@@ -90,12 +94,13 @@ public class ManifestLauncher {
JarFile jar = new JarFile(jarFileName);
if (jar == null) {
// create a Manifest obj
Manifest mf = jar.getManifest();
if (mf == null) {
throw new IllegalStateException("Cannot read " + jarFileName
+ ":!META-INF/MANIFEST.MF from " + jarFileName);
}
// create a Manifest obj
Manifest mf = jar.getManifest();
final Attributes mainAttributes = mf.getMainAttributes();
// get the mainComposite attribute value
......
......@@ -84,8 +84,8 @@ import org.ow2.frascati.util.FrascatiException;
public class AssemblyFactoryManager
extends AbstractFractalLoggeable<ManagerException>
implements ClassLoaderManager,
CompositeManager {
CompositeManager
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
......@@ -149,7 +149,8 @@ public class AssemblyFactoryManager
* @see AbstractFractalLoggeable#newException(String)
*/
@Override
protected final ManagerException newException(String message) {
protected final ManagerException newException(String message)
{
return new ManagerException(message);
}
......@@ -212,7 +213,8 @@ public class AssemblyFactoryManager
* Initialization.
*/
@Init
public final void initialize() throws FrascatiException {
public final void initialize() throws FrascatiException
{
// init the FraSCAti class loader used.
setClassLoader(new FrascatiClassLoader());
// create the top level domain composite.
......@@ -220,24 +222,11 @@ public class AssemblyFactoryManager
setFractalComponentName(topLevelDomainComposite, "Top Level Domain Composite");
}
/**
* Finalization.
*/
public final void finalize() throws Throwable {
this.contributionParser = null;
this.compositeParser = null;
this.membraneGeneration = null;
this.compositeProcessor = null;
this.mainClassLoader = null;
this.topLevelDomainComposite = null;
this.loadedComposites = null;
super.finalize();
}
/**
* @see org.ow2.frascati.assembly.factory.api.ClassLoaderManager#getClassLoader()
*/
public final URLClassLoader getClassLoader() {
public final URLClassLoader getClassLoader()
{
return this.mainClassLoader;
}
......@@ -328,14 +317,14 @@ public class AssemblyFactoryManager
}
} catch (MalformedURLException e) {
severe(new ManagerException(e));
return null;
return new Component[0];
} catch (IOException e) {
severe(new ManagerException(e));
return null;
return new Component[0];
}
if (scaContribution == null) {
return null;
return new Component[0];
}
ArrayList<Component> components = new ArrayList<Component>();
......@@ -358,7 +347,7 @@ public class AssemblyFactoryManager
} catch (ParserException pe) {
severe(new ManagerException("Error when loading the contribution file " + contribution
+ " with the SCA XML Processor", pe));
return null;
return new Component[0];
}
// Iterate over 'Deployable' defined in contribution descriptor
......@@ -368,7 +357,7 @@ public class AssemblyFactoryManager
components.add(c);
} catch(Exception exc) {
severe(new ManagerException("Error when loading the composite " + deployable.getComposite(), exc));
return null;
return new Component[0];
}
}
// return loaded components
......
......@@ -45,8 +45,8 @@ import org.ow2.frascati.assembly.factory.api.ProcessorException;
* @version 1.3
*/
public abstract class AbstractProcessorManager<ElementType extends EObject>
extends AbstractProcessor<ElementType> {
extends AbstractProcessor<ElementType>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
......@@ -54,12 +54,12 @@ public abstract class AbstractProcessorManager<ElementType extends EObject>
/**
* List of processors.
*/
private List<Processor<ElementType>> processors;
private List<Processor<ElementType>> processors = null;
/**
* Map indexing processors by their processor ID.
*/
private Map<String, Processor<ElementType>> processorsByID;
private Map<String, Processor<ElementType>> processorsByID = null;
//---------------------------------------------------------------------------
// Internal methods.
......@@ -68,7 +68,8 @@ public abstract class AbstractProcessorManager<ElementType extends EObject>
/**
* Set the list of processors.
*/
protected final void setProcessors(List<Processor<ElementType>> processors) {
protected final void setProcessors(List<Processor<ElementType>> processors)
{
this.processors = processors;
this.processorsByID = null;
}
......@@ -140,7 +141,8 @@ public abstract class AbstractProcessorManager<ElementType extends EObject>
* Initialize the map of processors indexed by their id.
*/
@Init
public final void initializeProcessorsByID() {
public final void initializeProcessorsByID()
{
this.processorsByID = new HashMap<String, Processor<ElementType>>();
for (Processor<ElementType> processor : this.processors) {
this.processorsByID.put(processor.getProcessorID(), processor);
......
......@@ -120,7 +120,7 @@ public class ScaPropertyTypeXsdProcessor
/**
* Map of the XSD datatypes.
*/
protected static final Map<String, XsdType> VALUES = new HashMap<String, XsdType>();
public static final Map<String, XsdType> VALUES = new HashMap<String, XsdType>();
static {
VALUES.put(ANYSIMPLETYPE.getLabel(), ANYSIMPLETYPE);
VALUES.put(ANYURI.getLabel(), ANYURI);
......
......@@ -36,26 +36,28 @@ import org.osoa.sca.annotations.Reference;
* @author Philippe Merle.
*/
@Service(interfaces={Runnable.class, Sender.class})
public class Node implements Runnable, Sender {
public final void run() {
System.out.println("Node(name=" + componentName + ") run()...");
public class Node
implements Runnable, Sender
{
public final void run()
{
log("run()...");
if(out != null) {
Message msg = new Message();
msg.setFrom(componentName);
msg.setTo("all");
msg.setTitle("HelloWorld");
msg.setBody("Best Regards.");
System.out.println("Node(name=" + componentName + ") send " + toString(msg) + "...");
log("send " + toString(msg) + "...");
out.send(msg);
}
}
public final void send(Message msg) {
System.out.println("Node(name=" + componentName + ") receive " + toString(msg));
log("receive " + toString(msg));
if(out != null) {
msg.setFrom(componentName);
System.out.println("Node(name=" + componentName + ") send " + toString(msg));
log("send " + toString(msg));
out.send(msg);
}
}
......@@ -79,4 +81,9 @@ public class Node implements Runnable, Sender {
sb.append("')");
return sb.toString();
}
private void log(String message)
{
System.out.println("Node(name=" + componentName + ") " + message);
}
}
......@@ -131,6 +131,7 @@ public class ComponentFactoryImpl
String membraneDescription = membraneProvider.getMembraneDescription();
Component fractalBootstrapComponent;
String msg = "create the " + membraneDescription + " bootstrap component";
try {
Class<?> membraneClass = membraneProvider.getMembraneClass();
HashMap<String, Object> hints = new HashMap<String, Object>();
......@@ -139,11 +140,11 @@ public class ComponentFactoryImpl
// to load Fractal bootstrap classes instead of the class loader
// where Fractal API was loaded.
hints.put("classloader", Thread.currentThread().getContextClassLoader());
logDo("create the " + membraneDescription + " bootstrap component");
logDo(msg);
fractalBootstrapComponent = Fractal.getBootstrapComponent(hints);
logDone("create the " + membraneDescription + " bootstrap component");
logDone(msg);
} catch (InstantiationException ie) {
severe(new FactoryException("Can't create the " + membraneDescription + " bootstrap component", ie));
severe(new FactoryException("Can't " + msg, ie));
return;
}
......@@ -201,9 +202,10 @@ public class ComponentFactoryImpl
/**
* @see ComponentFactory#generateScaCompositeMembrane(ComponentType)
*/
public final void generateScaCompositeMembrane(ComponentType componentType)
public final void generateScaCompositeMembrane(ComponentType ct)
throws FactoryException
{
ComponentType componentType = ct;
if(componentType == null) {
componentType = createComponentType(new InterfaceType[0]);
}
......@@ -252,9 +254,10 @@ public class ComponentFactoryImpl
/**
* @see ComponentFactory#createScaCompositeComponent(ComponentType)
*/
public final Component createScaCompositeComponent(ComponentType componentType)
public final Component createScaCompositeComponent(ComponentType ct)
throws FactoryException
{
ComponentType componentType = ct;
if(componentType == null) {
componentType = createComponentType(new InterfaceType[0]);
}
......
......@@ -67,15 +67,12 @@ implements ExternalContext
* Wait the BPEL reply message.
*/
protected final synchronized BPELInternalMessage waitReply()
throws InterruptedException
{
if(this.reply == null) {
try {
this.wait();
} catch(InterruptedException ie) {
// TODO: Is there something to do???
}
}
return this.reply;
while(this.reply == null) {
this.wait();
}
return this.reply;
}
/**
......@@ -84,7 +81,7 @@ implements ExternalContext
protected final synchronized void notifyReply(BPELInternalMessage reply)
{
this.reply = reply;
this.notify();
this.notifyAll();
}
//---------------------------------------------------------------------------
......
......@@ -72,11 +72,6 @@ public class EasyBpelEngine
@Property(name="explorer")
private boolean withExplorer = false;
/**
* An EasyBPEL BPELFactory.
*/
private BPELFactory bpelFactory;
/**
* An EasyBPEL BPELFactory.
*/
......@@ -112,7 +107,7 @@ public class EasyBpelEngine
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
log.fine("OW2 FraSCAti EasyBPEL initialization...");
this.bpelFactory = BPELFactoryImpl.getInstance();
BPELFactory bpelFactory = BPELFactoryImpl.getInstance();
this.bpelReader = bpelFactory.newBPELReader();
log.fine("EasyBPEL Core initialization...");
......@@ -144,17 +139,15 @@ public class EasyBpelEngine
public final BPELProcess newBPELProcess(String processUri) throws Exception
{
log.fine("Create an EasyBPEL BPELProcess for '" + processUri + "'...");
EasyBpelProcess bpelProcess = new EasyBpelProcess();
bpelProcess.processUri = processUri;
com.ebmwebsourcing.easybpel.model.bpel.api.BPELProcess bpelProcess = null;
try {
bpelProcess.bpelProcess = bpelReader.readBPEL(new URI(processUri));
bpelProcess = bpelReader.readBPEL(new URI(processUri));
} catch(BPELException bexc) {
throw new FrascatiException("EasyBPEL can not read the BPEL process '" + processUri + "'", bexc);
}
bpelProcess.core = this.core;
bpelProcess.init();
log.fine(bpelProcess.toString());
return bpelProcess;
EasyBpelProcess easyBpelProcess = new EasyBpelProcess(this.core, processUri, bpelProcess);
log.fine(easyBpelProcess.toString());
return easyBpelProcess;
}
}
......@@ -45,6 +45,8 @@ extends AbstractLoggeable
// Internal state.
// --------------------------------------------------------------------------
private static final String NL = "'\n";
/**
* The OW2 FraSCAti EasyBPEL process.
*/
......@@ -83,12 +85,12 @@ extends AbstractLoggeable
{
StringBuffer sb = new StringBuffer();
sb.append("EasyBpelPartnerLink\n");
sb.append("\t - name = '" + easyBpelPartnerLink.getName() + "'\n");
sb.append("\t - myRole = '" + easyBpelPartnerLink.getMyRole() + "'\n");
sb.append("\t - partnerRole = '" + easyBpelPartnerLink.getPartnerRole() + "'\n");
sb.append("\t - initializePartnerRole = '" + easyBpelPartnerLink.getInitializePartnerRole() + "'\n");
sb.append("\t - partnerLinkType = '" + easyBpelPartnerLink.getPartnerLinkType() + "'\n");
sb.append("\t - role.interface.qname = '" + (roleInterfaceType == null ? null : roleInterfaceType.getQName()) + "'\n");
sb.append("\t - name = '" + easyBpelPartnerLink.getName() + NL);
sb.append("\t - myRole = '" + easyBpelPartnerLink.getMyRole() + NL);
sb.append("\t - partnerRole = '" + easyBpelPartnerLink.getPartnerRole() + NL);
sb.append("\t - initializePartnerRole = '" + easyBpelPartnerLink.getInitializePartnerRole() + NL);
sb.append("\t - partnerLinkType = '" + easyBpelPartnerLink.getPartnerLinkType() + NL);
sb.append("\t - role.interface.qname = '" + (roleInterfaceType == null ? null : roleInterfaceType.getQName()) + NL);
return sb.toString();
}
......
......@@ -115,7 +115,7 @@ implements BPELPartnerLinkInput
log.fine(" message.content=" + bpelMessage.toString());
EasyBpelContextImpl context = new EasyBpelContextImpl();
context.easyBpelProcess = easyBpelProcess;
easyBpelProcess.core.getEngine().accept(bpelMessage, context);
easyBpelProcess.getCore().getEngine().accept(bpelMessage, context);
if(method.getAnnotation(Oneway.class) != null) {
// When oneway invocation return nothing immediately.
......