geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r505432 [3/11] - in /geronimo/server/trunk: applications/magicGball/magicGball-ear/src/main/plan/ configs/client-corba-yoko/src/plan/ configs/j2ee-corba-yoko/src/plan/ configs/openejb-corba-deployer/src/plan/ modules/ modules/geronimo-corba...
Date Fri, 09 Feb 2007 19:24:39 GMT
Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBABean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBABean.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBABean.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBABean.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,344 @@
+/**
+ * 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.geronimo.corba;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+
+import javax.ejb.spi.HandleDelegate;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.corba.security.config.ConfigAdapter;
+import org.apache.geronimo.corba.security.config.ssl.SSLConfig;
+import org.apache.geronimo.corba.security.config.tss.TSSConfig;
+import org.apache.geronimo.corba.security.config.tss.TSSSSLTransportConfig;
+import org.apache.geronimo.corba.security.config.tss.TSSTransportMechConfig;
+import org.apache.geronimo.corba.util.Util;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.Policy;
+import org.omg.PortableServer.POA;
+import org.omg.PortableServer.POAHelper;
+
+
+/**
+ * A CORBABean is a main CORBA server configuration.  The
+ * CORBABean is the hosting ORB to which additional TSSBeans
+ * attach to export EJBs.  The CORBABean may be configured
+ * to use either plain socket listeners or SSL listeners, based
+ * on the bean specification.  All TSSBean objects attached
+ * to this Bean instance will share the same listener
+ * endpoint and transport-level security.
+ * @version $Revision: 497125 $ $Date: 2007-01-17 10:51:30 -0800 (Wed, 17 Jan 2007) $
+ */
+public class CORBABean implements GBeanLifecycle, ORBRef, ORBConfiguration {
+    private final Log log = LogFactory.getLog(CORBABean.class);
+
+    private final ClassLoader classLoader;
+    private final ConfigAdapter configAdapter;
+    // the initial listener port
+    private int listenerPort;
+    // the host name we expose in IORs
+    private String host;
+    private TSSConfig tssConfig;
+    private SSLConfig sslConfig;
+    private ORB orb;
+    private POA rootPOA;
+    private NameService nameService;
+    private AbstractName abstractName;
+    // ORB-specific policy overrides we need to add to POA policies created by 
+    // child TSSBeans.  
+    private Policy[] policyOverrides = null; 
+
+    public CORBABean() {
+        this.classLoader = null;
+        this.configAdapter = null;
+        this.sslConfig = null;
+        this.listenerPort = -1;
+        this.host = null;
+        this.abstractName = null;
+        this.policyOverrides = null; 
+    }
+
+    /**
+     * Instantiate a CORBABean instance.
+     *
+     * @param abstractName
+     *               The server-created abstract name for this bean instance.
+     * @param configAdapter
+     *               The ORB ConfigAdapter used to interface with the
+     *               JVM-configured ORB instance.
+     * @param host   The hostname we publish ourselves under.
+     * @param listenerPort
+     *               The initial listener port to use.
+     * @param classLoader
+     *               The ClassLoader used for ORB context class loading.
+     * @param nameService
+     *               The initial name service the created ORB will use
+     *               for object resolution.
+     * @param ssl    The SSL configuration, including the KeystoreManager.
+     *
+     */
+    public CORBABean(AbstractName abstractName, ConfigAdapter configAdapter, String host, int listenerPort, ClassLoader classLoader, NameService nameService, SSLConfig ssl) {
+        this.abstractName = abstractName;
+        this.classLoader = classLoader;
+        this.configAdapter = configAdapter;
+        sslConfig = ssl;
+        this.nameService = nameService;
+        this.host = host;
+        this.listenerPort = listenerPort;
+        this.policyOverrides = null; 
+    }
+
+    /**
+     * Retrieve the NameService this CORBA server depends upon.
+     *
+     * @return The configured NameService instance.
+     */
+    public NameService getNameService() {
+        return nameService;
+    }
+
+    /**
+     * Setter attribute for the NameService.
+     *
+     * @param s      The new target name service.
+     */
+    public void setNameService(NameService s) {
+        nameService = s;
+    }
+
+    /**
+     * Get the optional TSSConfig object specified for this
+     * CORBABean server.
+     *
+     * @return The TSSConfig object (if any).
+     */
+    public TSSConfig getTssConfig() {
+        // if nothing has been explicitly set, ensure we return
+        // a default one.
+        if (tssConfig == null) {
+            tssConfig = new TSSConfig();
+        }
+        return tssConfig;
+    }
+
+    /**
+     * Set a TSSConfig value for this CORBA instance.
+     *
+     * @param config The required TSSConfig information.
+     */
+    public void setTssConfig(TSSConfig config) {
+        this.tssConfig = config;
+    }
+
+    /**
+     * Return the SSLConfig used for this ORB instance.
+     * if one has not been configured, this returns
+     * a default configuration.
+     *
+     * @return The SSLConfig object use to manage transport-level
+     *         security.
+     */
+    public SSLConfig getSslConfig() {
+        if (sslConfig == null) {
+            sslConfig = new SSLConfig();
+        }
+        return sslConfig;
+    }
+
+    /**
+     * Attribute setter for the SSL configuration.
+     *
+     * @param c      The new SSLConfig object used for secure communications.
+     */
+    public void setSslConfing(SSLConfig c) {
+        sslConfig = c;
+    }
+
+
+    /**
+     * Return the ORB instance created for this CORBABean.
+     *
+     * @return The ORB instance backing this bean.
+     */
+    public ORB getORB() {
+        return orb;
+    }
+
+    public HandleDelegate getHandleDelegate() {
+        return new CORBAHandleDelegate();
+    }
+
+    /**
+     * Get the root POA() instance associated with the ORB.
+     *
+     * @return The rootPOA instance obtained from the ORB.
+     */
+    public POA getRootPOA() {
+        return rootPOA;
+    }
+
+    /**
+     * Retrieve the listener address (host/port combo) used
+     * by the ORB.
+     *
+     * @return An InetSocketAddress item identifying the end point
+     *         for the ORB.
+     */
+    public InetSocketAddress getListenAddress() {
+        return new InetSocketAddress(host, listenerPort);
+    }
+
+    /**
+     * Start the ORB associated with this bean instance.
+     *
+     * @exception Exception
+     */
+    public void doStart() throws Exception {
+
+        ClassLoader savedLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(classLoader);
+
+            // make sure we've decided how the listener should be configured.
+            resolveListenerAddress();
+
+            log.debug("CORBABean " + getURI() + " creating listener on port " + listenerPort);
+            // the config adapter creates the actual ORB instance for us.
+            orb = configAdapter.createServerORB(this);
+
+            // we set this ORB value into the Util.  The Util ORB is used for a lot of utility things, so
+            // we'll cache the first instance created.
+            Util.setORB(orb);
+
+            // TSSBeans are going to need our rootPOA instance, so resolve this now.
+            org.omg.CORBA.Object obj = orb.resolve_initial_references("RootPOA");
+            rootPOA = POAHelper.narrow(obj);
+        } finally {
+            Thread.currentThread().setContextClassLoader(savedLoader);
+        }
+
+    }
+
+    public void doStop() throws Exception {
+        orb.destroy();
+        log.debug("Stopped CORBABean");
+    }
+
+    public void doFail() {
+        log.warn("Failed CORBABean");
+    }
+
+    /**
+     * Process the specified host/port information on
+     * both the bean and the TSSConfig to arrive at a
+     * target port.  This must be called prior to creating
+     * the ORB.
+     */
+    private void resolveListenerAddress() {
+        // if we have a config with a TSSSSLTransportConfig defined, the
+        // host and port from the config override bean-configured values.
+        if (tssConfig != null) {
+            TSSTransportMechConfig transportMech = tssConfig.getTransport_mech();
+            if (transportMech != null) {
+                if (transportMech instanceof TSSSSLTransportConfig) {
+                    TSSSSLTransportConfig transportConfig = (TSSSSLTransportConfig) transportMech;
+                    host = transportConfig.getHostname();
+                    listenerPort = transportConfig.getPort();
+                }
+            }
+        }
+        // now provide defaults for anything still needing resolving
+        if (host == null) {
+            try {
+                host = InetAddress.getLocalHost().getHostName();
+            } catch (UnknownHostException e) {
+                // just punt an use localhost as an absolute fallback.
+                host = "localhost";
+            }
+        }
+
+        // if nothing has been explicitly specified, we use a port value of -1, which
+        // allows the ORB to allocate the address.
+    }
+
+    /**
+     * Return the retrieval URI for this bean.
+     *
+     * @return The URI for the bean AbstractName;
+     */
+    public String getURI() {
+        return abstractName.toString();
+    }
+
+    /**
+     * Get the configured listener port.
+     *
+     * @return The configeration port value.
+     */
+    public int getPort() {
+        return listenerPort;
+    }
+
+    /**
+     * Get the configuration host name.
+     *
+     * @return The configuration host name.  The default is "localhost".
+     */
+    public String getHost() {
+        return host;
+    }
+    
+    /**
+     * Set a set of policy overrides to be used with 
+     * this ORB instance.  These are normally set by 
+     * the ORBConfigAdapter instance when the ORB 
+     * is created. 
+     * 
+     * @param overrides The new override list.
+     */
+    public void setPolicyOverrides(Policy[] overrides) {
+        policyOverrides = overrides; 
+    }
+    
+    /**
+     * Add the policy overrides (if any) to the list 
+     * of policies used to create a POA instance.
+     * 
+     * @param policies The base set of policies.
+     * 
+     * @return A new Policy array with the overrides added.  Returns
+     *         the same array if no overrides are required.
+     */
+    public Policy[] addPolicyOverrides(Policy[] policies) {
+        // just return the same list of no overrides exist 
+        if (policyOverrides == null) {
+            return policies; 
+        }
+        
+        Policy[] newPolicies = new Policy[policies.length + policyOverrides.length]; 
+        
+        System.arraycopy(policies, 0, newPolicies, 0, policies.length); 
+        System.arraycopy(policyOverrides, 0, newPolicies, policies.length, policyOverrides.length); 
+        
+        return newPolicies; 
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBABeanGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBABeanGBean.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBABeanGBean.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBABeanGBean.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,68 @@
+/**
+ * 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.geronimo.corba;
+
+import java.net.InetSocketAddress;
+
+import javax.ejb.spi.HandleDelegate;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.corba.security.config.ConfigAdapter;
+import org.apache.geronimo.corba.security.config.ssl.SSLConfig;
+import org.apache.geronimo.corba.security.config.tss.TSSConfig;
+import org.omg.CORBA.ORB;
+import org.omg.PortableServer.POA;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public final class CORBABeanGBean {
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(CORBABeanGBean.class, "OpenEJB ORB Adapter", CORBABean.class, NameFactory.CORBA_SERVICE);
+
+        infoBuilder.addAttribute("abstractName", AbstractName.class, false);
+        infoBuilder.addAttribute("host", String.class, true);
+        infoBuilder.addAttribute("port", int.class, true);
+        infoBuilder.addAttribute("tssConfig", TSSConfig.class, true);
+
+        infoBuilder.addAttribute("listenAddress", InetSocketAddress.class, false);
+        infoBuilder.addAttribute("ORB", ORB.class, false);
+        infoBuilder.addAttribute("rootPOA", POA.class, false);
+
+        infoBuilder.addAttribute("handleDelegate", HandleDelegate.class, false);
+
+        infoBuilder.addAttribute("classLoader", ClassLoader.class, false);
+
+        infoBuilder.addReference("ConfigAdapter", ConfigAdapter.class, NameFactory.ORB_CONFIG);
+        infoBuilder.addReference("SSLConfig", SSLConfig.class, NameFactory.CORBA_SSL);
+        infoBuilder.addReference("NameService", NameService.class, NameFactory.CORBA_NAME_SERVICE);
+
+        infoBuilder.setConstructor(new String[]{"abstractName", "ConfigAdapter", "host", "port", "classLoader", "NameService", "SSLConfig"});
+
+        GBEAN_INFO = infoBuilder.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAEJBMemento.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAEJBMemento.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAEJBMemento.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAEJBMemento.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,66 @@
+/**
+ * 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.geronimo.corba;
+
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import java.io.InvalidObjectException;
+import javax.ejb.EJBObject;
+import javax.ejb.EJBHome;
+import javax.rmi.PortableRemoteObject;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.omg.CORBA.ORB;
+
+/**
+ * @version $Revision: 474745 $ $Date: 2006-11-14 03:30:38 -0800 (Tue, 14 Nov 2006) $
+ */
+public class CORBAEJBMemento implements Serializable {
+    private final String ior;
+    private final boolean home;
+
+    public CORBAEJBMemento(String ior, boolean home) {
+        this.ior = ior;
+        this.home = home;
+    }
+
+    private Object readResolve() throws ObjectStreamException {
+        Class type;
+        if (home) {
+            type = EJBHome.class;
+        } else {
+            type = EJBObject.class;
+        }
+
+        try {
+            return PortableRemoteObject.narrow(getOrb().string_to_object(ior), type);
+        } catch (Exception e) {
+            throw (InvalidObjectException) new InvalidObjectException("Unable to convert IOR into object").initCause(e);
+        }
+    }
+
+    private static ORB getOrb() {
+        try {
+            Context context = new InitialContext();
+            ORB orb = (ORB) context.lookup("java:comp/ORB");
+            return orb;
+        } catch (Throwable e) {
+            throw new org.omg.CORBA.MARSHAL("Could not find ORB in jndi at java:comp/ORB", 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
+        }
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAEJBMetaData.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAEJBMetaData.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAEJBMetaData.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAEJBMetaData.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,111 @@
+/**
+ * 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.geronimo.corba;
+
+import javax.ejb.EJBMetaData;
+import javax.ejb.EJBHome;
+import javax.rmi.PortableRemoteObject;
+
+/**
+ * @version $Revision: 465108 $ $Date: 2006-10-17 17:23:40 -0700 (Tue, 17 Oct 2006) $
+ */
+public class CORBAEJBMetaData implements EJBMetaData, java.io.Serializable {
+
+    private static final long serialVersionUID = 8085488135161906381L;
+
+    public final static byte ENTITY = 1;
+    public final static byte STATEFUL = 2;
+    public final static byte STATELESS = 3;
+
+    /**
+     * The Class of the bean's home interface.
+     */
+    private final Class homeInterface;
+
+    /**
+     * The Class of the bean's remote interface.
+     */
+    private final Class remoteInterface;
+
+    /**
+     * The Class of the bean's primary key or null if the
+     * bean is of a type that does not require a primary key.
+     */
+    private final Class primaryKeyClass;
+
+    /**
+     * The EJBHome stub/proxy for this bean deployment.
+     */
+    private final EJBHome ejbHome;
+
+    /**
+     * The type of bean that this MetaData implementation represents.
+     *
+     * @see #ENTITY
+     * @see #STATEFUL
+     * @see #STATELESS
+     */
+    private final byte ejbType;
+
+    public CORBAEJBMetaData(EJBHome ejbHome, byte ejbType, Class homeInterface, Class remoteInterface, Class primaryKeyClass) {
+        if (homeInterface == null) {
+            throw new IllegalArgumentException("Home interface is null");
+        }
+        if (remoteInterface == null) {
+            throw new IllegalArgumentException("Remote interface is null");
+        }
+        if (ejbType == ENTITY && primaryKeyClass == null) {
+            throw new IllegalArgumentException("Entity bean must have a primary key class");
+        }
+        if (ejbType != ENTITY && primaryKeyClass != null) {
+            throw new IllegalArgumentException("Session bean must have a primary key class");
+        }
+        this.ejbHome = ejbHome;
+        this.ejbType = ejbType;
+        this.homeInterface = homeInterface;
+        this.remoteInterface = remoteInterface;
+        this.primaryKeyClass = primaryKeyClass;
+    }
+
+    public Class getHomeInterfaceClass() {
+        return homeInterface;
+    }
+
+    public Class getRemoteInterfaceClass() {
+        return remoteInterface;
+    }
+
+    public Class getPrimaryKeyClass() {
+        if (ejbType == ENTITY) {
+            return primaryKeyClass;
+        } else {
+            throw new UnsupportedOperationException("Session objects are private resources and do not have primary keys");
+        }
+    }
+
+    public boolean isSession() {
+        return (ejbType == STATEFUL || ejbType == STATELESS);
+    }
+
+    public boolean isStatelessSession() {
+        return ejbType == STATELESS;
+    }
+
+    public EJBHome getEJBHome() {
+        return (EJBHome) PortableRemoteObject.narrow(ejbHome, EJBHome.class);
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAException.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAException.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAException.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAException.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,39 @@
+/**
+ * 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.geronimo.corba;
+
+
+/**
+ * @version $Revision: 465172 $ $Date: 2006-10-18 01:16:14 -0700 (Wed, 18 Oct 2006) $
+ */
+public class CORBAException extends Exception {
+    public CORBAException() {
+        super();
+    }
+
+    public CORBAException(String message) {
+        super(message);
+    }
+
+    public CORBAException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public CORBAException(Throwable cause) {
+        super(cause);
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHandle.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHandle.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHandle.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHandle.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,97 @@
+/**
+ * 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.geronimo.corba;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.rmi.RemoteException;
+import javax.ejb.EJBObject;
+import javax.ejb.Handle;
+import javax.ejb.spi.HandleDelegate;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.omg.CORBA.ORB;
+
+
+/**
+ * EJB v2.1 spec, section 19.5.5.1
+ * <p/>
+ * The <code>javax.ejb.spi.HandleDelegate</code> service provider interface
+ * defines methods that enable portable implementations of <code>Handle</code>
+ * and <code>HomeHandle</code> that are instantiated in a different vendor’s
+ * container to serialize and deserialize EJBObject and EJBHome references.
+ * The <code>HandleDelegate</code> interface is not used by enterprise beans
+ * or J2EE application components directly.
+ *
+ * @version $Revision: 494431 $ $Date: 2007-01-09 07:18:14 -0800 (Tue, 09 Jan 2007) $
+ */
+public class CORBAHandle implements Handle, Serializable {
+
+    private static final long serialVersionUID = -3390719015323727224L;
+
+    // the actual EJBObject instance
+    private EJBObject ejbObject;
+    private Object primaryKey;
+
+    public CORBAHandle(EJBObject ejb, Object primaryKey) {
+        this.ejbObject = ejb;
+        this.primaryKey = primaryKey;
+    }
+
+    public EJBObject getEJBObject() throws RemoteException {
+        return ejbObject;
+    }
+
+    public Object getPrimaryKey() {
+        return primaryKey;
+    }
+
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        HandleDelegate handleDelegate = getHandleDelegate();
+        handleDelegate.writeEJBObject(getEJBObject(), out);
+        out.writeObject(primaryKey);
+    }
+
+    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+        HandleDelegate handleDelegate = getHandleDelegate();
+        ejbObject = handleDelegate.readEJBObject(in);
+        primaryKey = in.readObject();
+    }
+
+    private static ORB getOrb() {
+        try {
+            Context context = new InitialContext();
+            ORB orb = (ORB) context.lookup("java:comp/ORB");
+            return orb;
+        } catch (Throwable e) {
+            throw new org.omg.CORBA.MARSHAL("Could not find ORB in jndi at java:comp/ORB", 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
+        }
+    }
+
+    private static HandleDelegate getHandleDelegate() {
+        try {
+            Context context = new InitialContext();
+            HandleDelegate handleDelegate = (HandleDelegate) context.lookup("java:comp/HandleDelegate");
+            return handleDelegate;
+        } catch (Throwable e) {
+            throw new org.omg.CORBA.MARSHAL("Could not find handle delegate in jndi at java:comp/HandleDelegate", 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
+        }
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHandleDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHandleDelegate.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHandleDelegate.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHandleDelegate.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,73 @@
+/**
+ * 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.geronimo.corba;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import javax.ejb.EJBHome;
+import javax.ejb.EJBObject;
+import javax.ejb.spi.HandleDelegate;
+import javax.rmi.PortableRemoteObject;
+
+
+/**
+ * See ejb spec 2.1, 19.5.5.1
+ *
+ * @version $Revision: 465108 $ $Date: 2006-10-17 17:23:40 -0700 (Tue, 17 Oct 2006) $
+ */
+public class CORBAHandleDelegate implements HandleDelegate {
+
+    /**
+     * Called by home handles to deserialize stubs in any app server, including ones by other vendors.
+     * The spec seems to imply that a simple cast of in.readObject() should work but in certain
+     * orbs this does not seem to work and in.readObject returns a generic remote stub that needs
+     * to be narrowed.  Although we think this is likely an orb bug this code with narrow will
+     * work in both circumstances.
+     * @param in
+     * @return
+     * @throws ClassNotFoundException
+     * @throws IOException
+     */
+    public EJBHome readEJBHome(ObjectInputStream in) throws ClassNotFoundException, IOException {
+        Object o = in.readObject();
+        EJBHome home = (EJBHome) PortableRemoteObject.narrow(o, EJBHome.class);
+        return home;
+    }
+
+    /**
+     * Called by handles to deserialize stubs in any app server.  See comment to readEJBHome.
+     * @param in
+     * @return
+     * @throws ClassNotFoundException
+     * @throws IOException
+     */
+    public EJBObject readEJBObject(ObjectInputStream in) throws ClassNotFoundException, IOException {
+        Object o = in.readObject();
+        EJBObject object = (EJBObject) PortableRemoteObject.narrow(o, EJBObject.class);
+        return object;
+    }
+
+    public void writeEJBHome(EJBHome ejbHome, ObjectOutputStream out) throws IOException {
+        out.writeObject(ejbHome);
+    }
+
+    public void writeEJBObject(EJBObject ejbObject, ObjectOutputStream out) throws IOException {
+        out.writeObject(ejbObject);
+    }
+
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHomeHandle.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHomeHandle.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHomeHandle.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CORBAHomeHandle.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,100 @@
+/**
+ * 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.geronimo.corba;
+
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.rmi.RemoteException;
+import javax.ejb.EJBHome;
+import javax.ejb.HomeHandle;
+import javax.ejb.spi.HandleDelegate;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.rmi.PortableRemoteObject;
+
+import org.omg.CORBA.ORB;
+
+
+/**
+ * EJB v2.1 spec, section 19.5.5.1
+ * <p/>
+ * The <code>javax.ejb.spi.HandleDelegate</code> service provider interface
+ * defines methods that enable portable implementations of <code>Handle</code>
+ * and <code>HomeHandle</code> that are instantiated in a different vendor’s
+ * container to serialize and deserialize EJBObject and EJBHome references.
+ * The <code>HandleDelegate</code> interface is not used by enterprise beans
+ * or J2EE application components directly.
+ *
+ * @version $Revision: 474745 $ $Date: 2006-11-14 03:30:38 -0800 (Tue, 14 Nov 2006) $
+ */
+public class CORBAHomeHandle implements HomeHandle, Serializable {
+
+    private static final long serialVersionUID = -5537884768260058215L;
+
+    private String ior;
+
+    public CORBAHomeHandle(String ior) {
+        this.ior = ior;
+    }
+
+    public EJBHome getEJBHome() throws RemoteException {
+
+        try {
+            return (EJBHome) PortableRemoteObject.narrow(getOrb().string_to_object(ior), EJBHome.class);
+        } catch (Exception e) {
+            throw new RemoteException("Unable to convert IOR into home", e);
+        }
+
+    }
+
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        HandleDelegate handleDelegate = getHandleDelegate();
+        handleDelegate.writeEJBHome(getEJBHome(), out);
+    }
+
+    private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
+        HandleDelegate handleDelegate = getHandleDelegate();
+        EJBHome home = handleDelegate.readEJBHome(in);
+
+        try {
+            ior = getOrb().object_to_string((org.omg.CORBA.Object) home);
+        } catch (Exception e) {
+            throw new RemoteException("Unable to convert object to IOR", e);
+        }
+    }
+
+    private static ORB getOrb() {
+        try {
+            Context context = new InitialContext();
+            ORB orb = (ORB) context.lookup("java:comp/ORB");
+            return orb;
+        } catch (Throwable e) {
+            throw new org.omg.CORBA.MARSHAL("Could not find ORB in jndi at java:comp/ORB", 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
+        }
+    }
+
+    private static HandleDelegate getHandleDelegate() {
+        try {
+            Context context = new InitialContext();
+            HandleDelegate handleDelegate = (HandleDelegate) context.lookup("java:comp/HandleDelegate");
+            return handleDelegate;
+        } catch (Throwable e) {
+            throw new org.omg.CORBA.MARSHAL("Could not find handle delegate in jndi at java:comp/HandleDelegate", 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
+        }
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CSSBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CSSBean.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CSSBean.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CSSBean.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,217 @@
+/**
+ * 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.geronimo.corba;
+
+import java.net.URI;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.corba.security.config.ConfigAdapter;
+import org.apache.geronimo.corba.security.config.css.CSSConfig;
+import org.apache.geronimo.corba.security.config.ssl.SSLConfig;
+import org.apache.geronimo.corba.security.config.tss.TSSConfig;
+import org.apache.geronimo.corba.security.ClientPolicy;
+import org.apache.geronimo.corba.transaction.ClientTransactionPolicyConfig;
+import org.apache.geronimo.corba.transaction.ClientTransactionPolicy;
+import org.apache.geronimo.corba.transaction.nodistributedtransactions.NoDTxClientTransactionPolicyConfig;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.UserException;
+import org.omg.CORBA.PolicyManager;
+import org.omg.CORBA.Policy;
+import org.omg.CORBA.SetOverrideType;
+import org.omg.CosNaming.NameComponent;
+import org.omg.CosNaming.NamingContextExt;
+import org.omg.CosNaming.NamingContextExtHelper;
+
+
+/**
+ * A CSSBean is an ORB instance configured for
+ * accessing EJBs using a specific security profile.  A single
+ * CSSBean can be referenced by multiple ejb-refs that share a
+ * common security profile.
+ *
+ * For each CSSBean instance, there will be a backing
+ * ORB configured with the appropriate interceptors and
+ * principal information to access the target object.
+ * @version $Revision: 502382 $ $Date: 2007-02-01 14:23:31 -0800 (Thu, 01 Feb 2007) $
+ */
+public class CSSBean implements GBeanLifecycle, ORBConfiguration {
+
+    private final static Log log = LogFactory.getLog(CSSBean.class);
+
+    private final ClassLoader classLoader;
+    private final ConfigAdapter configAdapter;
+    private final TransactionManager transactionManager;
+    private String description;
+    private CSSConfig cssConfig;
+    private SSLConfig sslConfig;
+    // ORB used for activating and accessing the target bean.
+    private ORB cssORB;
+    // ORB used for nameservice lookups.
+    private ORB nssORB;
+    private AbstractName abstractName;
+
+    public CSSBean() {
+        this.classLoader = null;
+        this.configAdapter = null;
+        this.transactionManager = null;
+        this.abstractName = null;
+        this.sslConfig = null;
+        this.cssConfig = null;
+    }
+
+    public CSSBean(ConfigAdapter configAdapter, TransactionManager transactionManager, SSLConfig ssl, AbstractName abstractName, ClassLoader classLoader) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
+        this.abstractName = abstractName;
+        this.classLoader = classLoader;
+        this.transactionManager = transactionManager;
+        this.configAdapter = configAdapter;
+        this.sslConfig = ssl;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public CSSConfig getCssConfig() {
+        return cssConfig;
+    }
+
+    public void setCssConfig(CSSConfig config) {
+        if (config == null) config = new CSSConfig();
+        this.cssConfig = config;
+    }
+
+    public TSSConfig getTssConfig() {
+        // just return a default no security one.
+        return new TSSConfig();
+    }
+
+    /**
+     * Return the SSLConfig used for this ORB instance.
+     * if one has not been configured, this returns
+     * a default configuration.
+     *
+     * @return The SSLConfig object use to manage transport-level
+     *         security.
+     */
+    public SSLConfig getSslConfig() {
+        if (sslConfig == null) {
+            sslConfig = new SSLConfig();
+        }
+        return sslConfig;
+    }
+
+    public ORB getORB() {
+        return cssORB;
+    }
+
+    /**
+     * Return the retrieval URI for this bean.
+     *
+     * @return The URI for the bean AbstractName;
+     */
+    public String getURI() {
+        return abstractName.toString();
+    }
+
+    public org.omg.CORBA.Object getHome(URI nsURI, String name) {
+
+        if (log.isDebugEnabled())
+            log.debug(description + " - Looking up home from " + nsURI.toString() + " at " + name);
+
+        try {
+            // The following may seem unncecessary, but it isn't.  We need to use one ORB to
+            // retrieve the object reference from the NameService because the SecurityInterceptor
+            // attached to the main ORB instance may add additional service contexts to the
+            // NameService request that will cause failures.  We use one configuration to access
+            // the server, and the activate the object on the real one.
+            org.omg.CORBA.Object ref = nssORB.string_to_object(nsURI.toString());
+            NamingContextExt ic = NamingContextExtHelper.narrow(ref);
+
+            NameComponent[] nameComponent = ic.to_name(name);
+            org.omg.CORBA.Object bean = ic.resolve(nameComponent);
+
+            //Install the client interceptors
+            String beanIOR = nssORB.object_to_string(bean);
+            bean = cssORB.string_to_object(beanIOR);
+
+            return bean;
+        } catch (UserException ue) {
+            log.error(description + " - Looking up home", ue);
+            throw new RuntimeException(ue);
+        }
+    }
+
+    /**
+     * Start this GBean instance, which essentially
+     * sets up an ORB and configures a client context
+     * for handling requests.
+     *
+     * @exception Exception
+     */
+    public void doStart() throws Exception {
+
+        // we create a dummy CSSConfig if one has not be specified prior to this.
+        if (cssConfig == null) {
+            cssConfig = new CSSConfig();
+        }
+
+        ClassLoader savedLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            log.debug("Starting CSS ORB " + getURI());
+
+            Thread.currentThread().setContextClassLoader(classLoader);
+
+            // create an ORB using the name service.
+            nssORB = configAdapter.createNameServiceClientORB(this);
+            // the configAdapter creates the ORB instance for us.
+            cssORB = configAdapter.createClientORB(this);
+            PolicyManager policyManager = (PolicyManager) cssORB.resolve_initial_references("ORBPolicyManager");
+            Policy[] policies = new Policy[] {new ClientPolicy(cssConfig), new ClientTransactionPolicy(buildClientTransactionPolicyConfig())};
+            policyManager.set_policy_overrides(policies, SetOverrideType.ADD_OVERRIDE);
+        } finally {
+            Thread.currentThread().setContextClassLoader(savedLoader);
+        }
+
+        log.debug("Started CORBA Client Security Server - " + description);
+    }
+
+    private ClientTransactionPolicyConfig buildClientTransactionPolicyConfig() {
+        return new NoDTxClientTransactionPolicyConfig(transactionManager);
+    }
+
+    public void doStop() throws Exception {
+        cssORB.destroy();
+        nssORB.destroy();
+        cssORB = null;
+        nssORB = null;
+        log.debug("Stopped CORBA Client Security Server - " + description);
+    }
+
+    public void doFail() {
+        log.debug("Failed CORBA Client Security Server " + description);
+    }
+
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CSSBeanGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CSSBeanGBean.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CSSBeanGBean.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CSSBeanGBean.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,61 @@
+/**
+ * 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.geronimo.corba;
+
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.corba.security.config.ConfigAdapter;
+import org.apache.geronimo.corba.security.config.css.CSSConfig;
+import org.apache.geronimo.corba.security.config.ssl.SSLConfig;
+import org.omg.CORBA.ORB;
+
+import java.net.URI;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public final class CSSBeanGBean {
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(CSSBeanGBean.class, CSSBean.class, NameFactory.CORBA_CSS);
+
+        infoFactory.addAttribute("description", String.class, true);
+        infoFactory.addAttribute("cssConfig", CSSConfig.class, true);
+        infoFactory.addAttribute("ORB", ORB.class, false);
+        infoFactory.addOperation("getHome", new Class[]{URI.class, String.class});
+
+        infoFactory.addReference("TransactionManager", TransactionManager.class, NameFactory.TRANSACTION_MANAGER);
+        infoFactory.addReference("SSLConfig", SSLConfig.class, NameFactory.CORBA_SSL);
+        infoFactory.addReference("ConfigAdapter", ConfigAdapter.class, NameFactory.ORB_CONFIG);
+        infoFactory.addAttribute("abstractName", AbstractName.class, false);
+        infoFactory.addAttribute("classLoader", ClassLoader.class, false);
+
+        infoFactory.setConstructor(new String[]{"ConfigAdapter", "TransactionManager", "SSLConfig", "abstractName", "classLoader"});
+
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CorbaApplicationServer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CorbaApplicationServer.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CorbaApplicationServer.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/CorbaApplicationServer.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,108 @@
+/**
+ * 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.geronimo.corba;
+
+import javax.ejb.EJBHome;
+import javax.ejb.EJBMetaData;
+import javax.ejb.EJBObject;
+import javax.ejb.Handle;
+import javax.ejb.HomeHandle;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.rmi.PortableRemoteObject;
+
+import org.omg.CORBA.ORB;
+import org.apache.openejb.ProxyInfo;
+import org.apache.openejb.ContainerType;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.spi.ApplicationServer;
+
+/**
+ * @version $Revision: 494431 $ $Date: 2007-01-09 07:18:14 -0800 (Tue, 09 Jan 2007) $
+ */
+public class CorbaApplicationServer implements ApplicationServer {
+    public EJBObject getEJBObject(ProxyInfo proxyInfo) {
+        try {
+            RefGenerator refGenerator = AdapterWrapper.getRefGenerator((String) proxyInfo.getDeploymentInfo().getDeploymentID());
+            org.omg.CORBA.Object object = refGenerator.genObjectReference(proxyInfo.getPrimaryKey());
+            EJBObject ejbObject = (EJBObject) PortableRemoteObject.narrow(object, EJBObject.class);
+            return ejbObject;
+        } catch (Throwable e) {
+            throw new org.omg.CORBA.MARSHAL(e.getClass().getName() + " thrown while marshaling the reply: " + e.getMessage(), 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
+        }
+    }
+
+    public EJBHome getEJBHome(ProxyInfo proxyInfo) {
+        try {
+            RefGenerator refGenerator = AdapterWrapper.getRefGenerator((String) proxyInfo.getDeploymentInfo().getDeploymentID());
+            org.omg.CORBA.Object home = refGenerator.genHomeReference();
+            EJBHome ejbHome = (EJBHome) PortableRemoteObject.narrow(home, EJBHome.class);
+            return ejbHome;
+        } catch (Throwable e) {
+            throw new org.omg.CORBA.MARSHAL(e.getClass().getName() + " thrown while marshaling the reply: " + e.getMessage(), 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
+        }
+    }
+
+    public javax.ejb.Handle getHandle(ProxyInfo proxyInfo) {
+        Handle handle = new CORBAHandle(getEJBObject(proxyInfo), proxyInfo.getPrimaryKey());
+        return handle;
+    }
+
+    public javax.ejb.HomeHandle getHomeHandle(ProxyInfo proxyInfo) {
+        org.omg.CORBA.Object ejbHome = (org.omg.CORBA.Object) getEJBHome(proxyInfo);
+        String ior = getOrb().object_to_string(ejbHome);
+        HomeHandle homeHandle = new CORBAHomeHandle(ior);
+        return homeHandle;
+    }
+
+    public EJBMetaData getEJBMetaData(ProxyInfo proxyInfo) {
+        ContainerType componentType = proxyInfo.getBeanContainer().getContainerType();
+        byte ejbType;
+        switch (componentType) {
+            case STATEFUL:
+                ejbType = CORBAEJBMetaData.STATEFUL;
+                break;
+            case STATELESS:
+                ejbType = CORBAEJBMetaData.STATELESS;
+                break;
+            case BMP_ENTITY:
+            case CMP_ENTITY:
+                ejbType = CORBAEJBMetaData.ENTITY;
+                break;
+            default:
+                throw new IllegalArgumentException("Unknown component type: " + componentType);
+        }
+
+        DeploymentInfo deploymentInfo = proxyInfo.getDeploymentInfo();
+        CORBAEJBMetaData ejbMetaData = new CORBAEJBMetaData(getEJBHome(proxyInfo),
+                ejbType,
+                deploymentInfo.getHomeInterface(),
+                deploymentInfo.getRemoteInterface(),
+                deploymentInfo.getPrimaryKeyClass());
+        return ejbMetaData;
+    }
+
+    private static ORB getOrb() {
+        try {
+            Context context = new InitialContext();
+            ORB orb = (ORB) context.lookup("java:comp/ORB");
+            return orb;
+        } catch (Throwable e) {
+            throw new org.omg.CORBA.MARSHAL("Could not find ORB in jndi at java:comp/ORB", 0, org.omg.CORBA.CompletionStatus.COMPLETED_YES);
+        }
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/NameService.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/NameService.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/NameService.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/NameService.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,186 @@
+/**
+  * 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.geronimo.corba;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
+
+import org.apache.geronimo.corba.security.config.ConfigAdapter;
+
+import java.net.InetSocketAddress;
+
+/**
+ * Starts the openejb transient cos naming service.
+ * <p/>
+ * <gbean name="NameServer" class="org.apache.geronimo.corba.NameService">
+ * <reference name="ServerInfo">
+ * <reference name="ConfigAdapter">
+ * <attribute name="port">2809</attribute>
+ * <attribute name="host">localhost</attribute>
+ * </gbean>
+ *
+ * @version $Revision: 465108 $ $Date: 2006-10-17 17:23:40 -0700 (Tue, 17 Oct 2006) $
+ */
+public class NameService implements GBeanLifecycle {
+    private static final Log log = LogFactory.getLog(NameService.class);
+
+    // the ORB configurator
+    private final ConfigAdapter config;
+    // the name service instance
+    private Object service;
+    // the name service listening port
+    private final int port;
+    // the published port name (defaults to "localhost").
+    private String host;
+    // indicates whether we start and host this server locally.
+    private boolean localServer;
+
+    protected NameService() {
+        service = null;
+        config = null;
+        port = -1;
+        host = "localhost";
+        localServer = true;
+    }
+
+    /**
+     * GBean constructor to create a NameService instance.
+     *
+     * @param serverInfo The dependent ServerInfo.  This value is not used,
+     *                   but is in the constructor to create an ordering
+     *                   dependency.
+     * @param config     The ORB ConfigAdapter used to create the real
+     *                   NameService instance.
+     * @param host       The advertised host name.
+     * @param port       The listener port.
+     *
+     * @exception Exception
+     */
+    public NameService(ServerInfo serverInfo, ConfigAdapter config, String host, int port) throws Exception {
+        this.host = host;
+        this.port = port;
+        this.config = config;
+        localServer = true;
+        service = null;
+        // if not specified, our default host is "localhost".
+        if (this.host == null) {
+            this.host = "localhost";
+        }
+    }
+
+    /**
+     * Retrieve the host name for this NameService instance.
+     *
+     * @return The String host name.
+     */
+    public String getHost() {
+        return host;
+    }
+
+    /**
+     * Get the port information for this NameService instance.
+     *
+     * @return The configured name service listener port.
+     */
+    public int getPort() {
+        return port;
+    }
+
+    /**
+     * Get the "local" value for this server.  If true, an
+     * in-process NameService instance will be created when
+     * the service is started.  If false, this is an
+     * indirect reference to a NameService (possibly located
+     * elsewhere).
+     *
+     * @return The current localServer value.  The default is
+     *         true.
+     */
+    public boolean getLocal() {
+        return localServer;
+    }
+
+    /**
+     * Get the "local" value for this server.  If true, an
+     * in-process NameService instance will be created when
+     * the service is started.  If false, this is an
+     * indirect reference to a NameService (possibly located
+     * elsewhere).
+     *
+     * @param l      The new local setting.
+     */
+    public void setLocal(boolean l) {
+        localServer = l;
+    }
+
+    /**
+     * Get the InetSocketAddress for this NameService.
+     *
+     * @return An InetSocketAddress containing the host and port
+     *         information.
+     */
+    public InetSocketAddress getAddress() {
+        return new InetSocketAddress(host, getPort());
+    }
+
+
+    /**
+     * Return the NameService locator as a URI (generally
+     * using the corbaloc:: protocol);
+     *
+     * @return The URI in String format.
+     */
+    public String getURI() {
+        return "corbaloc::" + host + ":" + port + "/NameService";
+    }
+
+    /**
+     * Start the NameService instance.  If the local
+     * setting is true, will launch an appropriate
+     * in-process name server instance.
+     *
+     * @exception Exception
+     */
+    public void doStart() throws Exception {
+        if (localServer) {
+            service = config.createNameService(host, port);
+            log.debug("Started transient CORBA name service on port " + port);
+        }
+    }
+
+    /**
+     * Stop the name server.  Only has an effect if doStart()
+     * launched an NameServer instance.
+     *
+     * @exception Exception
+     */
+    public void doStop() throws Exception {
+        if (service != null) {
+            config.destroyNameService(service);
+            log.debug("Stopped transient CORBA name service on port " + port);
+        }
+    }
+
+    public void doFail() {
+        if (service != null) {
+            config.destroyNameService(service);
+            log.warn("Failed transient CORBA name service on port " + port);
+        }
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/NameServiceGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/NameServiceGBean.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/NameServiceGBean.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/NameServiceGBean.java Fri Feb  9 11:24:30 2007
@@ -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.geronimo.corba;
+
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
+
+import org.apache.geronimo.corba.security.config.ConfigAdapter;
+
+import java.net.InetSocketAddress;
+
+/**
+ * @version $Revision: 465108 $ $Date: 2006-10-17 17:23:40 -0700 (Tue, 17 Oct 2006) $
+ */
+public final class NameServiceGBean {
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(NameServiceGBean.class, "CORBA Naming Service", NameService.class, NameFactory.CORBA_NAME_SERVICE);
+
+        infoFactory.addReference("ServerInfo", ServerInfo.class, NameFactory.GERONIMO_SERVICE);
+        infoFactory.addReference("ConfigAdapter", ConfigAdapter.class, NameFactory.ORB_CONFIG);
+        infoFactory.addAttribute("host", String.class, true);
+        infoFactory.addAttribute("port", int.class, true);
+        infoFactory.addAttribute("address", InetSocketAddress.class, false);
+        infoFactory.addAttribute("local", boolean.class, true);
+        infoFactory.setConstructor(new String[]{"ServerInfo", "ConfigAdapter", "host", "port"});
+
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/ORBConfiguration.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/ORBConfiguration.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/ORBConfiguration.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/ORBConfiguration.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,42 @@
+/**
+ *  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.geronimo.corba;
+
+import org.apache.geronimo.corba.security.config.tss.TSSConfig;
+import org.apache.geronimo.corba.security.config.ssl.SSLConfig;
+
+/**
+ * Interface implemented by both CORBABean and CSSBean
+ * to provide common configuration information to
+ * ConfigAdapter instances.
+ * @version $Revision: 485135 $ $Date: 2006-12-09 20:25:29 -0800 (Sat, 09 Dec 2006) $
+ */
+public interface ORBConfiguration {
+    /**
+     * Provide the SSLConfig information to the ConfigAdapter.
+     *
+     * @return A configured SSLConfig GBean.
+     */
+    SSLConfig getSslConfig();
+    /**
+     * Retrieve the TSSConfig settings to a ConfigAdapter instance.
+     *
+     * @return An appropriate TSSConfig object containing transport-level
+     *         security information.
+     */
+    TSSConfig getTssConfig();
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/ORBRef.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/ORBRef.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/ORBRef.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/ORBRef.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,26 @@
+/**
+ * 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.geronimo.corba;
+
+import org.omg.CORBA.ORB;
+
+/**
+ * @version $Revision: 465172 $ $Date: 2006-10-18 01:16:14 -0700 (Wed, 18 Oct 2006) $
+ */
+public interface ORBRef {
+    ORB getORB();
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/RefGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/RefGenerator.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/RefGenerator.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/RefGenerator.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,28 @@
+/**
+ * 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.geronimo.corba;
+
+/**
+ * @version $Revision: 465108 $ $Date: 2006-10-17 17:23:40 -0700 (Tue, 17 Oct 2006) $
+ */
+public interface RefGenerator {
+
+    public org.omg.CORBA.Object genHomeReference() throws CORBAException;
+
+    public org.omg.CORBA.Object genObjectReference(Object primaryKey) throws CORBAException;
+
+}

Added: geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/StandardServant.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/StandardServant.java?view=auto&rev=505432
==============================================================================
--- geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/StandardServant.java (added)
+++ geronimo/server/trunk/modules/geronimo-corba/src/main/java/org/apache/geronimo/corba/StandardServant.java Fri Feb  9 11:24:30 2007
@@ -0,0 +1,307 @@
+/**
+ * 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.geronimo.corba;
+
+import java.lang.reflect.Method;
+import java.rmi.AccessException;
+import java.rmi.MarshalException;
+import java.rmi.NoSuchObjectException;
+import java.rmi.RemoteException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ejb.EJBHome;
+import javax.ejb.EJBObject;
+import javax.ejb.Handle;
+import javax.ejb.RemoveException;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.rmi.PortableRemoteObject;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.TransactionRequiredException;
+import javax.transaction.TransactionRolledbackException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
+import org.apache.geronimo.naming.java.RootContext;
+import org.apache.geronimo.openejb.EjbDeployment;
+import org.apache.openejb.InterfaceType;
+import org.apache.openejb.BeanType;
+import org.apache.openejb.RpcContainer;
+import org.apache.openejb.OpenEJBException;
+import org.apache.geronimo.corba.util.Util;
+import org.omg.CORBA.INVALID_TRANSACTION;
+import org.omg.CORBA.MARSHAL;
+import org.omg.CORBA.NO_PERMISSION;
+import org.omg.CORBA.OBJECT_NOT_EXIST;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.SystemException;
+import org.omg.CORBA.TRANSACTION_REQUIRED;
+import org.omg.CORBA.TRANSACTION_ROLLEDBACK;
+import org.omg.CORBA.UNKNOWN;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.InvokeHandler;
+import org.omg.CORBA.portable.OutputStream;
+import org.omg.CORBA.portable.ResponseHandler;
+import org.omg.CORBA.portable.UnknownException;
+import org.omg.PortableServer.Servant;
+
+/**
+ * @version $Revision: 494431 $ $Date: 2007-01-09 07:18:14 -0800 (Tue, 09 Jan 2007) $
+ */
+public class StandardServant extends Servant implements InvokeHandler {
+    private static final Log log = LogFactory.getLog(StandardServant.class);
+
+    private static final Method GETEJBMETADATA = getMethod(EJBHome.class, "getEJBMetaData", null);
+    private static final Method GETHOMEHANDLE = getMethod(EJBHome.class, "getHomeHandle", null);
+    private static final Method REMOVE_W_KEY = getMethod(EJBHome.class, "remove", new Class[]{Object.class});
+    private static final Method REMOVE_W_HAND = getMethod(EJBHome.class, "remove", new Class[]{Handle.class});
+    private static final Method GETEJBHOME = getMethod(EJBObject.class, "getEJBHome", null);
+    private static final Method GETHANDLE = getMethod(EJBObject.class, "getHandle", null);
+    private static final Method GETPRIMARYKEY = getMethod(EJBObject.class, "getPrimaryKey", null);
+    private static final Method ISIDENTICAL = getMethod(EJBObject.class, "isIdentical", new Class[]{EJBObject.class});
+    private static final Method REMOVE = getMethod(EJBObject.class, "remove", null);
+
+
+    private final InterfaceType interfaceType;
+    private final EjbDeployment ejbDeployment;
+    private final Object primaryKey;
+    private final String[] typeIds;
+    private final Map operations;
+    private final Context enc;
+
+    public StandardServant(ORB orb, InterfaceType ejbInterfaceType, EjbDeployment ejbDeployment) {
+        this(orb, ejbInterfaceType, ejbDeployment, null);
+    }
+
+    public StandardServant(ORB orb, InterfaceType ejbInterfaceType, EjbDeployment ejbDeployment, Object primaryKey) {
+        this.interfaceType = ejbInterfaceType;
+        this.ejbDeployment = ejbDeployment;
+        this.primaryKey = primaryKey;
+
+        // get the interface class
+        Class type;
+        if (InterfaceType.EJB_HOME == ejbInterfaceType) {
+            type = ejbDeployment.getHomeInterface();
+        } else if (InterfaceType.EJB_OBJECT == ejbInterfaceType) {
+            type = ejbDeployment.getRemoteInterface();
+        } else {
+            throw new IllegalArgumentException("Only home and remote interfaces are supported in this servant: " + ejbInterfaceType);
+        }
+
+        // build the operations index
+        this.operations = Util.mapOperationToMethod(type);
+
+        // creat the corba ids array
+        typeIds = Util.createCorbaIds(type);
+
+        // create ReadOnlyContext
+        Map componentContext = new HashMap(2);
+        componentContext.put("ORB", orb);
+        componentContext.put("HandleDelegate", new CORBAHandleDelegate());
+        try {
+            enc = EnterpriseNamingContext.createEnterpriseNamingContext(componentContext);
+        } catch (NamingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public InterfaceType getInterfaceType() {
+        return interfaceType;
+    }
+
+    public EjbDeployment getEjbDeployment() {
+        return ejbDeployment;
+    }
+
+    public Object getPrimaryKey() {
+        return primaryKey;
+    }
+
+    public String[] _all_interfaces(org.omg.PortableServer.POA poa, byte[] objectId) {
+        return typeIds;
+    }
+
+    public OutputStream _invoke(String operationName, InputStream _in, ResponseHandler reply) throws SystemException {
+        // get the method object
+        Method method = (Method) operations.get(operationName);
+
+        org.omg.CORBA_2_3.portable.InputStream in = (org.omg.CORBA_2_3.portable.InputStream) _in;
+
+        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+        Context oldContext = RootContext.getComponentContext();
+        try {
+            Thread.currentThread().setContextClassLoader(ejbDeployment.getClassLoader());
+            RootContext.setComponentContext(enc);
+
+            // read in all of the arguments
+            Class[] parameterTypes = method.getParameterTypes();
+            Object[] arguments = new Object[parameterTypes.length];
+            for (int i = 0; i < parameterTypes.length; i++) {
+                Class parameterType = parameterTypes[i];
+                arguments[i] = Util.readObject(parameterType, in);
+            }
+
+            // invoke the method
+            Object result = null;
+            try {
+
+                if (log.isDebugEnabled()) log.debug("Calling " + method.getName());
+
+                if (method.getDeclaringClass() == javax.ejb.EJBObject.class) {
+                    if (method.equals(GETHANDLE)) {
+                        result = ejbDeployment.getEjbObject(primaryKey).getHandle();
+                    } else if (method.equals(GETPRIMARYKEY)) {
+                        result = ejbDeployment.getEjbObject(primaryKey).getPrimaryKey();
+                    } else if (method.equals(ISIDENTICAL)) {
+                        org.omg.CORBA.Object thisObject = this._this_object();
+                        org.omg.CORBA.Object otherObject = (org.omg.CORBA.Object)arguments[0];
+                        result = new Boolean(thisObject._is_equivalent(otherObject));
+                    } else if (method.equals(GETEJBHOME)) {
+                        result = ejbDeployment.getEJBHome();
+                    } else if (method.equals(REMOVE)) {
+                        try {
+                            ejbDeployment.getEjbObject(primaryKey).remove();
+                            result = null;
+                        } catch (RemoveException e) {
+                            return Util.writeUserException(method, reply, e);
+                        }
+                    } else {
+                        throw new UnsupportedOperationException("unknown method: " + method);
+                    }
+                } else if (method.getDeclaringClass() == javax.ejb.EJBHome.class) {
+                   if (method.equals(GETEJBMETADATA)) {
+                        result = ejbDeployment.getEJBHome().getEJBMetaData();
+                    } else if (method.equals(GETHOMEHANDLE)) {
+                        result = ejbDeployment.getEJBHome().getHomeHandle();
+                    } else if (method.equals(REMOVE_W_HAND)) {
+                        CORBAHandle handle = (CORBAHandle) arguments[0];
+                        try {
+                            if (ejbDeployment.getComponentType() == BeanType.STATELESS) {
+                                if (handle == null) {
+                                    throw new RemoveException("Handle is null");
+                                }
+                                Class remoteInterface = ejbDeployment.getRemoteInterface();
+
+
+                                try {
+                                    EJBObject narrowed = (EJBObject)PortableRemoteObject.narrow(handle.getEJBObject(), remoteInterface);
+                                    if (narrowed == null) {
+                                        throw new RemoteException("Handle does not hold a " + remoteInterface.getName());
+                                    }
+                                } catch (ClassCastException e) {
+                                    throw new RemoteException("Handle does not hold a " + remoteInterface.getName());
+                                }
+                            } else {
+                                try {
+                                    RpcContainer container = (RpcContainer) ejbDeployment.getContainer();
+                                    result = container.invoke(ejbDeployment.getDeploymentId(), method, arguments, primaryKey, null);
+                                } catch (OpenEJBException e) {
+                                    Throwable cause = e.getCause();
+                                    if (cause instanceof Exception) {
+                                        Exception exception = (Exception) cause;
+                                        return Util.writeUserException(method, reply, exception);
+                                    }
+                                    throw cause;
+                                }
+                            }
+                        } catch (RemoveException e) {
+
+                            return Util.writeUserException(method, reply, e);
+                        }
+                        result = null;
+                    } else if (method.equals(REMOVE_W_KEY)) {
+                        try {
+                            ejbDeployment.getEJBHome().remove(arguments[0]);
+                            result = null;
+                        } catch (RemoveException e) {
+                            return Util.writeUserException(method, reply, e);
+                        }
+                    } else {
+                        throw new UnsupportedOperationException("unknown method: " + method);
+                    }
+                } else {
+                    try {
+                        RpcContainer container = (RpcContainer) ejbDeployment.getContainer();
+                        result = container.invoke(ejbDeployment.getDeploymentId(), method, arguments, primaryKey, null);
+                    } catch (OpenEJBException e) {
+                        Throwable cause = e.getCause();
+                        if (cause instanceof Exception) {
+                            Exception exception = (Exception) cause;
+                            return Util.writeUserException(method, reply, exception);
+                        }
+                        throw cause;
+                    }
+                }
+            } catch (TransactionRolledbackException e) {
+                log.debug("TransactionRolledbackException", e);
+                throw new TRANSACTION_ROLLEDBACK(e.toString());
+            } catch (TransactionRequiredException e) {
+                log.debug("TransactionRequiredException", e);
+                throw new TRANSACTION_REQUIRED(e.toString());
+            } catch (InvalidTransactionException e) {
+                log.debug("InvalidTransactionException", e);
+                throw new INVALID_TRANSACTION(e.toString());
+            } catch (NoSuchObjectException e) {
+                log.debug("NoSuchObjectException", e);
+                throw new OBJECT_NOT_EXIST(e.toString());
+            } catch (AccessException e) {
+                log.debug("AccessException", e);
+                throw new NO_PERMISSION(e.toString());
+            } catch (MarshalException e) {
+                log.debug("MarshalException", e);
+                throw new MARSHAL(e.toString());
+            } catch (RemoteException e) {
+                log.debug("RemoteException", e);
+                e.printStackTrace();
+                throw new UnknownException(e);
+            } catch (RuntimeException e) {
+                log.debug("RuntimeException", e);
+                e.printStackTrace();
+                RemoteException remoteException = new RemoteException(e.getClass().getName() + " thrown from " + ejbDeployment.getDeploymentId() + ": " + e.getMessage());
+                throw new UnknownException(remoteException);
+            } catch (Error e) {
+                log.debug("Error", e);
+                RemoteException remoteException = new RemoteException(e.getClass().getName() + " thrown from " + ejbDeployment.getDeploymentId() + ": " + e.getMessage());
+                throw new UnknownException(remoteException);
+            } catch (Throwable e) {
+                log.warn("Unexpected throwable", e);
+                throw new UNKNOWN("Unknown exception type " + e.getClass().getName() + ": " + e.getMessage());
+            }
+
+            // creat the output stream
+            org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
+
+            // write the output value
+            Util.writeObject(method.getReturnType(), result, out);
+
+            return out;
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldClassLoader);
+            RootContext.setComponentContext(oldContext);
+        }
+    }
+
+    private static Method getMethod(Class c, String method, Class[] params) {
+        try {
+            return c.getMethod(method, params);
+        } catch (NoSuchMethodException e) {
+            throw (IllegalStateException) new IllegalStateException().initCause(e);
+        }
+    }
+}



Mime
View raw message