001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.geronimo.openejb;
018:
019: import java.lang.reflect.Method;
020: import java.util.Set;
021:
022: import javax.ejb.EJBHome;
023: import javax.ejb.EJBLocalHome;
024: import javax.ejb.EJBObject;
025: import javax.naming.Context;
026: import javax.security.auth.Subject;
027: import javax.security.auth.login.LoginException;
028:
029: import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
030: import org.apache.geronimo.management.EJB;
031: import org.apache.geronimo.security.jacc.RunAsSource;
032: import org.apache.openejb.BeanType;
033: import org.apache.openejb.Container;
034: import org.apache.openejb.InterfaceType;
035: import org.apache.openejb.core.CoreDeploymentInfo;
036: import org.apache.openejb.core.ivm.EjbObjectProxyHandler;
037:
038: public class EjbDeployment implements EJB, EjbDeploymentIdAccessor {
039: private final String objectName;
040: protected final String deploymentId;
041: private final String ejbName;
042:
043: private final String homeInterfaceName;
044: private final String remoteInterfaceName;
045: private final String localHomeInterfaceName;
046: private final String localInterfaceName;
047: private final String serviceEndpointInterfaceName;
048: private final String beanClassName;
049: private final ClassLoader classLoader;
050:
051: private final boolean securityEnabled;
052: private final Subject defaultSubject;
053: private final Subject runAs;
054:
055: private final Context componentContext;
056:
057: // connector stuff
058: private final Set unshareableResources;
059: private final Set applicationManagedSecurityResources;
060: private final TrackedConnectionAssociator trackedConnectionAssociator;
061:
062: protected final OpenEjbSystem openEjbSystem;
063:
064: protected CoreDeploymentInfo deploymentInfo;
065:
066: private Context javaCompSubContext;
067:
068: public EjbDeployment() throws LoginException {
069: this (null, null, null, null, null, null, null, null, null,
070: null, false, null, null, null, null, null, null, null,
071: null);
072: }
073:
074: public EjbDeployment(String objectName, String deploymentId,
075: String ejbName, String homeInterfaceName,
076: String remoteInterfaceName, String localHomeInterfaceName,
077: String localInterfaceName,
078: String serviceEndpointInterfaceName, String beanClassName,
079: ClassLoader classLoader, boolean securityEnabled,
080: String defaultRole, String runAsRole,
081: RunAsSource runAsSource, Context componentContext,
082: Set unshareableResources,
083: Set applicationManagedSecurityResources,
084: TrackedConnectionAssociator trackedConnectionAssociator,
085: OpenEjbSystem openEjbSystem) throws LoginException {
086: this .objectName = objectName;
087: this .deploymentId = deploymentId;
088: this .ejbName = ejbName;
089: this .homeInterfaceName = homeInterfaceName;
090: this .remoteInterfaceName = remoteInterfaceName;
091: this .localHomeInterfaceName = localHomeInterfaceName;
092: this .localInterfaceName = localInterfaceName;
093: this .serviceEndpointInterfaceName = serviceEndpointInterfaceName;
094: this .beanClassName = beanClassName;
095: this .classLoader = classLoader;
096: this .securityEnabled = securityEnabled;
097: if (runAsSource == null) {
098: runAsSource = RunAsSource.NULL;
099: }
100: this .defaultSubject = defaultRole == null ? runAsSource
101: .getDefaultSubject() : runAsSource
102: .getSubjectForRole(defaultRole);
103: this .runAs = runAsSource.getSubjectForRole(runAsRole);
104: this .componentContext = componentContext;
105: this .unshareableResources = unshareableResources;
106: this .applicationManagedSecurityResources = applicationManagedSecurityResources;
107: this .trackedConnectionAssociator = trackedConnectionAssociator;
108: this .openEjbSystem = openEjbSystem;
109: }
110:
111: public CoreDeploymentInfo getDeploymentInfo() {
112: return deploymentInfo;
113: }
114:
115: public String getDeploymentId() {
116: return deploymentId;
117: }
118:
119: public String getEjbName() {
120: return ejbName;
121: }
122:
123: public String getHomeInterfaceName() {
124: return homeInterfaceName;
125: }
126:
127: public String getRemoteInterfaceName() {
128: return remoteInterfaceName;
129: }
130:
131: public String getLocalHomeInterfaceName() {
132: return localHomeInterfaceName;
133: }
134:
135: public String getLocalInterfaceName() {
136: return localInterfaceName;
137: }
138:
139: public String getServiceEndpointInterfaceName() {
140: return serviceEndpointInterfaceName;
141: }
142:
143: public String getBeanClassName() {
144: return beanClassName;
145: }
146:
147: public ClassLoader getClassLoader() {
148: return classLoader;
149: }
150:
151: public boolean isSecurityEnabled() {
152: return securityEnabled;
153: }
154:
155: public Subject getDefaultSubject() {
156: return defaultSubject;
157: }
158:
159: public Subject getRunAs() {
160: return runAs;
161: }
162:
163: public Context getComponentContext() {
164: return javaCompSubContext;
165: }
166:
167: public Set getUnshareableResources() {
168: return unshareableResources;
169: }
170:
171: public Set getApplicationManagedSecurityResources() {
172: return applicationManagedSecurityResources;
173: }
174:
175: public TrackedConnectionAssociator getTrackedConnectionAssociator() {
176: return trackedConnectionAssociator;
177: }
178:
179: public EJBHome getEJBHome() {
180: return deploymentInfo.getEJBHome();
181: }
182:
183: public EJBLocalHome getEJBLocalHome() {
184: return deploymentInfo.getEJBLocalHome();
185: }
186:
187: public Object getBusinessLocalHome() {
188: return deploymentInfo.getBusinessLocalHome();
189: }
190:
191: public Object getBusinessRemoteHome() {
192: return deploymentInfo.getBusinessRemoteHome();
193: }
194:
195: public EJBObject getEjbObject(Object primaryKey) {
196: return (EJBObject) EjbObjectProxyHandler.createProxy(
197: deploymentInfo, primaryKey, InterfaceType.EJB_HOME);
198: }
199:
200: public Class getHomeInterface() {
201: return deploymentInfo.getHomeInterface();
202: }
203:
204: public Class getRemoteInterface() {
205: return deploymentInfo.getRemoteInterface();
206: }
207:
208: public Class getLocalHomeInterface() {
209: return deploymentInfo.getLocalHomeInterface();
210: }
211:
212: public Class getLocalInterface() {
213: return deploymentInfo.getLocalInterface();
214: }
215:
216: public Class getBeanClass() {
217: return deploymentInfo.getBeanClass();
218: }
219:
220: public Class getBusinessLocalInterface() {
221: return deploymentInfo.getBusinessLocalInterface();
222: }
223:
224: public Class getBusinessRemoteInterface() {
225: return deploymentInfo.getBusinessRemoteInterface();
226: }
227:
228: public Class getMdbInterface() {
229: return deploymentInfo.getMdbInterface();
230: }
231:
232: public Class getServiceEndpointInterface() {
233: return deploymentInfo.getServiceEndpointInterface();
234: }
235:
236: public BeanType getComponentType() {
237: return deploymentInfo.getComponentType();
238: }
239:
240: public Container getContainer() {
241: return deploymentInfo.getContainer();
242: }
243:
244: public boolean isBeanManagedTransaction() {
245: return deploymentInfo.isBeanManagedTransaction();
246: }
247:
248: public byte getTransactionAttribute(Method method) {
249: return deploymentInfo.getTransactionAttribute(method);
250: }
251:
252: public String getObjectName() {
253: return objectName;
254: }
255:
256: public boolean isStateManageable() {
257: return true;
258: }
259:
260: public boolean isStatisticsProvider() {
261: return false;
262: }
263:
264: public boolean isEventProvider() {
265: return true;
266: }
267:
268: protected void start() throws Exception {
269: deploymentInfo = (CoreDeploymentInfo) openEjbSystem
270: .getDeploymentInfo(deploymentId);
271: if (deploymentInfo == null) {
272: throw new IllegalStateException("Ejb does not exist "
273: + deploymentId);
274: }
275:
276: javaCompSubContext = (Context) deploymentInfo.getJndiEnc()
277: .lookup("java:comp");
278: if (componentContext != null) {
279: javaCompSubContext.bind("geronimo", componentContext);
280: }
281: deploymentInfo.set(EjbDeployment.class, this );
282: }
283:
284: protected void stop() {
285: if (deploymentInfo != null) {
286: deploymentInfo.set(EjbDeployment.class, null);
287: deploymentInfo = null;
288: }
289: }
290: }
|