Commit 583f316d authored by Philippe Merle's avatar Philippe Merle
Browse files

Added preliminary support for <implementation.widget>

parent 2568caa8
......@@ -56,7 +56,7 @@
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-implementation-resource</artifactId>
<artifactId>frascati-implementation-widget</artifactId>
<version>${project.version}</version>
</dependency>
......@@ -71,13 +71,6 @@
<artifactId>frascati-binding-ws</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Generate JavaScript client code for Web Services. -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-javascript</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
</project>
......@@ -38,7 +38,7 @@
</component>
<component name="Widget">
<tuscany:implementation.resource location="widget" />
<web:implementation.widget location="widget" />
<service name="Resource">
<tuscany:binding.http uri="/SayHelloWidget"/>
</service>
......
OW2 FraSCAti 1.5
----------------
* Added support for <web:implementation.widget>. See:
- /trunk/frascati/modules/frascati-metamodel-web/
- /trunk/frascati/modules/frascati-implementation-widget/
- /trunk/examples/helloworld-widget/
* Added a new example illustrating how to invoke Web Services from HTML/JavaScript pages. See:
- /trunk/examples/helloworld-widget/
......
......@@ -2,7 +2,7 @@
<!--
* OW2 FraSCAti: All Modules
*
* Copyright (c) 2010-2011 INRIA, University of Lille 1
* Copyright (c) 2010-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
......@@ -319,6 +319,13 @@
<version>${project.version}</version>
</dependency>
<!-- OW2 FraSCAti SCA Implementation Widget. -->
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-implementation-widget</artifactId>
<version>${project.version}</version>
</dependency>
<!-- OW2 FraSCAti SCA Interface Native. -->
<dependency>
<groupId>org.ow2.frascati.native</groupId>
......
<?xml version="1.0"?>
<!--
* OW2 FraSCAti: SCA Implementation Widget
*
* Copyright (c) 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
* 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: Philippe Merle
*
* Contributor(s):
*
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ===================== -->
<!-- General Information -->
<!-- ===================== -->
<parent>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-modules</artifactId>
<version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-implementation-widget</artifactId>
<packaging>jar</packaging>
<name>OW2 FraSCAti: SCA Implementation Widget Module</name>
<url>http://frascati.ow2.org/</url>
<inceptionYear>2007</inceptionYear>
<developers>
<developer>
<id>merle</id>
<name>Philippe Merle</name>
<email>Philippe.Merle@inria.fr</email>
<organization>INRIA</organization>
<organizationUrl>http://www.inria.fr</organizationUrl>
<roles>
<role>Architect</role>
<role>Developer</role>
</roles>
</developer>
</developers>
<!-- ========== -->
<!-- Properties -->
<!-- ========== -->
<properties>
</properties>
<!-- ======= -->
<!-- Build -->
<!-- ======= -->
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<!-- Compile OW2 FraSCAti SCA composite. -->
<plugin>
<groupId>org.ow2.frascati.mojo</groupId>
<artifactId>frascati-compiler-plugin</artifactId>
<configuration>
<composite>org/ow2/frascati/FraSCAti</composite>
</configuration>
</plugin>
</plugins>
</build>
<!-- ============ -->
<!-- Dependencies -->
<!-- ============ -->
<dependencies>
<!-- OW2 FraSCAti Assembly Factory Module. -->
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-assembly-factory</artifactId>
<version>${project.version}</version>
</dependency>
<!-- For <web:implementation.widget>. -->
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-metamodel-web</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Servlet API. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<!-- Generate JavaScript client code for Web Services. -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-javascript</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- ============ -->
<!-- For testing -->
<!-- ============ -->
<!-- OW2 FraSCAti Runtime Factory Module. -->
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-runtime-factory</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<!-- OW2 FraSCAti Binding HTTP Module. -->
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-binding-http</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- ============= -->
<!-- Repositories -->
<!-- ============= -->
<repositories>
</repositories>
</project>
/**
* OW2 FraSCAti: SCA Implementation Widget
* Copyright (C) 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
* 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: Philippe Merle
*
* Contributor:
*
*/
package org.ow2.frascati.implementation.widget;
import java.util.List;
import javax.servlet.Servlet;
import org.eclipse.stp.sca.Component;
import org.eclipse.stp.sca.ComponentService;
import org.eclipse.stp.sca.Interface;
import org.eclipse.stp.sca.JavaInterface;
import org.eclipse.stp.sca.ScaFactory;
import org.ow2.frascati.assembly.factory.api.ProcessingContext;
import org.ow2.frascati.assembly.factory.api.ProcessorException;
import org.ow2.frascati.assembly.factory.processor.AbstractComponentFactoryBasedImplementationProcessor;
import org.ow2.frascati.metamodel.web.WidgetImplementation;
import org.ow2.frascati.metamodel.web.WebPackage;
import org.ow2.frascati.tinfi.api.control.SCAPropertyController;
/**
* OW2 FraSCAti Assembly Factory implementation widget processor class.
*
* @author Philippe Merle - INRIA
* @version 1.5
*/
public class FrascatiImplementationWidgetProcessor
extends AbstractComponentFactoryBasedImplementationProcessor<WidgetImplementation>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Internal methods.
// --------------------------------------------------------------------------
/**
* @see org.ow2.frascati.assembly.factory.processor.AbstractProcessor#toStringBuilder(EObjectType, StringBuilder)
*/
@Override
protected final void toStringBuilder(WidgetImplementation widgetImplementation, StringBuilder sb)
{
sb.append("web:implementation.widget");
append(sb, "location", widgetImplementation.getLocation());
append(sb, "default", widgetImplementation.getDefault());
super.toStringBuilder(widgetImplementation, sb);
}
/**
* @see org.ow2.frascati.assembly.factory.processor.api.Processor#check(ElementType, ProcessingContext)
*/
@Override
protected final void doCheck(WidgetImplementation widgetImplementation, ProcessingContext processingContext)
throws ProcessorException
{
String location = widgetImplementation.getLocation();
checkAttributeMustBeSet(widgetImplementation, "location", location, processingContext);
// Check that location is present in the class path.
if(!isNullOrEmpty(location) && processingContext.getClassLoader().getResourceAsStream(location) == null) {
// Location not found.
error(processingContext, widgetImplementation, "Location '" + location + "' not found");
}
// TODO check widgetImplementation.default
// Get the enclosing SCA component.
Component component = getParent(widgetImplementation, Component.class);
List<ComponentService> services = component.getService();
if(services.size() > 1) {
error(processingContext, widgetImplementation, "<implementation.widget> can't have more than one SCA service");
} else {
ComponentService service = null;
if(services.size() == 0) {
// The component has zero service then add a service to the component.
service = ScaFactory.eINSTANCE.createComponentService();
service.setName("Widget");
services.add(service);
} else {
// The component has one service.
service = services.get(0);
}
// Get the service interface.
Interface itf = service.getInterface();
if(itf == null) {
// The component service has no interface than add a Java Servlet interface.
JavaInterface javaInterface = ScaFactory.eINSTANCE.createJavaInterface();
javaInterface.setInterface(Servlet.class.getName());
service.setInterface(javaInterface);
} else {
// Check if this is a Java Servlet interface.
boolean isServletInterface = (itf instanceof JavaInterface)
? Servlet.class.getName().equals(((JavaInterface)itf).getInterface())
: false;
if(!isServletInterface) {
error(processingContext, widgetImplementation, "<service name=\"" + service.getName() + "\"> must have an <interface.java interface=\"" + Servlet.class.getName() + "\">");
}
}
}
// check attributes 'policySets' and 'requires'.
checkImplementation(widgetImplementation, processingContext);
}
/**
* @see org.ow2.frascati.assembly.factory.processor.api.Processor#generate(ElementType, ProcessingContext)
*/
@Override
protected final void doGenerate(WidgetImplementation widgetImplementation, ProcessingContext processingContext)
throws ProcessorException
{
// Generate a FraSCAti SCA primitive component.
generateScaPrimitiveComponent(widgetImplementation, processingContext, ImplementationWidgetComponent.class.getName());
}
/**
* @see org.ow2.frascati.assembly.factory.processor.api.Processor#instantiate(ElementType, ProcessingContext)
*/
@Override
protected final void doInstantiate(WidgetImplementation widgetImplementation, ProcessingContext processingContext)
throws ProcessorException
{
// Instantiate a FraSCAti SCA primitive component.
org.objectweb.fractal.api.Component component =
instantiateScaPrimitiveComponent(widgetImplementation, processingContext, ImplementationWidgetComponent.class.getName());
// Retrieve the SCA property controller of this Fractal component.
SCAPropertyController propertyController = (SCAPropertyController)getFractalInterface(component, SCAPropertyController.NAME);
// Set the classloader property.
propertyController.setValue("classloader", processingContext.getClassLoader());
// Set the location property.
propertyController.setValue("location", widgetImplementation.getLocation());
// Set the default property.
propertyController.setValue("default", widgetImplementation.getDefault());
}
//---------------------------------------------------------------------------
// Public methods.
// --------------------------------------------------------------------------
/**
* @see org.ow2.frascati.assembly.factory.api.processor.Processor#getProcessorID()
*/
public final String getProcessorID()
{
return getID(WebPackage.Literals.WIDGET_IMPLEMENTATION);
}
}
/**
* OW2 FraSCAti: SCA Implementation Widget
* Copyright (C) 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
* 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: Philippe Merle
*
* Contributor:
*
*/
package org.ow2.frascati.implementation.widget;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;
import org.ow2.frascati.util.Stream;
/**
* OW2 FraSCAti implementation widget component class.
*
* @author Philippe Merle - INRIA
* @version 1.5
*/
@Scope("COMPOSITE")
@Service(Servlet.class)
public class ImplementationWidgetComponent
extends HttpServlet
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
/**
* Mapping between file extensions and MIME types.
*/
private static Properties extensions2mimeTypes = new Properties();
static {
// Load mapping between file extensions and MIME types.
try {
extensions2mimeTypes.load(
ImplementationWidgetComponent.class.getClassLoader().getResourceAsStream(
ImplementationWidgetComponent.class.getPackage().getName().replace('.', '/') + "/extensions2mimeTypes.properties"
)
);
} catch(IOException ioe) {
throw new Error(ioe);
}
}
/**
* Classloader where resources are searched.
*/
@Property(name = "classloader")
private ClassLoader classloader;
/**
* Location where resources are searched.
*/
@Property(name = "location")
private String location;
/**
* Default resource.
*/
@Property(name = "default")
private String defaultResource;
//---------------------------------------------------------------------------
// Internal methods.
// --------------------------------------------------------------------------
/**
* @see HttpServlet#doGet(HttpServletRequest, HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// The requested resource.
String pathInfo = request.getPathInfo();
if(pathInfo == null) {
pathInfo = "";
}
int idx = pathInfo.lastIndexOf('.');
String extension = (idx != -1) ? pathInfo.substring(idx) : "";
// Search the requested resource into the class loader.
InputStream is = this.classloader.getResourceAsStream(this.location + pathInfo);
if(is == null) {
// Requested resource not found.
super.doGet(request, response);
return;
}
// Requested resource found.
response.setStatus(HttpServletResponse.SC_OK);
String mimeType = extensions2mimeTypes.getProperty(extension);
if(mimeType == null) {
mimeType = "text/plain";
}
response.setContentType(mimeType);
// Copy the resource stream to the servlet output stream.
Stream.copy(is, response.getOutputStream());
}
//---------------------------------------------------------------------------
// Public methods.
// --------------------------------------------------------------------------
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
* OW2 FraSCAti: SCA Implementation Widget
* Copyright (C) 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
* 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: Philippe Merle
*