diff options
Diffstat (limited to 'branches/java-post-M1/sca/model/src/main/java')
78 files changed, 5795 insertions, 0 deletions
diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/ModelRuntimeException.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/ModelRuntimeException.java new file mode 100644 index 0000000000..e167882786 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/ModelRuntimeException.java @@ -0,0 +1,42 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model; + +import org.apache.tuscany.common.TuscanyRuntimeException; + +/** + * The root runtime exception for the model. + * + * @version $Rev$ $Date$ + */ +@SuppressWarnings({"serial"}) +public abstract class ModelRuntimeException extends TuscanyRuntimeException { + + public ModelRuntimeException() { + super(); + } + + public ModelRuntimeException(String message) { + super(message); + } + + public ModelRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + public ModelRuntimeException(Throwable cause) { + super(cause); + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyContext.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyContext.java new file mode 100644 index 0000000000..48aed5f35a --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyContext.java @@ -0,0 +1,64 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.model.assembly.loader.AssemblyModelLoader; + +import commonj.sdo.helper.TypeHelper; + +/** + * Context object supplied by visitors that are processing the model. + */ +public interface AssemblyContext { + + /** + * Returns a factory that can be used to create other model objects + * + * @return a factory for model objects + */ + AssemblyFactory getAssemblyFactory(); + + /** + * Returns a loader for resources in the application environment. + * + * @return a loader for resources in the system environment + */ + ResourceLoader getApplicationResourceLoader(); + + /** + * Returns a loader that can be used to load sub-models. + * + * @return a loader for sub-models + */ + AssemblyModelLoader getAssemblyLoader(); + + /** + * Returns an SDO type helper. + * + * @return an SDO type helper + */ + TypeHelper getTypeHelper(); + + /** + * Returns the Web application module URI + * + * @return the module name of the Web app + */ + String getWebAppName(); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyFactory.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyFactory.java new file mode 100644 index 0000000000..efbc6bffa4 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyFactory.java @@ -0,0 +1,260 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.model.types.java.JavaServiceContract; +import org.apache.tuscany.model.types.wsdl.WSDLServiceContract; + +/** + * The Factory for the assembly model. Provides a create method for each non-abstract class of the model. + */ +public interface AssemblyFactory { + + /** + * Returns a new SimpleComponent. + * + * @return a new SimpleComponent + */ + AtomicComponent createSimpleComponent(); + + /** + * Returns a new ComponentType. + * + * @return a new ComponentType + */ + ComponentType createComponentType(); + + /** + * Returns a new EntryPoint. + * + * @return a new EntryPoint + */ + EntryPoint createEntryPoint(); + + /** + * Returns a new ExternalService. + * + * @return a new ExternalService + */ + ExternalService createExternalService(); + + /** + * Returns a new JavaServiceContract. + * + * @return a new JavaServiceContract + */ + JavaServiceContract createJavaServiceContract(); + + /** + * Returns a new Module. + * + * @return a new Module + */ + Module createModule(); + + /** + * Returns a new ModuleComponent. + * + * @return a new ModuleComponent + */ + ModuleComponent createModuleComponent(); + + /** + * Returns a new ModuleFragment. + * + * @return a new ModuleFragment + */ + ModuleFragment createModuleFragment(); + + /** + * Returns a new Reference. + * + * @return a new Reference + */ + Reference createReference(); + + /** + * Returns a new ConfiguredReference. + * + * @return a new ConfiguredReference + */ + ConfiguredReference createConfiguredReference(); + + /** + * Returns a new Service. + * + * @return a new Service + */ + Service createService(); + + /** + * Returns a new ConfiguredService. + * + * @return a new ConfiguredService + */ + ConfiguredService createConfiguredService(); + + /** + * Returns a new Subsystem. + * + * @return a new Subsystem + */ + Subsystem createSubsystem(); + + /** + * Returns a new Property. + * + * @return a new Property + */ + Property createProperty(); + + /** + * Returns a new ConfiguredProperty. + * + * @return a new ConfiguredProperty + */ + ConfiguredProperty createConfiguredProperty(); + + /** + * Returns a new WSDLServiceContract. + * + * @return a new WSDLServiceContract + */ + WSDLServiceContract createWSDLServiceContract(); + + /** + * Create a new ServiceURI from the given uri string. + * + * @param uri the URI for the service + * @return a new ServiceURI created from the supplied URI + */ + ServiceURI createServiceURI(String uri); + + /** + * Creates a new ServiceURI from a module component and a service name. + * + * @param moduleComponent the module component exposing the service + * @param serviceName the name of the service exposed by the module + * @return a new ServiceURI for the exposed service + */ + ServiceURI createServiceURI(ModuleComponent moduleComponent, String serviceName); + + /** + * Creates a new ServiceURI from a module component and configured port. + * + * @param moduleComponent the module component exposing the service + * @param part the part that is providing the service + * @param configuredPort the port on the part + * @return a new serviceURI for the exposed service + */ + ServiceURI createServiceURI(ModuleComponent moduleComponent, Part part, ConfiguredPort configuredPort); + + ServiceURI createServiceURI(ModuleComponent moduleComponent, String partName, String serviceName); + + /** + * Create a qname from a URI + * + * @param uri + * @return a new qname + */ + QName createQName(String uri); + + /** + * Create a wire + * + * @return an new wire + */ + Wire createWire(); + + /** + * Helper method for creating a reference. + * + * @param name the name of the reference + * @param service the Java type of the service + * @return a Reference + */ + Reference createReference(String name, Class<?> service); + + /** + * Helper method for creating a reference. + * + * @param name the name of the reference + * @param service the Java type of the service + * @param multiplicity the multiplicity of the reference + * @return a Reference + */ + Reference createReference(String name, Class<?> service, Multiplicity multiplicity); + + /** + * Helper method for creating a configured reference. + * + * @param name the name of the reference + * @param targets the targets for the reference + * @return a ConfiguredReference + */ + ConfiguredReference createConfiguredReference(String name, String... targets); + + /** + * Helper method for creating an EntryPoint wired to a single target. + * + * @param entryPointName the name of the entry point + * @param serviceContract the service contract the EntryPoint should expose + * @param binding the binding the EntryPoint should use + * @param targetName the target the EntryPoint exposes + * @return an EntryPoint that exposes the supplied service and is wired to the target + */ + EntryPoint createEntryPoint(String entryPointName, ServiceContract serviceContract, Binding binding, String targetName); + + /** + * Helper method for creating an EntryPoint wired to a single target. + * + * @param entryPointName the name of the entry point + * @param configuredService the configured service to expose + * @param binding the binding the EntryPoint should use + * @param configuredReference a configured reference to the target + * @return an EntryPoint that exposes the supplied service using the supplied bindng and which is wired + * using the supplied reference + */ + EntryPoint createEntryPoint(String entryPointName, ConfiguredService configuredService, Binding binding, ConfiguredReference configuredReference); + + /** + * Helper method for creating a simple Property. + * + * @param name the property name + * @param type the Java type of the property + * @return a Property with the supplied name and type + */ + Property createProperty(String name, Class<?> type); + + /** + * Returns a new ImportWSDL model object. + * + * @return a new ImportWSDL model object + */ + ImportWSDL createImportWSDL(); + + /** + * Returns a new ImportWSDL model object initialized with the supplied values. + * + * @param location the location where the WSDL definition can be found + * @param namespace the namespace URI for this import + * @return a new ImportWSDL model object + */ + ImportWSDL createImportWSDL(String location, String namespace); +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyInitializationException.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyInitializationException.java new file mode 100644 index 0000000000..69a7854df9 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyInitializationException.java @@ -0,0 +1,46 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import org.apache.tuscany.model.ModelRuntimeException; + +/** + * Denotes an exception initializing an assembly model artifact. + * + * @version $Rev$ $Date$ + */ +public class AssemblyInitializationException extends ModelRuntimeException { + private static final long serialVersionUID = 747289653378365323L; + + public AssemblyInitializationException() { + super(); + } + + public AssemblyInitializationException(String message) { + super(message); + } + + public AssemblyInitializationException(String message, Throwable cause) { + super(message, cause); + } + + public AssemblyInitializationException(Throwable cause) { + super(cause); + } + +} + diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyObject.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyObject.java new file mode 100644 index 0000000000..d25f114902 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyObject.java @@ -0,0 +1,45 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * Base interface for all assembly model objects providing methods for managing the model itself. + */ +public interface AssemblyObject { + + /** + * Initialize this model object. + * + * @param modelContext context providing access to the environment in which this model is being used + * @throws AssemblyInitializationException if an error ocurrs initializing the artifact + */ + void initialize(AssemblyContext modelContext) throws AssemblyInitializationException; + + /** + * Freeze this model object preventing any additional changes. + */ + void freeze(); + + /** + * Accept a visitor + * + * @param visitor a visitor that is visiting the model + * @return true if processing is complete and the visitor should stop traversing the model + */ + boolean accept(AssemblyVisitor visitor); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyVisitor.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyVisitor.java new file mode 100644 index 0000000000..f153b9b4f6 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AssemblyVisitor.java @@ -0,0 +1,32 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * A visitor that traverses the model performing some operation. + */ +public interface AssemblyVisitor { + + /** + * Visit the given model object. + * + * @param modelObject the assembly model object to visit + * @return true if processing is complete + */ + boolean visit(AssemblyObject modelObject); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AtomicComponent.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AtomicComponent.java new file mode 100644 index 0000000000..0c98bbbe95 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AtomicComponent.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + +/** + * An atomic component, specifically not an {@link Composite}. + */ +public interface AtomicComponent extends Component<AtomicImplementation> { +} +
\ No newline at end of file diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AtomicImplementation.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AtomicImplementation.java new file mode 100644 index 0000000000..4d0703186b --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/AtomicImplementation.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + +/** + * The implementation for a specific atomic component instance. + * This interface will typically be extended by component type implementations to indicate the + * specific implementation to be used by a runtime and to allow for additional runtime configuration + * properties. + */ +public interface AtomicImplementation extends Implementation { + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Binding.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Binding.java new file mode 100644 index 0000000000..51becc29c2 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Binding.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + +/** + * The binding of an entry point or external service to a transport. + * This model object will typically be extended by binding implementations to allow + * specification of binding/transport specific information. + */ +public interface Binding extends AssemblyObject { + /** + * Returns the binding URI. + * @return the binding uri + * TODO do we need this? + */ + String getURI(); + + /** + * Sets binding URI. + * @param value the binding uri + * TODO do we need this? + */ + void setURI(String value); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Component.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Component.java new file mode 100644 index 0000000000..b8d566f1d6 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Component.java @@ -0,0 +1,81 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import java.util.List; + + +/** + * A component is a configured instance of a generic {@link Implementation}. + */ +public interface Component<I extends Implementation> extends Part { + + /** + * Returns the Implementation for this configured instance. + * @return the Implementation for this configured instance + */ + I getImplementation(); + + /** + * Sets the Implementation for this configured instance + * @param value the Implementation for this configured instance + */ + void setImplementation(I value); + + /** + * Returns a list of configured property values for this configured instance. + * These values will be used to initialize the component when it is activated. + * @return a list of ConfiguredProperty values + */ + List<ConfiguredProperty> getConfiguredProperties(); + + /** + * Returns the ConfiguredProperty value for the specified property. + * + * @param name the name of the Property + * @return the configured property value for the named property + */ + ConfiguredProperty getConfiguredProperty(String name); + + /** + * Returns the configured references for the configured instance. + * + * @return the configured references for the configured instance + */ + List<ConfiguredReference> getConfiguredReferences(); + + /** + * Returns the ConfiguredReference value for the specified reference. + * @param name the name of the Property + * @return the configured reference value for the named reference + */ + ConfiguredReference getConfiguredReference(String name); + + /** + * Returns the configured services for the configured instance. + * @return the configured services for the configured instance + */ + List<ConfiguredService> getConfiguredServices(); + + /** + * Returns the ConfiguredService value for the specified property. + * @param name the name of the Property + * @return the configured service value for the named service + */ + ConfiguredService getConfiguredService(String name); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ComponentType.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ComponentType.java new file mode 100644 index 0000000000..58ac9bc9de --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ComponentType.java @@ -0,0 +1,66 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import java.util.List; + + +/** + * A logical definition of a type of component separate from any specific implementation. + */ +public interface ComponentType extends Extensible { + + /** + * Returns a list of services exposed by this component type. + * @return a list of services exposed by this component type + */ + List<Service> getServices(); + + /** + * Returns the specfied service if exposed by this component type. + * @param name the name of the service + * @return the service identified by the supplied name, or null if there is no service with that name + */ + Service getService(String name); + + /** + * Returns the list of references this component type consumes. + * @return the list of references this component type consumes + */ + List<Reference> getReferences(); + + /** + * Returns the specified reference. + * @param name the name of the reference + * @return the reference identified by the supplied name, or null if there is no reference with that name + */ + Reference getReference(String name); + + /** + * Returns the list of properties that can be used to configure components with this component type. + * @return the list of properties that can be used to configure components with this component type + */ + List<Property> getProperties(); + + /** + * Returns the specified property + * @param name the name of the property + * @return the property with the supplied name, or null if there is no property with that name + */ + Property getProperty(String name); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Composite.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Composite.java new file mode 100644 index 0000000000..09f51945bb --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Composite.java @@ -0,0 +1,94 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import java.util.List; + +/** + * A model object that describes a container for parts. + */ +public interface Composite extends Implementation { + + /** + * Returns the name of the composite. + * @return the name of the composite + */ + String getName(); + + /** + * Sets the name of the composite. + * @param name the name of the composite + */ + void setName(String name); + + /** + * Returns the named part. + * @param name + */ + Part getPart(String name); + + /** + * Returns all entry points contained in this composite. + * @return a list of all EntryPoint model objects contained in this composite + */ + List<EntryPoint> getEntryPoints(); + + /** + * Returns all components contained in this composite. + * @return a list of all Component model objects contained in this composite + */ + List<Component> getComponents(); + + /** + * Returns all external services contained in this composite. + * @return a list of all ExternalService model objects contained in this composite + */ + List<ExternalService> getExternalServices(); + + /** + * Returns the wires contained in this composite. + */ + List<Wire> getWires(); + + /** + * Returns the WSDL imports declared in this composite. + */ + List<ImportWSDL> getWSDLImports(); + + /** + * Returns the WSDL imports for the given namespace. + * @param namespace + */ + List<ImportWSDL> getWSDLImports(String namespace); + + /** + * Returns the configured service at the given address. + * @param address + */ + ConfiguredService getConfiguredService(ServiceURI address); + + /** + * Returns the implementation class. + */ + Class<?> getImplementationClass(); + + /** + * Sets the implementation class. + */ + void setImplementationClass(Class<?> value); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/CompositeComponent.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/CompositeComponent.java new file mode 100644 index 0000000000..c78fe28ff5 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/CompositeComponent.java @@ -0,0 +1,35 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * Specialization of Component that represents a configured {@link Module}. + */ +public interface CompositeComponent<I extends Composite> extends Component<I> { + + /** + * Returns the uri that uniquely identifies this module component. + * @return the uri that uniquely identifies this module component + */ + String getURI(); + + /** + * Sets the uri that uniquely identifies this module component. + * @param uri the uri that uniquely identifies this module component + */ + void setURI(String uri); +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredPort.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredPort.java new file mode 100644 index 0000000000..7f562e99d9 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredPort.java @@ -0,0 +1,63 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + +/** + * Represents a configured port (e.g. a configured reference or configured service). + */ +public interface ConfiguredPort<P extends Port> extends AssemblyObject, ProxyFactoryHolder { + + /** + * Returns the name of the port being configured. + * + * @return the name of the port being configured + */ + String getName(); + + /** + * Set the name of the port being configured. + * + * @param name the name of the port being configured + */ + void setName(String name); + + /** + * Returns the port that is being configured. + * @return the port that is being configured + */ + P getPort(); + + /** + * Sets the port that is being configured. + * @param port the port that is being configured + */ + void setPort(P port); + + /** + * Returns the part containing this port. + * @return the part that contains this port + */ + Part getPart(); + + /** + * Sets the configured part containing this port. + * @param part the configured part containing this port. + */ + void setPart(Part part); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredProperty.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredProperty.java new file mode 100644 index 0000000000..0d3a3e5011 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredProperty.java @@ -0,0 +1,74 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * The configured value of a {@link Property}. + */ +public interface ConfiguredProperty extends AssemblyObject { + + //FIXME remove the name attribute? + /** + * Returns the name of the property being configured. + * @return the name of the property being configured + */ + String getName(); + + /** + * Set the name of the property being configured. + * @param name the name of the property being configured + */ + void setName(String name); + + /** + * Returns the {@link Property} whose value is being set. + * @return the {@link Property} whose value is being set + */ + Property getProperty(); + + /** + * Sets the {@link Property} whose value is being set. + * @param property the {@link Property} whose value is being set + */ + void setProperty(Property property); + + /** + * Returns the value being set for this usage of the {@link Property}. + * @return the value being set for this usage of the {@link Property} + */ + Object getValue(); + + /** + * Sets the value being set for this usage of the {@link Property}. + * @param value the value being set for this usage of the {@link Property} + */ + void setValue(Object value); + + /** + * Returns the override option that determines if any configuration for this property + * that is contained in this composite can be overridden by configuration supplied from outside. + */ + OverrideOption getOverrideOption(); + + /** + * Set the override option that determines if any configuration for this property + * that is contained in this composite can be overridden by configuration supplied from outside. + * + * @param value the option that determines how property configuration can be overriden + */ + void setOverrideOption(OverrideOption value); +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredReference.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredReference.java new file mode 100644 index 0000000000..22cb734869 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredReference.java @@ -0,0 +1,44 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import java.util.List; + +/** + * A configured reference associated with a particular usage. + * Each configuredReference represents a configured version of an logical + * reference defined in the ComponentType. If the logical reference + * has a multiplicity greater than 1 (0..n or 1..n) then the configured + * reference many have multiple targets. + */ +public interface ConfiguredReference extends ConfiguredPort<Reference> { + + /** + * List of URIs for the targets of this reference. + * + * @return the list of URIs for the targets of this reference + */ + List<String> getTargets(); + + /** + * Returns the list of configured services that are wired to this configured reference. + * + * @return the list of configured services that are wired to this configured reference + */ + List<ConfiguredService> getTargetConfiguredServices(); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredService.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredService.java new file mode 100644 index 0000000000..696250ea44 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ConfiguredService.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + +/** + * A configured service associated with a particular usage. + */ +public interface ConfiguredService extends ConfiguredPort<Service> { + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ContextFactoryHolder.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ContextFactoryHolder.java new file mode 100644 index 0000000000..20259f245d --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ContextFactoryHolder.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * A model object that can hold a runtime context factory object. + */ +public interface ContextFactoryHolder { + + /** + * Sets the context factory + */ + void setContextFactory(Object contextFactory); + + /** + * Returns the context factory + */ + Object getContextFactory(); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/EntryPoint.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/EntryPoint.java new file mode 100644 index 0000000000..a90b89c4f5 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/EntryPoint.java @@ -0,0 +1,67 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import java.util.List; + + +/** + * An entry point exposed by its containing {@link Composite}. + * References from outside the composite can only be connected to its entry points. + */ +public interface EntryPoint extends Part { + + /** + * Returns the bindings supported by this entry point. + * A single entry point may be bound to multiple transports. + * + * @return a list of bindings supported by this entry point + */ + List<Binding> getBindings(); + + /** + * Returns the configured service exposed by this entry point. + * + * @return the configured service exposed by this entry point + */ + ConfiguredService getConfiguredService(); + + /** + * Sets the configured service exposed by this entry point. + * + * @param configuredService the configured service exposed by this entry point + */ + void setConfiguredService(ConfiguredService configuredService); + + /** + * Returns the configured reference that wires this entry point to the published service + * inside the composite. + * + * @return the reference that wires this entry point to the published service + */ + ConfiguredReference getConfiguredReference(); + + /** + * Sets the configured reference that wires this entry point to the published service + * inside the composite. + * + * @param configuredReference the configured reference that wires this entry point to + * the published service inside the composite + */ + void setConfiguredReference(ConfiguredReference configuredReference); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Extensible.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Extensible.java new file mode 100644 index 0000000000..b4651a6186 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Extensible.java @@ -0,0 +1,37 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import java.util.List; + +/** + * An extensible model object. We actually need this even though we have the ability to load specializations + * of individual model objects + */ +public interface Extensible extends AssemblyObject { + + /** + * Returns the extensibility elements. + */ + List<Object> getExtensibilityElements(); + + /** + * Returns the extensibility attributes. + */ + List<Object> getExtensibilityAttributes(); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ExternalService.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ExternalService.java new file mode 100644 index 0000000000..f2b72ec928 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ExternalService.java @@ -0,0 +1,59 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import java.util.List; + + +/** + * An external service consumed by its containing {@link Composite}. + * All references used by the composite are specified as external services. + */ +public interface ExternalService extends Part { + + /** + * Returns the bindings that can be used by operations on this external service. + * A single external service may be bound to multiple transports. + */ + List<Binding> getBindings(); + + /** + * Returns the override option that determines if any wiring for this external service + * that is contained in this composite can be overridden by wired supplied from outside. + */ + OverrideOption getOverrideOption(); + + /** + * Set the override option that determines if any wiring for this external service + * that is contained in this composite can be overridden by wired supplied from outside. + * + * @param value the option that determines how wires can be overriden + */ + void setOverrideOption(OverrideOption value); + + /** + * Returns the configured service that this external service provides to other parts of the containing composite. + * @return the configured service that this external service provides to other parts of the containing composite + */ + ConfiguredService getConfiguredService(); + + /** + * Sets the configured service that this external service provides to other parts of the containing composite + * @param configuredService the configured service that this external service provides to other parts of the containing composite + */ + void setConfiguredService(ConfiguredService configuredService); +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Implementation.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Implementation.java new file mode 100644 index 0000000000..2777d985f8 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Implementation.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + +/** + * The implementation for a specific component instance. + * This interface will typically be extended by component type implementations to indicate the + * specific implementation to be used by a runtime and to allow for additional runtime configuration + * properties. + */ +public interface Implementation extends Extensible { + + /** + * Returns the generic component type corresponding to this implementation. + * @return the generic component type corresponding to this implementation + */ + ComponentType getComponentType(); + + /** + * Sets the generic component type corresponding to this implementation. + * @param componentType the generic component type corresponding to this implementation + */ + void setComponentType(ComponentType componentType); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ImportWSDL.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ImportWSDL.java new file mode 100644 index 0000000000..7c858a1b76 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ImportWSDL.java @@ -0,0 +1,62 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.model.assembly; + +import javax.wsdl.Definition; + +/** + * Model object that represents the import of an external WSDL definition. + * + * @version $Rev$ $Date$ + */ +public interface ImportWSDL extends AssemblyObject { + /** + * Returns the location where the WSDL definition can be found. + * @return the location where the WSDL definition can be found + */ + String getLocation(); + + /** + * Set the location where the WSDL definition can be found. + * @param uri the location where the WSDL definition can be found + */ + void setLocation(String uri); + + /** + * Returns the namespace URI for this import. + * @return the namespace URI for this import + */ + String getNamespace(); + + /** + * Sets the namespace URI for this import. + * @param uri the namespace URI for this import + */ + void setNamespace(String uri); + + /** + * Returns the WSDL Definition. + * @return the WSDL Definition + */ + Definition getDefinition(); + + /** + * Sets the WSDL Definition. + * @param definition the WSDL Definition + */ + void setDefinition(Definition definition); +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Module.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Module.java new file mode 100644 index 0000000000..40d1d1534b --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Module.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +import java.util.List; + +/** + * A specialized {@link Implementation} that defines a modular unit of assembly. + * A Module denotes the extent of assembly in which pass-by-reference semantics are supported. + */ +public interface Module extends Composite { + + /** + * Returns a list of assembly fragments that combine to form a single module. + * @return a list of assembly fragments that combine to form a single module + */ + List<ModuleFragment> getModuleFragments(); + + /** + * Returns the specified assembly fragment. + * @param name the name of the fragment + * @return the fragment with the specified name, or null if there is no fragment with that name + */ + ModuleFragment getModuleFragment(String name); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ModuleComponent.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ModuleComponent.java new file mode 100644 index 0000000000..00f6079096 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ModuleComponent.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * Specialization of Component that represents a configured {@link Module}. + */ +public interface ModuleComponent extends CompositeComponent<Module> { + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ModuleFragment.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ModuleFragment.java new file mode 100644 index 0000000000..dec1e8bfd3 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ModuleFragment.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * A fragment of assembly configuration within a module. + * To support flexibility and reuse, modules can be defined in multiple fragments that are + * then combined by the runtime to form the complete module definition. + */ +public interface ModuleFragment extends Composite { +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Multiplicity.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Multiplicity.java new file mode 100644 index 0000000000..c51ab7b8ea --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Multiplicity.java @@ -0,0 +1,46 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * Enumeration for multiplicity. + */ +public enum Multiplicity { + /** + * Indicates a relationship that is optionally connected to the requestor and which, if supplied, + * must be connected to exactly one provider. + */ + ZERO_ONE, + + /** + * Indicates a relationship that must be connected between exactly one requestor and + * exactly one provider. + */ + ONE_ONE, + + /** + * Indicates a relationship that is optionally connects the requestor to zero to unbounded providers. + */ + ZERO_N, + + /** + * Indicates a relationship that must be connected at the requestor and which connects it to + * zero to unbounded providers. + */ + ONE_N + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/OverrideOption.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/OverrideOption.java new file mode 100644 index 0000000000..68489d0200 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/OverrideOption.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * Enumeration for override options that are used to control whether configuration information + * can be overridden by larger grained definitions. + */ +public enum OverrideOption { + /** + * Indicates that the supplied configuration cannot be overridden. + */ + NO, + + /** + * Indicates that the supplied configuration may be overriden. + */ + MAY, + + /** + * Indicates that the supplied configuration must be overriden. + */ + MUST + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Part.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Part.java new file mode 100644 index 0000000000..9645ad6d35 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Part.java @@ -0,0 +1,49 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + + +/** + * A configured object that is contained inside a {@link Composite}. + */ +public interface Part extends Extensible, ContextFactoryHolder { + /** + * Returns the name that uniquely identifies this component within its containing composite. + * @return the name that uniquely identifies this component within its containing composite + */ + String getName(); + + /** + * Sets the name that uniquely identifies this component within its containing composite. + * @param value the name that uniquely identifies this component within its containing composite + */ + void setName(String value); + + /** + * Returns the composite that contains this component. + * @return the composite that contains this component + */ + Composite getComposite(); + + /** + * Sets the composite that contains this component. + * @param the composite that contains this component + */ + void setComposite(Composite composite); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Port.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Port.java new file mode 100644 index 0000000000..13b9d0a1db --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Port.java @@ -0,0 +1,47 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * Abstraction for the association of a service contract with a requestor or provider. + */ +public interface Port extends AssemblyObject { + /** + * Returns the contract for invocations of a service using this port. + * @return the oontract for invocations of a service using this port + */ + ServiceContract getServiceContract(); + + /** + * Set the contract for invocations of a service using this port. + * @param contract the contract for invocations of a service using this port + */ + void setServiceContract(ServiceContract contract); + + /** + * Returns the name of the port where it is associated with a requestor or provider. + * @return the name of the port + */ + String getName(); + + /** + * Sets the name of the port where it is associated with a requestor or provider. + * @param name the name of the port where it is associated with a requestor or provider + */ + void setName(String name); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Property.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Property.java new file mode 100644 index 0000000000..1f238efce6 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Property.java @@ -0,0 +1,91 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + + +/** + * A description of a property that can be used to configure a component. + */ +public interface Property extends Extensible { + // todo should we decalre this as Property<T> where T would be the type of this Property? + + /** + * Returns the property name. + * @return the property name + */ + String getName(); + + /** + * Sets the property name. + * @param name the property name + */ + void setName(String name); + + /** + * Returns the default value of the property. + * @return the default value of ths property + */ + Object getDefaultValue(); + + /** + * Sets the default value of the property. + * @param value the default value of ths property + */ + void setDefaultValue(Object value); + + /** + * Returns true if the property allows multiple values. + * @return true if the property allows multiple values + */ + boolean isMany(); + + /** + * Sets whether or not the property allows multiple values. + * @param value true if the property should allow multiple values + */ + void setMany(boolean value); + + /** + * Returns true if a value must be supplied for the property. + * @return true is a value must be supplied for the property + */ + boolean isRequired(); + + /** + * Sets whether a value must be supplied for the property. + * For ease of use, it is recommended that a meaningful default value should + * be supplied for all properties; users should only be required to specify + * a value if there is no reasonable default. + * + * @param value set to true to require that a value be supplied for uses of this property + */ + void setRequired(boolean value); + + /** + * Returns the type of this property as used by the runtime. + * @return the type of this property as used by the runtime + */ + Class<?> getType(); + + /** + * Sets the type of this property as used by the runtime + * @param value the type of this property as used by the runtime + */ + void setType(Class<?> value); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ProxyFactoryHolder.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ProxyFactoryHolder.java new file mode 100644 index 0000000000..055448b2f5 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ProxyFactoryHolder.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * A model object that can hold a runtime proxy factory object. + */ +public interface ProxyFactoryHolder { + + /** + * Sets the proxy factory + */ + void setProxyFactory(Object proxyFactory); + + /** + * Returns the proxy factory + */ + Object getProxyFactory(); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Reference.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Reference.java new file mode 100644 index 0000000000..8cc13e98ec --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Reference.java @@ -0,0 +1,36 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + +/** + * The association of a port with a requestor. + */ +public interface Reference extends Port { + /** + * Returns the multiplicity allowed for wires connected to this reference. + * @return the multiplicity allowed for wires connected to this reference + */ + Multiplicity getMultiplicity(); + + /** + * Sets the multiplicity allowed for wires connected to this reference. + * @param multiplicity the multiplicity allowed for wires connected to this reference + */ + void setMultiplicity(Multiplicity multiplicity); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Scope.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Scope.java new file mode 100644 index 0000000000..c7194292f0 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Scope.java @@ -0,0 +1,31 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * The types of scope supported by assemblies. + */ +public enum Scope { + // todo define what these are + INSTANCE, + REQUEST, + SESSION, + MODULE, + AGGREGATE, + UNDEFINED + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Service.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Service.java new file mode 100644 index 0000000000..c73002efba --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Service.java @@ -0,0 +1,24 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + +/** + * The association of a port with a provider. + */ +public interface Service extends Port { +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ServiceContract.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ServiceContract.java new file mode 100644 index 0000000000..1600e11663 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ServiceContract.java @@ -0,0 +1,60 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * The contract specified by a requestor or provider for invocations across a port. + */ +public interface ServiceContract extends Extensible { + + /** + * Returns the interface for invocations from the requestor to the provider. + * @return the interface for invocations from the requestor to the provider + */ + Class getInterface(); + + /** + * Sets the interface for invocations from the requestor to the provider. + * @param value the interface for invocations from the requestor to the provider + */ + void setInterface(Class value); + + /** + * Returns the callback interface for wire from the provider back to its requestor. + * @return the callback interface for wire from the provider back to its requestor + */ + Class getCallbackInterface(); + + /** + * Sets the callback interface for wire from the provider back to its requestor. + * @param value the callback interface for wire from the provider back to its requestor + */ + void setCallbackInterface(Class value); + + /** + * Returns the scope of this service contract. + * @return + */ + Scope getScope(); + + /** + * Sets the scope. + * @param scope of this service contract. + */ + void setScope(Scope scope); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ServiceURI.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ServiceURI.java new file mode 100644 index 0000000000..740febc360 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/ServiceURI.java @@ -0,0 +1,58 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + +/** + * Represents a service URI. + */ +public interface ServiceURI { + + /** + * Returns true if the address scheme is sca + * @return + */ + public boolean isSCAScheme(); + + /** + * @return Returns the address. + */ + public String getAddress(); + + /** + * @return Returns the path. + */ + public String getPath(); + + /** + * Returns the module component name + * @return + */ + public String getModuleComponentName(); + + /** + * Returns the part name + * @return + */ + public String getPartName(); + + /** + * Returns the service name + * @return + */ + public String getServiceName(); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Subsystem.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Subsystem.java new file mode 100644 index 0000000000..709ba4da35 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Subsystem.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + + +/** + * Represents a subsystem. + */ +public interface Subsystem extends Composite { + + /** + * Returns the subsystem uri. + * @return + */ + String getURI(); + + /** + * Sets the subsystem uri. + * @param value + */ + void setURI(String value); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Wire.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Wire.java new file mode 100644 index 0000000000..dfe553210a --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/Wire.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly; + + +/** + * A connection between a requestor (source) and a provider (target). + */ +public interface Wire extends Extensible { + /** + * Returns the URI for the source of the request. + * @return the URI for the source of the request + */ + ServiceURI getSource(); + + /** + * Sets the URI for the source of the request. + * @param uri the URI for the source of the request + */ + void setSource(ServiceURI uri); + + /** + * Returns the URI for the target of the request. + * @return the URI for the target of the request + */ + ServiceURI getTarget(); + + /** + * Sets the URI for the target of the request. + * @param uri the URI for the target of the request + */ + void setTarget(ServiceURI uri); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AssemblyContextImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AssemblyContextImpl.java new file mode 100644 index 0000000000..a7f9012db7 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AssemblyContextImpl.java @@ -0,0 +1,88 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.model.assembly.AssemblyFactory; +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.loader.AssemblyModelLoader; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.helper.TypeHelper; + +/** + */ +public class AssemblyContextImpl implements AssemblyContext { + + private final AssemblyFactory assemblyFactory; + private final AssemblyModelLoader assemblyLoader; + private final ResourceLoader applicationResourceLoader; + private final TypeHelper typeHelper; + private String webAppName; + + public AssemblyContextImpl(AssemblyModelLoader assemblyLoader, ResourceLoader resourceLoader) { + this(new AssemblyFactoryImpl(), assemblyLoader, resourceLoader); + } + + public AssemblyContextImpl(AssemblyFactory assemblyFactory, AssemblyModelLoader assemblyLoader, ResourceLoader artifactLoader) { + this(assemblyFactory, assemblyLoader, artifactLoader, SDOUtil.createTypeHelper()); + } + + public AssemblyContextImpl(AssemblyFactory assemblyFactory, AssemblyModelLoader assemblyLoader, ResourceLoader artifactLoader, String webAppName) { + this(assemblyFactory, assemblyLoader, artifactLoader, SDOUtil.createTypeHelper(), webAppName); + } + public AssemblyContextImpl(AssemblyFactory assemblyFactory, AssemblyModelLoader assemblyLoader, ResourceLoader artifactLoader, TypeHelper typeHelper) { + this(assemblyFactory, assemblyLoader, artifactLoader, SDOUtil.createTypeHelper(), null); + } + + public AssemblyContextImpl(AssemblyFactory assemblyFactory, AssemblyModelLoader assemblyLoader, ResourceLoader artifactLoader, TypeHelper typeHelper, String webAppName) { + this.assemblyFactory = assemblyFactory; + this.assemblyLoader = assemblyLoader; + this.applicationResourceLoader = artifactLoader; + this.typeHelper=typeHelper; + this.webAppName=webAppName; + } + + /** + * @see org.apache.tuscany.model.assembly.AssemblyContext#getAssemblyFactory() + */ + public AssemblyFactory getAssemblyFactory() { + return assemblyFactory; + } + + public ResourceLoader getApplicationResourceLoader() { + return applicationResourceLoader; + } + + /** + * @see org.apache.tuscany.model.assembly.AssemblyContext#getAssemblyLoader() + */ + public AssemblyModelLoader getAssemblyLoader() { + return assemblyLoader; + } + + /** + * @see org.apache.tuscany.model.assembly.AssemblyContext#getTypeHelper() + */ + public TypeHelper getTypeHelper() { + return typeHelper; + } + + public String getWebAppName() { + return webAppName; + } +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AssemblyFactoryImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AssemblyFactoryImpl.java new file mode 100644 index 0000000000..c88ea4448f --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AssemblyFactoryImpl.java @@ -0,0 +1,217 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.model.assembly.Part; +import org.apache.tuscany.model.assembly.AssemblyFactory; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.ConfiguredPort; +import org.apache.tuscany.model.assembly.ConfiguredProperty; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.EntryPoint; +import org.apache.tuscany.model.assembly.ExternalService; +import org.apache.tuscany.model.assembly.Module; +import org.apache.tuscany.model.assembly.ModuleComponent; +import org.apache.tuscany.model.assembly.ModuleFragment; +import org.apache.tuscany.model.assembly.Multiplicity; +import org.apache.tuscany.model.assembly.Property; +import org.apache.tuscany.model.assembly.Reference; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.ServiceURI; +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.Subsystem; +import org.apache.tuscany.model.assembly.Wire; +import org.apache.tuscany.model.assembly.Binding; +import org.apache.tuscany.model.assembly.ServiceContract; +import org.apache.tuscany.model.assembly.ImportWSDL; +import org.apache.tuscany.model.types.java.JavaServiceContract; +import org.apache.tuscany.model.types.java.impl.JavaServiceContractImpl; +import org.apache.tuscany.model.types.wsdl.WSDLServiceContract; +import org.apache.tuscany.model.types.wsdl.impl.WSDLServiceContractImpl; + +/** + * Default implementation of AssemblyFactory + */ +public class AssemblyFactoryImpl implements AssemblyFactory { + + /** + * Constructor + */ + public AssemblyFactoryImpl() { + super(); + } + + public AtomicComponent createSimpleComponent() { + return new AtomicComponentImpl(); + } + + public ComponentType createComponentType() { + return new ComponentTypeImpl(); + } + + public EntryPoint createEntryPoint() { + return new EntryPointImpl(); + } + + public ExternalService createExternalService() { + return new ExternalServiceImpl(); + } + + public JavaServiceContract createJavaServiceContract() { + return new JavaServiceContractImpl(); + } + + public Module createModule() { + return new ModuleImpl(); + } + + public ModuleFragment createModuleFragment() { + return new ModuleFragmentImpl(); + } + + public ModuleComponent createModuleComponent() { + return new ModuleComponentImpl(); + } + + public Property createProperty() { + return new PropertyImpl(); + } + + public ConfiguredProperty createConfiguredProperty() { + return new ConfiguredPropertyImpl(); + } + + public Reference createReference() { + return new ReferenceImpl(); + } + + public ConfiguredReference createConfiguredReference() { + return new ConfiguredReferenceImpl(); + } + + public Service createService() { + return new ServiceImpl(); + } + + public ConfiguredService createConfiguredService() { + return new ConfiguredServiceImpl(); + } + + public Subsystem createSubsystem() { + return new SubsystemImpl(); + } + + public WSDLServiceContract createWSDLServiceContract() { + return new WSDLServiceContractImpl(); + } + + public ServiceURI createServiceURI(String uri) { + return new ServiceURIImpl(uri); + } + + public ServiceURI createServiceURI(ModuleComponent moduleComponent, String serviceName) { + return new ServiceURIImpl(moduleComponent, serviceName); + } + + public ServiceURI createServiceURI(ModuleComponent moduleComponent, Part part, ConfiguredPort configuredPort) { + return new ServiceURIImpl(moduleComponent, part, configuredPort); + } + + public ServiceURI createServiceURI(ModuleComponent moduleComponent, String partName, String serviceName) { + return new ServiceURIImpl(moduleComponent,partName,serviceName); + } + + public QName createQName(String uri) { + int h = uri.indexOf('#'); + return new QName(uri.substring(0, h), uri.substring(h + 1)); + } + + public Wire createWire() { + return new WireImpl(); + } + + public Reference createReference(String name, Class<?> service) { + return createReference(name,service,Multiplicity.ZERO_ONE); + } + + public Reference createReference(String name, Class<?> service, Multiplicity multiplicity){ + JavaServiceContract refContract = createJavaServiceContract(); + refContract.setInterface(service); + Reference reference = createReference(); + reference.setName(name); + reference.setServiceContract(refContract); + reference.setMultiplicity(multiplicity); + return reference; + } + + public ConfiguredReference createConfiguredReference(String name, String... targets) { + ConfiguredReference ref = createConfiguredReference(); + ref.setName(name); + for (String target : targets) { + ref.getTargets().add(target); + } + return ref; + } + + public EntryPoint createEntryPoint(String entryPointName, ServiceContract serviceContract, Binding binding, String targetName) { + // create and configure the exposed service + Service service = createService(); + service.setName(entryPointName); + service.setServiceContract(serviceContract); + ConfiguredService configuredService = createConfiguredService(); + configuredService.setPort(service); + + // create and configure a reference to target + Reference reference = createReference(); + reference.setMultiplicity(Multiplicity.ONE_ONE); + reference.setServiceContract(serviceContract); + ConfiguredReference configuredReference = createConfiguredReference(null, targetName); + configuredReference.setPort(reference); + + return createEntryPoint(entryPointName, configuredService, binding, configuredReference); + } + + public EntryPoint createEntryPoint(String entryPointName, ConfiguredService configuredService, Binding binding, ConfiguredReference configuredReference) { + EntryPoint entryPoint = createEntryPoint(); + entryPoint.setName(entryPointName); + entryPoint.setConfiguredService(configuredService); + entryPoint.setConfiguredReference(configuredReference); + entryPoint.getBindings().add((Binding)binding); + return entryPoint; + } + + public Property createProperty(String name, Class<?> type) { + Property property = createProperty(); + property.setName(name); + property.setType(type); + return property; + } + + public ImportWSDL createImportWSDL() { + return new ImportWSDLImpl(); + } + + public ImportWSDL createImportWSDL(String location, String namespace) { + ImportWSDL importWSDL = createImportWSDL(); + importWSDL.setLocation(location); + importWSDL.setNamespace(namespace); + return importWSDL; + } +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AssemblyObjectImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AssemblyObjectImpl.java new file mode 100644 index 0000000000..38056e1e1c --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AssemblyObjectImpl.java @@ -0,0 +1,123 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyObject; +import org.apache.tuscany.model.assembly.AssemblyVisitor; + +/** + * A base class for assembly model objects. + */ +public abstract class AssemblyObjectImpl implements AssemblyObject { + + private boolean frozen; + private boolean initialized; + + protected AssemblyObjectImpl() { + } + + public boolean accept(AssemblyVisitor visitor) { + return visitor.visit(this); + } + + /** + * Walk a visitor through a collection of model objects. + * @param collection + * @param visitor + */ + protected boolean accept(Collection collection, AssemblyVisitor visitor) { + for (Object member : collection) { + if (member instanceof AssemblyObject) { + if (!((AssemblyObject)member).accept(visitor)) + return false; + } + } + return true; + } + + public void freeze() { + if (!frozen) + frozen=true; + } + + /** + * Returns true if the object is frozen + */ + protected boolean isFrozen() { + return frozen; + } + + /** + * Freeze a list and its members + */ + protected <T> List<T> freeze(List<T> list) { + list=Collections.unmodifiableList(list); + for (Object member : list) { + if (member instanceof AssemblyObject) { + ((AssemblyObject)member).freeze(); + } + } + return list; + } + + /** + * Check that the current model object can be modified. + * @throws IllegalStateException + */ + protected void checkNotFrozen() { + if (frozen) + throw new IllegalStateException("Attempt to modify a frozen assembly model"); + } + + public void initialize(AssemblyContext modelContext) { + if (!initialized) + initialized=true; + } + + /** + * Returns true if the object is initialized + */ + protected boolean isInitialized() { + return initialized; + } + + /** + * Initialize members of a collection + */ + protected void initialize(Collection collection, AssemblyContext modelContext) { + for (Object member : collection) { + if (member instanceof AssemblyObject) { + ((AssemblyObject)member).initialize(modelContext); + } + } + } + + /** + * Check that the current model object is initialized. + * @throws IllegalStateException + */ + protected void checkInitialized() { + if (!initialized) + throw new IllegalStateException("Attempt to use an uninitialized assembly model"); + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AtomicComponentImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AtomicComponentImpl.java new file mode 100644 index 0000000000..186d685d12 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AtomicComponentImpl.java @@ -0,0 +1,30 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.AtomicComponent; +import org.apache.tuscany.model.assembly.AtomicImplementation; + +/** + * An implementation of AtomicComponent. + */ +public class AtomicComponentImpl extends ComponentImpl<AtomicImplementation> implements AtomicComponent { + + protected AtomicComponentImpl() { + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AtomicImplementationImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AtomicImplementationImpl.java new file mode 100644 index 0000000000..1f85afa2cc --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AtomicImplementationImpl.java @@ -0,0 +1,29 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.AtomicImplementation; + +/** + * An implementation of AtomicImplementation. + */ +public abstract class AtomicImplementationImpl extends ImplementationImpl implements AtomicImplementation { + + protected AtomicImplementationImpl() { + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/BindingImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/BindingImpl.java new file mode 100644 index 0000000000..c13dabb17e --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/BindingImpl.java @@ -0,0 +1,62 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.Binding; + +/** + * An implementation of Binding. + */ +public class BindingImpl extends ExtensibleImpl implements Binding { + + private String uri; + + protected BindingImpl() { + } + + public String getURI() { + return uri; + } + + public void setURI(String value) { + checkNotFrozen(); + uri=value; + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + return true; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ComponentImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ComponentImpl.java new file mode 100644 index 0000000000..a952ebe34d --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ComponentImpl.java @@ -0,0 +1,213 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyFactory; +import org.apache.tuscany.model.assembly.AssemblyInitializationException; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.Component; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.ConfiguredPort; +import org.apache.tuscany.model.assembly.ConfiguredProperty; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.Implementation; +import org.apache.tuscany.model.assembly.Property; +import org.apache.tuscany.model.assembly.Reference; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.util.NotifyingList; + +/** + * An implementation of Component. + */ +public abstract class ComponentImpl<I extends Implementation> extends PartImpl implements Component<I> { + + /** + * A list of configured ports synchronized with a map + */ + private class ConfiguredPortList<E extends ConfiguredPort> extends NotifyingList<E>{ + + Map<String, E> map; + + private ConfiguredPortList(Map<String, E> map) { + this.map=map; + } + + protected void added(E element) { + String name=element.getPort()!=null? element.getPort().getName():element.getName(); + map.put(name, element); + element.setPart(ComponentImpl.this); + } + protected void removed(E element) { + String name=element.getPort()!=null? element.getPort().getName():element.getName(); + map.remove(name); + element.setPart(null); + } + } + + private Map<String, ConfiguredReference> configuredReferencesMap = new HashMap<String, ConfiguredReference>(); + private List<ConfiguredReference> configuredReferences = new ConfiguredPortList<ConfiguredReference>(configuredReferencesMap); + + private Map<String, ConfiguredService> configuredServicesMap = new HashMap<String, ConfiguredService>(); + private List<ConfiguredService> configuredServices = new ConfiguredPortList<ConfiguredService>(configuredServicesMap); + + /** + * A list of properties synchronized with a map + */ + private class ConfiguredPropertyList<E extends ConfiguredProperty> extends NotifyingList<E>{ + + protected void added(E element) { + String name=element.getProperty()!=null? element.getProperty().getName():element.getName(); + configuredPropertiesMap.put(name, element); + } + protected void removed(E element) { + String name=element.getProperty()!=null? element.getProperty().getName():element.getName(); + configuredPropertiesMap.remove(name); + } + } + + private List<ConfiguredProperty> configuredProperties = new ConfiguredPropertyList<ConfiguredProperty>(); + private Map<String, ConfiguredProperty> configuredPropertiesMap=new HashMap<String, ConfiguredProperty>(); + + private I implementation; + + public I getImplementation() { + return implementation; + } + + public void setImplementation(I value) { + checkNotFrozen(); + implementation = value; + } + + public List<ConfiguredService> getConfiguredServices() { + return configuredServices; + } + + public ConfiguredService getConfiguredService(String name) { + return configuredServicesMap.get(name); + } + + public List<ConfiguredReference> getConfiguredReferences() { + return configuredReferences; + } + + public ConfiguredReference getConfiguredReference(String name) { + return configuredReferencesMap.get(name); + } + + public List<ConfiguredProperty> getConfiguredProperties() { + return configuredProperties; + } + + public ConfiguredProperty getConfiguredProperty(String name) { + return configuredPropertiesMap.get(name); + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + // Initialize the implementation + if (implementation == null) { + throw new AssemblyInitializationException("No implementation for component [" + getName() + ']'); + } + implementation.initialize(modelContext); + + // Derive the configured services from the component implementation + ComponentType componentType=implementation.getComponentType(); + AssemblyFactory factory = modelContext.getAssemblyFactory(); + for (Service service : componentType.getServices()) { + ConfiguredService configuredService = factory.createConfiguredService(); + configuredService.setPort(service); + configuredServices.add(configuredService); + configuredService.initialize(modelContext); + } + + // Derive the configured references from the references on the component info + for (Reference reference : componentType.getReferences()) { + ConfiguredReference configuredReference = configuredReferencesMap.get(reference.getName()); + if (configuredReference==null) { + configuredReference=factory.createConfiguredReference(); + configuredReference.setPort(reference); + configuredReferences.add(configuredReference); + configuredReference.initialize(modelContext); + } else { + configuredReference.setPort(reference); + configuredReference.initialize(modelContext); + } + } + for (ConfiguredReference configuredReference : configuredReferences) { + if (configuredReference.getPort()==null) { + throw new AssemblyInitializationException("Undefined reference ["+configuredReference.getName()+"]"); + } + } + + // Derive the configured properties from the properties on the component info + for (Property property : componentType.getProperties()) { + ConfiguredProperty configuredProperty = configuredPropertiesMap.get(property.getName()); + if (configuredProperty != null) { + configuredProperty.setProperty(property); + configuredProperty.initialize(modelContext); + } + } + for (ConfiguredProperty configuredProperty : configuredProperties) { + if (configuredProperty.getProperty()==null) { + throw new AssemblyInitializationException("Undefined property ["+configuredProperty.getName()+"]"); + } + } + + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + // Freeze configured services, references and properties + configuredServices = freeze(configuredServices); + configuredReferences = freeze(configuredReferences); + configuredProperties = freeze(configuredProperties); + if (implementation != null) + implementation.freeze(); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + if (!accept(configuredServices, visitor)) + return false; + if (!accept(configuredReferences, visitor)) + return false; + if (!accept(configuredProperties, visitor)) + return false; + if (implementation != null) { + if (!implementation.accept(visitor)) + return false; + } + + return true; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ComponentTypeImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ComponentTypeImpl.java new file mode 100644 index 0000000000..617206b6af --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ComponentTypeImpl.java @@ -0,0 +1,147 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Port; +import org.apache.tuscany.model.assembly.Property; +import org.apache.tuscany.model.assembly.Reference; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.util.NotifyingList; + +/** + * An implementation of ComponentType. + */ +public class ComponentTypeImpl extends ExtensibleImpl implements ComponentType { + + /** + * A list of ports synchronized with a map + */ + private class PortList<E extends Port> extends NotifyingList<E>{ + + Map<String, E> map; + + private PortList(Map<String, E> map) { + this.map=map; + } + + protected void added(E element) { + map.put(element.getName(), element); + } + protected void removed(E element) { + map.remove(element.getName()); + } + } + + private Map<String, Reference> referencesMap=new HashMap<String, Reference>(); + private List<Reference> references=new PortList<Reference>(referencesMap); + + private Map<String, Service> servicesMap=new HashMap<String, Service>(); + private List<Service> services=new PortList<Service>(servicesMap); + + /** + * A list of properties synchronized with a map + */ + private class PropertyList<E extends Property> extends NotifyingList<E>{ + + protected void added(E element) { + propertiesMap.put(element.getName(), element); + } + protected void removed(E element) { + propertiesMap.remove(element.getName()); + } + } + + private Map<String, Property> propertiesMap=new HashMap<String, Property>(); + private List<Property> properties=new PropertyList<Property>(); + + protected ComponentTypeImpl() { + } + + public List<Reference> getReferences() { + return references; + } + + public Reference getReference(String name) { + return referencesMap.get(name); + } + + public List<Service> getServices() { + return services; + } + + public Service getService(String name) { + return servicesMap.get(name); + } + + public List<Property> getProperties() { + return properties; + } + + public Property getProperty(String name) { + return propertiesMap.get(name); + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + // Initialize references, properties and services + for (Reference reference : references) { + reference.initialize(modelContext); + } + for (Property property : properties) { + property.initialize(modelContext); + } + for (Service service : services) { + service.initialize(modelContext); + } + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + // Freeze lists of services, references and properties + services=freeze(services); + references=freeze(references); + properties=freeze(properties); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + if (!accept(services, visitor)) + return false; + if (!accept(references, visitor)) + return false; + if (!accept(properties, visitor)) + return false; + + return true; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/CompositeImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/CompositeImpl.java new file mode 100644 index 0000000000..fff32e3398 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/CompositeImpl.java @@ -0,0 +1,357 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyFactory; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.Component; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Composite; +import org.apache.tuscany.model.assembly.ConfiguredProperty; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.EntryPoint; +import org.apache.tuscany.model.assembly.ExternalService; +import org.apache.tuscany.model.assembly.Implementation; +import org.apache.tuscany.model.assembly.ImportWSDL; +import org.apache.tuscany.model.assembly.Multiplicity; +import org.apache.tuscany.model.assembly.OverrideOption; +import org.apache.tuscany.model.assembly.Part; +import org.apache.tuscany.model.assembly.Reference; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.ServiceContract; +import org.apache.tuscany.model.assembly.ServiceURI; +import org.apache.tuscany.model.assembly.Wire; +import org.apache.tuscany.model.util.NotifyingList; + +/** + * An implementation of Composite. + */ +public abstract class CompositeImpl extends ExtensibleImpl implements Composite { + + private String name; + private ComponentType componentType; + private Class<?> implementationClass; + + /** + * A list of parts synchronized with a map + */ + private class PartList<E extends Part> extends NotifyingList<E> { + protected void added(E element) { + partsMap.put(element.getName(), element); + element.setComposite(CompositeImpl.this); + } + + protected void removed(E element) { + partsMap.remove(element.getName()); + element.setComposite(null); + } + } + + private Map<String, Part> partsMap = new HashMap<String, Part>(); + + private List<Component> components = new PartList<Component>(); + private List<EntryPoint> entryPoints = new PartList<EntryPoint>(); + private List<ExternalService> externalServices = new PartList<ExternalService>(); + + private List<Wire> wires = new ArrayList<Wire>(); + + /** + * A list of WSDL imports synchronized with a map + */ + private class ImportWSDLList extends NotifyingList<ImportWSDL> { + protected void added(ImportWSDL element) { + List<ImportWSDL> importList = wsdlImportsMap.get(element.getNamespace()); + if (importList == null) { + importList = new ArrayList<ImportWSDL>(); + wsdlImportsMap.put(element.getNamespace(), importList); + } + importList.add(element); + } + + protected void removed(ImportWSDL element) { + List<ImportWSDL> importList = wsdlImportsMap.get(element.getNamespace()); + if (importList != null) { + importList.remove(element); + if (importList.isEmpty()) + wsdlImportsMap.remove(element.getNamespace()); + } + } + } + + private Map<String, List<ImportWSDL>> wsdlImportsMap = new HashMap<String, List<ImportWSDL>>(); + + private List<ImportWSDL> wsdlImports = new ImportWSDLList(); + + protected CompositeImpl() { + } + + public String getName() { + return name; + } + + public void setName(String newName) { + checkNotFrozen(); + name = newName; + } + + public List<Component> getComponents() { + return components; + } + + public List<EntryPoint> getEntryPoints() { + return entryPoints; + } + + public List<ExternalService> getExternalServices() { + return externalServices; + } + + public Part getPart(String name) { + return partsMap.get(name); + } + + public List<Wire> getWires() { + return wires; + } + + public List<ImportWSDL> getWSDLImports() { + return wsdlImports; + } + + public List<ImportWSDL> getWSDLImports(String namespace) { + return wsdlImportsMap.get(namespace); + } + + public ComponentType getComponentType() { + return componentType; + } + + public void setComponentType(ComponentType componentType) { + checkNotFrozen(); + this.componentType = componentType; + } + + public ConfiguredService getConfiguredService(ServiceURI address) { + String partName = address.getPartName(); + String serviceName = address.getServiceName(); + Part part = getPart(partName); + if (part instanceof Component) { + Component<?> component = (Component<?>) part; + if (serviceName != null) { + return component.getConfiguredService(serviceName); + } else { + if (!component.getConfiguredServices().isEmpty()) { + return component.getConfiguredServices().get(0); + } else { + return null; + } + } + + } + if (part instanceof ExternalService) { + ExternalService externalService = (ExternalService) part; + return externalService.getConfiguredService(); + } else + return null; + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + // Initialize WSDL imports + for (ImportWSDL importWSDL : wsdlImports) { + importWSDL.initialize(modelContext); + } + + // Initialize parts + for (Part part : externalServices) { + part.initialize(modelContext); + } + for (Part part : components) { + part.initialize(modelContext); + } + for (Part part : entryPoints) { + part.initialize(modelContext); + } + + // Derive the component type from the entry points and external services in the composite + // Also derive properties from the overridable properties of the components in the composite + if (componentType == null) { + AssemblyFactory factory = modelContext.getAssemblyFactory(); + componentType = factory.createComponentType(); + for (EntryPoint entryPoint : getEntryPoints()) { + Service service = factory.createService(); + service.setName(entryPoint.getName()); + ServiceContract serviceContract = entryPoint.getConfiguredService().getPort().getServiceContract(); + if (serviceContract != null) + service.setServiceContract(serviceContract); + componentType.getServices().add(service); + + ConfiguredReference configuredReference = entryPoint.getConfiguredReference(); + ServiceURI sourceURI = factory.createServiceURI(null, entryPoint, configuredReference); + for (String target : configuredReference.getTargets()) { + ServiceURI targetURI = factory.createServiceURI(null, target); + Wire wire = factory.createWire(); + wire.setSource(sourceURI); + wire.setTarget(targetURI); + getWires().add(wire); + } + } + for (ExternalService externalService : getExternalServices()) { + if (externalService.getOverrideOption() == null || externalService.getOverrideOption() == OverrideOption.NO) + continue; + Reference reference = factory.createReference(); + reference.setName(externalService.getName()); + ServiceContract serviceContract = externalService.getConfiguredService().getPort().getServiceContract(); + if (serviceContract != null) + reference.setServiceContract(serviceContract); + componentType.getReferences().add(reference); + } + for (Component<Implementation> component : getComponents()) { + for (ConfiguredProperty configuredProperty : component.getConfiguredProperties()) { + if (configuredProperty.getOverrideOption() == null || configuredProperty.getOverrideOption() == OverrideOption.NO) + continue; + componentType.getProperties().add(configuredProperty.getProperty()); + } + + for (ConfiguredReference configuredReference : component.getConfiguredReferences()) { + // Create a wire + ServiceURI sourceURI = factory.createServiceURI(null, component, configuredReference); + for (String target : configuredReference.getTargets()) { + ServiceURI targetURI = factory.createServiceURI(null, target); + Wire wire = factory.createWire(); + wire.setSource(sourceURI); + wire.setTarget(targetURI); + getWires().add(wire); + } + } + } + } + componentType.initialize(modelContext); + + // Wire the parts in this composite + wire(modelContext); + } + + /** + * Wire the parts in this composite. + * @param modelContext + */ + protected void wire(AssemblyContext modelContext) { + for (Wire wire : getWires()) { + + // Get the source reference + ServiceURI sourceURI = wire.getSource(); + ConfiguredReference configuredReference = null; + String partName = sourceURI.getPartName(); + String referenceName = sourceURI.getServiceName(); + if (referenceName != null) { + //Component<?> component = (Component<?>)getPart(partName); +// if (component != null) { + Part part = getPart(partName); + if (part instanceof Component) { + configuredReference = ((Component) part).getConfiguredReference(referenceName); + } else if (part instanceof EntryPoint) { + configuredReference = ((EntryPoint) part).getConfiguredReference(); + } + } else { + EntryPoint entryPoint = (EntryPoint) getPart(partName); + if (entryPoint != null) { + configuredReference = entryPoint.getConfiguredReference(); + } + } + if (configuredReference == null) { + throw new IllegalArgumentException("Cannot find wire source " + sourceURI.getPath()); + } else { + + // Resolve the target service endpoint + ServiceURI targetURI = wire.getTarget(); + ConfiguredService configuredService = getConfiguredService(targetURI); + if (configuredService != null) { + + // Wire the reference to the target + Multiplicity multiplicity = configuredReference.getPort().getMultiplicity(); + if (multiplicity == Multiplicity.ZERO_N || multiplicity == Multiplicity.ONE_N) { + configuredReference.getTargetConfiguredServices().add(configuredService); + } else { + configuredReference.getTargetConfiguredServices().clear(); + configuredReference.getTargetConfiguredServices().add(configuredService); + } + } else { + throw new IllegalArgumentException("Cannot find service '" + targetURI.getPath() +"'."); + } + } + } + } + + public Class<?> getImplementationClass() { + return implementationClass; + } + + public void setImplementationClass(Class<?> clazz) { + checkNotFrozen(); + this.implementationClass = clazz; + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + // Freeze component type + if (componentType != null) + componentType.freeze(); + + // Freeze lists + wsdlImports = freeze(wsdlImports); + components = freeze(components); + entryPoints = freeze(entryPoints); + externalServices = freeze(externalServices); + wires = freeze(wires); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + if (!accept(wsdlImports, visitor)) + return false; + + if (!accept(partsMap.values(), visitor)) + return false; + + if (!accept(wires, visitor)) + return false; + + if (componentType != null) { + if (!componentType.accept(visitor)) + return false; + } + + return true; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredPortImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredPortImpl.java new file mode 100644 index 0000000000..f1007e8c07 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredPortImpl.java @@ -0,0 +1,106 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.Part; +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.ConfiguredPort; +import org.apache.tuscany.model.assembly.Port; + +/** + * Implementation of ConfiguredPort. + */ +public abstract class ConfiguredPortImpl<P extends Port> extends AssemblyObjectImpl implements ConfiguredPort<P> { + private String name; + private Part part; + private P port; + + private Object proxyFactory; + + protected ConfiguredPortImpl() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + checkNotFrozen(); + this.name=name; + } + + public P getPort() { + return port; + } + + public void setPort(P port) { + checkNotFrozen(); + this.port = port; + } + + public Part getPart() { + return part; + } + + public void setPart(Part part) { + checkNotFrozen(); + this.part=part; + } + + public Object getProxyFactory() { + return proxyFactory; + } + + public void setProxyFactory(Object proxyFactory) { + checkNotFrozen(); + this.proxyFactory = proxyFactory; + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + if (port!=null) { + name=port.getName(); + port.initialize(modelContext); + } + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + if (port!=null) + port.freeze(); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + if (port!=null) { + if (!port.accept(visitor)) + return false; + } + + return true; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredPropertyImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredPropertyImpl.java new file mode 100644 index 0000000000..4c64676451 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredPropertyImpl.java @@ -0,0 +1,102 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.ConfiguredProperty; +import org.apache.tuscany.model.assembly.OverrideOption; +import org.apache.tuscany.model.assembly.Property; + +/** + * Implementation of ConfiguredProperty + */ +public class ConfiguredPropertyImpl extends AssemblyObjectImpl implements ConfiguredProperty { + private String name; + private OverrideOption overrideOption; + private Object value; + private Property property; + + protected ConfiguredPropertyImpl() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Property getProperty() { + return property; + } + + public void setProperty(Property property) { + checkNotFrozen(); + this.property = property; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + checkNotFrozen(); + this.value = value; + } + + public OverrideOption getOverrideOption() { + return overrideOption; + } + + public void setOverrideOption(OverrideOption value) { + checkNotFrozen(); + this.overrideOption=value; + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + if (property!=null) + property.initialize(modelContext); + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + if (property!=null) + property.freeze(); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + if (property!=null) { + if (!property.accept(visitor)) + return false; + } + + return true; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredReferenceImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredReferenceImpl.java new file mode 100644 index 0000000000..f21a5be52e --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredReferenceImpl.java @@ -0,0 +1,53 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.Reference; + +/** + * An implementation of ConfiguredReference. + */ +public class ConfiguredReferenceImpl extends ConfiguredPortImpl<Reference> implements ConfiguredReference { + + private List<String> targets = new ArrayList<String>(); + + private List<ConfiguredService> targetConfiguredServices = new ArrayList<ConfiguredService>(); + + protected ConfiguredReferenceImpl() { + } + + public List<String> getTargets() { + return targets; + } + + public List<ConfiguredService> getTargetConfiguredServices() { + return targetConfiguredServices; + } + + public void freeze() { + super.freeze(); + + targetConfiguredServices = freeze(targetConfiguredServices); + targets = freeze(targets); + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredServiceImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredServiceImpl.java new file mode 100644 index 0000000000..923af1882c --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ConfiguredServiceImpl.java @@ -0,0 +1,30 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.Service; + +/** + * An implementation of ConfiguredService. + */ +public class ConfiguredServiceImpl extends ConfiguredPortImpl<Service> implements ConfiguredService { + + protected ConfiguredServiceImpl() { + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/EntryPointImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/EntryPointImpl.java new file mode 100644 index 0000000000..a894a7c48f --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/EntryPointImpl.java @@ -0,0 +1,116 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.Binding; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.EntryPoint; + +/** + * An implementation of EntryPoint. + */ +public class EntryPointImpl extends PartImpl implements EntryPoint { + + private ConfiguredService configuredService; + private ConfiguredReference configuredReference; + private List<Binding> bindings=new ArrayList<Binding>(); + + protected EntryPointImpl() { + } + + public ConfiguredReference getConfiguredReference() { + return configuredReference; + } + + public void setConfiguredReference(ConfiguredReference configuredReference) { + checkNotFrozen(); + configuredReference.setPart(this); + this.configuredReference=configuredReference; + } + + public ConfiguredService getConfiguredService() { + return configuredService; + } + + public void setConfiguredService(ConfiguredService configuredService) { + checkNotFrozen(); + configuredService.setPart(this); + this.configuredService=configuredService; + } + + public List<Binding> getBindings() { + return bindings; + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + // Initialize the service contract and reference to the published service + if (configuredReference != null) { + configuredReference.initialize(modelContext); + } + if (configuredService != null) { + configuredService.initialize(modelContext); + } + + // Initialize the bindings + initialize(bindings, modelContext); + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + // Freeze the service contract and configured reference + if (configuredReference != null) + configuredReference.freeze(); + if (configuredService != null) + configuredService.freeze(); + + // Freeze the bindings + bindings=freeze(bindings); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + if (configuredReference!=null) { + if (!configuredReference.accept(visitor)) + return false; + } + + if (configuredService!=null) { + if (!configuredService.accept(visitor)) + return false; + } + + if (!accept(bindings, visitor)) + return false; + + return true; + } +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ExtensibleImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ExtensibleImpl.java new file mode 100644 index 0000000000..6adf66dc9e --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ExtensibleImpl.java @@ -0,0 +1,75 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.Extensible; + +/** + * An implementation of Extensible. + */ +public abstract class ExtensibleImpl extends AssemblyObjectImpl implements Extensible { + + private List<Object> extensibilityElements = new ArrayList<Object>(); + private List<Object> extensibilityAttributes = new ArrayList<Object>(); + + protected ExtensibleImpl() { + } + + public List<Object> getExtensibilityElements() { + return extensibilityElements; + } + + public List<Object> getExtensibilityAttributes() { + return extensibilityAttributes; + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + // Initialize extensibility elements and attributes + initialize(extensibilityElements, modelContext); + initialize(extensibilityAttributes, modelContext); + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + // Freeze extensibility elements and attributes + freeze(extensibilityElements); + freeze(extensibilityAttributes); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + if (!accept(extensibilityElements, visitor)) + return false; + return accept(extensibilityAttributes, visitor); + + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ExternalServiceImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ExternalServiceImpl.java new file mode 100644 index 0000000000..9110731c34 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ExternalServiceImpl.java @@ -0,0 +1,116 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.Binding; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.ExternalService; +import org.apache.tuscany.model.assembly.OverrideOption; + +/** + * An implementation ExternalService. + */ +public class ExternalServiceImpl extends PartImpl implements ExternalService { + + private ConfiguredService configuredService; + private OverrideOption overrideOption; + private List<Binding> bindings=new ArrayList<Binding>(); + + private Object contextFactory; + + protected ExternalServiceImpl() { + } + + public OverrideOption getOverrideOption() { + return overrideOption; + } + + public void setOverrideOption(OverrideOption newOverridable) { + checkNotFrozen(); + overrideOption=newOverridable; + } + + public List<Binding> getBindings() { + return bindings; + } + + public ConfiguredService getConfiguredService() { + return configuredService; + } + + public void setConfiguredService(ConfiguredService configuredService) { + checkNotFrozen(); + configuredService.setPart(this); + this.configuredService=configuredService; + } + + public Object getContextFactory() { + return contextFactory; + } + + public void setContextFactory(Object contextFactory) { + this.contextFactory=contextFactory; + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + // Initialize the configured service + if (configuredService != null) { + configuredService.initialize(modelContext); + } + + // Initialize the bindings + initialize(bindings, modelContext); + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + // Freeze the configured service + if (configuredService!= null) + configuredService.freeze(); + + // Freeze the bindings + bindings=freeze(bindings); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + if (configuredService!=null) { + if (!configuredService.accept(visitor)) + return false; + } + + if (!accept(bindings, visitor)) + return false; + + return true; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ImplementationImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ImplementationImpl.java new file mode 100644 index 0000000000..a44d80cc66 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ImplementationImpl.java @@ -0,0 +1,72 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Implementation; + +/** + * An implementation of Implementation. + */ +public abstract class ImplementationImpl extends ExtensibleImpl implements Implementation { + + private ComponentType componentType; + + public ComponentType getComponentType() { + return componentType; + } + + public void setComponentType(ComponentType componentType) { + checkNotFrozen(); + this.componentType=componentType; + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + // Initialize the component type + if (componentType!=null) { + componentType.initialize(modelContext); + } + + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + if (componentType!=null) + componentType.freeze(); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + if (componentType!=null) { + if (!componentType.accept(visitor)) + return false; + } + return true; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ImportWSDLImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ImportWSDLImpl.java new file mode 100644 index 0000000000..56aedd18f5 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ImportWSDLImpl.java @@ -0,0 +1,82 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed 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.model.assembly.impl; + +import java.net.URL; + +import javax.wsdl.Definition; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.ImportWSDL; + +/** + * Implementation of ImportWSDL. + * + * @version $Rev$ $Date$ + */ +public class ImportWSDLImpl extends AssemblyObjectImpl implements ImportWSDL { + private String location; + private String namespace; + private Definition definition; + + protected ImportWSDLImpl() { + } + + public String getLocation() { + return location; + } + + public void setLocation(String uri) { + checkNotFrozen(); + this.location = uri; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String uri) { + checkNotFrozen(); + this.namespace = uri; + } + + public Definition getDefinition() { + return definition; + } + + public void setDefinition(Definition definition) { + checkNotFrozen(); + this.definition = definition; + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + // Load the WSDL definition if necessary + ResourceLoader resourceLoader = modelContext.getApplicationResourceLoader(); + if (definition == null) { + URL url = resourceLoader.getResource(location); + if (url == null) + throw new IllegalArgumentException("Cannot find " + location); + definition = modelContext.getAssemblyLoader().loadDefinition(url.toString()); + } + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ModuleComponentImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ModuleComponentImpl.java new file mode 100644 index 0000000000..60cb42a981 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ModuleComponentImpl.java @@ -0,0 +1,41 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.Module; +import org.apache.tuscany.model.assembly.ModuleComponent; + +/** + * An implementation of ModuleComponent. + */ +public class ModuleComponentImpl extends ComponentImpl<Module> implements ModuleComponent { + + private String uri; + + protected ModuleComponentImpl() { + } + + public String getURI() { + return uri; + } + + public void setURI(String value) { + checkNotFrozen(); + uri=value; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ModuleFragmentImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ModuleFragmentImpl.java new file mode 100644 index 0000000000..08536d23b8 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ModuleFragmentImpl.java @@ -0,0 +1,35 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.ModuleFragment; + +/** + * An implementation of ModuleFragment. + */ +public class ModuleFragmentImpl extends CompositeImpl implements ModuleFragment { + + protected ModuleFragmentImpl() { + } + + protected void wire(AssemblyContext modelContext) { + // No wiring inside a module fragment + // Wires are handled at the module level + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ModuleImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ModuleImpl.java new file mode 100644 index 0000000000..f64317ac86 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ModuleImpl.java @@ -0,0 +1,104 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.Module; +import org.apache.tuscany.model.assembly.ModuleFragment; +import org.apache.tuscany.model.util.NotifyingList; + +/** + * An implementation of Module. + */ +public class ModuleImpl extends CompositeImpl implements Module { + + /** + * A list of module fragments synchronized with a map + */ + private class ModuleFragmentList<E extends ModuleFragment> extends NotifyingList<E> { + protected void added(E element) { + moduleFragmentsMap.put(element.getName(), element); + } + + protected void removed(E element) { + moduleFragmentsMap.remove(element.getName()); + } + } + + private List<ModuleFragment> moduleFragments = new ModuleFragmentList<ModuleFragment>(); + private Map<String, ModuleFragment> moduleFragmentsMap = new HashMap<String, ModuleFragment>(); + + /** + * Constructor + */ + protected ModuleImpl() { + } + + public List<ModuleFragment> getModuleFragments() { + return moduleFragments; + } + + public ModuleFragment getModuleFragment(String name) { + checkInitialized(); + return moduleFragmentsMap.get(name); + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + + // Initialize module fragments + for (ModuleFragment moduleFragment : moduleFragments) { + + // Add all WSDL imports, components, entry points and external services from the module fragments + getWSDLImports().addAll(moduleFragment.getWSDLImports()); + getComponents().addAll(moduleFragment.getComponents()); + getEntryPoints().addAll(moduleFragment.getEntryPoints()); + getExternalServices().addAll(moduleFragment.getExternalServices()); + + // Add all the wires from the module fragments + getWires().addAll(moduleFragment.getWires()); + + moduleFragment.initialize(modelContext); + } + + // Initialize the composite + super.initialize(modelContext); + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + moduleFragments = freeze(moduleFragments); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + return accept(moduleFragments, visitor); + + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PartImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PartImpl.java new file mode 100644 index 0000000000..3743c7505b --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PartImpl.java @@ -0,0 +1,61 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.Composite; +import org.apache.tuscany.model.assembly.Part; + +/** + * Implementation of Part. + */ +public abstract class PartImpl extends ExtensibleImpl implements Part { + private Composite composite; + private String name; + + private Object contextFactory; + + protected PartImpl() { + } + + public String getName() { + return name; + } + + public void setName(String value) { + checkNotFrozen(); + name=value; + } + + public Composite getComposite() { + return composite; + } + + public void setComposite(Composite composite) { + checkNotFrozen(); + this.composite=composite; + } + + public Object getContextFactory() { + return contextFactory; + } + + public void setContextFactory(Object contextFactory) { + checkNotFrozen(); + this.contextFactory=contextFactory; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PortImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PortImpl.java new file mode 100644 index 0000000000..c11cee590a --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PortImpl.java @@ -0,0 +1,82 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.AssemblyVisitor; +import org.apache.tuscany.model.assembly.Port; +import org.apache.tuscany.model.assembly.ServiceContract; + +/** + * An implementation of Port. + */ +public abstract class PortImpl extends AssemblyObjectImpl implements Port { + + private ServiceContract serviceContract; + private String name; + + protected PortImpl() { + } + + public String getName() { + return name; + } + + public void setName(String value) { + checkNotFrozen(); + name=value; + } + + public ServiceContract getServiceContract() { + return serviceContract; + } + + public void setServiceContract(ServiceContract value) { + checkNotFrozen(); + serviceContract=value; + } + + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + if (serviceContract!=null) + serviceContract.initialize(modelContext); + } + + public void freeze() { + if (isFrozen()) + return; + super.freeze(); + + if (serviceContract!=null) + serviceContract.freeze(); + } + + public boolean accept(AssemblyVisitor visitor) { + if (!super.accept(visitor)) + return false; + + if (serviceContract!=null) { + if (!serviceContract.accept(visitor)) + return false; + } + + return true; + } +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PropertyImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PropertyImpl.java new file mode 100644 index 0000000000..e91245504b --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PropertyImpl.java @@ -0,0 +1,80 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.Property; + +/** + * An implementation of Property. + */ +public class PropertyImpl extends ExtensibleImpl implements Property { + + private Object defaultValue; + private String name; + private boolean many; + private boolean required; + private Class<?> type; + + protected PropertyImpl() { + } + + public Object getDefaultValue() { + return defaultValue; + } + + public String getName() { + return name; + } + + public Class<?> getType() { + return type; + } + + public boolean isMany() { + return many; + } + + public boolean isRequired() { + return required; + } + + public void setDefaultValue(Object value) { + checkNotFrozen(); + defaultValue = value; + } + + public void setMany(boolean value) { + checkNotFrozen(); + many = value; + } + + public void setName(String value) { + checkNotFrozen(); + name = value; + } + + public void setRequired(boolean value) { + checkNotFrozen(); + required = value; + } + + public void setType(Class<?> value) { + checkNotFrozen(); + type = value; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ReferenceImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ReferenceImpl.java new file mode 100644 index 0000000000..1a064e5092 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ReferenceImpl.java @@ -0,0 +1,41 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.Multiplicity; +import org.apache.tuscany.model.assembly.Reference; + +/** + * An implementation of Reference. + */ +public class ReferenceImpl extends PortImpl implements Reference { + + private Multiplicity multiplicity; + + protected ReferenceImpl() { + } + + public Multiplicity getMultiplicity() { + return multiplicity; + } + + public void setMultiplicity(Multiplicity multiplicity) { + checkNotFrozen(); + this.multiplicity=multiplicity; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ServiceContractImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ServiceContractImpl.java new file mode 100644 index 0000000000..f71702792b --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ServiceContractImpl.java @@ -0,0 +1,60 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.Scope; +import org.apache.tuscany.model.assembly.ServiceContract; + +/** + * An implementation of ServiceContract. + */ +public class ServiceContractImpl extends ExtensibleImpl implements ServiceContract { + + private Class interface_; + private Class callbackInterface; + private Scope scope; + + protected ServiceContractImpl() { + } + + public Class getCallbackInterface() { + return callbackInterface; + } + + public Class getInterface() { + return interface_; + } + + public Scope getScope() { + return scope; + } + + public void setCallbackInterface(Class value) { + checkNotFrozen(); + callbackInterface=value; + } + + public void setInterface(Class value) { + checkNotFrozen(); + interface_=value; + } + + public void setScope(Scope scope) { + checkNotFrozen(); + this.scope=scope; + } +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ServiceImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ServiceImpl.java new file mode 100644 index 0000000000..d1432d0149 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ServiceImpl.java @@ -0,0 +1,29 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.Service; + +/** + * An implementation of Service. + */ +public class ServiceImpl extends PortImpl implements Service { + + protected ServiceImpl() { + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ServiceURIImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ServiceURIImpl.java new file mode 100644 index 0000000000..ef180814ff --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/ServiceURIImpl.java @@ -0,0 +1,210 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.ConfiguredPort; +import org.apache.tuscany.model.assembly.ConfiguredReference; +import org.apache.tuscany.model.assembly.ConfiguredService; +import org.apache.tuscany.model.assembly.ModuleComponent; +import org.apache.tuscany.model.assembly.Part; +import org.apache.tuscany.model.assembly.Service; +import org.apache.tuscany.model.assembly.ServiceURI; + +/** + * An implementation of ServiceURI. + */ +public class ServiceURIImpl implements ServiceURI { + + private String address; + private Boolean isSCAScheme; + private boolean isParsed; + private String moduleComponentName; + private String partName; + private String serviceName; + + /** + * Constructs a new ServiceURIImpl. + * @param address + */ + protected ServiceURIImpl(String address) { + this.address = address; + } + + /** + * Constructs a new ServiceURIImpl. + * @param moduleComponent + * @param partName + * @param portName + */ + protected ServiceURIImpl(ModuleComponent moduleComponent, String partName, String portName) { + if (moduleComponent != null) + moduleComponentName = moduleComponent.getName(); + else + moduleComponentName = ""; + this.partName = partName; + this.serviceName = portName; + } + + /** + * Constructs a new ServiceURIImpl. + * @param moduleComponent + * @param configuredPort + */ + protected ServiceURIImpl(ModuleComponent moduleComponent, Part part, ConfiguredPort configuredPort) { + if (moduleComponent != null) + moduleComponentName = moduleComponent.getName(); + else + moduleComponentName = ""; + if (configuredPort instanceof ConfiguredService) { + partName = part.getName(); + ConfiguredService configuredService = (ConfiguredService) configuredPort; + Service service = configuredService.getPort(); + if (service != null) { + serviceName = configuredService.getPort().getName(); + address = "sca:///" + moduleComponentName + '/' + partName + '/' + serviceName; + } else { + address = "sca:///" + moduleComponentName + '/' + partName; + } + + } else if (configuredPort instanceof ConfiguredReference) { + ConfiguredReference configuredReference = (ConfiguredReference) configuredPort; + partName = part.getName(); + serviceName = configuredReference.getPort().getName(); + if (serviceName!=null) + address = "sca:///" + moduleComponentName + '/' + partName + '/' + serviceName; + else + address = "sca:///" + moduleComponentName + '/' + partName; + } + + isSCAScheme = Boolean.TRUE; + isParsed = true; + } + + /** + * Constructor + * + * @param moduleComponent + * @param targetServiceName + */ + protected ServiceURIImpl(ModuleComponent moduleComponent, String targetServiceName) { + if (moduleComponent != null) + moduleComponentName = moduleComponent.getName(); + else + moduleComponentName = ""; + int s = targetServiceName.indexOf('/'); + if (s == -1) { + partName = targetServiceName; + address = "sca:///" + moduleComponentName + '/' + partName; + } else { + partName = targetServiceName.substring(0, s); + this.serviceName = targetServiceName.substring(s + 1); + address = "sca:///" + moduleComponentName + '/' + partName + '/' + this.serviceName; + } + isSCAScheme = Boolean.TRUE; + isParsed = true; + } + + public boolean isSCAScheme() { + if (isSCAScheme == null) { + if (address != null && address.startsWith("sca://")) { + isSCAScheme = Boolean.TRUE; + } else { + isSCAScheme = Boolean.FALSE; + } + } + return isSCAScheme.booleanValue(); + } + + public String getAddress() { + return address; + } + + public String getPath() { + StringBuffer path = new StringBuffer(); + String mc = getModuleComponentName(); + if (mc != null) { + path.append(mc); + } + String p = getPartName(); + if (p !=null) { + if (path.length()!=0) + path.append('/'); + path.append(p); + } + String s = getServiceName(); + if (s !=null) { + if (path.length()!=0) + path.append('/'); + path.append(s); + } + return path.toString(); + } + + /** + * Parse the address. + */ + private void parse() { + isParsed = true; + if (isSCAScheme()) { + int s1 = address.indexOf('/', 6); + if (s1 == -1) + return; + s1++; + int s2 = address.indexOf('/', s1); + if (s2 == -1) + return; + moduleComponentName = address.substring(s1, s2); + s2++; + int s3 = address.indexOf('/', s2); + if (s3 == -1) { + partName = address.substring(s2); + return; + } + partName = address.substring(s2, s3); + s3++; + serviceName = address.substring(s3); + } + } + + /** + * Returns the module component name + */ + public String getModuleComponentName() { + if (!isParsed) + parse(); + return moduleComponentName; + } + + /** + * Returns the part name + */ + public String getPartName() { + if (!isParsed) + parse(); + return partName; + } + + /** + * Returns the service name + */ + public String getServiceName() { + if (!isParsed) + parse(); + return serviceName; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/SubsystemImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/SubsystemImpl.java new file mode 100644 index 0000000000..334e34ba5b --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/SubsystemImpl.java @@ -0,0 +1,51 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.ComponentType; +import org.apache.tuscany.model.assembly.Subsystem; + +/** + * An implementation of Subsystem. + */ +public class SubsystemImpl extends CompositeImpl implements Subsystem { + + private String uri; + + protected SubsystemImpl() { + } + + public String getURI() { + return uri; + } + + public void setURI(String value) { + checkNotFrozen(); + uri=value; + } + + public ComponentType getComponentType() { + //TODO implement + return null; + } + + public void setComponentType(ComponentType componentType) { + } + + + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/WireImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/WireImpl.java new file mode 100644 index 0000000000..c7c4bda7a1 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/WireImpl.java @@ -0,0 +1,51 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.impl; + +import org.apache.tuscany.model.assembly.ServiceURI; +import org.apache.tuscany.model.assembly.Wire; + +/** + * An implementation of Wire. + */ +public class WireImpl extends ExtensibleImpl implements Wire { + + private ServiceURI source; + private ServiceURI target; + + protected WireImpl() { + } + + public ServiceURI getSource() { + return source; + } + + public void setSource(ServiceURI uri) { + checkNotFrozen(); + source=uri; + } + + public ServiceURI getTarget() { + return target; + } + + public void setTarget(ServiceURI uri) { + checkNotFrozen(); + target=uri; + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/loader/AssemblyModelLoader.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/loader/AssemblyModelLoader.java new file mode 100644 index 0000000000..95793cc439 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/assembly/loader/AssemblyModelLoader.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.assembly.loader; + +import java.util.List; + +import javax.wsdl.Definition; + +/** + * An assembly model loader. + */ +public interface AssemblyModelLoader { + + /** + * Load a WSDL definition + */ + Definition loadDefinition(String uri); + + /** + * Load definitions by namespace + */ + List<Definition> loadDefinitions(String namespace); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/AssemblyModelLoadException.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/AssemblyModelLoadException.java new file mode 100644 index 0000000000..6c5e0ef75d --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/AssemblyModelLoadException.java @@ -0,0 +1,42 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.scdl.loader.impl; + +import org.apache.tuscany.common.TuscanyRuntimeException; + +/** + * The root runtime exception for the model loader. + * + * @version $Rev$ $Date$ + */ +public class AssemblyModelLoadException extends TuscanyRuntimeException { + private static final long serialVersionUID = -5891723952359470362L; + + public AssemblyModelLoadException() { + super(); + } + + public AssemblyModelLoadException(String message) { + super(message); + } + + public AssemblyModelLoadException(String message, Throwable cause) { + super(message, cause); + } + + public AssemblyModelLoadException(Throwable cause) { + super(cause); + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/SCDLAssemblyModelLoaderImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/SCDLAssemblyModelLoaderImpl.java new file mode 100644 index 0000000000..8413350e50 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/SCDLAssemblyModelLoaderImpl.java @@ -0,0 +1,71 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.scdl.loader.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; + +import org.apache.tuscany.model.assembly.loader.AssemblyModelLoader; + +/** + */ +public class SCDLAssemblyModelLoaderImpl implements AssemblyModelLoader { + private WSDLReader wsdlReader; + private Map<String, Definition> definitions=new HashMap<String, Definition>(); + private Map<String, List<Definition>> definitionsByNamespace=new HashMap<String, List<Definition>>(); + + public Definition loadDefinition(String uri) { + Definition definition=definitions.get(uri); + if (definition!=null) + return definition; + + try { + if (wsdlReader==null) { + wsdlReader=WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose", false); + } + definition = wsdlReader.readWSDL(uri); + } catch (WSDLException e) { + throw new IllegalArgumentException(e); + } + if (definition==null) + throw new IllegalArgumentException("Could not load WSDL definition at "+uri); + + definitions.put(uri, definition); + + String namespace=definition.getTargetNamespace(); + List<Definition> list=definitionsByNamespace.get(namespace); + if (list==null) { + list=new ArrayList<Definition>(); + definitionsByNamespace.put(namespace, list); + } + list.add(definition); + + return definition; + } + + public List<Definition> loadDefinitions(String namespace) { + return definitionsByNamespace.get(namespace); + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/java/JavaServiceContract.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/java/JavaServiceContract.java new file mode 100644 index 0000000000..68f9dfa6f8 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/java/JavaServiceContract.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.types.java; + +import org.apache.tuscany.model.assembly.ServiceContract; + + +/** + * Represents a Java service contract. + */ +public interface JavaServiceContract extends ServiceContract { + + String getInterfaceName(); + + void setInterfaceName(String interfaceName); + + String getCallbackInterfaceName(); + + void setCallbackInterfaceName(String callbackInterfaceName); +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/java/impl/JavaServiceContractImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/java/impl/JavaServiceContractImpl.java new file mode 100644 index 0000000000..d384bcd670 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/java/impl/JavaServiceContractImpl.java @@ -0,0 +1,89 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.types.java.impl; + +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.impl.ServiceContractImpl; +import org.apache.tuscany.model.types.java.JavaServiceContract; + +/** + * An implementation of JavaServiceContract. + */ +public class JavaServiceContractImpl extends ServiceContractImpl implements JavaServiceContract { + + private String interfaceName; + private String callbackInterfaceName; + + /** + * Constructor + */ + public JavaServiceContractImpl() { + } + + /** + * @param interfaceName The interfaceName to set. + */ + public void setInterfaceName(String interfaceName) { + this.interfaceName = interfaceName; + } + + /** + * @param callbackInterfaceName The callbackInterfaceName to set. + */ + public void setCallbackInterfaceName(String callbackInterfaceName) { + this.callbackInterfaceName = callbackInterfaceName; + } + + public String getInterfaceName() { + return interfaceName; + } + + public String getCallbackInterfaceName() { + return callbackInterfaceName; + } + + /** + * @see org.apache.tuscany.model.assembly.impl.ExtensibleImpl#initialize(org.apache.tuscany.model.assembly.AssemblyContext) + */ + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + + // Load the interface + if (getInterface()==null && interfaceName!=null) { + try { + Class<?> interfaceClass=modelContext.getApplicationResourceLoader().loadClass(interfaceName); + setInterface(interfaceClass); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(e); + } + } + + // Load the callback interface + if (getCallbackInterface()==null && callbackInterfaceName!=null) { + try { + Class<?> callbackInterfaceClass=modelContext.getApplicationResourceLoader().loadClass(callbackInterfaceName); + setInterface(callbackInterfaceClass); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(e); + } + } + + super.initialize(modelContext); + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/wsdl/WSDLServiceContract.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/wsdl/WSDLServiceContract.java new file mode 100644 index 0000000000..999242a4c2 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/wsdl/WSDLServiceContract.java @@ -0,0 +1,51 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.types.wsdl; + +import javax.wsdl.PortType; + +import org.apache.tuscany.model.assembly.ServiceContract; + +/** + * A WSDL service contract. + */ +public interface WSDLServiceContract extends ServiceContract { + + /** + * Returns the WSDL portType. + * @return the WSDL portType + */ + PortType getPortType(); + + /** + * Sets the WSDL portType. + * @param portType + */ + void setPortType(PortType portType); + + /** + * Returns the callback WSDL portType. + * @return the callback WSDL portType + */ + PortType getCallbackPortType(); + + /** + * Sets the callback WSDL portType. + * @param portType + */ + void setCallbackPortType(PortType portType); +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/wsdl/impl/WSDLServiceContractImpl.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/wsdl/impl/WSDLServiceContractImpl.java new file mode 100644 index 0000000000..a596eb539f --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/types/wsdl/impl/WSDLServiceContractImpl.java @@ -0,0 +1,234 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.types.wsdl.impl; + +import static org.objectweb.asm.Opcodes.ACC_ABSTRACT; +import static org.objectweb.asm.Opcodes.ACC_INTERFACE; +import static org.objectweb.asm.Opcodes.ACC_PUBLIC; +import static org.objectweb.asm.Opcodes.V1_5; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Operation; +import javax.wsdl.Part; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.common.resource.ResourceLoader; +import org.apache.tuscany.model.assembly.AssemblyContext; +import org.apache.tuscany.model.assembly.impl.ServiceContractImpl; +import org.apache.tuscany.model.types.wsdl.WSDLServiceContract; +import org.apache.tuscany.model.util.XMLNameUtil; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Type; + +import commonj.sdo.Property; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * An implementation of WSDLServiceContract. + */ +public class WSDLServiceContractImpl extends ServiceContractImpl implements WSDLServiceContract { + + private PortType portType; + + private PortType callbackPortType; + + private static final String[] EMPTY_STRINGS = new String[0]; + + /** + * Constructor + */ + public WSDLServiceContractImpl() { + } + + public PortType getPortType() { + return portType; + } + + public void setPortType(PortType portType) { + checkNotFrozen(); + this.portType = portType; + } + + public PortType getCallbackPortType() { + return callbackPortType; + } + + public void setCallbackPortType(PortType portType) { + checkNotFrozen(); + callbackPortType = portType; + } + + /** + * @see org.apache.tuscany.model.assembly.impl.ExtensibleImpl#initialize(org.apache.tuscany.model.assembly.AssemblyContext) + */ + public void initialize(AssemblyContext modelContext) { + if (isInitialized()) + return; + super.initialize(modelContext); + + // Load the Java interface for the portType + if (portType != null && getInterface() == null) { + QName qname = portType.getQName(); + String interfaceName = XMLNameUtil.getFullyQualifiedClassNameFromQName(qname.getNamespaceURI(), qname.getLocalPart()); + Class<?> interfaceClass; + try { + // Load the interface + interfaceClass = modelContext.getApplicationResourceLoader().loadClass(interfaceName); + } catch (ClassNotFoundException e) { + // Generate the interface on the fly + interfaceClass = generateJavaInterface(modelContext.getTypeHelper(), modelContext.getApplicationResourceLoader(), portType, interfaceName); + } + super.setInterface(interfaceClass); + } + + // Load the Java interface for the callback portType + if (callbackPortType != null && getCallbackInterface() == null) { + QName qname = callbackPortType.getQName(); + String interfaceName = XMLNameUtil.getFullyQualifiedClassNameFromQName(qname.getNamespaceURI(), qname.getLocalPart()); + Class<?> interfaceClass; + try { + // Load the interface + interfaceClass = modelContext.getApplicationResourceLoader().loadClass(interfaceName); + } catch (ClassNotFoundException e) { + // Generate the interface on the fly + interfaceClass = generateJavaInterface(modelContext.getTypeHelper(), modelContext.getApplicationResourceLoader(), portType, interfaceName); + } + super.setCallbackInterface(interfaceClass); + } + } + + /** + * Generate a Java interface from a WSDL portType. + * + * @param portType + * @param interfaceName + * @return a Java interface that provides the same service contract as the WSDL portType + */ + @SuppressWarnings("unchecked") + private static Class<?> generateJavaInterface(TypeHelper typeHelper, ResourceLoader resourceLoader, PortType portType, String interfaceName) { + + ClassLoader cl=Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(resourceLoader.getClassLoader()); + + // Create an XSD helper + XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper); + + ClassWriter cw = new ClassWriter(false); + + // Generate the interface + interfaceName = interfaceName.replace('.', '/'); + cw.visit(V1_5, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, interfaceName, null, "java/lang/Object", EMPTY_STRINGS); + + // Generate methods from the WSDL operations + for (Operation operation : (List<Operation>) portType.getOperations()) { + + //FIXME Workaround for TUSCANY-170, we will need to make this consistent with the algorithm used by Axis2 WSDL2Java + // to generate method names from operations names + //String methodName = XMLNameUtil.getJavaNameFromXMLName(operation.getName(), false); + String methodName = operation.getName(); + + // FIXME later we may want to wwitch to use the Axis2 WSDL2Java (not to generate the Java source, + // just to figure the WSDL to Java mapping) + + // Derive the method signature from the input message part (and check if it's a doc-wrapped or doc-bare operation) + List<Class> inputTypes=new ArrayList<Class>(); + boolean wrapped = false; + if (operation.getInput() != null && operation.getInput().getMessage()!=null && !operation.getInput().getMessage().getParts().isEmpty()) { + QName qname=((Part)operation.getInput().getMessage().getParts().values().iterator().next()).getElementName(); + if (qname!=null) { + Property property = xsdHelper.getGlobalProperty(qname.getNamespaceURI(), qname.getLocalPart(), true); + commonj.sdo.Type type = property.getType(); + if (property.getName().equals(operation.getName())) { + String localName = xsdHelper.getLocalName(type); + if (localName.indexOf("_._")!=-1) { + for (Property param : (List<Property>)type.getProperties()) { + Class inputType = param.getType().getInstanceClass(); + if (inputType == null) + inputType = Object.class; + inputTypes.add(inputType); + } + wrapped=true; + } + } + + // Bare doc style + if (!wrapped) { + Class inputType = type.getInstanceClass(); + if (inputType == null) + inputType = Object.class; + inputTypes.add(inputType); + } + + } else { + // FIXME only support elements for now + } + } + + // Derive the return type from the output message part (also support doc-wrapped and doc-bare here) + Class outputType=Void.class; + if (operation.getOutput() != null && operation.getOutput().getMessage()!=null && !operation.getOutput().getMessage().getParts().isEmpty()) { + QName qname=((Part)operation.getOutput().getMessage().getParts().values().iterator().next()).getElementName(); + if (qname!=null) { + Property property = xsdHelper.getGlobalProperty(qname.getNamespaceURI(), qname.getLocalPart(), true); + commonj.sdo.Type type = property.getType(); + if (wrapped) { + if (!type.getProperties().isEmpty()) { + outputType=((Property)type.getProperties().get(0)).getType().getInstanceClass(); + if (outputType==null) + outputType=Object.class; + } + } else { + outputType = type.getInstanceClass(); + if (outputType==null) + outputType=Object.class; + } + } else { + // FIXME only support elements for now + } + } + + // FIXME integrate XSD to Java type mapping here + StringBuffer inputSignature=new StringBuffer(); + for (Class inputType : inputTypes) { + inputSignature.append(Type.getDescriptor(inputType)); + } + String outputSignature = Type.getDescriptor(outputType); + + cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, methodName, '(' + inputSignature.toString() + ')' + outputSignature, null, null).visitEnd(); + } + + // Generate the bytecodes + cw.visitEnd(); + byte[] bytes = cw.toByteArray(); + + // Add the class to the resource loader + + return resourceLoader.addClass(bytes); + + } finally { + Thread.currentThread().setContextClassLoader(cl); + } + + } + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/util/NotifyingList.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/util/NotifyingList.java new file mode 100644 index 0000000000..1f064e0977 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/util/NotifyingList.java @@ -0,0 +1,108 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * A list that invokes added or removed methods when elements are added or removed. + * + */ +public abstract class NotifyingList<E> extends ArrayList<E> { + + private boolean frozen; + + public NotifyingList() { + } + + public void freeze() { + frozen=true; + } + + protected void checkNotFrozen() { + if (frozen) + throw new IllegalStateException("Attempt to modify a frozen list"); + } + + public boolean add(E element) { + checkNotFrozen(); + boolean result=super.add(element); + added(element); + return result; + } + + public void add(int index, E element) { + checkNotFrozen(); + super.add(index, element); + added(element); + } + + public boolean addAll(Collection<? extends E> c) { + checkNotFrozen(); + boolean result=super.addAll(c); + for (E element : c) + added(element); + return result; + } + + public boolean addAll(int index, Collection<? extends E> c) { + checkNotFrozen(); + boolean result=super.addAll(index, c); + for (E element : c) + added(element); + return result; + } + + public void clear() { + checkNotFrozen(); + List<E> l=new ArrayList<E>(this); + super.clear(); + for (E element : l) + removed(element); + } + + public E remove(int index) { + checkNotFrozen(); + E element=super.remove(index); + removed(element); + return element; + } + + @SuppressWarnings("unchecked") + public boolean remove(Object element) { + checkNotFrozen(); + boolean result=super.remove(element); + removed((E)element); + return result; + } + + @SuppressWarnings("unchecked") + public boolean removeAll(Collection<?> c) { + checkNotFrozen(); + boolean result=super.removeAll(c); + for (E element : (Collection<? extends E>)c) + removed(element); + return result; + } + + protected abstract void added(E element); + + protected abstract void removed(E element); + +} diff --git a/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/util/XMLNameUtil.java b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/util/XMLNameUtil.java new file mode 100644 index 0000000000..f493356594 --- /dev/null +++ b/branches/java-post-M1/sca/model/src/main/java/org/apache/tuscany/model/util/XMLNameUtil.java @@ -0,0 +1,212 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.model.util; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.apache.tuscany.sdo.helper.SDOXSDEcoreBuilder; + + + +/** + * A utility class that converts between XML names and Java names. + */ +public final class XMLNameUtil { + + private static final List<String> DOMAINS = Arrays.asList(new String[]{"COM", "com", "ORG", "org"}); + + /** + * Constructor + */ + private XMLNameUtil() { + super(); + } + + /** + * Return an EPackage name for the given namespace. + * + * @param namespace + * @return an EPackage name for the given namespace + */ + public static String getPackageNameFromNamespace(String namespace) { + return org.apache.tuscany.sdo.helper.SDOXSDEcoreBuilder.getDefaultPackageName(namespace); + } + + /** + * Trim the file extension from a path. + * @param path + * @return + */ + private static String trimFileExtension(String path) { + int s=path.lastIndexOf('/'); + int d=path.lastIndexOf('.'); + if (d>s) { + return path.substring(0,d); + } else { + return path; + } + } + + /** + * Returns a namespace prefix for the given package Name. + * + * @param packageName + * @return a namespace prefix for the given package Name + */ + public static String getNSPrefixFromPackageName(String packageName) { + int index = packageName.lastIndexOf('.'); + return index == -1 ? packageName : packageName.substring(index + 1); + } + + /** + * Parse the given name. + * + * @param sourceName + * @param separator + * @return some stuff parsed from the name + */ + private static List<String> parseName(String sourceName, char separator) { + List<String> result = new ArrayList<String>(); + if (sourceName != null) { + StringBuilder currentWord = new StringBuilder(64); + boolean lastIsLower = false; + int index; + int length; + for (index = 0, length = sourceName.length(); index < length; ++index) { + char curChar = sourceName.charAt(index); + if (!Character.isJavaIdentifierPart(curChar)) { + curChar = separator; + } + if (Character.isUpperCase(curChar) + || (!lastIsLower && Character.isDigit(curChar)) + || curChar == separator) { + + if (lastIsLower && currentWord.length() > 1 + || curChar == separator && currentWord.length() > 0) { + result.add(currentWord.toString()); + currentWord = new StringBuilder(64); + } + lastIsLower = false; + } else { + if (!lastIsLower) { + int currentWordLength = currentWord.length(); + if (currentWordLength > 1) { + char lastChar = currentWord.charAt(--currentWordLength); + currentWord.setLength(currentWordLength); + result.add(currentWord.toString()); + currentWord = new StringBuilder(64); + currentWord.append(lastChar); + } + } + lastIsLower = true; + } + + if (curChar != separator) { + currentWord.append(curChar); + } + } + + result.add(currentWord.toString()); + } + return result; + } + + /** + * Returns a valid Java name from an XML Name. + * + * @param name + * @param isUpperCase + * @return a valid Java name from an XML Name + */ + public static String getJavaNameFromXMLName(String name, boolean isUpperCase) { + List<String> parsedName = parseName(name, '_'); + StringBuilder result = new StringBuilder(64 * parsedName.size()); + for (String nameComponent: parsedName) { + if (nameComponent.length() > 0) { + if (result.length() > 0 || isUpperCase) { + result.append(Character.toUpperCase(nameComponent.charAt(0))); + result.append(nameComponent.substring(1)); + } else { + result.append(nameComponent); + } + } + } + + if (result.length() == 0) { + return "_"; + } + if (Character.isJavaIdentifierStart(result.charAt(0))) { + return isUpperCase ? result.toString() : decapitalizeName(result.toString()); + } + return "_" + result; + } + + /** + * Returns a valid fully qualified class name from a QName. + * @param namespace + * @param name + * @return a valid fully qualified class name from a QName + */ + public static String getFullyQualifiedClassNameFromQName(String namespace, String name) { + return XMLNameUtil.getPackageNameFromNamespace(namespace) + '.' + + XMLNameUtil.getJavaNameFromXMLName(name, true); + } + + /** + * Decapitalize a name. + * @param name + * @return a decapitalized name + */ + public static String decapitalizeName(String name) { + if (name.length() == 0) { + return name; + } else { + String lowerName = name.toLowerCase(); + int i; + for (i = 0; i < name.length(); i++) { + if (name.charAt(i) == lowerName.charAt(i)) { + break; + } + } + if (i > 1 && i < name.length()) { + --i; + } + return name.substring(0, i).toLowerCase() + name.substring(i); + } + } + + /** + * Capitalize a name. + * @param name + * @return a capitalized name + */ + public static String capitalizeName(String name) { + int l = name.length(); + if (l == 0) { + return name; + } else if (l == 1) { + return name.toUpperCase(); + } else { + return name.substring(0, 1).toUpperCase() + name.substring(1); + } + } + +} |