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.core.ivm;
017:
018: import java.io.ObjectStreamException;
019:
020: import javax.ejb.EJBHome;
021:
022: import org.apache.openejb.DeploymentInfo;
023: import org.apache.openejb.BeanType;
024: import org.apache.openejb.core.ServerFederation;
025: import org.apache.openejb.spi.ApplicationServer;
026: import org.apache.openejb.util.proxy.ProxyManager;
027:
028: public class IntraVmMetaData implements javax.ejb.EJBMetaData,
029: java.io.Serializable {
030:
031: protected Class homeClass;
032:
033: protected Class remoteClass;
034:
035: protected Class keyClass;
036:
037: protected EJBHome homeStub;
038:
039: protected BeanType type;
040:
041: public IntraVmMetaData(Class homeInterface, Class remoteInterface,
042: BeanType typeOfBean) {
043: this (homeInterface, remoteInterface, null, typeOfBean);
044: }
045:
046: public IntraVmMetaData(Class homeInterface, Class remoteInterface,
047: Class primaryKeyClass, BeanType typeOfBean) {
048: this .type = typeOfBean;
049: if (homeInterface == null || remoteInterface == null) {
050: throw new IllegalArgumentException();
051: }
052: if (typeOfBean.isEntity() && primaryKeyClass == null) {
053: throw new IllegalArgumentException(
054: "Entity beans must have a primary key class");
055: }
056: type = typeOfBean;
057: homeClass = homeInterface;
058: remoteClass = remoteInterface;
059: keyClass = primaryKeyClass;
060: }
061:
062: public Class getHomeInterfaceClass() {
063: return homeClass;
064: }
065:
066: public Class getRemoteInterfaceClass() {
067: return remoteClass;
068: }
069:
070: public Class getPrimaryKeyClass() {
071: if (type.isEntity())
072: return keyClass;
073: else
074: throw new UnsupportedOperationException(
075: "Session objects are private resources and do not have primary keys");
076: }
077:
078: public boolean isSession() {
079: return type.isSession();
080: }
081:
082: public boolean isStatelessSession() {
083: return type == BeanType.STATELESS;
084: }
085:
086: public void setEJBHome(EJBHome home) {
087: homeStub = home;
088: }
089:
090: public javax.ejb.EJBHome getEJBHome() {
091: return homeStub;
092: }
093:
094: protected Object writeReplace() throws ObjectStreamException {
095:
096: /*
097: * If the meta data is being copied between bean instances in a RPC
098: * call we use the IntraVmArtifact
099: */
100: if (IntraVmCopyMonitor.isIntraVmCopyOperation()) {
101: return new IntraVmArtifact(this );
102: /*
103: * If the meta data is referenced by a stateful bean that is being
104: * passivated by the container, we allow this object to be serialized.
105: */
106: } else if (IntraVmCopyMonitor.isStatefulPassivationOperation()) {
107: return this ;
108: /*
109: * If the proxy is being copied between class loaders
110: * we allow this object to be serialized.
111: */
112: } else if (IntraVmCopyMonitor.isCrossClassLoaderOperation()) {
113: return this ;
114: /*
115: * If the meta data is serialized outside the core container system,
116: * we allow the application server to handle it.
117: */
118: } else {
119: BaseEjbProxyHandler handler = (BaseEjbProxyHandler) ProxyManager
120: .getInvocationHandler(homeStub);
121: ApplicationServer applicationServer = ServerFederation
122: .getApplicationServer();
123: return applicationServer.getEJBMetaData(handler
124: .getProxyInfo());
125: }
126: }
127: }
|