summaryrefslogtreecommitdiffstats
path: root/sandbox/lresende/backup/container.das/src/main/java/org/apache/tuscany/container/dataaccess/DataAccessComponent.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/lresende/backup/container.das/src/main/java/org/apache/tuscany/container/dataaccess/DataAccessComponent.java')
-rw-r--r--sandbox/lresende/backup/container.das/src/main/java/org/apache/tuscany/container/dataaccess/DataAccessComponent.java128
1 files changed, 128 insertions, 0 deletions
diff --git a/sandbox/lresende/backup/container.das/src/main/java/org/apache/tuscany/container/dataaccess/DataAccessComponent.java b/sandbox/lresende/backup/container.das/src/main/java/org/apache/tuscany/container/dataaccess/DataAccessComponent.java
new file mode 100644
index 0000000000..abd1a587d0
--- /dev/null
+++ b/sandbox/lresende/backup/container.das/src/main/java/org/apache/tuscany/container/dataaccess/DataAccessComponent.java
@@ -0,0 +1,128 @@
+/*
+ * 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.container.dataaccess;
+
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.tuscany.container.dataaccessscript.DataAccessInstanceImpl;
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.AtomicComponentExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireService;
+
+/**
+ * The DAS component implementation.
+ */
+public class DataAccessComponent extends AtomicComponentExtension {
+
+ private final List<Class<?>> services;
+ //private final Map<String, Object> properties;
+
+ private DataAccessInstanceFactory factory;
+
+
+ public DataAccessComponent(String name,
+ DataAccessInstanceFactory factory,
+ /*Map<String, Object> propValues,*/
+ List<Class<?>> services,
+ CompositeComponent parent,
+ ScopeContainer scopeContainer,
+ WireService wireService,
+ WorkScheduler workScheduler,
+ WorkContext workContext) {
+ super(name, parent, /*scopeContainer,*/ wireService, workContext, workScheduler, null, 0);
+ this.factory = factory;
+ this.services = services;
+ this.scope = scopeContainer.getScope();
+ //this.properties = propValues;
+ }
+
+ public DataAccessComponent(DataAccessComponentConfiguration config) {
+ super(config.getName(),
+ config.getParent(),
+ /*config.getScopeContainer(),*/
+ config.getWireService(),
+ config.getWorkContext(),
+ config.getWorkScheduler(),
+ config.getMonitor(),
+ config.getInitLevel());
+ this.factory = config.getFactory();
+ this.services = config.getServices();
+ this.scope = config.getScopeContainer().getScope();
+ //this.properties = config.getPropertyValues();
+ }
+
+
+
+ public Object createInstance() throws ObjectCreationException {
+// Map<String, Object> context = new HashMap<String, Object>(getProperties());
+// Object instance = dataAccessAdapter.createScriptInstance(context, dataAccessAdapter.getDataAccessType());
+//
+// return instance;
+
+ return factory.getInstance();
+ }
+
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation, InboundWire callbackWire) {
+ //System.out.println("operation:"+operation.getName()+operation.getMetaData());
+ //return new DataAccessInvoker(operation.getName(), this, operation.getOutputType().getPhysical().getClass());
+
+ Method[] methods = operation.getServiceContract().getInterfaceClass().getMethods();
+ Method method = findMethod(operation, methods);
+ return new DataAccessInvoker(method.getName(), this, operation.getOutputType().getPhysical().getClass());
+ }
+ // TODO: move all the following up to AtomicComponentExtension?
+ public List<Class<?>> getServiceInterfaces() {
+ return services;
+ }
+
+// public Map<String, Object> getProperties() {
+// return properties;
+// }
+
+ public Object getServiceInstance() throws TargetResolutionException {
+ return getServiceInstance(null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object getServiceInstance(String service) throws TargetResolutionException {
+ InboundWire wire = getInboundWire(service);
+ if (wire == null) {
+ throw new TargetResolutionException("Service '" + service + "'not found"); // TODO better error message
+ }
+ Class<?> clazz = wire.getServiceContract().getInterfaceClass();
+ return wireService.createProxy(clazz, wire);
+ }
+
+ public DataAccessInstanceImpl getTargetInstance() throws TargetResolutionException {
+ return (DataAccessInstanceImpl) scopeContainer.getInstance(this);
+ }
+
+}