001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.corba;
017:
018: import javax.ejb.EJBHome;
019: import javax.ejb.EJBMetaData;
020: import javax.ejb.EJBObject;
021: import javax.ejb.Handle;
022: import javax.ejb.HomeHandle;
023: import javax.naming.Context;
024: import javax.naming.InitialContext;
025: import javax.rmi.PortableRemoteObject;
026:
027: import org.omg.CORBA.ORB;
028: import org.apache.openejb.ProxyInfo;
029: import org.apache.openejb.ContainerType;
030: import org.apache.openejb.DeploymentInfo;
031: import org.apache.openejb.spi.ApplicationServer;
032:
033: /**
034: * @version $Revision: 494431 $ $Date: 2007-01-09 07:18:14 -0800 (Tue, 09 Jan 2007) $
035: */
036: public class CorbaApplicationServer implements ApplicationServer {
037: public EJBObject getEJBObject(ProxyInfo proxyInfo) {
038: try {
039: RefGenerator refGenerator = AdapterWrapper
040: .getRefGenerator((String) proxyInfo
041: .getDeploymentInfo().getDeploymentID());
042: org.omg.CORBA.Object object = refGenerator
043: .genObjectReference(proxyInfo.getPrimaryKey());
044: EJBObject ejbObject = (EJBObject) PortableRemoteObject
045: .narrow(object, EJBObject.class);
046: return ejbObject;
047: } catch (Throwable e) {
048: throw (org.omg.CORBA.MARSHAL) new org.omg.CORBA.MARSHAL(e
049: .getClass().getName()
050: + " thrown while marshaling the reply: "
051: + e.getMessage(), 0,
052: org.omg.CORBA.CompletionStatus.COMPLETED_YES)
053: .initCause(e);
054: }
055: }
056:
057: /**
058: * DMB: My vague understanding is that business interfaces aren't supported by
059: * corba as they do not extend java.rmi.Remote. But we can try.
060: */
061: public Object getBusinessObject(ProxyInfo proxyInfo) {
062: try {
063: RefGenerator refGenerator = AdapterWrapper
064: .getRefGenerator((String) proxyInfo
065: .getDeploymentInfo().getDeploymentID());
066: org.omg.CORBA.Object object = refGenerator
067: .genObjectReference(proxyInfo.getPrimaryKey());
068: return object;
069: } catch (Throwable e) {
070: throw (org.omg.CORBA.MARSHAL) new org.omg.CORBA.MARSHAL(e
071: .getClass().getName()
072: + " thrown while marshaling the reply: "
073: + e.getMessage(), 0,
074: org.omg.CORBA.CompletionStatus.COMPLETED_YES)
075: .initCause(e);
076: }
077: }
078:
079: public EJBHome getEJBHome(ProxyInfo proxyInfo) {
080: try {
081: RefGenerator refGenerator = AdapterWrapper
082: .getRefGenerator((String) proxyInfo
083: .getDeploymentInfo().getDeploymentID());
084: org.omg.CORBA.Object home = refGenerator.genHomeReference();
085: EJBHome ejbHome = (EJBHome) PortableRemoteObject.narrow(
086: home, EJBHome.class);
087: return ejbHome;
088: } catch (Throwable e) {
089: throw (org.omg.CORBA.MARSHAL) new org.omg.CORBA.MARSHAL(e
090: .getClass().getName()
091: + " thrown while marshaling the reply: "
092: + e.getMessage(), 0,
093: org.omg.CORBA.CompletionStatus.COMPLETED_YES)
094: .initCause(e);
095: }
096: }
097:
098: public javax.ejb.Handle getHandle(ProxyInfo proxyInfo) {
099: Handle handle = new CORBAHandle(getEJBObject(proxyInfo),
100: proxyInfo.getPrimaryKey());
101: return handle;
102: }
103:
104: public javax.ejb.HomeHandle getHomeHandle(ProxyInfo proxyInfo) {
105: org.omg.CORBA.Object ejbHome = (org.omg.CORBA.Object) getEJBHome(proxyInfo);
106: String ior = getOrb().object_to_string(ejbHome);
107: HomeHandle homeHandle = new CORBAHomeHandle(ior);
108: return homeHandle;
109: }
110:
111: public EJBMetaData getEJBMetaData(ProxyInfo proxyInfo) {
112: ContainerType componentType = proxyInfo.getBeanContainer()
113: .getContainerType();
114: byte ejbType;
115: switch (componentType) {
116: case STATEFUL:
117: ejbType = CORBAEJBMetaData.STATEFUL;
118: break;
119: case STATELESS:
120: ejbType = CORBAEJBMetaData.STATELESS;
121: break;
122: case BMP_ENTITY:
123: case CMP_ENTITY:
124: ejbType = CORBAEJBMetaData.ENTITY;
125: break;
126: default:
127: throw new IllegalArgumentException(
128: "Unknown component type: " + componentType);
129: }
130:
131: DeploymentInfo deploymentInfo = proxyInfo.getDeploymentInfo();
132: CORBAEJBMetaData ejbMetaData = new CORBAEJBMetaData(
133: getEJBHome(proxyInfo), ejbType, deploymentInfo
134: .getHomeInterface(), deploymentInfo
135: .getRemoteInterface(), deploymentInfo
136: .getPrimaryKeyClass());
137: return ejbMetaData;
138: }
139:
140: private static ORB getOrb() {
141: try {
142: Context context = new InitialContext();
143: ORB orb = (ORB) context.lookup("java:comp/ORB");
144: return orb;
145: } catch (Throwable e) {
146: throw (org.omg.CORBA.MARSHAL) new org.omg.CORBA.MARSHAL(
147: "Could not find ORB in jndi at java:comp/ORB", 0,
148: org.omg.CORBA.CompletionStatus.COMPLETED_YES)
149: .initCause(e);
150: }
151: }
152: }
|