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.ejb3.metamodel;
023:
024: import java.util.ArrayList;
025: import java.util.List;
026: import java.util.Collection;
027: import java.util.HashSet;
028: import javax.ejb.TransactionManagementType;
029: import org.jboss.logging.Logger;
030:
031: import org.jboss.metamodel.descriptor.SecurityRoleRef;
032: import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
033: import org.jboss.metamodel.descriptor.InjectionTarget;
034: import org.jboss.metamodel.descriptor.MessageDestinationRef;
035: import org.jboss.metamodel.descriptor.ResourceEnvRef;
036: import org.jboss.metamodel.descriptor.ResourceRef;
037:
038: /**
039: * Represents an EJB element of the ejb-jar.xml deployment descriptor for the
040: * 1.4 schema
041: *
042: * @author <a href="mailto:bdecoste@jboss.com">William DeCoste</a>
043: * @version <tt>$Revision: 63839 $</tt>
044: */
045: public abstract class EnterpriseBean extends EnvironmentRefGroup
046: implements Injectable {
047: private static final Logger log = Logger
048: .getLogger(EnterpriseBean.class);
049:
050: public static final String BEAN = "Bean";
051:
052: public static final String CONTAINER = "Container";
053:
054: // ejb-jar.xml
055: private String ejbName = null;
056:
057: private String home = null;
058:
059: private String remote = null;
060:
061: private String localHome = null;
062:
063: private String local = null;
064:
065: private String ejbClass = null;
066:
067: private List<RemoteBinding> remoteBindings = new ArrayList();
068:
069: private SecurityIdentity securityIdentity;
070:
071: protected TransactionManagementType tmType = null;
072:
073: // jboss.xml
074: private String jndiName;
075: private String homeJndiName;
076:
077: private String localJndiName;
078: private String localHomeJndiName;
079:
080: private String securityDomain;
081:
082: private boolean callByValue = false;
083:
084: private String aopDomainName = null;
085:
086: private MethodAttributes methodAttributes = null;
087:
088: private Collection<String> dependencies = new HashSet<String>();
089:
090: private Collection<InjectionTarget> ignoreDependencies = new HashSet<InjectionTarget>();
091:
092: private Collection<XmlAnnotation> xmlAnnotations = new HashSet<XmlAnnotation>();
093:
094: private PoolConfig poolConfig = null;
095:
096: /** The security-role-ref element(s) info */
097: private Collection<SecurityRoleRef> securityRoleRefs = new HashSet<SecurityRoleRef>();
098:
099: public void addXmlAnnotation(XmlAnnotation annotation) {
100: xmlAnnotations.add(annotation);
101: }
102:
103: public Collection<XmlAnnotation> getXmlAnnotations() {
104: return xmlAnnotations;
105: }
106:
107: public void setPoolConfig(PoolConfig poolConfig) {
108: this .poolConfig = poolConfig;
109: }
110:
111: public PoolConfig getPoolConfig() {
112: return poolConfig;
113: }
114:
115: public void addRemoteBinding(RemoteBinding binding) {
116: remoteBindings.add(binding);
117: }
118:
119: public List<RemoteBinding> getRemoteBindings() {
120: return remoteBindings;
121: }
122:
123: public void addDependency(String depends) {
124: dependencies.add(depends);
125: }
126:
127: public Collection<String> getDependencies() {
128: return dependencies;
129: }
130:
131: public void addIgnoreDependency(InjectionTarget ignore) {
132: ignoreDependencies.add(ignore);
133: }
134:
135: public Collection<InjectionTarget> getIgnoreDependencies() {
136: return ignoreDependencies;
137: }
138:
139: public void mergeMessageDestinationRef(MessageDestinationRef ref) {
140: MessageDestinationRef tmpRef = (MessageDestinationRef) messageDestinationRefs
141: .get(ref.getMessageDestinationRefName());
142: if (tmpRef != null)
143: tmpRef.merge(ref);
144: }
145:
146: public void mergeResourceRef(ResourceRef ref) {
147: ResourceRef tmpRef = (ResourceRef) resourceRefs.get(ref
148: .getResRefName());
149: if (tmpRef != null)
150: tmpRef.merge(ref);
151: }
152:
153: public void mergeResourceEnvRef(ResourceEnvRef ref) {
154: ResourceEnvRef tmpRef = (ResourceEnvRef) resourceEnvRefs
155: .get(ref.getResRefName());
156: if (tmpRef != null)
157: tmpRef.merge(ref);
158: }
159:
160: public void setMethodAttributes(MethodAttributes methodAttributes) {
161: this .methodAttributes = methodAttributes;
162: }
163:
164: public MethodAttributes getMethodAttributes() {
165: return methodAttributes;
166: }
167:
168: public void setAopDomainName(String aopDomainName) {
169: this .aopDomainName = aopDomainName;
170: }
171:
172: public String getAopDomainName() {
173: return aopDomainName;
174: }
175:
176: public void setRunAsPrincipal(String principal) {
177: /**
178: * A case where the RunAs is defined in annotations and the
179: * RunAsPrincipal is specified in jboss.xml
180: */
181: if (securityIdentity == null) {
182: securityIdentity = new SecurityIdentity();
183: }
184: securityIdentity.setRunAsPrincipal(principal);
185: }
186:
187: public void setCallByValue(boolean callByValue) {
188: this .callByValue = callByValue;
189: }
190:
191: public boolean isCallByValue() {
192: return callByValue;
193: }
194:
195: public String getSecurityDomain() {
196: return securityDomain;
197: }
198:
199: public void setSecurityDomain(String securityDomain) {
200: this .securityDomain = securityDomain;
201: }
202:
203: public String getJndiName() {
204: return jndiName;
205: }
206:
207: public void setJndiName(String jndiName) {
208: this .jndiName = jndiName;
209: }
210:
211: public String getHomeJndiName() {
212: return homeJndiName;
213: }
214:
215: public void setHomeJndiName(String homeJndiName) {
216: this .homeJndiName = homeJndiName;
217: }
218:
219: public String getLocalJndiName() {
220: return localJndiName;
221: }
222:
223: public void setLocalJndiName(String localJndiName) {
224: this .localJndiName = localJndiName;
225: }
226:
227: public String getLocalHomeJndiName() {
228: return localHomeJndiName;
229: }
230:
231: public void setLocalHomeJndiName(String localHomeJndiName) {
232: this .localHomeJndiName = localHomeJndiName;
233: }
234:
235: public TransactionManagementType getTransactionManagementType() {
236: return tmType;
237: }
238:
239: public void setTransactionManagementType(String transactionType) {
240: if (transactionType.equals(BEAN))
241: tmType = TransactionManagementType.BEAN;
242: else if (transactionType.equals(CONTAINER))
243: tmType = TransactionManagementType.CONTAINER;
244: }
245:
246: public boolean isSessionBean() {
247: return this instanceof SessionEnterpriseBean;
248: }
249:
250: public boolean isConsumer() {
251: return this instanceof Consumer;
252: }
253:
254: public boolean isEntityBean() {
255: return this instanceof EntityEnterpriseBean;
256: }
257:
258: public boolean isMessageDrivenBean() {
259: return this instanceof MessageDrivenBean;
260: }
261:
262: public boolean isService() {
263: return this instanceof Service;
264: }
265:
266: public String getEjbName() {
267: return ejbName;
268: }
269:
270: public void setEjbName(String ejbName) {
271: this .ejbName = ejbName;
272: }
273:
274: public String getHome() {
275: return home;
276: }
277:
278: public void setHome(String home) {
279: this .home = home;
280: }
281:
282: public String getRemote() {
283: return remote;
284: }
285:
286: public void setRemote(String remote) {
287: this .remote = remote;
288: }
289:
290: public String getLocalHome() {
291: return localHome;
292: }
293:
294: public void setLocalHome(String localHome) {
295: this .localHome = localHome;
296: }
297:
298: public String getLocal() {
299: return local;
300: }
301:
302: public void setLocal(String local) {
303: this .local = local;
304: }
305:
306: public String getEjbClass() {
307: return ejbClass;
308: }
309:
310: public void setEjbClass(String ejbClass) {
311: this .ejbClass = ejbClass;
312: }
313:
314: public SecurityIdentity getSecurityIdentity() {
315: return securityIdentity;
316: }
317:
318: public void setSecurityIdentity(SecurityIdentity securityIdentity) {
319: this .securityIdentity = securityIdentity;
320: }
321:
322: public void addSecurityRoleRef(SecurityRoleRef roleRef) {
323: this .securityRoleRefs.add(roleRef);
324: }
325:
326: public Collection<SecurityRoleRef> getSecurityRoleRefs() {
327: return securityRoleRefs;
328: }
329:
330: public String toString() {
331: StringBuffer sb = new StringBuffer(100);
332: sb.append("ejbName=").append(ejbName);
333: sb.append(",remoteBindings=").append(remoteBindings);
334: sb.append(",jndiName=").append(jndiName);
335: sb.append(",local=").append(local);
336: sb.append(",remote=").append(remote);
337: sb.append(",home=").append(home);
338: sb.append(",localHome=").append(localHome);
339: sb.append(",ejbClass=").append(ejbClass);
340: sb.append(",ejbRefs=").append(ejbRefs);
341: sb.append(",ejbLocalRefs=").append(ejbLocalRefs);
342: sb.append(",resourceRefs=").append(resourceRefs);
343: sb.append(",resourceEnvRefs=").append(resourceEnvRefs);
344: sb.append(",methodAttributes=").append(methodAttributes);
345: sb.append(",aopDomainName=").append(aopDomainName);
346: sb.append(",dependencies=").append(dependencies);
347: sb.append(",securityRoleRefs=").append(securityRoleRefs);
348: return sb.toString();
349: }
350:
351: }
|