summaryrefslogtreecommitdiffstats
path: root/sandbox/ant/implementation-das/src/main
diff options
context:
space:
mode:
authordims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
committerdims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
commitbdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch)
tree38a92061c0793434c4be189f1d70c3458b6bc41d /sandbox/ant/implementation-das/src/main
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/ant/implementation-das/src/main')
-rw-r--r--sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASImplementation.java62
-rw-r--r--sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASImplementationActivator.java52
-rw-r--r--sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASInvoker.java60
-rw-r--r--sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASInvokerFactory.java50
-rw-r--r--sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DataAccessEngine.java52
-rw-r--r--sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DataAccessEngineManager.java70
-rw-r--r--sandbox/ant/implementation-das/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator20
7 files changed, 366 insertions, 0 deletions
diff --git a/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASImplementation.java b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASImplementation.java
new file mode 100644
index 0000000000..3d5877cb21
--- /dev/null
+++ b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASImplementation.java
@@ -0,0 +1,62 @@
+/*
+ * 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.sca.implementation.das;
+
+/**
+ * The model representing a sample DAS implementation in an SCA assembly model.
+ */
+public class DASImplementation {
+
+ private String config;
+ private String dataAccessType;
+
+ /**
+ * Return the DAS configuration side file
+ *
+ * @return the name of the das configuration side file
+ */
+ public String getConfig() {
+ return config;
+ }
+
+ /**
+ * Sets the DAS configuration side file
+ *
+ * @param config The name of the das configuration side file
+ */
+ public void setConfig(String config) {
+ this.config = config;
+ }
+
+ /**
+ * Return the data store type being used
+ * @return The data store type
+ */
+ public String getDataAccessType() {
+ return dataAccessType;
+ }
+
+ /**
+ * Sets the data store type being used
+ * @param dataAccessType The data store type in use
+ */
+ public void setDataAccessType(String dataAccessType) {
+ this.dataAccessType = dataAccessType;
+ }
+}
diff --git a/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASImplementationActivator.java b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASImplementationActivator.java
new file mode 100644
index 0000000000..184805188c
--- /dev/null
+++ b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASImplementationActivator.java
@@ -0,0 +1,52 @@
+/*
+ * 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.sca.implementation.das;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.spi.ImplementationActivator;
+import org.apache.tuscany.sca.spi.InvokerFactory;
+
+public class DASImplementationActivator implements ImplementationActivator<DASImplementation>{
+
+ private final DataAccessEngineManager dataAccessEngineManager;
+
+ private static final QName IMPLEMENTATION_DAS = new QName(Constants.SCA10_NS, "implementation.das");
+
+ public DASImplementationActivator() {
+ this.dataAccessEngineManager = new DataAccessEngineManager();
+ }
+
+ public InvokerFactory createInvokerFactory(RuntimeComponent rc, ComponentType ct, DASImplementation impl) {
+ return new DASInvokerFactory(rc, ct, impl, dataAccessEngineManager);
+ }
+
+ public Class<DASImplementation> getImplementationClass() {
+ return DASImplementation.class;
+ }
+
+ public QName getSCDLQName() {
+ return IMPLEMENTATION_DAS;
+ }
+
+}
diff --git a/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASInvoker.java b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASInvoker.java
new file mode 100644
index 0000000000..0949b41f6e
--- /dev/null
+++ b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASInvoker.java
@@ -0,0 +1,60 @@
+/*
+ * 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.sca.implementation.das;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+/**
+ * Implements a target invoker for DAS component implementations.
+ *
+ * The target invoker is responsible for dispatching invocations to the particular
+ * component implementation logic. The current component implementation will
+ * dispatch calls to the DAS apis to retrieve the requested data from the backend store
+ *
+ */
+public class DASInvoker implements Invoker {
+
+ private final Operation operation;
+ private final DataAccessEngine dataAccessEngine;
+
+ public DASInvoker(Operation operation, DataAccessEngine dataAccessEngine) {
+ this.operation = operation;
+ this.dataAccessEngine = dataAccessEngine;
+ }
+
+ public Message invoke(Message msg) {
+ Object[] args = msg.getBody();
+ Object resp = doTheWork(args);
+ msg.setBody(resp);
+ return msg;
+ }
+
+ public Object doTheWork(Object[] args) {
+ //simple execute command by name
+ if(args==null || args.length < 1){
+ return this.dataAccessEngine.executeCommand(operation.getName());
+ } else {
+ String xPath = (String) args[0];
+ return this.dataAccessEngine.executeCommand(operation.getName(), xPath);
+ }
+ }
+}
diff --git a/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASInvokerFactory.java b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASInvokerFactory.java
new file mode 100644
index 0000000000..f81cf29202
--- /dev/null
+++ b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DASInvokerFactory.java
@@ -0,0 +1,50 @@
+/*
+ * 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.sca.implementation.das;
+
+import org.apache.tuscany.das.rdb.DAS;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.spi.InvokerFactory;
+import org.osoa.sca.ServiceRuntimeException;
+
+public class DASInvokerFactory implements InvokerFactory {
+
+ DASImplementation impl;
+ DataAccessEngineManager dataAccessEngineManager;
+
+ public DASInvokerFactory(RuntimeComponent rc, ComponentType ct, DASImplementation impl, DataAccessEngineManager dataAccessEngineManager) {
+ this.impl = impl;
+ this.dataAccessEngineManager = dataAccessEngineManager;
+ }
+
+ public Invoker createInvoker(Operation operation) {
+ DAS das = null;
+ try {
+ das = dataAccessEngineManager.getDAS(impl.getConfig());
+ } catch(Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ return new DASInvoker(operation, new DataAccessEngine(das) );
+ }
+
+}
diff --git a/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DataAccessEngine.java b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DataAccessEngine.java
new file mode 100644
index 0000000000..a847695480
--- /dev/null
+++ b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DataAccessEngine.java
@@ -0,0 +1,52 @@
+/*
+ * 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.sca.implementation.das;
+
+import org.apache.tuscany.das.rdb.Command;
+import org.apache.tuscany.das.rdb.DAS;
+
+import commonj.sdo.DataObject;
+
+/**
+ * Facade to hide DAS implementation details of handling commands
+ */
+public class DataAccessEngine {
+ private final DAS das;
+
+ public DataAccessEngine(DAS das) {
+ this.das = das;
+ }
+
+ public DataObject executeCommand(String commandName) {
+ try {
+ Command command = this.das.getCommand(commandName);
+ return command.executeQuery();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public DataObject executeCommand(String commandName, String xPath) {
+ DataObject root = executeCommand(commandName);
+ return root.getDataObject(xPath);
+ }
+
+}
diff --git a/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DataAccessEngineManager.java b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DataAccessEngineManager.java
new file mode 100644
index 0000000000..6701ca993c
--- /dev/null
+++ b/sandbox/ant/implementation-das/src/main/java/org/apache/tuscany/sca/implementation/das/DataAccessEngineManager.java
@@ -0,0 +1,70 @@
+/*
+ * 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.sca.implementation.das;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.das.rdb.DAS;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * The DataAccessEngineManager acts like a registry and factory for DAS instances
+ * It holds DAS by it's config file name, reusing the same DAS for all components
+ * using the same config file.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataAccessEngineManager {
+
+ private final Map<String, DAS> registry = new HashMap<String, DAS>();
+
+ protected DAS initializeDAS(String config) {
+ //load the config file
+ System.out.println("Initializing DAS");
+ DAS das = DAS.FACTORY.createDAS(this.getConfigStream(config));
+
+ return das;
+ }
+
+ protected InputStream getConfigStream(String config) {
+ InputStream configStream = null;
+
+ try {
+ configStream = this.getClass().getResourceAsStream(config);
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+
+ return configStream;
+ }
+
+ public DAS getDAS(String config) {
+ DAS das = registry.get(config);
+ if ( das == null) {
+ das = this.initializeDAS(config);
+ this.registry.put(config, das);
+ }
+ return das;
+ }
+
+
+}
diff --git a/sandbox/ant/implementation-das/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator b/sandbox/ant/implementation-das/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator
new file mode 100644
index 0000000000..4e48eb63dd
--- /dev/null
+++ b/sandbox/ant/implementation-das/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator
@@ -0,0 +1,20 @@
+# 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.
+#
+# Implementation class for the ExtensionActivator
+#
+org.apache.tuscany.sca.implementation.das.DASImplementationActivator