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 */
017 package org.apache.geronimo.corba;
018
019 import javax.ejb.EJBMetaData;
020 import javax.ejb.EJBHome;
021 import javax.rmi.PortableRemoteObject;
022
023 /**
024 * @version $Revision: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
025 */
026 public class CORBAEJBMetaData implements EJBMetaData, 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, Class homeInterface, Class remoteInterface, Class primaryKeyClass) {
065 if (homeInterface == null) {
066 throw new IllegalArgumentException("Home interface is null");
067 }
068 if (remoteInterface == null) {
069 throw new IllegalArgumentException("Remote interface is null");
070 }
071 if (ejbType == ENTITY && primaryKeyClass == null) {
072 throw new IllegalArgumentException("Entity bean must have a primary key class");
073 }
074 if (ejbType != ENTITY && primaryKeyClass != null) {
075 throw new IllegalArgumentException("Session bean must have a primary key class");
076 }
077 this.ejbHome = ejbHome;
078 this.ejbType = ejbType;
079 this.homeInterface = homeInterface;
080 this.remoteInterface = remoteInterface;
081 this.primaryKeyClass = primaryKeyClass;
082 }
083
084 public Class getHomeInterfaceClass() {
085 return homeInterface;
086 }
087
088 public Class getRemoteInterfaceClass() {
089 return remoteInterface;
090 }
091
092 public Class getPrimaryKeyClass() {
093 if (ejbType == ENTITY) {
094 return primaryKeyClass;
095 } else {
096 throw new UnsupportedOperationException("Session objects are private resources and do not have primary keys");
097 }
098 }
099
100 public boolean isSession() {
101 return (ejbType == STATEFUL || ejbType == STATELESS);
102 }
103
104 public boolean isStatelessSession() {
105 return ejbType == STATELESS;
106 }
107
108 public EJBHome getEJBHome() {
109 return (EJBHome) PortableRemoteObject.narrow(ejbHome, EJBHome.class);
110 }
111 }