Commit 92e263a6 authored by Christophe Demarey's avatar Christophe Demarey

Explorer is now able to dynamically add intents.

parent 85ceca6b
/***
* OW2 FraSCAti Explorer
* Copyright (C) 2008-2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Christophe Demarey
*
* Contributor(s):
*/
package org.ow2.frascati.explorer.action;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.explorer.context.ClientInterfaceWrapper;
import org.objectweb.fractal.util.Fractal;
import org.objectweb.util.explorer.api.DropAction;
import org.objectweb.util.explorer.api.DropTreeView;
import org.objectweb.util.explorer.api.MenuItem;
import org.ow2.frascati.tinfi.TinfiDomain;
import org.ow2.frascati.tinfi.control.intent.IntentHandler;
import org.ow2.frascati.tinfi.control.intent.SCABasicIntentController;
/**
* This class provides the ability dynamically add an intent
* on an SCA service (or an SCA reference) via the "Add intent"
* Menu item {@link MenuItem}.
*
* @author Christophe Demarey
*/
public class AddIntentOnDropAction implements DropAction
{
// --------------------------------------------------------------------------
// Internal state
// --------------------------------------------------------------------------
public static final Logger log = Logger.getLogger("org.ow2.frascati.explorer.action.AddIntentOnDropAction");
// --------------------------------------------------------------------------
// Internal methods
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Constructor
// --------------------------------------------------------------------------
/**
* The default constructor.
*/
public AddIntentOnDropAction () { }
// --------------------------------------------------------------------------
// Public methods.
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Implementation of the DropAction interface
// --------------------------------------------------------------------------
/**
* @see org.objectweb.util.explorer.api.DropAction#execute(DropTreeView)
*/
public void execute(DropTreeView dropTreeView) throws Exception {
if (dropTreeView != null) {
Component intent = null,
owner = null;
Interface itf = null;
SCABasicIntentController ic = null;
String intentName = null;
try {
intent = (Component) dropTreeView.getDragSourceObject();
} catch (ClassCastException cce) {
JOptionPane.showMessageDialog(null, "An intent must be an SCA component! source object is "
+dropTreeView.getDragSourceObject().getClass());
return;
}
try {
// SCA components
owner = (Component) dropTreeView.getSelectedObject();
} catch (ClassCastException cce) {
// SCA services
try {
itf = (Interface) dropTreeView.getSelectedObject();
owner = itf.getFcItfOwner();
} catch (ClassCastException cce2) {
// SCCA references
try {
ClientInterfaceWrapper wrapper = (ClientInterfaceWrapper) dropTreeView.getSelectedObject();
itf = wrapper.getItf();
owner = itf.getFcItfOwner();
} catch (ClassCastException cce3) {
JOptionPane.showMessageDialog(null, "An intent can only be applied on components, services and references!");
return;
}
}
}
// Get intent controller
try {
ic = (SCABasicIntentController) owner.getFcInterface(SCABasicIntentController.NAME);
} catch (NoSuchInterfaceException nsie) {
JOptionPane.showMessageDialog(null, "Cannot access to intent controller");
log.log(Level.SEVERE, "Cannot access to intent controller", nsie);
return;
}
if (intent != null) {
String itfName = null;
try {
intentName = Fractal.getNameController(intent).getFcName();
} catch (NoSuchInterfaceException nsie) {
log.log(Level.SEVERE, "Cannot find the Name Controller!", nsie);
}
try {
// Stop intent component
Fractal.getLifeCycleController(intent).stopFc();
// Stop owner component
Fractal.getLifeCycleController(owner).stopFc();
// Get intent handler
IntentHandler h = TinfiDomain.getService(intent, IntentHandler.class, "intent");
// Add intent
if ( itf != null ) {
itfName = itf.getFcItfName();
ic.addFcIntentHandler(h, itfName);
} else {
ic.addFcIntentHandler(h);
}
// Start intent component
Fractal.getLifeCycleController(intent).startFc();
// Start owner component
Fractal.getLifeCycleController(owner).startFc();
} catch (Exception e1) {
String errorMsg = (itf != null) ? "interface " + itfName : "component";
JOptionPane.showMessageDialog(null,"Intent '" + intentName
+ "' cannot be added to " + errorMsg);
log.log(Level.SEVERE, "Intent '" + intentName
+ "' cannot be added to " + errorMsg, e1);
}
}
}
}
}
......@@ -125,17 +125,6 @@ public class ComponentContext
e.printStackTrace();
}
// ** Display SCA intents
/*
try {
SCAIntentController intentCtl = (SCAIntentController) ci.getFcInterface(SCAIntentController.NAME);
if ( hasIntents(intentCtl) )
additionalEntries.add( new DefaultEntry("intents", intentCtl) );
} catch (NoSuchInterfaceException e) {
e.printStackTrace();
}*/
// ** Return entries
int nbAdditionalEntries = additionalEntries.size();
Entry[] defaultEntries = super.getEntries(object);
......
......@@ -26,7 +26,9 @@ package org.ow2.frascati.explorer.context;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
......@@ -37,8 +39,6 @@ import org.objectweb.fractal.api.control.ContentController;
import org.objectweb.fractal.bf.AbstractSkeleton;
import org.objectweb.fractal.bf.connectors.rest.RestSkeletonContentAttributes;
import org.objectweb.fractal.bf.connectors.rest.RestStubContentAttributes;
import org.objectweb.fractal.bf.connectors.rmi.RmiSkeletonAttributes;
import org.objectweb.fractal.bf.connectors.rmi.RmiStubAttributes;
import org.objectweb.fractal.bf.connectors.ws.WsSkeletonContentAttributes;
import org.objectweb.fractal.bf.connectors.ws.WsStubContentAttributes;
import org.objectweb.fractal.explorer.FcExplorer;
......@@ -83,7 +83,10 @@ public abstract class ScaInterfaceContext implements Context {
*/
protected List<Entry> getIntentEntries(Component owner, String itfName) {
List<Entry> entries = new ArrayList<Entry>();
List<IntentHandler> intents = getIntents(owner, itfName);
Set<IntentHandler> intents = new HashSet<IntentHandler>();
// We get 1 intent Handler / intent & method => group them to avoid duplicates
intents.addAll( getIntents(owner, itfName) );
if ( !intents.isEmpty() ) {
for (IntentHandler intent : intents) {
......
......@@ -46,9 +46,6 @@
<code>org.ow2.frascati.explorer.context.ComponentContext</code>
</wrapper>
<menu>
<!-- <item label="FScript action">-->
<!-- <code>org.ow2.frascati.explorer.action.FscriptAction</code>-->
<!-- </item>-->
<item label="Start">
<code>org.objectweb.fractal.explorer.menu.StartComponentAction</code>
<icon><icon-file url="icons/Start.png"/></icon>
......@@ -63,6 +60,9 @@
<code>org.objectweb.fractal.explorer.menu.FixComponentNameOnComponentAction</code>
</item>
</menu>
<drop-action label="Add intent">
<code>org.ow2.frascati.explorer.action.AddIntentOnDropAction</code>
</drop-action>
<panel>
<panel>
<code>org.objectweb.fractal.explorer.panel.ComponentPanel</code>
......@@ -85,6 +85,9 @@
<info>
<code>org.objectweb.fractal.explorer.info.InterfaceInfo</code>
</info>
<drop-action label="Add intent">
<code>org.ow2.frascati.explorer.action.AddIntentOnDropAction</code>
</drop-action>
</node>
<!-- ================================================================= -->
......@@ -101,8 +104,8 @@
<code>org.objectweb.fractal.explorer.menu.UnbindAction</code>
</item>
</menu>
<drop-action label="Bind interface">
<code>org.objectweb.fractal.explorer.menu.BindOnDropAction</code>
<drop-action label="Add intent">
<code>org.ow2.frascati.explorer.action.AddIntentOnDropAction</code>
</drop-action>
</node>
......@@ -110,7 +113,6 @@
<wrapper>
<code>org.ow2.frascati.explorer.context.ReferenceContext</code>
</wrapper>
<!-- <icon><icon-file url="icons/scaService.png" /></icon> -->
</node>
<!-- ================================================================= -->
......
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