Commit 94f2ead7 authored by Philippe Merle's avatar Philippe Merle

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

  - Added 'final' to all not overridden methods.
  - Moved from 'protected' to 'private' fields.
  - Removed 'public' to interface methods.
  - Removed 'public static final' to interface fields.
  - Removed unused import statements.
  - Added @SuppressWarnings("serial").
  - Added missed brackets for if/else statements.
  - Added getter methods into Twitter JAXB-based classes.

* Replaced 'USTL' by 'University of Lille 1'.
* Updated copyright date to 2010.
* Cosmetic updates.
parent 6f18232f
/**
* OW2 FraSCAti Examples: Availability Intent
* Copyright (C) 2010 INRIA
* Copyright (C) 2010 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
......@@ -21,6 +21,7 @@
* Author: Mahmoud Ben Hassine
*
* Contributor(s): Philippe Merle
*
*/
package org.ow2.frascati.intent.availability;
......@@ -34,71 +35,111 @@ import org.ow2.frascati.tinfi.control.intent.IntentJoinPoint;
@Scope("COMPOSITE")
@Service(IntentHandler.class)
public class AvailabilityIntentHandler implements IntentHandler {
// Default timeout if not set.
public class AvailabilityIntentHandler
implements IntentHandler
{
/**
* Default timeout if not set.
*/
private static final long DEFAULT_TIMEOUT = 2000;
// Timeout for the proceed thread.
/**
* Timeout for the proceed thread.
*/
private long timeout = DEFAULT_TIMEOUT;
/**
* Setter for the timeout property.
* @param timeout
* Setter for the SCA timeout property.
*
* @param timeout the timeout.
*/
@Property
public void setTimeout(final long timeout) {
System.out.println(this + ".setTimeout(" + timeout + ")");
this.timeout = timeout;
public final void setTimeout(final long timeout)
{
System.out.println(this + ".setTimeout(" + timeout + ")");
this.timeout = timeout;
}
@Override
public Object invoke(final IntentJoinPoint ijp) throws ServiceUnavailableException, Throwable {
// run the proceed in a separate thread.
ProceedThread pt = new ProceedThread();
// set the IntentJoinPoint to proceed.
pt.ijp = ijp;
// start the proceed thread.
pt.start();
try {
// wait the proceed thread to return for maximum timeout value.
pt.join(timeout);
// timeout exceeded and the thread didn't returned yet.
if (pt.isAlive()) {
// don't interrupt the proceed thread because we don't know in which state it is.
throw new ServiceUnavailableException("Timeout of " + timeout + " ms exceeded");
}
} catch (InterruptedException e) {
}
// throw the exception catched by the proceed thread.
if(pt.throwable != null)
throw pt.throwable;
// the thread returned before timeout => return the value.
return pt.result;
public final Object invoke(final IntentJoinPoint ijp)
throws Throwable
{
// call the proceed in a separate thread.
ProceedThread pt = new ProceedThread(ijp);
// start the proceed thread.
pt.start();
// wait the proceed thread to return for maximum timeout value.
pt.join(timeout);
// timeout exceeded and the thread didn't returned yet.
if (pt.isAlive()) {
// don't interrupt the proceed thread because we don't know in which state it is.
throw new ServiceUnavailableException("Timeout of " + timeout + " ms exceeded");
}
// throw the throwable of the proceed thread.
if(pt.getThrowable() != null) {
throw pt.getThrowable();
}
// the thread returned before timeout then return the thread's result.
return pt.getResult();
}
}
class ProceedThread extends Thread {
// The intent join point to proceed.
IntentJoinPoint ijp = null;
class ProceedThread extends Thread
{
/**
* The intent join point to proceed.
*/
private IntentJoinPoint ijp;
/**
* The result returned by proceed().
*/
private Object result = null;
/**
* Throwable thrown by proceed().
*/
private Throwable throwable = null;
/**
* Constructs with a given intent join point.
*/
public ProceedThread(IntentJoinPoint ijp)
{
this.ijp = ijp;
}
// The result returned by proceed().
Object result = null;
/**
* #see Runnable#run()
*/
public final void run()
{
try {
result = ijp.proceed();
} catch (Throwable e) {
throwable = e;
}
}
// Exception thrown by proceed().
Throwable throwable = null;
/**
* Get the throwable.
*/
public final Throwable getThrowable()
{
return this.throwable;
}
public void run() {
try {
result = ijp.proceed();
} catch (Throwable e) {
throwable = e;
}
/**
* Get the result.
*/
public final Object getResult()
{
return this.result;
}
}
/**
* OW2 FraSCAti Examples: Availability Intent
* Copyright (C) 2010 INRIA
* Copyright (C) 2010 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
......@@ -35,9 +35,9 @@ import org.osoa.sca.ServiceUnavailableException;
import org.ow2.frascati.FraSCAti;
public class AvailabilityTestCase {
protected static FraSCAti frascati;
public class AvailabilityTestCase
{
private static FraSCAti frascati;
@BeforeClass
public static void init() throws Exception {
......@@ -45,7 +45,7 @@ public class AvailabilityTestCase {
}
@Test
public void availability() throws Exception {
public final void availability() throws Exception {
// Load the availability-test composite.
Component scaComposite = frascati.getComposite("availability-test");
// Obtain the service to test.
......@@ -69,7 +69,7 @@ public class AvailabilityTestCase {
}
@Test
public void availability1s() throws Exception {
public final void availability1s() throws Exception {
// Load the availability-test composite.
Component scaComposite = frascati.getComposite("availability-1s-test");
// Obtain the service to test.
......@@ -93,7 +93,7 @@ public class AvailabilityTestCase {
}
@Test
public void availability2s() throws Exception {
public final void availability2s() throws Exception {
// Load the availability-test composite.
Component scaComposite = frascati.getComposite("availability-2s-test");
// Obtain the service to test.
......@@ -117,7 +117,7 @@ public class AvailabilityTestCase {
}
@Test
public void availability3s() throws Exception {
public final void availability3s() throws Exception {
// Load the availability-test composite.
Component scaComposite = frascati.getComposite("availability-3s-test");
// Obtain the service to test.
......@@ -142,7 +142,7 @@ public class AvailabilityTestCase {
}
@Test
public void availability4s() throws Exception {
public final void availability4s() throws Exception {
// Load the availability-test composite.
Component scaComposite = frascati.getComposite("availability-4s-test");
// Obtain the service to test.
......@@ -168,7 +168,7 @@ public class AvailabilityTestCase {
}
@Test
public void availability5s() throws Exception {
public final void availability5s() throws Exception {
// Load the availability-test composite.
Component scaComposite = frascati.getComposite("availability-5s-test");
// Obtain the service to test.
......@@ -195,7 +195,7 @@ public class AvailabilityTestCase {
}
@Test
public void availability10s() throws Exception {
public final void availability10s() throws Exception {
// Load the availability-test composite.
Component scaComposite = frascati.getComposite("availability-10s-test");
// Obtain the service to test.
......@@ -221,7 +221,7 @@ public class AvailabilityTestCase {
workThrownServiceUnavailableException(si, 15000);
}
void workThrownIllegalArgumentException(ServiceInterface si, long milliseconds) {
private void workThrownIllegalArgumentException(ServiceInterface si, long milliseconds) {
try {
si.work(milliseconds);
Assert.fail("IllegalArgumentException must be thrown!");
......@@ -230,7 +230,7 @@ public class AvailabilityTestCase {
}
}
void work(ServiceInterface si, long milliseconds) {
private void work(ServiceInterface si, long milliseconds) {
try {
long response = si.work(milliseconds);
Assert.assertEquals("Incorrect response!", milliseconds, response);
......@@ -240,7 +240,7 @@ public class AvailabilityTestCase {
}
}
void workThrownServiceUnavailableException(ServiceInterface si, long milliseconds) {
private void workThrownServiceUnavailableException(ServiceInterface si, long milliseconds) {
try {
si.work(milliseconds);
Assert.fail("ServiceUnavailableException must be thrown!");
......
/**
* OW2 FraSCAti Examples: Availability Intent
* Copyright (C) 2010 INRIA
* Copyright (C) 2010 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
......@@ -27,7 +27,8 @@ package org.ow2.frascati.intent.availability.test;
public class Implementation implements ServiceInterface {
public long work(long milliseconds) {
public final long work(long milliseconds)
{
System.out.println("Working " + milliseconds + " milliseconds...");
if (milliseconds < 0) {
throw new IllegalArgumentException();
......
/**
* OW2 FraSCAti Examples: Availability Intent
* Copyright (C) 2010 INRIA
* Copyright (C) 2010 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
......
/***
/**
* OW2 FraSCAti Examples: Soap Calculator Client
* Copyright (C) 2009 INRIA, USTL
* Copyright (C) 2009-2010 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
......@@ -20,7 +20,7 @@
*
* Author: Nicolas Dolet
*
* Contributor(s):
* Contributor(s): Philippe Merle
*/
package org.ow2.frascati.examples.soapcalc.api;
......@@ -31,10 +31,10 @@ import org.osoa.sca.annotations.Service;
* Interface for the FraSCAti calculator service.
*/
@Service
public interface Calculator {
public int add(String i, String j);
public int sub(String i, String j);
public int mult(String i, String j);
public double div(String i, String j);
public interface Calculator
{
int add(String i, String j);
int sub(String i, String j);
int mult(String i, String j);
double div(String i, String j);
}
/***
/**
* OW2 FraSCAti Examples: Soap Calculator Client
* Copyright (C) 2009 INRIA, USTL
* Copyright (C) 2009-2010 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
......@@ -26,11 +26,10 @@
package org.ow2.frascati.examples.soapcalc.lib;
import org.osoa.sca.annotations.Reference;
import org.ow2.frascati.examples.soapcalc.api.CalcService;
import org.ow2.frascati.examples.soapcalc.api.CalcServicePortType;
import org.ow2.frascati.examples.soapcalc.api.Calculator;
/**
* SCA Java Component implementation using the FraSCAti calculator web service
*/
......@@ -38,24 +37,29 @@ public class Client
implements Calculator {
@Reference
protected CalcServicePortType calcservice;
private CalcServicePortType calcservice;
// --------------------------------------------------------------------------
// Implementation of the Calculator interface
// --------------------------------------------------------------------------
public int add(String i, String j) {
return calcservice.add(new Integer(i).intValue(), new Integer(j).intValue());
public final int add(String i, String j)
{
return calcservice.add(Integer.valueOf(i), Integer.valueOf(j));
}
public int sub(String i, String j) {
return calcservice.sub(new Integer(i).intValue(), new Integer(j).intValue());
public final int sub(String i, String j)
{
return calcservice.sub(Integer.valueOf(i), Integer.valueOf(j));
}
public int mult(String i, String j) {
return calcservice.mult(new Integer(i).intValue(), new Integer(j).intValue());
public final int mult(String i, String j)
{
return calcservice.mult(Integer.valueOf(i), Integer.valueOf(j));
}
public double div(String i, String j) {
return calcservice.div(new Integer(i).intValue(), new Integer(j).intValue());
public final double div(String i, String j)
{
return calcservice.div(Integer.valueOf(i), Integer.valueOf(j));
}
}
/***
/**
* OW2 FraSCAti Examples: Soap Calculator
* Copyright (C) 2009 INRIA, USTL
* Copyright (C) 2009-2010 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
......@@ -32,18 +32,17 @@ import org.osoa.sca.annotations.Service;
@Service
@WebService
public interface CalcService {
public interface CalcService
{
@WebMethod
public int add(int i, int j);
int add(int i, int j);
@WebMethod
public int sub(int i, int j);
int sub(int i, int j);
@WebMethod
public int mult(int i, int j);
int mult(int i, int j);
@WebMethod
public double div(int i, int j);
double div(int i, int j);
}
/***
/**
* OW2 FraSCAti Examples: Soap calculator
* Copyright (C) 2009 INRIA, USTL
* Copyright (C) 2009-2010 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
......@@ -20,7 +20,7 @@
*
* Author: Christophe Demarey
*
* Contributor(s):
* Contributor(s): Philippe Merle
*
*/
......@@ -40,7 +40,8 @@ public class CalculatorMenuItem extends AbstractAlwaysEnabledMenuItem<CalcServic
* @see org.ow2.frascati.explorer.action.AbstractAlwaysEnabledMenuItem#execute()
*/
@Override
protected void execute(CalcService calc) {
protected final void execute(CalcService calc)
{
System.out.println("1 + 2 = " + calc.add(2, 1));
}
}
/***
/**
* OW2 FraSCAti Examples: Soap Calculator
* Copyright (C) 2009 INRIA, USTL
* Copyright (C) 2009-2010 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
......@@ -20,7 +20,7 @@
*
* Author: Christophe Demarey
*
* Contributor(s):
* Contributor(s): Philippe Merle
*
*/
......@@ -44,7 +44,9 @@ import org.ow2.frascati.explorer.gui.AbstractSelectionPanel;
* @author Christophe Demarey
*/
@SuppressWarnings("serial")
public class CalculatorPanel extends AbstractSelectionPanel<CalcService> {
public class CalculatorPanel
extends AbstractSelectionPanel<CalcService>
{
private JButton jButtonAdd;
private JButton jButtonDiv;
private JButton jButtonMult;
......@@ -69,7 +71,8 @@ public class CalculatorPanel extends AbstractSelectionPanel<CalcService> {
/**
* Default constructor creates the panel.
*/
public CalculatorPanel() {
public CalculatorPanel()
{
super();
jButtonAdd = new JButton("=");
......@@ -179,7 +182,7 @@ public class CalculatorPanel extends AbstractSelectionPanel<CalcService> {
// actions
jButtonAdd.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
public final void actionPerformed(ActionEvent e) {
int result = selected.add( Integer.parseInt(jTextField1.getText()),
Integer.parseInt(jTextField2.getText()) );
jLabelAddResult.setText(Integer.toString(result));
......@@ -187,7 +190,7 @@ public class CalculatorPanel extends AbstractSelectionPanel<CalcService> {
}
);
jButtonSub.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
public final void actionPerformed(ActionEvent e) {
int result = selected.sub( Integer.parseInt(jTextField4.getText()),
Integer.parseInt(jTextField3.getText()) );
jLabelSubResult.setText(Integer.toString(result));
......@@ -195,7 +198,7 @@ public class CalculatorPanel extends AbstractSelectionPanel<CalcService> {
}
);
jButtonMult.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
public final void actionPerformed(ActionEvent e) {
int result = selected.mult( Integer.parseInt(jTextField5.getText()),
Integer.parseInt(jTextField6.getText()) );
jLabelMultResult.setText(Integer.toString(result));
......@@ -203,14 +206,13 @@ public class CalculatorPanel extends AbstractSelectionPanel<CalcService> {
}
);
jButtonDiv.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
public final void actionPerformed(ActionEvent e) {
double result = selected.div( Integer.parseInt(jTextField8.getText()),
Integer.parseInt(jTextField7.getText()) );
jLabelDivResult.setText(Double.toString(result));
}
}
);
}
}
/***
/**
* OW2 FraSCAti Examples: Soap Calculator
* Copyright (C) 2009 INRIA, USTL
* Copyright (C) 2009-2010 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
......@@ -20,7 +20,8 @@
*
* Author: Nicolas Dolet
*
* Contributor(s):
* Contributor(s): Philippe Merle
*
*/
package org.ow2.frascati.examples.soapcalc.lib;
......@@ -28,24 +29,30 @@ package org.ow2.frascati.examples.soapcalc.lib;
import org.ow2.frascati.examples.soapcalc.api.CalcService;
public class CalcImpl
implements CalcService {
implements CalcService
{
// --------------------------------------------------------------------------
// Implementation of the CalcService interface
// --------------------------------------------------------------------------
public int add(int i, int j) {
public final int add(int i, int j)
{
return i+j;
}
public int sub(int i, int j) {
public final int sub(int i, int j)
{
return i-j;
}