TUSCANY-3565 - Registering dojo resource servlet only when implementation widget starts...
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@951244 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
21a870046c
commit
0508938671
9 changed files with 74 additions and 107 deletions
|
@ -19,6 +19,7 @@ Import-Package: javax.servlet,
|
|||
org.apache.tuscany.sca.core;version="2.0.0",
|
||||
org.apache.tuscany.sca.host.http;version="2.0.0",
|
||||
org.apache.tuscany.sca.implementation.widget;version="2.0.0",
|
||||
org.apache.tuscany.sca.implementation.widget.javascript;version="2.0.0",
|
||||
org.apache.tuscany.sca.implementation.widget.provider;version="2.0.0",
|
||||
org.apache.tuscany.sca.interfacedef;version="2.0.0",
|
||||
org.apache.tuscany.sca.invocation;version="2.0.0",
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.tuscany.sca.assembly.Binding;
|
|||
import org.apache.tuscany.sca.assembly.ComponentService;
|
||||
import org.apache.tuscany.sca.host.http.ServletHost;
|
||||
import org.apache.tuscany.sca.implementation.widget.WidgetImplementation;
|
||||
import org.apache.tuscany.sca.implementation.widget.javascript.WidgetImplementationJavascriptProvider;
|
||||
import org.apache.tuscany.sca.interfacedef.Operation;
|
||||
import org.apache.tuscany.sca.invocation.Invoker;
|
||||
import org.apache.tuscany.sca.provider.ImplementationProvider;
|
||||
|
@ -46,6 +47,7 @@ class WidgetImplementationProvider implements ImplementationProvider {
|
|||
|
||||
private RuntimeComponent component;
|
||||
|
||||
private WidgetImplementationJavascriptProvider javascriptProvider;
|
||||
private ComponentJavaScriptGenerator javaScriptGenerator;
|
||||
private ServletHost servletHost;
|
||||
|
||||
|
@ -59,9 +61,11 @@ class WidgetImplementationProvider implements ImplementationProvider {
|
|||
* Constructs a new resource implementation provider.
|
||||
*/
|
||||
WidgetImplementationProvider(RuntimeComponent component,
|
||||
WidgetImplementation implementation,
|
||||
WidgetImplementation implementation,
|
||||
WidgetImplementationJavascriptProvider javascriptProvider,
|
||||
ComponentJavaScriptGenerator javaScriptGenerator,
|
||||
ServletHost servletHost) {
|
||||
|
||||
this.component = component;
|
||||
|
||||
this.javaScriptGenerator = javaScriptGenerator;
|
||||
|
@ -86,7 +90,6 @@ class WidgetImplementationProvider implements ImplementationProvider {
|
|||
public void start() {
|
||||
String baseURI = getBaseURI();
|
||||
|
||||
// get the ScaDomainScriptServlet, if it doesn't yet exist create one
|
||||
// this uses removeServletMapping / addServletMapping as there is no getServletMapping facility
|
||||
scriptURI = URI.create(baseURI + "/" + this.widgetName + ".js").toString();
|
||||
Servlet servlet = servletHost.getServletMapping(scriptURI);
|
||||
|
@ -95,6 +98,12 @@ class WidgetImplementationProvider implements ImplementationProvider {
|
|||
widgetScriptServlet = new WidgetComponentScriptServlet(this.component, javaScriptGenerator);
|
||||
servletHost.addServletMapping(scriptURI, widgetScriptServlet);
|
||||
}
|
||||
|
||||
// If added to the class path, start dojo provider
|
||||
if(javascriptProvider != null) {
|
||||
javascriptProvider.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
@ -104,6 +113,10 @@ class WidgetImplementationProvider implements ImplementationProvider {
|
|||
// Remove the Servlet mapping
|
||||
servletHost.removeServletMapping(scriptURI);
|
||||
}
|
||||
|
||||
if(javascriptProvider != null) {
|
||||
javascriptProvider.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,9 +19,11 @@
|
|||
package org.apache.tuscany.sca.implementation.widget.provider;
|
||||
|
||||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
|
||||
import org.apache.tuscany.sca.host.http.ServletHost;
|
||||
import org.apache.tuscany.sca.host.http.ServletHostHelper;
|
||||
import org.apache.tuscany.sca.implementation.widget.WidgetImplementation;
|
||||
import org.apache.tuscany.sca.implementation.widget.javascript.WidgetImplementationJavascriptProvider;
|
||||
import org.apache.tuscany.sca.provider.ImplementationProvider;
|
||||
import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
|
||||
import org.apache.tuscany.sca.runtime.RuntimeComponent;
|
||||
|
@ -35,21 +37,26 @@ import org.apache.tuscany.sca.web.javascript.ComponentJavaScriptGeneratorExtensi
|
|||
*/
|
||||
public class WidgetImplementationProviderFactory implements ImplementationProviderFactory<WidgetImplementation> {
|
||||
private ServletHost servletHost;
|
||||
private ComponentJavaScriptGenerator javaScriptGenerator;
|
||||
|
||||
private WidgetImplementationJavascriptProvider javascriptProvider;
|
||||
private ComponentJavaScriptGenerator javascriptGenerator;
|
||||
|
||||
/**
|
||||
* Constructs a resource implementation.
|
||||
*/
|
||||
public WidgetImplementationProviderFactory(ExtensionPointRegistry extensionPoints) {
|
||||
this.servletHost = ServletHostHelper.getServletHost(extensionPoints);
|
||||
public WidgetImplementationProviderFactory(ExtensionPointRegistry registry) {
|
||||
this.servletHost = ServletHostHelper.getServletHost(registry);
|
||||
|
||||
ComponentJavaScriptGeneratorExtensionPoint javascriptGeneratorExtensionPoint = extensionPoints.getExtensionPoint(ComponentJavaScriptGeneratorExtensionPoint.class);
|
||||
javaScriptGenerator = javascriptGeneratorExtensionPoint.getComponentJavaScriptGenerators().get(0);
|
||||
UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
|
||||
javascriptProvider = utilities.getUtility(WidgetImplementationJavascriptProvider.class);
|
||||
|
||||
ComponentJavaScriptGeneratorExtensionPoint javascriptGeneratorExtensionPoint = registry.getExtensionPoint(ComponentJavaScriptGeneratorExtensionPoint.class);
|
||||
javascriptGenerator = javascriptGeneratorExtensionPoint.getComponentJavaScriptGenerators().get(0);
|
||||
|
||||
}
|
||||
|
||||
public ImplementationProvider createImplementationProvider(RuntimeComponent component, WidgetImplementation implementation) {
|
||||
return new WidgetImplementationProvider(component, implementation, javaScriptGenerator, servletHost);
|
||||
return new WidgetImplementationProvider(component, implementation, javascriptProvider, javascriptGenerator, servletHost);
|
||||
}
|
||||
|
||||
public Class<WidgetImplementation> getModelType() {
|
||||
|
|
|
@ -6,7 +6,8 @@ Export-Package: org.apache.tuscany.sca.implementation.widget;version="2.0.0";
|
|||
org.apache.tuscany.sca.contribution.resolver,
|
||||
org.apache.tuscany.sca.contribution.processor,
|
||||
org.apache.tuscany.sca.core,
|
||||
javax.xml.namespace"
|
||||
javax.xml.namespace",
|
||||
org.apache.tuscany.sca.implementation.widget.javascript;version="2.0.0"
|
||||
SCA-Version: 1.1
|
||||
Bundle-Name: Apache Tuscany SCA Widget Implementation Model
|
||||
Bundle-Vendor: The Apache Software Foundation
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.implementation.widget.javascript;
|
||||
|
||||
import org.apache.tuscany.sca.core.ModuleActivator;
|
||||
|
||||
|
||||
/**
|
||||
* A widget javascript provider which
|
||||
* provides dojo and tuscany dojo extensions
|
||||
* to an application using implementation.widget
|
||||
*
|
||||
* @version $Rev$ $Date$
|
||||
*/
|
||||
public interface WidgetImplementationJavascriptProvider extends ModuleActivator {
|
||||
|
||||
}
|
|
@ -15,6 +15,7 @@ Import-Package: javax.servlet,
|
|||
org.apache.tuscany.sca.core;version="2.0.0",
|
||||
org.apache.tuscany.sca.extensibility;version="2.0.0",
|
||||
org.apache.tuscany.sca.host.http;version="2.0.0",
|
||||
org.apache.tuscany.sca.implementation.widget.javascript;version="2.0.0",
|
||||
org.apache.tuscany.sca.monitor;version="2.0.0",
|
||||
org.apache.tuscany.sca.runtime;version="2.0.0"
|
||||
Bundle-SymbolicName: org.apache.tuscany.sca.core.web.javascript.dojo
|
||||
|
|
|
@ -35,6 +35,12 @@
|
|||
<artifactId>tuscany-core</artifactId>
|
||||
<version>2.0-M5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-implementation-widget</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tuscany.sca.web.javascript.dojo;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.servlet.Servlet;
|
||||
|
||||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
import org.apache.tuscany.sca.core.ModuleActivator;
|
||||
import org.apache.tuscany.sca.host.http.ServletHost;
|
||||
import org.apache.tuscany.sca.host.http.ServletHostHelper;
|
||||
import org.apache.tuscany.sca.host.http.ServletMappingException;
|
||||
|
||||
public class DojoModuleActivator implements ModuleActivator {
|
||||
private final static Logger logger = Logger.getLogger(DojoModuleActivator.class.getName());
|
||||
|
||||
private static final String dojoBaseUri = URI.create("/dojo").toString();
|
||||
private static final String dojoUri = URI.create("/dojo/*").toString();
|
||||
|
||||
private static final String tuscanyBaseUri = URI.create("/tuscany").toString();
|
||||
private static final String tuscanyUri = URI.create("/tuscany/*").toString();
|
||||
|
||||
private ServletHost servletHost;
|
||||
|
||||
public DojoModuleActivator(ExtensionPointRegistry registry) {
|
||||
this.servletHost = ServletHostHelper.getServletHost(registry);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
||||
if (servletHost == null) {
|
||||
throw new IllegalStateException("Can't find ServletHost reference !");
|
||||
}
|
||||
|
||||
Servlet servlet = null;
|
||||
|
||||
servlet = servletHost.getServletMapping(dojoBaseUri);
|
||||
if(servlet == null) {
|
||||
try {
|
||||
DojoResourceServlet baseResourceServlet = new DojoResourceServlet();
|
||||
servletHost.addServletMapping(dojoBaseUri, baseResourceServlet);
|
||||
|
||||
DojoResourceServlet resourceServlet = new DojoResourceServlet();
|
||||
servletHost.addServletMapping(dojoUri, resourceServlet);
|
||||
} catch (ServletMappingException me ) {
|
||||
logger.warning("Dojo already registered at :" + dojoBaseUri);
|
||||
}
|
||||
}
|
||||
|
||||
servlet = servletHost.getServletMapping(tuscanyBaseUri);
|
||||
if(servlet == null) {
|
||||
try {
|
||||
DojoResourceServlet baseResourceServlet = new DojoResourceServlet();
|
||||
servletHost.addServletMapping(tuscanyBaseUri, baseResourceServlet);
|
||||
|
||||
DojoResourceServlet resourceServlet = new DojoResourceServlet();
|
||||
servletHost.addServletMapping(tuscanyUri, resourceServlet);
|
||||
} catch (ServletMappingException me ) {
|
||||
logger.warning("Tuscany dojo extensions already registered at :" + tuscanyBaseUri);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Servlet servlet = servletHost.getServletMapping(dojoBaseUri);
|
||||
if(servlet != null) {
|
||||
servletHost.removeServletMapping(dojoBaseUri);
|
||||
servletHost.removeServletMapping(dojoUri);
|
||||
|
||||
servletHost.removeServletMapping(tuscanyBaseUri);
|
||||
servletHost.removeServletMapping(tuscanyUri);
|
||||
}
|
||||
|
||||
servletHost = null;
|
||||
|
||||
}
|
||||
}
|
|
@ -14,5 +14,6 @@
|
|||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
# Implementation class for the ModuleActivator
|
||||
org.apache.tuscany.sca.web.javascript.dojo.DojoModuleActivator;priority=9999
|
||||
org.apache.tuscany.sca.web.javascript.dojo.DojoWidgetJavascriptProvider;priority=9999
|
Loading…
Add table
Reference in a new issue