diff options
Diffstat (limited to 'sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplAtomicComponent.java')
-rw-r--r-- | sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplAtomicComponent.java | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplAtomicComponent.java b/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplAtomicComponent.java new file mode 100644 index 0000000000..a6bd04baad --- /dev/null +++ b/sandbox/SPI/implementation-spi-impl/src/main/java/org/apache/tuscany/spi/implementation/impl/ImplAtomicComponent.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.implementation.impl; + +import java.net.URI; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.assembly.ComponentProperty; +import org.apache.tuscany.assembly.Implementation; +import org.apache.tuscany.core.component.ComponentContextImpl; +import org.apache.tuscany.core.component.ComponentContextProvider; +import org.apache.tuscany.core.component.ServiceReferenceImpl; +import org.apache.tuscany.core.component.scope.InstanceWrapperBase; +import org.apache.tuscany.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.interfacedef.Operation; +import org.apache.tuscany.spi.ObjectCreationException; +import org.apache.tuscany.spi.ObjectFactory; +import org.apache.tuscany.spi.SingletonObjectFactory; +import org.apache.tuscany.spi.component.InstanceWrapper; +import org.apache.tuscany.spi.component.TargetInvokerCreationException; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.apache.tuscany.spi.extension.AtomicComponentExtension; +import org.apache.tuscany.spi.implementation.ImplementationActivator; +import org.apache.tuscany.spi.implementation.Invoker; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.Wire; +import org.osoa.sca.CallableReference; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.ServiceReference; + +public class ImplAtomicComponent extends AtomicComponentExtension implements ComponentContextProvider { + + private ComponentContext componentContext; + private ImplementationActivator ia; + private Implementation impl; + + private Map<String, Object> references; + private Map<String, ObjectFactory<?>> propertyValueFactories; + + private PropertyValueObjectFactory propertyValueObjectFactory = null; + private DataBindingExtensionPoint dataBindingRegistry; + + public ImplAtomicComponent(URI uri, URI groupId, ImplementationActivator ia, Implementation impl) { + super(uri, null, null, groupId, 50); + this.ia = ia; + this.componentContext = new ComponentContextImpl(this); + this.impl = impl; + references = new HashMap<String, Object>(); + propertyValueFactories = new HashMap<String, ObjectFactory<?>>(); + } + + public Object createInstance() throws ObjectCreationException { + Map<String, Object> properties = new HashMap<String, Object>(); + for (String propertyName : propertyValueFactories.keySet()) { + ObjectFactory<?> propertyValueFactory = propertyValueFactories.get(propertyName); + if ( propertyValueFactory != null) { + properties.put(propertyName, propertyValueFactory.getInstance()); + } + } + return ia.getInvokerFactory(impl).getInstance(references, properties); + } + + public InstanceWrapper createInstanceWrapper() throws ObjectCreationException { + return new InstanceWrapperBase(createInstance()); + } + + public void attachCallbackWire(Wire arg0) { + } + + public void attachWire(Wire wire) { + references.put(wire.getSourceUri().getFragment(), createWireProxy(wire)); + } + + protected Object createWireProxy(Wire wire) { + // TODO: this is completly wrong :) Need to create a proxy wraping the wire + Object ref; + try { + ref = wire.getTargetInstance(); + } catch (TargetResolutionException e) { + throw new RuntimeException(e); + } + return ref; + } + + public void attachWires(List<Wire> arg0) { + } + + public List<Wire> getWires(String arg0) { + return null; + } + + public TargetInvoker createTargetInvoker(String targetName, final Operation operation, boolean callback) + throws TargetInvokerCreationException { + Invoker invoker = ia.getInvokerFactory(impl).createInvoker(operation); + return new ImplTargetInvoker(invoker, this, scopeContainer, workContext); + } + + @Override + public ComponentContext getComponentContext() { + return componentContext; + } + + public <B, R extends CallableReference<B>> R cast(B target) { + return null; + } + + public <B> B getProperty(Class<B> type, String propertyName) { + return null; + } + + public <B> B getService(Class<B> businessInterface, String referenceName) { + return null; + } + + public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) { + return new ServiceReferenceImpl<B>(businessInterface, new SingletonObjectFactory<B>((B)createInstance())); + } + public void setDataBindingRegistry(DataBindingExtensionPoint dataBindingRegistry) { + this.dataBindingRegistry = dataBindingRegistry; + } + + public void setPropertyValueObjectFactory(PropertyValueObjectFactory propertyValueObjectFactory) { + this.propertyValueObjectFactory = propertyValueObjectFactory; + } + + public void initializePropertyValueFactories(List<ComponentProperty> properties) { + ObjectFactory<?> propertyObjectFactory = null; + + for (ComponentProperty aProperty : properties) { + if (aProperty.getValue() != null) { + propertyObjectFactory = propertyValueObjectFactory.createValueFactory(aProperty); + propertyValueFactories.put(aProperty.getName(), propertyObjectFactory); + } + } + } +} |