summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:14:18 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:14:18 +0000
commitfdd5b43d3c139cf2cbd1655d2efbfaf9032a5b5e (patch)
treebcd16e19fa4bbd45f956812be8b65f7a143b573f /sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main
parent3caf8614f25d6b1962e20331fdf423c863bc02f3 (diff)
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835145 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main')
-rw-r--r--sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/java/org/apache/tuscany/sca/host/corba/jee/CorbaRuntimeModuleActivator.java52
-rw-r--r--sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/java/org/apache/tuscany/sca/host/corba/jee/JEECorbaHost.java162
-rw-r--r--sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator18
3 files changed, 232 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/java/org/apache/tuscany/sca/host/corba/jee/CorbaRuntimeModuleActivator.java b/sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/java/org/apache/tuscany/sca/host/corba/jee/CorbaRuntimeModuleActivator.java
new file mode 100644
index 0000000000..b5fe9f5d0f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/java/org/apache/tuscany/sca/host/corba/jee/CorbaRuntimeModuleActivator.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.host.corba.jee;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.host.corba.CorbaHostExtensionPoint;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CorbaRuntimeModuleActivator implements ModuleActivator {
+
+ private JEECorbaHost server;
+
+ public void start(ExtensionPointRegistry extensionPointRegistry) {
+
+ // Register our Corba host
+ CorbaHostExtensionPoint corbaHosts = extensionPointRegistry.getExtensionPoint(CorbaHostExtensionPoint.class);
+
+ server = new JEECorbaHost();
+ try {
+ server.start();
+ corbaHosts.addCorbaHost(server);
+ } catch (Exception e) {
+
+ }
+ }
+
+ public void stop(ExtensionPointRegistry registry) {
+ if (server != null) {
+ server.stop();
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/java/org/apache/tuscany/sca/host/corba/jee/JEECorbaHost.java b/sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/java/org/apache/tuscany/sca/host/corba/jee/JEECorbaHost.java
new file mode 100644
index 0000000000..7e714c1ca5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/java/org/apache/tuscany/sca/host/corba/jee/JEECorbaHost.java
@@ -0,0 +1,162 @@
+/*
+ * 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.host.corba.jee;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.rmi.PortableRemoteObject;
+
+import org.apache.tuscany.sca.host.corba.CorbaHost;
+import org.apache.tuscany.sca.host.corba.CorbaHostException;
+import org.apache.tuscany.sca.host.corba.CorbaHostUtils;
+import org.apache.tuscany.sca.host.corba.CorbanameURL;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.Object;
+import org.omg.CosNaming.NameComponent;
+import org.omg.CosNaming.NamingContext;
+import org.omg.CosNaming.NamingContextExt;
+import org.omg.CosNaming.NamingContextExtHelper;
+import org.omg.CosNaming.NamingContextHelper;
+import org.omg.CosNaming.NamingContextPackage.InvalidName;
+import org.omg.CosNaming.NamingContextPackage.NotFound;
+
+/**
+ * @version $Rev$ $Date$
+ * Implementation of JEE CORBA host
+ */
+public class JEECorbaHost implements CorbaHost {
+
+ public static final String ORB_NAME = "java:comp/ORB";
+
+ private List<String> registeredServants = Collections.synchronizedList(new ArrayList<String>());
+ private ORB orb;
+
+ private void registerURI(String uri) {
+ registeredServants.add(uri);
+ }
+
+ private void removeURI(String uri) {
+ registeredServants.remove(uri);
+ }
+
+ private NamingContextExt getNamingContext(String nameService) throws Exception {
+ org.omg.CORBA.Object objRef = orb.resolve_initial_references(nameService);
+ return NamingContextExtHelper.narrow(objRef);
+ }
+
+ private void handleException(Exception e) throws CorbaHostException {
+ // The cause of the Exception is JDK specific
+ if (e instanceof NotFound) {
+ throw new CorbaHostException(CorbaHostException.NO_SUCH_OBJECT, e);
+ } else if (e instanceof InvalidName) {
+ throw new CorbaHostException(e);
+ } else {
+ throw new CorbaHostException(e);
+ }
+ }
+
+ public void registerServant(String uri, Object servantObject) throws CorbaHostException {
+ CorbanameURL details = CorbaHostUtils.getServiceDetails(uri);
+ try {
+ NamingContext namingCtx = getNamingContext(details.getNameService());
+ for (int i = 0; i < details.getNamePath().size() - 1; i++) {
+ NameComponent nc = new NameComponent(details.getNamePath().get(i), "");
+ NameComponent[] path = new NameComponent[] {nc};
+ try {
+ namingCtx = NamingContextHelper.narrow(namingCtx.resolve(path));
+ } catch (Exception e) {
+ namingCtx = namingCtx.bind_new_context(path);
+ }
+ }
+ NameComponent finalName =
+ new NameComponent(details.getNamePath().get(details.getNamePath().size() - 1), "");
+ try {
+ namingCtx.resolve(new NameComponent[] {finalName});
+ // no exception means that some object is already registered
+ // under this name, we need to crash here
+ throw new CorbaHostException(CorbaHostException.BINDING_IN_USE);
+ } catch (NotFound e) {
+ namingCtx.bind(new NameComponent[] {finalName}, servantObject);
+ registerURI(uri);
+ }
+ } catch (CorbaHostException e) {
+ throw e;
+ } catch (Exception e) {
+ handleException(e);
+ }
+ }
+
+ public void unregisterServant(String uri) throws CorbaHostException {
+ CorbanameURL details = CorbaHostUtils.getServiceDetails(uri);
+ try {
+ NamingContextExt namingCtx = getNamingContext(details.getNameService());
+ namingCtx.unbind(namingCtx.to_name(details.getName()));
+ removeURI(uri);
+ } catch (Exception e) {
+ handleException(e);
+ }
+ }
+
+ public Object lookup(String uri) throws CorbaHostException {
+ Object result = null;
+ try {
+ CorbanameURL url = new CorbanameURL(uri);
+ NamingContextExt context = getNamingContext(url.getNameService());
+ result = context.resolve_str(url.getName());
+ } catch (Exception e) {
+ // e.printStackTrace();
+ handleException(e);
+ }
+ if (result == null) {
+ throw new CorbaHostException(CorbaHostException.NO_SUCH_OBJECT);
+ }
+ return result;
+ }
+
+ // obtain ORB from environment
+ public void start() throws CorbaHostException {
+ Context ctx;
+ try {
+ ctx = new InitialContext();
+ orb = (ORB)PortableRemoteObject.narrow(ctx.lookup(ORB_NAME), org.omg.CORBA.ORB.class);
+ } catch (Exception e) {
+ throw new CorbaHostException(e);
+ }
+ }
+
+ // unregister registered servants
+ public void stop() {
+ // use copy because unregisterServant(...) method removes from
+ // registeredServants collection
+ List<String> rsCopy = new ArrayList<String>(registeredServants);
+ for (String servantURI : rsCopy) {
+ try {
+ unregisterServant(servantURI);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
new file mode 100644
index 0000000000..3762550c01
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.5.1/modules/host-corba-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
@@ -0,0 +1,18 @@
+# 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.
+
+org.apache.tuscany.sca.host.corba.jee.CorbaRuntimeModuleActivator