001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the License). You may not use this file except in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * Header Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022:
023: package com.sun.xml.ws.tx.common;
024:
025: import javax.ejb.Stateful;
026: import javax.ejb.Stateless;
027: import javax.ejb.TransactionAttribute;
028: import javax.ejb.TransactionManagement;
029: import java.lang.reflect.Method;
030:
031: /**
032: * Place all dependencies on javax.ejb in one file.
033: */
034: public class TransactionAnnotationProcessor {
035:
036: enum TransactionAttributeType {
037: NOT_SUPPORTED, NEVER, MANDATORY, SUPPORTS, REQUIRES_NEW, REQUIRED
038: }
039:
040: static public boolean isContainerManagedEJB(Class c) {
041: boolean result = false;
042: TransactionManagement tm = (TransactionManagement) c
043: .getAnnotation(TransactionManagement.class);
044: if (tm != null) {
045: switch (tm.value()) {
046: case BEAN:
047: return false;
048: case CONTAINER:
049: default:
050: return true;
051: }
052: }
053:
054: // No TransactionManagement annotation. Default is CONTAINER for EJB.
055: Stateful stateful = (Stateful) c.getAnnotation(Stateful.class);
056: Stateless stateless = (Stateless) c
057: .getAnnotation(Stateless.class);
058: if (c.getAnnotation(Stateful.class) != null
059: || c.getAnnotation(Stateless.class) != null) {
060: //TODO: Are there any other EJB annotations?
061: return true;
062: } else {
063: // servlet endpoint
064: return false;
065: }
066: }
067:
068: /**
069: * Precondition: isContainerManagedEjb(c) returned true.
070: */
071: static public TransactionAttributeType getTransactionAttributeDefault(
072: Class c) {
073: // defaults to REQUIRED if no annotation on class
074: TransactionAttributeType result = TransactionAttributeType.REQUIRED;
075: TransactionAttribute txnAttr = (TransactionAttribute) c
076: .getAnnotation(TransactionAttribute.class);
077: if (txnAttr != null) {
078: result = convert(txnAttr.value());
079: }
080: return result;
081: }
082:
083: /**
084: * DefaultTxnAttr was obtained from class TransactionAttribute annotation.
085: */
086: static public TransactionAttributeType getEffectiveTransactionAttribute(
087: Method m, TransactionAttributeType defaultTxnAttr) {
088: TransactionAttributeType result = defaultTxnAttr;
089: TransactionAttribute txnAttr = m
090: .getAnnotation(TransactionAttribute.class);
091: if (txnAttr != null) {
092: result = convert(txnAttr.value());
093: }
094: return result;
095: }
096:
097: private static TransactionAttributeType convert(
098: javax.ejb.TransactionAttributeType e) {
099: return TransactionAttributeType.valueOf(
100: TransactionAttributeType.class, e.name());
101: }
102: }
|