You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2007/04/11 12:23:57 UTC

svn commit: r527447 - /incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/

Author: antelder
Date: Wed Apr 11 03:23:55 2007
New Revision: 527447

URL: http://svn.apache.org/viewvc?view=rev&rev=527447
Log:
Add script artifact processor and associated classes

Added:
    incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptArtifactProcessor.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationDefinition.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptModuleActivator.java   (with props)

Added: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptArtifactProcessor.java?view=auto&rev=527447
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptArtifactProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptArtifactProcessor.java Wed Apr 11 03:23:55 2007
@@ -0,0 +1,118 @@
+/*
+ * 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.implementation.script;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.assembly.xml.Constants;
+import org.apache.tuscany.services.spi.contribution.ArtifactResolver;
+import org.apache.tuscany.services.spi.contribution.ContributionReadException;
+import org.apache.tuscany.services.spi.contribution.ContributionResolveException;
+import org.apache.tuscany.services.spi.contribution.ContributionWireException;
+import org.apache.tuscany.services.spi.contribution.ContributionWriteException;
+import org.apache.tuscany.services.spi.contribution.StAXArtifactProcessor;
+
+public class ScriptArtifactProcessor implements StAXArtifactProcessor<ScriptImplementation> {
+
+    private static final String SCRIPT = "script";
+    private static final String IMPLEMENTATION_SCRIPT = "implementation.script";
+    private static final QName IMPLEMENTATION_SCRIPT_QNAME = new QName(Constants.SCA10_NS, IMPLEMENTATION_SCRIPT);
+
+    public ScriptArtifactProcessor() {
+    }
+
+    public ScriptImplementation read(XMLStreamReader reader) throws ContributionReadException {
+
+        try {
+
+            ScriptImplementation scriptImplementation = new ScriptImplementation();
+            scriptImplementation.setUnresolved(true);
+            scriptImplementation.setName(reader.getAttributeValue(null, SCRIPT));
+
+            // Skip to end element
+            while (reader.hasNext()) {
+                if (reader.next() == END_ELEMENT && IMPLEMENTATION_SCRIPT_QNAME.equals(reader.getName())) {
+                    break;
+                }
+            }
+            return scriptImplementation;
+
+        } catch (XMLStreamException e) {
+            throw new ContributionReadException(e);
+        }
+    }
+
+    public void write(ScriptImplementation scriptImplementation, XMLStreamWriter writer) throws ContributionWriteException {
+        try {
+
+            writer.writeStartElement(Constants.SCA10_NS, IMPLEMENTATION_SCRIPT);
+            if (scriptImplementation.getName() != null) {
+                writer.writeAttribute(SCRIPT, scriptImplementation.getName());
+            }
+            writer.writeEndElement();
+
+        } catch (XMLStreamException e) {
+            throw new ContributionWriteException(e);
+        }
+    }
+
+    public void resolve(ScriptImplementation scriptImplementation, ArtifactResolver resolver) throws ContributionResolveException {
+        try {
+
+            // TODO: implement
+            URL scriptSrcUrl = Thread.currentThread().getContextClassLoader().getResource(scriptImplementation.getName());
+//            Class javaClass = Class.forName(scriptImplementation.getName(), true, Thread.currentThread().getContextClassLoader());
+//            scriptImplementation.setJavaClass(javaClass);
+//            
+//            //FIXME JavaImplementationDefinition should not be mandatory 
+//            if (scriptImplementation instanceof ScriptImplementationDefinition) {
+//                introspectionRegistry.introspect(scriptImplementation.getJavaClass(), (ScriptImplementationDefinition)scriptImplementation);
+//                
+//                //FIXME the introspector should always create at least one service
+//                if (scriptImplementation.getServices().isEmpty()) {
+//                    scriptImplementation.getServices().add(new ServiceImpl());
+//                }
+//            }
+
+        } catch (Exception e) {
+            throw new ContributionResolveException(e);
+        }
+    }
+
+    public void wire(ScriptImplementation model) throws ContributionWireException {
+        // TODO Auto-generated method stub
+    }
+
+    public QName getArtifactType() {
+        return IMPLEMENTATION_SCRIPT_QNAME;
+    }
+
+    public Class<ScriptImplementation> getModelType() {
+        return ScriptImplementation.class;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptArtifactProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptArtifactProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java?view=auto&rev=527447
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java Wed Apr 11 03:23:55 2007
@@ -0,0 +1,64 @@
+/*
+ * 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.implementation.script;
+
+import org.apache.tuscany.assembly.impl.ComponentTypeImpl;
+
+/**
+ * Represents a Script implementation.
+ */
+public class ScriptImplementation extends ComponentTypeImpl {
+
+    private String scriptName;
+    private String scriptSrc;
+
+    public String getName() {
+        return scriptName;
+    }
+
+    public void setName(String scriptName) {
+        if (!isUnresolved()) {
+            throw new IllegalStateException();
+        }
+        this.scriptName = scriptName;
+    }
+
+    public String getScriptSrc() {
+        return scriptSrc;
+    }
+
+    public void setScriptSrc(String scriptSrc) {
+        this.scriptSrc = scriptSrc;
+    }
+
+    @Override
+    public int hashCode() {
+        return String.valueOf(getName()).hashCode();
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this)
+            return true;
+        else if (obj instanceof ScriptImplementation && getName().equals(((ScriptImplementation)obj).getName()))
+             return true;
+        else
+            return false;
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementation.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationDefinition.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationDefinition.java?view=auto&rev=527447
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationDefinition.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationDefinition.java Wed Apr 11 03:23:55 2007
@@ -0,0 +1,243 @@
+/*
+ * 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.implementation.script;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A component type specialization for POJO implementations
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class ScriptImplementationDefinition extends ScriptImplementation {
+    private ConstructorDefinition<?> constructorDefinition;
+    private Map<Constructor, ConstructorDefinition> constructors = new HashMap<Constructor, ConstructorDefinition>();
+    private Method initMethod;
+    private Method destroyMethod;
+    private final Map<String, Resource> resources = new HashMap<String, Resource>();
+    private final Map<String, JavaElement> propertyMembers = new HashMap<String, JavaElement>();
+    private final Map<String, JavaElement> referenceMembers = new HashMap<String, JavaElement>();
+    private final Map<String, JavaElement> callbackMembers = new HashMap<String, JavaElement>();
+    private Member conversationIDMember;
+    private boolean eagerInit;
+    private boolean allowsPassByReference;
+    private List<Method> allowsPassByReferenceMethods = new ArrayList<Method>();
+    private long maxAge = -1;
+    private long maxIdleTime = -1;
+    private Scope scope = Scope.STATELESS;
+
+    /**
+     * Constructor specifying the java class for the POJO this is describing.
+     *
+     * @param implClass the java class for the POJO this is describing
+     */
+    public ScriptImplementationDefinition(String scriptSrc) {
+        super();
+        setScriptSrc(scriptSrc);
+    }
+    
+    public ScriptImplementationDefinition() {
+        super();
+    }    
+
+    /**
+     * Returns the constructor used to instantiate implementation instances.
+     *
+     * @return the constructor used to instantiate implementation instances
+     */
+    public ConstructorDefinition<?> getConstructorDefinition() {
+        return constructorDefinition;
+    }
+
+    /**
+     * Sets the constructor used to instantiate implementation instances
+     *
+     * @param definition the constructor used to instantiate implementation instances
+     */
+    public void setConstructorDefinition(ConstructorDefinition<?> definition) {
+        this.constructorDefinition = definition;
+    }
+
+    /**
+     * Returns the component initializer method.
+     *
+     * @return the component initializer method
+     */
+    public Method getInitMethod() {
+        return initMethod;
+    }
+
+    /**
+     * Sets the component initializer method.
+     *
+     * @param initMethod the component initializer method
+     */
+    public void setInitMethod(Method initMethod) {
+        this.initMethod = initMethod;
+    }
+
+    /**
+     * Returns the component destructor method.
+     *
+     * @return the component destructor method
+     */
+    public Method getDestroyMethod() {
+        return destroyMethod;
+    }
+
+    /**
+     * Sets the component destructor method.
+     *
+     * @param destroyMethod the component destructor method
+     */
+    public void setDestroyMethod(Method destroyMethod) {
+        this.destroyMethod = destroyMethod;
+    }
+
+    public Map<String, Resource> getResources() {
+        return resources;
+    }
+
+    public void add(Resource resource) {
+        resources.put(resource.getName(), resource);
+    }
+
+    public Member getConversationIDMember() {
+        return this.conversationIDMember;
+    }
+
+    public void setConversationIDMember(Member conversationIDMember) {
+        this.conversationIDMember = conversationIDMember;
+    }
+
+    /**
+     * @return the allowsPassByReference
+     */
+    public boolean isAllowsPassByReference() {
+        return allowsPassByReference;
+    }
+
+    /**
+     * @param allowsPassByReference the allowsPassByReference to set
+     */
+    public void setAllowsPassByReference(boolean allowsPassByReference) {
+        this.allowsPassByReference = allowsPassByReference;
+    }
+
+    /**
+     * @return the allowsPassByReferenceMethods
+     */
+    public List<Method> getAllowsPassByReferenceMethods() {
+        return allowsPassByReferenceMethods;
+    }
+    
+    public boolean isAllowsPassByReference(Method method) {
+        return allowsPassByReference || allowsPassByReferenceMethods.contains(method);
+    }
+
+    /**
+     * @return the constructors
+     */
+    public Map<Constructor, ConstructorDefinition> getConstructors() {
+        return constructors;
+    }
+
+    /**
+     * @return the eagerInit
+     */
+    public boolean isEagerInit() {
+        return eagerInit;
+    }
+
+    /**
+     * @param eagerInit the eagerInit to set
+     */
+    public void setEagerInit(boolean eagerInit) {
+        this.eagerInit = eagerInit;
+    }
+
+    /**
+     * @return the callbacks
+     */
+    public Map<String, JavaElement> getCallbackMembers() {
+        return callbackMembers;
+    }
+
+    /**
+     * @return the properties
+     */
+    public Map<String, JavaElement> getPropertyMembers() {
+        return propertyMembers;
+    }
+
+    /**
+     * @return the references
+     */
+    public Map<String, JavaElement> getReferenceMembers() {
+        return referenceMembers;
+    }
+
+    /**
+     * @return the scope
+     */
+    public Scope getScope() {
+        return scope;
+    }
+
+    /**
+     * @param scope the scope to set
+     */
+    public void setScope(Scope scope) {
+        this.scope = scope;
+    }
+
+    /**
+     * @return the maxAge
+     */
+    public long getMaxAge() {
+        return maxAge;
+    }
+
+    /**
+     * @param maxAge the maxAge to set
+     */
+    public void setMaxAge(long maxAge) {
+        this.maxAge = maxAge;
+    }
+
+    /**
+     * @return the maxIdleTime
+     */
+    public long getMaxIdleTime() {
+        return maxIdleTime;
+    }
+
+    /**
+     * @param maxIdleTime the maxIdleTime to set
+     */
+    public void setMaxIdleTime(long maxIdleTime) {
+        this.maxIdleTime = maxIdleTime;
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationDefinition.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptImplementationDefinition.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptModuleActivator.java?view=auto&rev=527447
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptModuleActivator.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptModuleActivator.java Wed Apr 11 03:23:55 2007
@@ -0,0 +1,56 @@
+/*
+ * 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.implementation.script;
+
+import java.util.Map;
+
+import org.apache.tuscany.services.spi.contribution.StAXArtifactProcessorRegistry;
+import org.apache.tuscany.spi.bootstrap.ExtensionPointRegistry;
+import org.apache.tuscany.spi.bootstrap.ModuleActivator;
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+
+public class ScriptModuleActivator implements ModuleActivator {
+
+    private ScriptArtifactProcessor scriptArtifactProcessor;
+    private ScriptComponentBuilder builder;
+    
+    public void start(ExtensionPointRegistry registry) {
+        StAXArtifactProcessorRegistry processors = registry.getExtensionPoint(StAXArtifactProcessorRegistry.class);
+        BuilderRegistry builderRegistry = registry.getExtensionPoint(BuilderRegistry.class);
+
+        scriptArtifactProcessor = new ScriptArtifactProcessor();
+        processors.addArtifactProcessor(scriptArtifactProcessor);
+
+        builder = new ScriptComponentBuilder();
+        builder.setBuilderRegistry(builderRegistry);
+        builder.init();
+    }
+
+    public void stop(ExtensionPointRegistry arg0) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public Map<Class, Object> getExtensionPoints() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptModuleActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/implementation/script/ScriptModuleActivator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org