diff options
Diffstat (limited to 'tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system')
32 files changed, 0 insertions, 2586 deletions
diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/annotation/Autowire.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/annotation/Autowire.java deleted file mode 100644 index 5eb1f6b926..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/annotation/Autowire.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * - * 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.core.system.annotation; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * A system annotation to inject an autowired instance - * - * @version $Rev$ $Date$ - */ -@Target( { METHOD, FIELD }) -@Retention(RUNTIME) -public @interface Autowire { - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/annotation/Monitor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/annotation/Monitor.java deleted file mode 100644 index aa552b8e0d..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/annotation/Monitor.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * - * 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.core.system.annotation; - -import java.lang.annotation.Target; -import java.lang.annotation.Retention; -import java.lang.annotation.ElementType; -import java.lang.annotation.RetentionPolicy; - -/** - * A system annotation to inject a monitor - * - * @version $Rev: 392146 $ $Date: 2006-04-06 18:11:28 -0700 (Thu, 06 Apr 2006) $ - */ -@Target( { ElementType.METHOD, ElementType.FIELD }) -@Retention(RetentionPolicy.RUNTIME) -public @interface Monitor { -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/annotation/ParentContext.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/annotation/ParentContext.java deleted file mode 100644 index a9d07dbb5f..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/annotation/ParentContext.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * - * 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.core.system.annotation; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * A system annotation to inject the parent context - * - * @version $Rev$ $Date$ - */ - -@Target( { METHOD, FIELD }) -@Retention(RUNTIME) -public @interface ParentContext { - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemAssemblyFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemAssemblyFactory.java deleted file mode 100644 index fea8d24ba6..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemAssemblyFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * - * 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.core.system.assembly; - -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Scope; - -/** - * A factory for building system assembly model artifacts - * - * @version $Rev$ $Date$ - */ -public interface SystemAssemblyFactory extends AssemblyFactory { - - /** - * Returns an assembly model artifact representing a system component implementation - */ - SystemImplementation createSystemImplementation(); - - /** - * Returns an assembly model artifact representing a system module - */ - SystemModule createSystemModule(); - - /** - * Returns an assembly model artifact representing a system binding - */ - SystemBinding createSystemBinding(); - - /** - * Helper method for creating a typical system component. - * - * @param name the name of the component - * @param service the service that the component provides - * @param impl the component implementation - * @param scope the component's scope - * @return a Component model object with the appropriate system implementation - */ - <T> Component createSystemComponent(String name, Class<T> service, Class<? extends T> impl, Scope scope); - - /** - * Helper method for creating a system entry point wired to a component. - * - * @param entryPointName the name of the entry point - * @param serviceContract the service contract exposed - * @param targetName the component to wire the entry point to - * @return a EntryPoint model object that exposes the service contract and is wired to the named component - */ - EntryPoint createSystemEntryPoint(String entryPointName, Class<?> serviceContract, String targetName); -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemBinding.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemBinding.java deleted file mode 100644 index edc7c87c85..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemBinding.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * - * 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.core.system.assembly; - -import org.apache.tuscany.model.assembly.Binding; - -/** - * Represents a system binding - * - * @version $Rev$ $Date$ - */ -public interface SystemBinding extends Binding { - - /** - * Returns the qualified name of the wire target the binding is associated with in component/service form - */ - public String getTargetName(); - - /** - * Sets the qualified name of the wire target the binding is associated with in component/service form - */ - public void setTargetName(String name); -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemImplementation.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemImplementation.java deleted file mode 100644 index a6a024ceca..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemImplementation.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * - * 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.core.system.assembly; - -import org.apache.tuscany.model.assembly.AtomicImplementation; - -/** - * Represents a system component implementation - * - * @version $Rev$ $Date$ - */ -public interface SystemImplementation extends AtomicImplementation { - - /** - * Returns the implementation class of the system component - */ - Class<?> getImplementationClass(); - - /** - * Sets the implementation class of the system component - */ - void setImplementationClass(Class<?> value); - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemModule.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemModule.java deleted file mode 100644 index a43aca67a2..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/SystemModule.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * - * 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.core.system.assembly; - -/** - * - */ -import org.apache.tuscany.model.assembly.Module; - -public interface SystemModule extends Module { - - /** - * Returns the implementation class of the system component - */ - Class<?> getImplementationClass(); - - /** - * Sets the implementation class of the system component - */ - void setImplementationClass(Class<?> value); - -} - diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemAssemblyFactoryImpl.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemAssemblyFactoryImpl.java deleted file mode 100644 index c0d97c9a35..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemAssemblyFactoryImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * - * 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.core.system.assembly.impl; - -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.SystemBinding; -import org.apache.tuscany.core.system.assembly.SystemImplementation; -import org.apache.tuscany.core.system.assembly.SystemModule; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * The default implementation of the system assembly factory - * - * @version $Rev$ $Date$ - */ -public class SystemAssemblyFactoryImpl extends AssemblyFactoryImpl implements SystemAssemblyFactory { - - public SystemAssemblyFactoryImpl() { - } - - public SystemImplementation createSystemImplementation() { - return new SystemImplementationImpl(); - } - - public SystemBinding createSystemBinding() { - return new SystemBindingImpl(); - } - - public <T> Component createSystemComponent(String name, Class<T> service, Class<? extends T> impl, Scope scope) { - JavaServiceContract jsc = createJavaServiceContract(); - jsc.setInterface(service); - jsc.setScope(scope); - Service s = createService(); - s.setServiceContract(jsc); - - ComponentType componentType = createComponentType(); - componentType.getServices().add(s); - - SystemImplementation sysImpl = createSystemImplementation(); - sysImpl.setImplementationClass(impl); - sysImpl.setComponentType(componentType); - - Component sc = createSimpleComponent(); - sc.setName(name); - sc.setImplementation(sysImpl); - return sc; - } - - public EntryPoint createSystemEntryPoint(String entryPointName, Class<?> serviceContract, String targetName) { - // create the system binding - SystemBinding systemBinding = createSystemBinding(); - - // define the EP's service contract - JavaServiceContract javaServiceContract = createJavaServiceContract(); - javaServiceContract.setInterface(serviceContract); - - return createEntryPoint(entryPointName, javaServiceContract, systemBinding, targetName); - } - - public SystemModule createSystemModule() { - return new SystemModuleImpl(); - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemBindingImpl.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemBindingImpl.java deleted file mode 100644 index a9996065e2..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemBindingImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * - * 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.core.system.assembly.impl; - -import org.apache.tuscany.core.system.assembly.SystemBinding; -import org.apache.tuscany.model.assembly.impl.BindingImpl; - -/** - * The default implementation of the system binding assembly artifact - * - * @version $Rev$ $Date$ - */ -public class SystemBindingImpl extends BindingImpl implements SystemBinding { - - protected SystemBindingImpl() { - } - - private String name; - - public String getTargetName() { - return name; - } - - public void setTargetName(String name) { - this.name = name; - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemImplementationImpl.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemImplementationImpl.java deleted file mode 100644 index cca3aef1bb..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemImplementationImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * 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.core.system.assembly.impl; - -import org.apache.tuscany.core.system.assembly.SystemImplementation; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.impl.AtomicImplementationImpl; - -/** - * The default implementation of the system implementation assembly artifact - * - * @version $Rev$ $Date$ - */ -public class SystemImplementationImpl extends AtomicImplementationImpl implements SystemImplementation { - - private Class<?> implementationClass; - - private AssemblyContext modelContext; - - protected SystemImplementationImpl() { - } - - public Class<?> getImplementationClass() { - return implementationClass; - } - - public void setImplementationClass(Class<?> value) { - checkNotFrozen(); - implementationClass = value; - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemModuleImpl.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemModuleImpl.java deleted file mode 100644 index 98198cba85..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/assembly/impl/SystemModuleImpl.java +++ /dev/null @@ -1,174 +0,0 @@ -/** - * - * 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.core.system.assembly.impl; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.core.system.assembly.SystemModule; -import org.apache.tuscany.core.system.context.SystemCompositeContextImpl; -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.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.ModuleFragment; -import org.apache.tuscany.model.assembly.Multiplicity; -import org.apache.tuscany.model.assembly.OverrideOption; -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.assembly.impl.CompositeImpl; - -/** - * An implementation of Module. - */ -public class SystemModuleImpl extends CompositeImpl implements SystemModule { - - private List<ModuleFragment> moduleFragments = new ArrayList<ModuleFragment>(); - private Map<String, ModuleFragment> moduleFragmentsMap; - private ComponentType componentType; - private Object contextFactory; - - /** - * Constructor - */ - protected SystemModuleImpl() { - } - - /** - * @see org.apache.tuscany.model.assembly.Implementation#getComponentType() - */ - public ComponentType getComponentType() { - return componentType; - } - - /** - * @see org.apache.tuscany.model.assembly.Implementation#setComponentType(org.apache.tuscany.model.assembly.ComponentType) - */ - public void setComponentType(ComponentType componentType) { - checkNotFrozen(); - this.componentType = componentType; - } - - /** - * @see org.apache.tuscany.model.assembly.Module#getModuleFragments() - */ - public List<ModuleFragment> getModuleFragments() { - return moduleFragments; - } - - /** - * @see org.apache.tuscany.model.assembly.Module#getModuleFragment(java.lang.String) - */ - public ModuleFragment getModuleFragment(String name) { - checkInitialized(); - return moduleFragmentsMap.get(name); - } - - /** - * @see org.apache.tuscany.model.assembly.AssemblyObject#initialize(org.apache.tuscany.model.assembly.AssemblyContext) - */ - 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); - } - - /** - * @see org.apache.tuscany.model.assembly.AssemblyObject#freeze() - */ - public void freeze() { - if (isFrozen()) - return; - super.freeze(); - - // Freeze component type and module fragments - if (componentType != null) - componentType.freeze(); - moduleFragments = Collections.unmodifiableList(moduleFragments); - freeze(moduleFragments); - } - - /** - * @see org.apache.tuscany.model.assembly.ContextFactoryHolder#getContextFactory() - */ - public Object getContextFactory() { - return contextFactory; - } - - /** - * @see org.apache.tuscany.model.assembly.ContextFactoryHolder#setContextFactory(java.lang.Object) - */ - public void setContextFactory(Object configuration) { - checkNotFrozen(); - this.contextFactory = configuration; - } - - /** - * @see org.apache.tuscany.model.assembly.impl.CompositeImpl#accept(org.apache.tuscany.model.assembly.AssemblyVisitor) - */ - public boolean accept(AssemblyVisitor visitor) { - if (!super.accept(visitor)) - return false; - - if (componentType != null) { - if (!componentType.accept(visitor)) - return false; - } - - return accept(moduleFragments, visitor); - - } - - public Class<?> getImplementationClass() { - return SystemCompositeContextImpl.class; // FIXME hack - } - - public void setImplementationClass(Class<?> clazz) { - // do nothing - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilder.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilder.java deleted file mode 100644 index 835324c392..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilder.java +++ /dev/null @@ -1,343 +0,0 @@ -/** - * - * 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.core.system.builder; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.apache.tuscany.common.monitor.MonitorFactory; -import org.apache.tuscany.core.builder.BuilderConfigException; -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.builder.NoAccessorException; -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.builder.UnknownTypeException; -import org.apache.tuscany.core.builder.impl.ArrayMultiplicityObjectFactory; -import org.apache.tuscany.core.builder.impl.ListMultiplicityObjectFactory; -import org.apache.tuscany.core.config.JavaIntrospectionHelper; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.extension.config.InjectorExtensibilityElement; -import org.apache.tuscany.core.extension.config.extensibility.ComponentNameExtensibilityElement; -import org.apache.tuscany.core.extension.config.extensibility.ContextExtensibilityElement; -import org.apache.tuscany.core.extension.config.extensibility.DestroyInvokerExtensibilityElement; -import org.apache.tuscany.core.extension.config.extensibility.InitInvokerExtensibilityElement; -import org.apache.tuscany.core.injection.EventInvoker; -import org.apache.tuscany.core.injection.FactoryInitException; -import org.apache.tuscany.core.injection.FieldInjector; -import org.apache.tuscany.core.injection.Injector; -import org.apache.tuscany.core.injection.MethodInjector; -import org.apache.tuscany.core.injection.NonProxiedTargetFactory; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.apache.tuscany.core.system.assembly.SystemImplementation; -import org.apache.tuscany.core.system.assembly.SystemModule; -import org.apache.tuscany.core.system.config.SystemContextFactory; -import org.apache.tuscany.core.system.config.SystemInjectorExtensibilityElement; -import org.apache.tuscany.core.system.config.extensibility.MonitorExtensibilityElement; -import org.apache.tuscany.core.system.context.SystemCompositeContextImpl; -import org.apache.tuscany.model.assembly.AssemblyObject; -import org.apache.tuscany.model.assembly.Component; -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.Implementation; -import org.apache.tuscany.model.assembly.Module; -import org.apache.tuscany.model.assembly.Multiplicity; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; - -/** - * Decorates components whose implementation type is a {@link org.apache.tuscany.core.system.assembly.SystemImplementation} - * with the appropriate runtime configuration. This builder handles both system composite components as well - * as system leaf or "simple" components. Consequently, both simple and composite component types may be - * injected and autowired. - * <p/> - * Note that system component references are not proxied. - * - * @version $Rev$ $Date$ - */ -public class SystemContextFactoryBuilder implements ContextFactoryBuilder { - - private final MonitorFactory monitorFactory; - - public SystemContextFactoryBuilder(MonitorFactory monitorFactory) { - this.monitorFactory = monitorFactory; - } - - @SuppressWarnings("unchecked") - public void build(AssemblyObject modelObject) throws BuilderException { - if (!(modelObject instanceof Component)) { - return; - } - Component component = (Component) modelObject; - - Class implClass; - Scope scope; - // Get the component implementation - Implementation componentImplementation = component.getImplementation(); - if (componentImplementation instanceof SystemImplementation - && component.getContextFactory() == null) { - - // The component is a system component, implemented by a Java class - SystemImplementation implementation = (SystemImplementation) componentImplementation; - if (componentImplementation.getComponentType().getServices() == null - || componentImplementation.getComponentType().getServices().size() < 1) { - BuilderConfigException e = new BuilderConfigException("No service configured on component type"); - e.setIdentifier(component.getName()); - throw e; - } - implClass = implementation.getImplementationClass(); - Scope previous = null; - scope = Scope.MODULE; - List<Service> services = component.getImplementation().getComponentType().getServices(); - for (Service service : services) { - // calculate and validate the scope of the component; ensure that all service scopes are the same unless - // a scope is stateless - Scope current = service.getServiceContract().getScope(); - if (previous != null && current != null && current != previous - && (current != Scope.INSTANCE && previous != Scope.INSTANCE)) { - BuilderException e = new BuilderConfigException("Incompatible scopes specified for services on component"); - e.setIdentifier(component.getName()); - throw e; - } - if (current != null && current != Scope.MODULE) { - scope = current; - } - } - - } else if (componentImplementation instanceof Composite) { - implClass = ((Composite) componentImplementation).getImplementationClass(); - if (implClass == null) { - // FIXME this is a hack - if (((Module) componentImplementation).getName().startsWith("org.apache.tuscany.core.system")) - { - // The component is a system module component, fix the implementation class to our implementation - // of system module component context - implClass = SystemCompositeContextImpl.class; - } else if (componentImplementation instanceof SystemModule) { - implClass = SystemCompositeContextImpl.class; - } else { - // The component is an app module component, fix the implementation class to our implementation - // of app module component context - //FIXME this should be extensible, i.e. the model should specify the impl class of the module - implClass = CompositeContextImpl.class; - } - //END hack - } - scope = Scope.AGGREGATE; - } else { - return; - } - Set<Field> fields; - Set<Method> methods; - SystemContextFactory contextFactory; - try { - fields = JavaIntrospectionHelper.getAllFields(implClass); - methods = JavaIntrospectionHelper.getAllUniqueMethods(implClass); - String name = component.getName(); - if (componentImplementation instanceof Module) { - Module module = (Module) componentImplementation; - contextFactory = new SystemContextFactory(name, module, JavaIntrospectionHelper.getDefaultConstructor(implClass), scope); - - } else { - contextFactory = new SystemContextFactory(name, JavaIntrospectionHelper.getDefaultConstructor(implClass), scope); - } - - //ContextObjectFactory contextObjectFactory = new ContextObjectFactory(contextFactory); - - List<Injector> injectors = new ArrayList<Injector>(); - - // handle properties - List<ConfiguredProperty> configuredProperties = component.getConfiguredProperties(); - if (configuredProperties != null) { - for (ConfiguredProperty property : configuredProperties) { - Injector injector = createPropertyInjector(property, fields, methods); - injectors.add(injector); - } - } - - // FIXME do not inject references on an application module yet - if (implClass != CompositeContextImpl.class) { - // handle references - List<ConfiguredReference> configuredReferences = component.getConfiguredReferences(); - if (configuredReferences != null) { - for (ConfiguredReference reference : configuredReferences) { - Injector injector = createReferenceInjector(reference, fields, methods, contextFactory); - injectors.add(injector); - } - } - } - List<Object> elements = componentImplementation.getComponentType().getExtensibilityElements(); - for (Object element : elements) { - if (element instanceof InitInvokerExtensibilityElement) { - InitInvokerExtensibilityElement invokerElement = (InitInvokerExtensibilityElement) element; - EventInvoker<Object> initInvoker = invokerElement.getEventInvoker(); - boolean eagerInit = invokerElement.isEager(); - contextFactory.setEagerInit(eagerInit); - contextFactory.setInitInvoker(initInvoker); - } else if (element instanceof DestroyInvokerExtensibilityElement) { - DestroyInvokerExtensibilityElement invokerElement = (DestroyInvokerExtensibilityElement) element; - EventInvoker<Object> destroyInvoker = invokerElement.getEventInvoker(); - contextFactory.setDestroyInvoker(destroyInvoker); - } else if (element instanceof ComponentNameExtensibilityElement) { - ComponentNameExtensibilityElement nameElement = (ComponentNameExtensibilityElement) element; - injectors.add(nameElement.getEventInvoker(name)); - } else if (element instanceof ContextExtensibilityElement) { - ContextExtensibilityElement contextElement = (ContextExtensibilityElement) element; - injectors.add(contextElement.getInjector(contextFactory)); - } else if (element instanceof InjectorExtensibilityElement) { - InjectorExtensibilityElement injectorElement = (InjectorExtensibilityElement) element; - injectors.add(injectorElement.getInjector(contextFactory)); - } else if (element instanceof SystemInjectorExtensibilityElement) { - SystemInjectorExtensibilityElement injectorElement = (SystemInjectorExtensibilityElement) element; - injectors.add(injectorElement.getInjector(contextFactory)); - } else if (element instanceof MonitorExtensibilityElement) { - MonitorExtensibilityElement monitorElement = (MonitorExtensibilityElement) element; - injectors.add(monitorElement.getInjector(monitorFactory)); - } - } - contextFactory.setSetters(injectors); - // decorate the logical model - component.setContextFactory(contextFactory); - } catch (BuilderConfigException e) { - e.addContextName(component.getName()); - throw e; - } catch (NoSuchMethodException e) { - BuilderConfigException ce = new BuilderConfigException("Class does not have a no-arg constructor", e); - ce.setIdentifier(implClass.getName()); - throw ce; - } catch (FactoryInitException e) { - BuilderConfigException ce = new BuilderConfigException("Error building component", e); - ce.addContextName(component.getName()); - throw ce; - } - } - - /** - * Creates an <code>Injector</code> for component properties - */ - private Injector createPropertyInjector(ConfiguredProperty property, Set<Field> fields, Set<Method> methods) - throws NoAccessorException { - Object value = property.getValue(); - String propName = property.getProperty().getName(); - // @FIXME is this how to get property type of object - Class type = value.getClass(); - - // There is no efficient way to do this - Method method = null; - Field field = JavaIntrospectionHelper.findClosestMatchingField(propName, type, fields); - if (field == null) { - method = JavaIntrospectionHelper.findClosestMatchingMethod(propName, new Class[]{type}, methods); - if (method == null) { - throw new NoAccessorException(propName); - } - } - Injector injector; - // FIXME support types other than String - if (JavaIntrospectionHelper.isImmutable(type)) { - if (field != null) { - injector = new FieldInjector(field, new SingletonObjectFactory<Object>(value)); - } else { - injector = new MethodInjector(method, new SingletonObjectFactory<Object>(value)); - } - } else { - if (field != null) { - throw new UnknownTypeException(field.getName()); - } else { - throw new UnknownTypeException(method.getName()); - } - } - return injector; - - } - - /** - * Creates object factories that resolve target(s) of a reference and an <code>Injector</code> responsible - * for injecting them into the reference - */ - private Injector createReferenceInjector(ConfiguredReference reference, Set<Field> fields, Set<Method> methods, - ContextResolver resolver) { - - List<ObjectFactory> objectFactories = new ArrayList<ObjectFactory>(); - String refName = reference.getPort().getName(); - Class refClass = reference.getPort().getServiceContract().getInterface(); - for (ConfiguredService configuredService : reference.getTargetConfiguredServices()) { - objectFactories.add(new NonProxiedTargetFactory(configuredService, resolver)); - } - boolean multiplicity = reference.getPort().getMultiplicity() == Multiplicity.ONE_N - || reference.getPort().getMultiplicity() == Multiplicity.ZERO_N; - return createInjector(refName, refClass, multiplicity, objectFactories, fields, methods); - - } - - /** - * Creates an <code>Injector</code> for an object factories associated with a reference. - */ - private Injector createInjector(String refName, Class refClass, boolean multiplicity, List<ObjectFactory> objectFactories, - Set<Field> fields, Set<Method> methods) throws NoAccessorException, BuilderConfigException { - Field field; - Method method = null; - if (multiplicity) { - // since this is a multiplicity, we cannot match on business interface type, so scan through the fields, - // matching on name and List or Array - field = JavaIntrospectionHelper.findMultiplicityFieldByName(refName, fields); - if (field == null) { - // No fields found. Again, since this is a multiplicity, we cannot match on interface type, so - // scan through the fields, matching on name and List or Array - method = JavaIntrospectionHelper.findMultiplicityMethodByName(refName, methods); - if (method == null) { - throw new NoAccessorException(refName); - } - } - Injector injector; - if (field != null) { - // for multiplicities, we need to inject the target or targets using an object factory - // which first delegates to create the proxies and then returns them in the appropriate List or array - // type - if (field.getType().isArray()) { - injector = new FieldInjector(field, new ArrayMultiplicityObjectFactory(refClass, objectFactories)); - } else { - injector = new FieldInjector(field, new ListMultiplicityObjectFactory(objectFactories)); - } - } else { - if (method.getParameterTypes()[0].isArray()) { - injector = new MethodInjector(method, new ArrayMultiplicityObjectFactory(refClass, objectFactories)); - } else { - injector = new MethodInjector(method, new ListMultiplicityObjectFactory(objectFactories)); - } - } - return injector; - } else { - field = JavaIntrospectionHelper.findClosestMatchingField(refName, refClass, fields); - if (field == null) { - method = JavaIntrospectionHelper.findClosestMatchingMethod(refName, new Class[]{refClass}, methods); - if (method == null) { - throw new NoAccessorException(refName); - } - } - Injector injector; - if (field != null) { - injector = new FieldInjector(field, objectFactories.get(0)); - } else { - injector = new MethodInjector(method, objectFactories.get(0)); - } - return injector; - } - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemEntryPointBuilder.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemEntryPointBuilder.java deleted file mode 100644 index c366da53d6..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemEntryPointBuilder.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - * 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.core.system.builder; - -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.BuilderInitException; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.injection.FactoryInitException; -import org.apache.tuscany.core.system.assembly.SystemBinding; -import org.apache.tuscany.core.system.config.SystemEntryPointContextFactory; -import org.apache.tuscany.model.assembly.AssemblyObject; -import org.apache.tuscany.model.assembly.ConfiguredService; -import org.apache.tuscany.model.assembly.EntryPoint; - -/** - * Decorates the logical model with entry point context configuration builders - * - * @version $Rev: 385747 $ $Date: 2006-03-13 22:12:53 -0800 (Mon, 13 Mar 2006) $ - */ -public class SystemEntryPointBuilder implements ContextFactoryBuilder { - - public SystemEntryPointBuilder() { - } - - public void build(AssemblyObject modelObject) throws BuilderException { - if (!(modelObject instanceof EntryPoint)) { - return; - } - EntryPoint entryPoint = (EntryPoint) modelObject; - if (!(entryPoint.getBindings().get(0) instanceof SystemBinding) - || entryPoint.getContextFactory() != null) { - return; - } - try { - String targetName; - ConfiguredService targetService = entryPoint.getConfiguredReference().getTargetConfiguredServices().get(0); - Class serviceInterface = entryPoint.getConfiguredReference().getPort().getServiceContract().getInterface(); - if (targetService.getPart() == null) { - // FIXME not correct - if (targetService.getPort() == null) { - BuilderInitException e = new BuilderInitException("No target service specified on "); - e.setIdentifier(entryPoint.getName()); - } - targetName = targetService.getPort().getName(); - } else { - targetName = targetService.getPart().getName(); - } - SystemEntryPointContextFactory contextFactory = new SystemEntryPointContextFactory(entryPoint.getName(), - targetName, serviceInterface); - entryPoint.setContextFactory(contextFactory); - } catch (FactoryInitException e) { - e.addContextName(entryPoint.getName()); - throw e; - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemExternalServiceBuilder.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemExternalServiceBuilder.java deleted file mode 100644 index a568e9aa2f..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemExternalServiceBuilder.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - * 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.core.system.builder; - -import org.apache.tuscany.core.builder.BuilderConfigException; -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.injection.InterCompositeReferenceFactory; -import org.apache.tuscany.core.system.assembly.SystemBinding; -import org.apache.tuscany.core.system.config.SystemExternalServiceContextFactory; -import org.apache.tuscany.core.system.injection.AutowireObjectFactory; -import org.apache.tuscany.model.assembly.AssemblyObject; -import org.apache.tuscany.model.assembly.ExternalService; - -/** - * Creates runtime configurations for system type external services - * - * @version $Rev$ $Date$ - */ -public class SystemExternalServiceBuilder implements ContextFactoryBuilder { - - public SystemExternalServiceBuilder() { - } - - public void build(AssemblyObject modelObject) throws BuilderException { - if (!(modelObject instanceof ExternalService)) { - return; - } - ExternalService externalService = (ExternalService) modelObject; - if (externalService.getConfiguredService() != null - && externalService.getContextFactory() != null) { - return; - } else if (externalService.getBindings() == null || externalService.getBindings().size() < 1 - || !(externalService.getBindings().get(0) instanceof SystemBinding)) { - return; - } - SystemBinding binding = (SystemBinding)externalService.getBindings().get(0); - if (binding.getTargetName() != null) { - SystemExternalServiceContextFactory contextFactory = new SystemExternalServiceContextFactory(externalService - .getName(), new InterCompositeReferenceFactory(binding.getTargetName())); - externalService.setContextFactory(contextFactory); - } else if (externalService.getConfiguredService().getPort().getServiceContract().getInterface() != null) { - // autowire - Class<Object> claz = externalService.getConfiguredService().getPort().getServiceContract().getInterface(); - if (claz == null) { - BuilderException e = new BuilderConfigException("Interface type not specified"); - e.setIdentifier(externalService.getName()); - e.addContextName(externalService.getName()); - throw e; - } - SystemExternalServiceContextFactory config = new SystemExternalServiceContextFactory(externalService - .getName(), new AutowireObjectFactory<Object>(claz)); - externalService.setContextFactory(config); - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemContextFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemContextFactory.java deleted file mode 100644 index 2e4a2916ce..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemContextFactory.java +++ /dev/null @@ -1,208 +0,0 @@ -/** - * - * Copyright 2005 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.core.system.config; - -import org.apache.tuscany.common.TuscanyRuntimeException; -import org.apache.tuscany.core.builder.ContextCreationException; -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.config.ConfigurationException; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.injection.EventInvoker; -import org.apache.tuscany.core.injection.Injector; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.wire.SourceWireFactory; -import org.apache.tuscany.core.wire.TargetWireFactory; -import org.apache.tuscany.core.system.context.SystemAtomicContext; -import org.apache.tuscany.model.assembly.Module; -import org.apache.tuscany.model.assembly.Scope; - -import java.lang.reflect.Constructor; -import java.util.List; -import java.util.Map; - -/** - * A <code>ContextFactory</code> that handles system component implementation types, which may be either simple, leaf - * types or an composites. - * <p> - * For composite types, this factory delegates to an {@link org.apache.tuscany.core.builder.ObjectFactory} to create an - * instance of the composite implementation and perform injection of configuration and references. Once an composite - * instance is created, the factory will register the composite's children. This process may be done recursively in a - * lazy fashion, descending down an composite hierarchy as a child composite is instantiated. - * - * @version $Rev$ $Date$ - */ -public class SystemContextFactory implements ContextFactory<Context>, ContextResolver { - - // the component name as configured in the hosting module - private String name; - - // if this factory produces composites, the module will be the logical model associated with its children - private Module module; - - private CompositeContext parentContext; - - // the implementation type constructor - private Constructor ctr; - - // injectors for properties, references and other metadata values such as @Context - private List<Injector> setters; - - // an invoker for a method decorated with @Init - private EventInvoker init; - - // whether the component should be eagerly initialized when its scope starts - private boolean eagerInit; - - // an invoker for a method decorated with @Destroy - private EventInvoker destroy; - - // the scope of the implementation instance - private Scope scope; - - // if the component implementation scope is stateless - private boolean stateless; - - // if the component implementation is an composite context - private boolean isComposite; - - /** - * Creates the runtime configuration - * - * @param name the SCDL name of the component the context refers to - * @param ctr the implementation type constructor - * @param scope the scope of the component implementation type - */ - public SystemContextFactory(String name, Constructor ctr, Scope scope) { - this(name, null, ctr, scope); - } - - /** - * Creates the runtime configuration - * - * @param name the SCDL name of the component the context refers to - * @param module if this factory produces aggregagtes, the logical model associated with its children; otherwise - * null - * @param ctr the implementation type constructor - * @param scope the scope of the component implementation type - */ - public SystemContextFactory(String name, Module module, Constructor ctr, Scope scope) { - assert (name != null) : "Name was null"; - assert (ctr != null) : "Constructor was null"; - this.name = name; - this.module = module; - this.ctr = ctr; - this.isComposite = CompositeContext.class.isAssignableFrom(ctr.getDeclaringClass()); - this.scope = scope; - if (isComposite) { - scope = Scope.AGGREGATE; - } else { - stateless = (scope == Scope.INSTANCE); - } - } - - public String getName() { - return name; - } - - public void addProperty(String propertyName, Object value) { - - } - - public Scope getScope() { - return scope; - } - - public Context createContext() throws ContextCreationException { - if (isComposite) { - try { - // composite context types are themselves an instance context - PojoObjectFactory<CompositeContext> objectFactory = new PojoObjectFactory<CompositeContext>(ctr, null, setters); - CompositeContext ctx = objectFactory.getInstance(); - ctx.setName(name); - // the composite has been created, now register its children - if (module != null) { - try { - ctx.registerModelObject(module); - } catch (ConfigurationException e) { - ContextCreationException cce = new ContextCreationException("Error creating context", e); - cce.setIdentifier(getName()); - throw cce; - } - - } - return ctx; - } catch (TuscanyRuntimeException e) { - e.addContextName(name); - throw e; - } - } else { - PojoObjectFactory objectFactory = new PojoObjectFactory(ctr, null, setters); - return new SystemAtomicContext(name, objectFactory, eagerInit, init, destroy, stateless); - } - } - - public void addTargetWireFactory(String serviceName, TargetWireFactory factory) { - throw new UnsupportedOperationException(); - } - - public TargetWireFactory getTargetWireFactory(String serviceName) { - return null; - } - - public Map<String, TargetWireFactory> getTargetWireFactories() { - return null; - } - - public void addSourceWireFactory(String referenceName, SourceWireFactory factory) { - throw new UnsupportedOperationException(); - } - - public void addSourceWireFactories(String referenceName, Class referenceInterface, List<SourceWireFactory> factory, boolean multiplicity) { - - } - - public List<SourceWireFactory> getSourceWireFactories() { - return null; - } - - public void setSetters(List<Injector> setters) { - this.setters = setters; - } - - public void setEagerInit(boolean val) { - eagerInit = val; - } - - public void setInitInvoker(EventInvoker invoker) { - init = invoker; - } - - public void setDestroyInvoker(EventInvoker invoker) { - destroy = invoker; - } - - public void prepare(CompositeContext parent) { - parentContext = parent; - } - - public CompositeContext getCurrentContext() { - return parentContext; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemEntryPointContextFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemEntryPointContextFactory.java deleted file mode 100644 index c9cfeccd6b..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemEntryPointContextFactory.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * - * 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.core.system.config; - -import org.apache.tuscany.core.builder.ContextCreationException; -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.EntryPointContext; -import org.apache.tuscany.core.wire.TargetWireFactory; -import org.apache.tuscany.core.wire.SourceWireFactory; -import org.apache.tuscany.core.system.context.SystemEntryPointContext; -import org.apache.tuscany.model.assembly.Scope; - -import java.util.List; -import java.util.Map; - -/** - * Creates {@link SystemEntryPointContext} instances based on an entry point configuration in an assembly model - * - * @version $Rev$ $Date$ - */ -public class SystemEntryPointContextFactory implements ContextFactory<EntryPointContext>, ContextResolver { - - // the name of the entry point - private String name; - - private CompositeContext parentContext; - - private String targetName; - - private Class serviceInterface; - - public SystemEntryPointContextFactory(String name, String targetName, Class serviceInterface) { - this.name = name; - this.targetName = targetName; - this.serviceInterface = serviceInterface; - } - - public EntryPointContext createContext() throws ContextCreationException { - return new SystemEntryPointContext(name, targetName, serviceInterface, this); - } - - public Scope getScope() { - return Scope.MODULE; - } - - public String getName() { - return name; - } - - - public void addTargetWireFactory(String serviceName, TargetWireFactory pFactory) { - throw new UnsupportedOperationException(); - } - - public TargetWireFactory getTargetWireFactory(String serviceName) { - return null; - } - - public Map<String, TargetWireFactory> getTargetWireFactories() { - return null; - } - - public void addSourceWireFactory(String referenceName, SourceWireFactory pFactory) { - throw new UnsupportedOperationException(); - } - - public void addSourceWireFactories(String referenceName, Class referenceInterface, List<SourceWireFactory> factory, boolean multiplicity) { - throw new UnsupportedOperationException(); - } - public void addProperty(String propertyName, Object value) { - - } - - public List<SourceWireFactory> getSourceWireFactories() { - return null; - } - - public void prepare(CompositeContext parent) { - this.parentContext = parent; - } - - public CompositeContext getCurrentContext() { - return parentContext; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemExtensibilityElement.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemExtensibilityElement.java deleted file mode 100644 index 14655c2393..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemExtensibilityElement.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - * 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.core.system.config; - -/** - * Base marker for system metadata extensions - * - * @version $$Rev$$ $$Date$$ - */ -public interface SystemExtensibilityElement { - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemExternalServiceContextFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemExternalServiceContextFactory.java deleted file mode 100644 index d62afa4425..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemExternalServiceContextFactory.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * - * 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.core.system.config; - -import org.apache.tuscany.core.builder.ContextCreationException; -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.ExternalServiceContext; -import org.apache.tuscany.core.injection.InterCompositeReferenceFactory; -import org.apache.tuscany.core.system.context.SystemExternalServiceContext; -import org.apache.tuscany.core.system.injection.AutowireObjectFactory; -import org.apache.tuscany.core.wire.SourceWireFactory; -import org.apache.tuscany.core.wire.TargetWireFactory; -import org.apache.tuscany.model.assembly.Scope; - -import java.util.List; -import java.util.Map; - -/** - * Creates system type external service contexts - * - * @version $Rev$ $Date$ - * @see org.apache.tuscany.core.context.ExternalServiceContext - * @see org.apache.tuscany.core.system.context.SystemExternalServiceContext - */ -public class SystemExternalServiceContextFactory implements ContextFactory<ExternalServiceContext>, ContextResolver { - - // the name of the external service - private String name; - - // the factory for returning a reference to the implementation instance of the component represented by the external - // service - private ObjectFactory factory; - - private CompositeContext parentContext; - - public SystemExternalServiceContextFactory(String name, ObjectFactory factory) { - assert (name != null) : "Name was null"; - assert (factory != null) : "Object factory was null"; - this.name = name; - this.factory = factory; - } - - public Scope getScope() { - return Scope.MODULE; - } - - public String getName() { - return name; - } - - public void addProperty(String propertyName, Object value) { - throw new UnsupportedOperationException(); - } - - public ExternalServiceContext createContext() throws ContextCreationException { - return new SystemExternalServiceContext(name, factory); - } - - public void addTargetWireFactory(String serviceName, TargetWireFactory pFactory) { - throw new UnsupportedOperationException(); - } - - public TargetWireFactory getTargetWireFactory(String serviceName) { - return null; - } - - public Map<String, TargetWireFactory> getTargetWireFactories() { - return null; - } - - public void addSourceWireFactory(String referenceName, SourceWireFactory pFactory) { - throw new UnsupportedOperationException(); - } - - public void addSourceWireFactories(String referenceName, Class referenceInterface, List<SourceWireFactory> factory, boolean multiplicity) { - - } - - public List<SourceWireFactory> getSourceWireFactories() { - return null; - } - - public void prepare(CompositeContext parent) { - parentContext = parent; - if (factory instanceof InterCompositeReferenceFactory) { - ((InterCompositeReferenceFactory) factory).setContextResolver(this); - } else if (factory instanceof AutowireObjectFactory) { - ((AutowireObjectFactory) factory).setContextResolver(this); - } - } - - public CompositeContext getCurrentContext() { - return parentContext; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemInjectorExtensibilityElement.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemInjectorExtensibilityElement.java deleted file mode 100644 index 7fca219399..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemInjectorExtensibilityElement.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * - * 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.core.system.config; - -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.injection.Injector; - -/** - * An extensiblity element which provides {@link org.apache.tuscany.core.injection.Injector}s based on - * component type metadata specific to system services - * - * @version $$Rev$$ $$Date$$ - */ -public interface SystemInjectorExtensibilityElement { - /** - * Creates an injector - * - * @param resolver that returns the current composite context - */ - public Injector<?> getInjector(ContextResolver resolver); - -} - diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemObjectContextFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemObjectContextFactory.java deleted file mode 100644 index d4a21dd427..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemObjectContextFactory.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * - * Copyright 2005 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.core.system.config; - -import org.apache.tuscany.core.builder.ContextCreationException; -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.apache.tuscany.core.wire.WireFactory; -import org.apache.tuscany.core.wire.SourceWireFactory; -import org.apache.tuscany.core.wire.TargetWireFactory; -import org.apache.tuscany.core.system.context.SystemAtomicContext; -import org.apache.tuscany.model.assembly.Scope; - -import java.util.List; -import java.util.Map; - -/** - * A ContextFactory that contains the configuration needed to convert a simple - * Java Object into a component. The object is assumed to be fully initialized and - * will always be added with MODULE scope. - * - * @version $Rev$ $Date$ - */ -public class SystemObjectContextFactory implements ContextFactory { - private final String name; - private final ObjectFactory<?> objectFactory; - - /** - * Construct a ContextFactory for the supplied Java Object. - * - * @param name the name to be assigned to the resulting component - * @param instance the Java Object that provides the implementation - */ - public SystemObjectContextFactory(String name, Object instance) { - this.name = name; - objectFactory = new SingletonObjectFactory<Object>(instance); - } - - public Context createContext() throws ContextCreationException { - return new SystemAtomicContext(name, objectFactory, false, null, null, false); - } - - public Scope getScope() { - return Scope.MODULE; - } - - public String getName() { - return name; - } - - public void addProperty(String propertyName, Object value) { - - } - - public void addTargetWireFactory(String serviceName, TargetWireFactory factory) { - throw new UnsupportedOperationException(); - } - - public TargetWireFactory getTargetWireFactory(String serviceName) { - throw new UnsupportedOperationException(); - } - - public Map getTargetWireFactories() { - throw new UnsupportedOperationException(); - } - - public void addSourceWireFactory(String referenceName, SourceWireFactory factory) { - throw new UnsupportedOperationException(); - } - - public void addSourceWireFactories(String referenceName, Class referenceInterface, List factory, boolean multiplicity) { - - } - - public List<WireFactory> getSourceWireFactories() { - throw new UnsupportedOperationException(); - } - - public void prepare(CompositeContext parent) { - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/extensibility/AutowireExtensibilityElement.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/extensibility/AutowireExtensibilityElement.java deleted file mode 100644 index 42d3151c78..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/extensibility/AutowireExtensibilityElement.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * 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.core.system.config.extensibility; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.injection.FieldInjector; -import org.apache.tuscany.core.injection.Injector; -import org.apache.tuscany.core.injection.MethodInjector; -import org.apache.tuscany.core.system.config.SystemInjectorExtensibilityElement; -import org.apache.tuscany.core.system.injection.AutowireObjectFactory; - -/** - * A metadata extensbility element for autowires; creates injectors which return the target of an autowire - * - * @version $$Rev$$ $$Date$$ - */ -public class AutowireExtensibilityElement implements SystemInjectorExtensibilityElement { - - private Method method; - private Field field; - - public AutowireExtensibilityElement(Method m) { - assert(m == null || m.getParameterTypes().length == 1): "Illegal number of parameters"; - method = m; - } - - public AutowireExtensibilityElement(Field f) { - field = f; - } - - @SuppressWarnings("unchecked") - public Injector<?> getInjector(ContextResolver resolver) { - if (method != null) { - return new MethodInjector(method, new AutowireObjectFactory(method.getParameterTypes()[0], resolver)); - } else { - return new FieldInjector(field, new AutowireObjectFactory(field.getType(), resolver)); - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/extensibility/MonitorExtensibilityElement.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/extensibility/MonitorExtensibilityElement.java deleted file mode 100644 index 61c89d991b..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/extensibility/MonitorExtensibilityElement.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - * 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.core.system.config.extensibility; - -import java.lang.reflect.Method; -import java.lang.reflect.Field; - -import org.apache.tuscany.core.system.config.SystemExtensibilityElement; -import org.apache.tuscany.core.injection.Injector; -import org.apache.tuscany.core.injection.MethodInjector; -import org.apache.tuscany.core.injection.ContextObjectFactory; -import org.apache.tuscany.core.injection.FieldInjector; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.common.monitor.MonitorFactory; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class MonitorExtensibilityElement implements SystemExtensibilityElement { - - private Method method; - private Field field; - - public MonitorExtensibilityElement(Method m) { - assert(m.getParameterTypes().length == 1): "Illegal number of parameters"; - method = m; - } - - public MonitorExtensibilityElement(Field f) { - field = f; - } - - public Injector<?> getInjector(MonitorFactory factory) { - if (method != null) { - Object monitor = factory.getMonitor(method.getParameterTypes()[0]); - return new MethodInjector(method, new SingletonObjectFactory<Object>(monitor)); - } else { - Object monitor = factory.getMonitor(field.getType()); - return new FieldInjector(field, new SingletonObjectFactory<Object>(monitor)); - } - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/extensibility/ParentContextExtensibilityElement.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/extensibility/ParentContextExtensibilityElement.java deleted file mode 100644 index b95b87c8de..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/extensibility/ParentContextExtensibilityElement.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * - * Copyright 2005 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.core.system.config.extensibility; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.injection.ContextObjectFactory; -import org.apache.tuscany.core.injection.FieldInjector; -import org.apache.tuscany.core.injection.Injector; -import org.apache.tuscany.core.injection.MethodInjector; -import org.apache.tuscany.core.system.config.SystemInjectorExtensibilityElement; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class ParentContextExtensibilityElement implements SystemInjectorExtensibilityElement { - - private Method method; - private Field field; - - public ParentContextExtensibilityElement(Method m) { - assert(m.getParameterTypes().length == 1): "Illegal number of parameters"; - method = m; - } - - public ParentContextExtensibilityElement(Field f) { - field = f; - } - - public Injector<?> getInjector(ContextResolver resolver) { - if (method != null) { - return new MethodInjector(method, new ContextObjectFactory(resolver)); - } else { - return new FieldInjector(field, new ContextObjectFactory(resolver)); - } - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/processor/AutowireProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/processor/AutowireProcessor.java deleted file mode 100644 index 1885a5eaaa..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/processor/AutowireProcessor.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * - * Copyright 2005 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.core.system.config.processor; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.config.InvalidSetterException; -import org.apache.tuscany.core.config.processor.ImplementationProcessorSupport; -import org.apache.tuscany.core.system.annotation.Autowire; -import org.apache.tuscany.core.system.config.extensibility.AutowireExtensibilityElement; -import org.apache.tuscany.core.context.SystemCompositeContext; -import org.apache.tuscany.core.context.ConfigurationContext; -import org.apache.tuscany.core.context.AutowireContext; -import org.apache.tuscany.core.runtime.RuntimeContext; -import org.apache.tuscany.core.builder.BuilderConfigException; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.common.monitor.MonitorFactory; - -/** - * Processes {@link Autowire} annotations - * - * @version $$Rev$$ $$Date$$ - */ -public class AutowireProcessor extends ImplementationProcessorSupport { - - @Override - public void visitMethod(Method method, ComponentType type) throws ConfigurationLoadException { - Autowire annotation = method.getAnnotation(Autowire.class); - if (annotation != null) { - if (!Modifier.isPublic(method.getModifiers())) { - InvalidSetterException e = new InvalidSetterException("Autowire setter method is not public"); - e.setIdentifier(method.toString()); - throw e; - } - if (method.getParameterTypes().length != 1){ - InvalidSetterException e = new InvalidSetterException("Autowire setter method must have one parameter"); - e.setIdentifier(method.toString()); - throw e; - } - checkAutowireType(method.getParameterTypes()[0],method.getDeclaringClass()); - type.getExtensibilityElements().add(new AutowireExtensibilityElement(method)); - } - } - - @Override - public void visitField(Field field, ComponentType type) throws ConfigurationLoadException { - checkAutowireType(field.getType(),field.getDeclaringClass()); - int modifiers = field.getModifiers(); - Autowire annotation = field.getAnnotation(Autowire.class); - if (annotation != null) { - if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) { - InvalidSetterException e = new InvalidSetterException("Autowire field is not public or protected"); - e.setIdentifier(field.getName()); - throw e; - } - type.getExtensibilityElements().add(new AutowireExtensibilityElement(field)); - } - } - - - - private void checkAutowireType(Class paramClass, Class declaringClass) throws BuilderConfigException{ - if (SystemCompositeContext.class.isAssignableFrom(declaringClass) - && !(paramClass.equals(ConfigurationContext.class) - || paramClass.equals(MonitorFactory.class) - || paramClass.equals(RuntimeContext.class) || paramClass.equals( - AutowireContext.class))) { - BuilderConfigException e = new BuilderConfigException("Illegal autowire type for system context"); - e.setIdentifier(paramClass.getName()); - throw e; - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/processor/MonitorProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/processor/MonitorProcessor.java deleted file mode 100644 index 9d7f535cc8..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/processor/MonitorProcessor.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * - * Copyright 2005 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.core.system.config.processor; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.config.InvalidSetterException; -import org.apache.tuscany.core.config.processor.ImplementationProcessorSupport; -import org.apache.tuscany.core.system.annotation.Monitor; -import org.apache.tuscany.core.system.config.extensibility.MonitorExtensibilityElement; -import org.apache.tuscany.model.assembly.ComponentType; - -/** - * Processes {@link org.apache.tuscany.core.system.annotation.Autowire} annotations - * - * @version $$Rev$$ $$Date$$ - */ -public class MonitorProcessor extends ImplementationProcessorSupport { - - @Override - public void visitMethod(Method method, ComponentType type) throws ConfigurationLoadException { - Monitor annotation = method.getAnnotation(Monitor.class); - if (annotation != null) { - if (!Modifier.isPublic(method.getModifiers())) { - InvalidSetterException e = new InvalidSetterException("Monitor setter method is not public"); - e.setIdentifier(method.toString()); - throw e; - } - if (method.getParameterTypes().length != 1) { - InvalidSetterException e = new InvalidSetterException("Monitor setter method must have one parameter"); - e.setIdentifier(method.toString()); - throw e; - } - type.getExtensibilityElements().add(new MonitorExtensibilityElement(method)); - } - } - - @Override - public void visitField(Field field, ComponentType type) throws ConfigurationLoadException { - int modifiers = field.getModifiers(); - Monitor annotation = field.getAnnotation(Monitor.class); - if (annotation != null) { - if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) { - InvalidSetterException e = new InvalidSetterException("Monitor field is not public or protected"); - e.setIdentifier(field.getName()); - throw e; - } - type.getExtensibilityElements().add(new MonitorExtensibilityElement(field)); - } - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/processor/ParentContextProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/processor/ParentContextProcessor.java deleted file mode 100644 index 1ddc68e3e8..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/processor/ParentContextProcessor.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * - * Copyright 2005 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.core.system.config.processor; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.config.InvalidSetterException; -import org.apache.tuscany.core.config.processor.ImplementationProcessorSupport; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.system.annotation.ParentContext; -import org.apache.tuscany.core.system.config.extensibility.ParentContextExtensibilityElement; -import org.apache.tuscany.model.assembly.ComponentType; - -/** - * Processes {@link org.apache.tuscany.core.system.annotation.Autowire} annotations - * - * @version $$Rev$$ $$Date$$ - */ -public class ParentContextProcessor extends ImplementationProcessorSupport { - - @Override - public void visitMethod(Method method, ComponentType type) throws ConfigurationLoadException { - ParentContext annotation = method.getAnnotation(ParentContext.class); - if (annotation != null) { - if (!Modifier.isPublic(method.getModifiers())) { - InvalidSetterException e = new InvalidSetterException("ParentContext setter method is not public"); - e.setIdentifier(method.toString()); - throw e; - } - if (method.getParameterTypes().length != 1 - && !CompositeContext.class.isAssignableFrom(method.getParameterTypes()[0])) { - InvalidSetterException e = new InvalidSetterException("ParentContext setter method must have one parameter of type " + CompositeContext.class.getName()); - e.setIdentifier(method.toString()); - throw e; - } - type.getExtensibilityElements().add(new ParentContextExtensibilityElement(method)); - } - } - - @Override - public void visitField(Field field, ComponentType type) throws ConfigurationLoadException { - int modifiers = field.getModifiers(); - ParentContext annotation = field.getAnnotation(ParentContext.class); - if (annotation != null) { - if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) { - InvalidSetterException e = new InvalidSetterException("ParentContext field is not public or protected"); - e.setIdentifier(field.getName()); - throw e; - } - type.getExtensibilityElements().add(new ParentContextExtensibilityElement(field)); - } - } - - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java deleted file mode 100644 index 374555bfb6..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java +++ /dev/null @@ -1,159 +0,0 @@ -/** - * - * 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.core.system.context; - -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.injection.EventInvoker; -import org.apache.tuscany.core.injection.ObjectCallbackException; -import org.apache.tuscany.core.injection.ObjectCreationException; -import org.apache.tuscany.core.context.AtomicContext; -import org.apache.tuscany.core.context.impl.AbstractContext; -import org.apache.tuscany.core.context.TargetException; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.ContextInitException; -import org.apache.tuscany.core.context.event.InstanceCreated; - -/** - * Manages system component implementation instances - * - * @version $Rev$ $Date$ - */ -public class SystemAtomicContext extends AbstractContext implements AtomicContext { - - private boolean eagerInit; - - private EventInvoker<Object> initInvoker; - - private EventInvoker<Object> destroyInvoker; - - private boolean stateless; - - // the cached target instance - private Object cachedTargetInstance; - - // responsible for creating a new implementation instance with injected references and properties - private ObjectFactory objectFactory; - - public SystemAtomicContext(String name, ObjectFactory objectFactory, boolean eagerInit, EventInvoker<Object> initInvoker, - EventInvoker<Object> destroyInvoker, boolean stateless) { - super(name); - assert (objectFactory != null) : "Object factory was null"; - if (eagerInit && initInvoker == null) { - throw new AssertionError("No intialization method found for eager init implementation"); - } - this.objectFactory = objectFactory; - this.eagerInit = eagerInit; - this.initInvoker = initInvoker; - this.destroyInvoker = destroyInvoker; - this.stateless = stateless; - } - - public void setName(String name) { - super.setName(name); - } - - protected int type; - - public int getType() { - return type; - } - - public void setType(int type) { - this.type = type; - } - - public void init() throws TargetException{ - getInstance(null); - } - - public void destroy() throws TargetException { - if (cachedTargetInstance != null) { - if (destroyInvoker != null) { - try { - destroyInvoker.invokeEvent(cachedTargetInstance); - } catch (ObjectCallbackException e) { - throw new TargetException(e.getCause()); - } - } - } - lifecycleState = STARTED; - } - - public synchronized Object getInstance(QualifiedName qName) throws TargetException { - if (cachedTargetInstance != null) { - return cachedTargetInstance; // already cached, just return - } - - if (getLifecycleState() == ERROR || getLifecycleState() == CONFIG_ERROR) { - return null; - } - synchronized (this) { - try { - Object instance = objectFactory.getInstance(); - // handle @Init - if (initInvoker != null) { - initInvoker.invokeEvent(instance); - } - publish(new InstanceCreated(this)); - lifecycleState = RUNNING; - if (stateless) { - return instance; - } else { - // cache the actual instance - cachedTargetInstance = instance; - return cachedTargetInstance; - } - } catch (ObjectCreationException e) { - lifecycleState = ERROR; - TargetException te = new TargetException("Error creating component instance", e); - te.setIdentifier(getName()); - throw te; - } - } - - } - - public Object getTargetInstance() throws TargetException { - return getInstance(null); - } - - public boolean isEagerInit() { - return eagerInit; - } - - public boolean isDestroyable() { - return (destroyInvoker != null); - } - - public void start() throws ContextInitException { - if (getLifecycleState() != UNINITIALIZED && getLifecycleState() != STOPPED) { - throw new IllegalStateException("Component must be in UNINITIALIZED state [" + getLifecycleState() + "]"); - } - if (objectFactory == null) { - lifecycleState = ERROR; - ContextInitException e = new ContextInitException("Object factory not found "); - e.setIdentifier(getName()); - throw e; - } - lifecycleState = INITIALIZED; - } - - public void stop() { - lifecycleState = STOPPED; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java deleted file mode 100644 index 9ac0abe38a..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * - * 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.core.system.context; - -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.tuscany.core.config.ConfigurationException; -import org.apache.tuscany.core.context.AutowireContext; -import org.apache.tuscany.core.context.AutowireResolutionException; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.ConfigurationContext; -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.ScopeContext; -import org.apache.tuscany.core.context.ScopeStrategy; -import org.apache.tuscany.core.context.SystemCompositeContext; -import org.apache.tuscany.core.context.impl.AbstractCompositeContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; -import org.apache.tuscany.core.system.config.SystemObjectContextFactory; -import org.apache.tuscany.core.wire.WireFactoryFactory; -import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; - - -/** - * Implements an composite context for system components. By default a system context uses the scopes specified by - * {@link org.apache.tuscany.core.system.context.SystemScopeStrategy}. In addition, it implements an autowire policy - * where entry points configured with a {@link org.apache.tuscany.core.system.assembly.SystemBinding} are matched - * according to their exposed interface. A system context may contain child composite contexts but an entry point in a - * child context will only be outwardly accessible if there is an entry point that exposes it configured in the - * top-level system context. - * - * @version $Rev$ $Date$ - */ -public class SystemCompositeContextImpl extends AbstractCompositeContext implements SystemCompositeContext { - public SystemCompositeContextImpl() { - super(); - eventContext = new EventContextImpl(); - scopeStrategy = new SystemScopeStrategy(); - } - - public SystemCompositeContextImpl(String name, - CompositeContext parent, - AutowireContext autowire, - ScopeStrategy strategy, - EventContext ctx, - ConfigurationContext configCtx - ) { - super(name, parent, strategy, ctx, configCtx); - setAutowireContext(autowire); - scopeIndex = new ConcurrentHashMap<String, ScopeContext>(); - } - - public void registerJavaObject(String componentName, Class<?> service, Object instance) throws ConfigurationException { - SystemObjectContextFactory configuration = new SystemObjectContextFactory(componentName, instance); - registerConfiguration(configuration); - ScopeContext scope = scopeContexts.get(configuration.getScope()); - registerAutowireInternal(service, componentName, scope); - } - - // FIXME These should be removed and configured - private static final MessageFactory messageFactory = new MessageFactoryImpl(); - - private static final WireFactoryFactory WIRE_FACTORY_FACTORY = new JDKWireFactoryFactory(); - - public <T> T resolveInstance(Class<T> instanceInterface) throws AutowireResolutionException { - if (CompositeContext.class.equals(instanceInterface)) { - return instanceInterface.cast(this); - } else if (MessageFactory.class.equals(instanceInterface)) { - return instanceInterface.cast(messageFactory); - } else if (WireFactoryFactory.class.equals(instanceInterface)) { - return instanceInterface.cast(WIRE_FACTORY_FACTORY); - } else { - return super.resolveInstance(instanceInterface); - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemEntryPointContext.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemEntryPointContext.java deleted file mode 100644 index 107e676c47..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemEntryPointContext.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * - * 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.core.system.context; - -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.context.impl.AbstractContext; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.context.CoreRuntimeException; -import org.apache.tuscany.core.context.EntryPointContext; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.TargetException; - -/** - * Manages an entry point into a system module. System entry points cache a direct (i.e. non-proxied) reference to a - * component instance. - * - * @version $Rev$ $Date$ - */ -public class SystemEntryPointContext extends AbstractContext implements EntryPointContext { - - // a reference to the component's implementation instance exposed by the entry point - private Object cachedInstance; - - private ContextResolver resolver; - - private QualifiedName targetName; - - private Class serviceInterface; - - public SystemEntryPointContext(String name, String targetName, Class serviceInterface, ContextResolver resolver) { - super(name); - assert (resolver != null) : "Context resolver was null"; - assert (targetName != null) : "Target name was null"; - assert (serviceInterface != null) : "Service interface is null"; - this.serviceInterface = serviceInterface; - this.resolver = resolver; - this.targetName = new QualifiedName(targetName); - } - - public Object getInstance(QualifiedName qName) throws TargetException { - try { - if (cachedInstance == null) { - Context ctx = resolver.getCurrentContext().getContext(targetName.getPartName()); - if (ctx == null){ - return null; - } - cachedInstance = ctx.getInstance(targetName); - } - return cachedInstance; - } catch (TargetException e) { - e.addContextName(getName()); - throw e; - } - } - - public void start() throws CoreRuntimeException { - lifecycleState = RUNNING; - } - - public void stop() throws CoreRuntimeException { - lifecycleState = STOPPED; - } - - public Object getHandler() throws TargetException { - return getInstance(null); - } - - public Class getServiceInterface() { - return serviceInterface; - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemExternalServiceContext.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemExternalServiceContext.java deleted file mode 100644 index b85bd2722b..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemExternalServiceContext.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - * 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.core.system.context; - -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.context.impl.AbstractContext; -import org.apache.tuscany.core.context.ExternalServiceContext; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.TargetException; - -/** - * An implementation of an external service for system wiring. As system components are not proxied and the system - * binding is by-reference, the implementation caches a reference to its configured target. - * - * @version $Rev$ $Date$ - */ -public class SystemExternalServiceContext extends AbstractContext implements ExternalServiceContext { - - // a factory for retrieving the target of the external service wire - private ObjectFactory factory; - - // the cached target - private Object cachedInstance; - - public SystemExternalServiceContext(String name, ObjectFactory factory) { - super(name); - assert (factory != null) : "Object factory was null"; - this.factory = factory; - } - - public Object getInstance(QualifiedName qName) throws TargetException { - try { - if (cachedInstance == null) { - cachedInstance = factory.getInstance(); - } - return cachedInstance; - } catch (TargetException e) { - e.addContextName(getName()); - throw e; - } - - } - - public void start() { - lifecycleState = RUNNING; - } - - public void stop() { - lifecycleState = STOPPED; - } - - public Object getHandler() throws TargetException { - return this; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemScopeStrategy.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemScopeStrategy.java deleted file mode 100644 index 76b9f2856d..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemScopeStrategy.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * - * 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.core.system.context; - -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.ScopeContext; -import org.apache.tuscany.core.context.scope.AbstractScopeStrategy; -import org.apache.tuscany.core.context.scope.CompositeScopeContext; -import org.apache.tuscany.core.context.scope.ModuleScopeContext; -import org.apache.tuscany.core.context.scope.StatelessScopeContext; -import org.apache.tuscany.model.assembly.Scope; - -import java.util.HashMap; -import java.util.Map; - -/** - * Implements a {@link org.apache.tuscany.core.context.ScopeStrategy} for a system composite context with the following scopes: - * <ul> - * <li>{@link org.apache.tuscany.model.assembly.Scope#AGGREGATE}</li> - * <li>{@link org.apache.tuscany.model.assembly.Scope#MODULE}</li> - * <li>{@link org.apache.tuscany.model.assembly.Scope#INSTANCE}</li> - * </ul> - * - * @version $Rev$ $Date$ - */ -public class SystemScopeStrategy extends AbstractScopeStrategy { - - public SystemScopeStrategy() { - } - - public Map<Scope, ScopeContext> getScopeContexts(EventContext eventContext) { - ScopeContext aggregrateScope = new CompositeScopeContext(eventContext); - ScopeContext moduleScoper = new ModuleScopeContext(eventContext); - ScopeContext statelessScope = new StatelessScopeContext(eventContext); - Map<Scope, ScopeContext> scopes = new HashMap<Scope, ScopeContext>(); - scopes.put(Scope.AGGREGATE, aggregrateScope); - scopes.put(Scope.MODULE, moduleScoper); - scopes.put(Scope.INSTANCE, statelessScope); - return scopes; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/injection/AutowireObjectFactory.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/injection/AutowireObjectFactory.java deleted file mode 100644 index 6c1d291673..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/injection/AutowireObjectFactory.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * - * 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.core.system.injection; - -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.AutowireContext; -import org.apache.tuscany.core.injection.FactoryInitException; -import org.apache.tuscany.core.injection.ObjectCreationException; - -/** - * Returns an instance by resolving against an AutowireContext. - * - * @version $Rev: 385139 $ $Date: 2006-03-11 11:03:11 -0800 (Sat, 11 Mar 2006) $ - */ -public class AutowireObjectFactory<T> implements ObjectFactory<T> { - - private ContextResolver resolver; - - private Class<T> autowireType; - - /** - * - * @throws FactoryInitException - */ - public AutowireObjectFactory(Class<T> autowireType,ContextResolver resolver) { - assert (autowireType != null) : "Target interface was null"; - this.resolver = resolver; - this.autowireType = autowireType; - } - - /** - * Creates a new factory that resolves against the cuurent context using the given implementation type - * - * @throws FactoryInitException - */ - public AutowireObjectFactory(Class<T> implementationType) { - this(implementationType, null); - } - - public T getInstance() throws ObjectCreationException { - CompositeContext parent = resolver.getCurrentContext(); - if (parent == null) { - return null;// FIXME semantic here means required is not followed - } - if (!(parent instanceof AutowireContext)) { - ObjectCreationException e = new ObjectCreationException("Parent does not implement " - + AutowireContext.class.getName()); - e.setIdentifier(parent.getName()); - throw e; - } - AutowireContext ctx = (AutowireContext) parent; - return ctx.resolveInstance(autowireType); - } - - public void setContextResolver(ContextResolver resolver) { - this.resolver = resolver; - } - -} |