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.openejb.server.ejbd;
017:
018: import java.net.URI;
019: import java.util.Properties;
020:
021: import org.apache.openejb.DeploymentInfo;
022: import org.apache.openejb.ProxyInfo;
023: import org.apache.openejb.client.ClientMetaData;
024: import org.apache.openejb.client.EJBHomeHandle;
025: import org.apache.openejb.client.EJBHomeHandler;
026: import org.apache.openejb.client.EJBMetaDataImpl;
027: import org.apache.openejb.client.EJBObjectHandle;
028: import org.apache.openejb.client.EJBObjectHandler;
029: import org.apache.openejb.client.ServerMetaData;
030:
031: class ClientObjectFactory implements
032: org.apache.openejb.spi.ApplicationServer {
033: protected ServerMetaData sMetaData;
034:
035: public ClientObjectFactory(EjbDaemon daemon, Properties props) {
036:
037: try {
038: String uriString = props.getProperty("openejb.ejbd.uri",
039: "foo://127.0.0.1:4201");
040: this .sMetaData = new ServerMetaData(new URI(uriString));
041: } catch (Exception e) {
042: e.printStackTrace();
043: }
044: }
045:
046: public javax.ejb.EJBMetaData getEJBMetaData(ProxyInfo info) {
047: CallContext call = CallContext.getCallContext();
048:
049: DeploymentInfo deployment = info.getDeploymentInfo();
050: int idCode = -1;
051:
052: EJBMetaDataImpl metaData = new EJBMetaDataImpl(deployment
053: .getHomeInterface(), deployment.getRemoteInterface(),
054: deployment.getPrimaryKeyClass(), deployment
055: .getComponentType().toString(), deployment
056: .getDeploymentID().toString(), idCode, null);
057: return metaData;
058: }
059:
060: public javax.ejb.Handle getHandle(ProxyInfo info) {
061: CallContext call = CallContext.getCallContext();
062: DeploymentInfo deployment = info.getDeploymentInfo();
063:
064: int idCode = -1;
065:
066: Object securityIdentity = null;
067: try {
068: securityIdentity = call.getEJBRequest().getClientIdentity();
069: } catch (Exception e) {
070:
071: }
072: ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
073: EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(deployment
074: .getHomeInterface(), deployment.getRemoteInterface(),
075: deployment.getPrimaryKeyClass(), deployment
076: .getComponentType().toString(), deployment
077: .getDeploymentID().toString(), idCode, null);
078: Object primKey = info.getPrimaryKey();
079:
080: EJBObjectHandler hanlder = EJBObjectHandler
081: .createEJBObjectHandler(eMetaData, sMetaData,
082: cMetaData, primKey);
083:
084: return new EJBObjectHandle(hanlder.createEJBObjectProxy());
085: }
086:
087: public javax.ejb.HomeHandle getHomeHandle(ProxyInfo info) {
088: CallContext call = CallContext.getCallContext();
089: DeploymentInfo deployment = info.getDeploymentInfo();
090:
091: int idCode = -1;
092:
093: Object securityIdentity = null;
094: try {
095: securityIdentity = call.getEJBRequest().getClientIdentity();
096: } catch (Exception e) {
097: e.printStackTrace();
098: }
099: ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
100: EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(deployment
101: .getHomeInterface(), deployment.getRemoteInterface(),
102: deployment.getPrimaryKeyClass(), deployment
103: .getComponentType().toString(), deployment
104: .getDeploymentID().toString(), idCode, null);
105:
106: EJBHomeHandler hanlder = EJBHomeHandler.createEJBHomeHandler(
107: eMetaData, sMetaData, cMetaData);
108:
109: return new EJBHomeHandle(hanlder.createEJBHomeProxy());
110: }
111:
112: public javax.ejb.EJBObject getEJBObject(ProxyInfo info) {
113: CallContext call = CallContext.getCallContext();
114: DeploymentInfo deployment = info.getDeploymentInfo();
115:
116: int idCode = -1;
117:
118: Object securityIdentity = null;
119: try {
120: securityIdentity = call.getEJBRequest().getClientIdentity();
121: } catch (Exception e) {
122: e.printStackTrace();
123: }
124: ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
125: EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(deployment
126: .getHomeInterface(), deployment.getRemoteInterface(),
127: deployment.getPrimaryKeyClass(), deployment
128: .getComponentType().toString(), deployment
129: .getDeploymentID().toString(), idCode, null);
130: Object primKey = info.getPrimaryKey();
131:
132: EJBObjectHandler hanlder = EJBObjectHandler
133: .createEJBObjectHandler(eMetaData, sMetaData,
134: cMetaData, primKey);
135:
136: return (javax.ejb.EJBObject) hanlder.createEJBObjectProxy();
137: }
138:
139: public Object getBusinessObject(ProxyInfo info) {
140: CallContext call = CallContext.getCallContext();
141: DeploymentInfo deployment = info.getDeploymentInfo();
142:
143: int idCode = -1;
144:
145: Object securityIdentity = null;
146: try {
147: securityIdentity = call.getEJBRequest().getClientIdentity();
148: } catch (Exception e) {
149: e.printStackTrace();
150: }
151: ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
152: EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(null, null,
153: deployment.getPrimaryKeyClass(), deployment
154: .getComponentType().toString(), deployment
155: .getDeploymentID().toString(), idCode, info
156: .getInterfaces());
157: Object primKey = info.getPrimaryKey();
158:
159: EJBObjectHandler hanlder = EJBObjectHandler
160: .createEJBObjectHandler(eMetaData, sMetaData,
161: cMetaData, primKey);
162:
163: return hanlder.createEJBObjectProxy();
164: }
165:
166: public javax.ejb.EJBHome getEJBHome(ProxyInfo info) {
167: CallContext call = CallContext.getCallContext();
168: DeploymentInfo deployment = info.getDeploymentInfo();
169:
170: int idCode = -1;
171:
172: Object securityIdentity = null;
173: try {
174: securityIdentity = call.getEJBRequest().getClientIdentity();
175: } catch (Exception e) {
176: e.printStackTrace();
177: }
178: ClientMetaData cMetaData = new ClientMetaData(securityIdentity);
179: EJBMetaDataImpl eMetaData = new EJBMetaDataImpl(deployment
180: .getHomeInterface(), deployment.getRemoteInterface(),
181: deployment.getPrimaryKeyClass(), deployment
182: .getComponentType().toString(), deployment
183: .getDeploymentID().toString(), idCode, null);
184:
185: EJBHomeHandler hanlder = EJBHomeHandler.createEJBHomeHandler(
186: eMetaData, sMetaData, cMetaData);
187:
188: return hanlder.createEJBHomeProxy();
189: }
190:
191: }
|