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.metadata;
023:
024: import org.jboss.deployment.DeploymentException;
025: import org.w3c.dom.Element;
026:
027: import java.util.HashMap;
028:
029: /** The meta data information specific to session beans.
030: *
031: * @author <a href="mailto:sebastien.alborini@m4x.org">Sebastien Alborini</a>
032: * @author Scott.Stark@jboss.org
033: * @author <a href="mailto:Christoph.Jung@infor.de">Christoph G. Jung</a>.
034: * @version $Revision: 59651 $
035: */
036: public class SessionMetaData extends BeanMetaData {
037: // Constants -----------------------------------------------------
038: public static final String DEFAULT_STATEFUL_INVOKER = "stateful-unified-invoker";
039: public static final String DEFAULT_CLUSTERED_STATEFUL_INVOKER = "clustered-stateful-unified-invoker";
040: public static final String DEFAULT_STATELESS_INVOKER = "stateless-unified-invoker";
041: public static final String DEFAULT_CLUSTERED_STATELESS_INVOKER = "clustered-stateless-unified-invoker";
042: public static final String DEFAULT_WEBSERVICE_INVOKER = "session-webservice-invoker";
043:
044: // Attributes ----------------------------------------------------
045: /** whether it is a stateful or stateless bean */
046: private boolean stateful;
047: /** the service-endpoint element contains the fully-qualified
048: * name of the session beanīs web service interface
049: */
050: protected String serviceEndpointClass;
051: /** the jboss port-component binding for a ejb webservice
052: */
053: protected EjbPortComponentMetaData portComponent;
054:
055: // Static --------------------------------------------------------
056:
057: // Constructors --------------------------------------------------
058: public SessionMetaData(ApplicationMetaData app) {
059: super (app, BeanMetaData.SESSION_TYPE);
060: }
061:
062: // Public --------------------------------------------------------
063: public boolean isStateful() {
064: return stateful;
065: }
066:
067: public boolean isStateless() {
068: return !stateful;
069: }
070:
071: public boolean isWebservice() {
072: return getServiceEndpoint() != null;
073: }
074:
075: public String getServiceEndpoint() {
076: return serviceEndpointClass;
077: }
078:
079: public EjbPortComponentMetaData getPortComponent() {
080: return portComponent;
081: }
082:
083: public String getDefaultConfigurationName() {
084: if (isStateful()) {
085: if (this .isClustered())
086: return ConfigurationMetaData.CLUSTERED_STATEFUL_13;
087: else
088: return ConfigurationMetaData.STATEFUL_13;
089: } else {
090: if (this .isClustered())
091: return ConfigurationMetaData.CLUSTERED_STATELESS_13;
092: else
093: return ConfigurationMetaData.STATELESS_13;
094: }
095: }
096:
097: protected void defaultInvokerBindings() {
098: invokerBindings = new HashMap();
099: if (isClustered()) {
100: if (stateful) {
101: invokerBindings.put(DEFAULT_CLUSTERED_STATEFUL_INVOKER,
102: getJndiName());
103: } else {
104: invokerBindings.put(
105: DEFAULT_CLUSTERED_STATELESS_INVOKER,
106: getJndiName());
107: }
108: if (isWebservice())
109: invokerBindings.put(DEFAULT_WEBSERVICE_INVOKER,
110: getJndiName());
111: } else {
112: if (stateful) {
113: invokerBindings.put(DEFAULT_STATEFUL_INVOKER,
114: getJndiName());
115: } else {
116: invokerBindings.put(DEFAULT_STATELESS_INVOKER,
117: getJndiName());
118: }
119: if (isWebservice())
120: invokerBindings.put(DEFAULT_WEBSERVICE_INVOKER,
121: getJndiName());
122: }
123: }
124:
125: public void importEjbJarXml(Element element)
126: throws DeploymentException {
127: super .importEjbJarXml(element);
128:
129: // set the session type
130: String sessionType = getElementContent(getUniqueChild(element,
131: "session-type"));
132: if (sessionType.equals("Stateful")) {
133: stateful = true;
134: } else if (sessionType.equals("Stateless")) {
135: stateful = false;
136: } else {
137: throw new DeploymentException(
138: "session type should be 'Stateful' or 'Stateless'");
139: }
140:
141: // set the transaction type
142: String transactionType = getElementContent(getUniqueChild(
143: element, "transaction-type"));
144: if (transactionType.equals("Bean")) {
145: containerManagedTx = false;
146: } else if (transactionType.equals("Container")) {
147: containerManagedTx = true;
148: } else {
149: throw new DeploymentException(
150: "transaction type should be 'Bean' or 'Container'");
151: }
152:
153: serviceEndpointClass = getElementContent(getOptionalChild(
154: element, "service-endpoint"));
155: }
156:
157: public void importJbossXml(Element element)
158: throws DeploymentException {
159: super .importJbossXml(element);
160: // port-component optional element
161: Element portElement = getOptionalChild(element,
162: "port-component");
163: if (portElement != null) {
164: portComponent = new EjbPortComponentMetaData(this);
165: portComponent.importJBossXml(portElement);
166: }
167: }
168:
169: }
|