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.EJBMetaData;
019: import javax.ejb.EJBHome;
020: import javax.rmi.PortableRemoteObject;
021:
022: /**
023: * @version $Revision: 465108 $ $Date: 2006-10-17 17:23:40 -0700 (Tue, 17 Oct 2006) $
024: */
025: public class CORBAEJBMetaData implements EJBMetaData,
026: java.io.Serializable {
027:
028: private static final long serialVersionUID = 8085488135161906381L;
029:
030: public final static byte ENTITY = 1;
031: public final static byte STATEFUL = 2;
032: public final static byte STATELESS = 3;
033:
034: /**
035: * The Class of the bean's home interface.
036: */
037: private final Class homeInterface;
038:
039: /**
040: * The Class of the bean's remote interface.
041: */
042: private final Class remoteInterface;
043:
044: /**
045: * The Class of the bean's primary key or null if the
046: * bean is of a type that does not require a primary key.
047: */
048: private final Class primaryKeyClass;
049:
050: /**
051: * The EJBHome stub/proxy for this bean deployment.
052: */
053: private final EJBHome ejbHome;
054:
055: /**
056: * The type of bean that this MetaData implementation represents.
057: *
058: * @see #ENTITY
059: * @see #STATEFUL
060: * @see #STATELESS
061: */
062: private final byte ejbType;
063:
064: public CORBAEJBMetaData(EJBHome ejbHome, byte ejbType,
065: Class homeInterface, Class remoteInterface,
066: Class primaryKeyClass) {
067: if (homeInterface == null) {
068: throw new IllegalArgumentException("Home interface is null");
069: }
070: if (remoteInterface == null) {
071: throw new IllegalArgumentException(
072: "Remote interface is null");
073: }
074: if (ejbType == ENTITY && primaryKeyClass == null) {
075: throw new IllegalArgumentException(
076: "Entity bean must have a primary key class");
077: }
078: if (ejbType != ENTITY && primaryKeyClass != null) {
079: throw new IllegalArgumentException(
080: "Session bean must have a primary key class");
081: }
082: this .ejbHome = ejbHome;
083: this .ejbType = ejbType;
084: this .homeInterface = homeInterface;
085: this .remoteInterface = remoteInterface;
086: this .primaryKeyClass = primaryKeyClass;
087: }
088:
089: public Class getHomeInterfaceClass() {
090: return homeInterface;
091: }
092:
093: public Class getRemoteInterfaceClass() {
094: return remoteInterface;
095: }
096:
097: public Class getPrimaryKeyClass() {
098: if (ejbType == ENTITY) {
099: return primaryKeyClass;
100: } else {
101: throw new UnsupportedOperationException(
102: "Session objects are private resources and do not have primary keys");
103: }
104: }
105:
106: public boolean isSession() {
107: return (ejbType == STATEFUL || ejbType == STATELESS);
108: }
109:
110: public boolean isStatelessSession() {
111: return ejbType == STATELESS;
112: }
113:
114: public EJBHome getEJBHome() {
115: return (EJBHome) PortableRemoteObject.narrow(ejbHome,
116: EJBHome.class);
117: }
118: }
|