001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.proxy.ejb;
023:
024: import java.io.Serializable;
025: import java.rmi.RemoteException;
026:
027: import javax.ejb.HomeHandle;
028: import javax.ejb.EJBMetaData;
029: import javax.ejb.EJBHome;
030: import javax.ejb.EJBException;
031:
032: /**
033: * An implementation of the EJBMetaData interface which allows a
034: * client to obtain the enterprise Bean's meta-data information.
035: *
036: * @author Rickard Öberg (rickard.oberg@telkel.com)
037: * @author <a href="mailto:marc.fleury@telkel.com">Marc Fleury</a>
038: * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
039: * @version $Revision: 57209 $
040: */
041: public class EJBMetaDataImpl implements EJBMetaData, Serializable {
042: /** Serial Version Identifier. @since 1.1 */
043: private static final long serialVersionUID = -3698855455664391097L;
044:
045: // Attributes ----------------------------------------------------
046: private final Class remote;
047: private final Class home;
048: private final Class pkClass;
049:
050: private final boolean session;
051: private final boolean statelessSession;
052: private final HomeHandle homeHandle;
053:
054: // Constructors --------------------------------------------------
055:
056: /**
057: * Construct an <tt>EJBMetaDataImpl</tt>.
058: * this should only be accessible from the factory.
059: */
060: public EJBMetaDataImpl(final Class remote, final Class home,
061: final Class pkClass, final boolean session,
062: final boolean statelessSession, final HomeHandle homeHandle) {
063: this .remote = remote;
064: this .home = home;
065: this .pkClass = pkClass;
066: this .session = session;
067: this .statelessSession = statelessSession;
068: this .homeHandle = homeHandle;
069: }
070:
071: // Constructors --------------------------------------------------
072:
073: // EJBMetaData ---------------------------------------------------
074:
075: // EJBMetaData ---------------------------------------------------
076:
077: /**
078: * Obtain the home interface of the enterprise Bean.
079: *
080: * @throws EJBException Failed to get EJBHome object.
081: */
082:
083: public EJBHome getEJBHome() {
084: try {
085: return homeHandle.getEJBHome();
086: } catch (RemoteException e) {
087: e.printStackTrace();
088: throw new EJBException(e);
089: }
090: }
091:
092: /**
093: * Obtain the Class object for the enterprise Bean's home interface.
094: */
095: public Class getHomeInterfaceClass() {
096: return home;
097: }
098:
099: /**
100: * Obtain the Class object for the enterprise Bean's remote interface.
101: */
102: public Class getRemoteInterfaceClass() {
103: return remote;
104: }
105:
106: /**
107: * Obtain the Class object for the enterprise Bean's primary key class.
108: */
109: public Class getPrimaryKeyClass() {
110: if (session == true)
111: throw new RuntimeException(
112: "A session bean does not have a primary key class");
113:
114: return pkClass;
115: }
116:
117: /**
118: * Test if the enterprise Bean's type is "session".
119: *
120: * @return True if the type of the enterprise Bean is session bean.
121: */
122: public boolean isSession() {
123: return session;
124: }
125:
126: /**
127: * Test if the enterprise Bean's type is "stateless session".
128: *
129: * @return True if the type of the enterprise Bean is stateless session.
130: */
131: public boolean isStatelessSession() {
132: return statelessSession;
133: }
134: }
|