KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > ContainerTransaction


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment;
24
25 import java.util.*;
26 import com.sun.enterprise.util.LocalStringManagerImpl;
27
28 /**
29  * This descriptor represents a specification of a transactional behavior.
30  *
31  * @author Danny Coward
32  */

33
34 public class ContainerTransaction extends Descriptor {
35     private String JavaDoc transactionAttribute;
36     /** Transactions are not supported. */
37     public static String JavaDoc NOT_SUPPORTED = "NotSupported";
38     /** Transactions need support. */
39     public static String JavaDoc SUPPORTS = "Supports";
40     /** A transaction is required. */
41     public static String JavaDoc REQUIRED = "Required";
42     /** A new transaction must be created. */
43     public static String JavaDoc REQUIRES_NEW = "RequiresNew";
44     /** Transaction is mandatory.*/
45     public static String JavaDoc MANDATORY = "Mandatory";
46     /** Never supply a transaction. */
47     public static String JavaDoc NEVER = "Never";
48     private static LocalStringManagerImpl localStrings =
49         new LocalStringManagerImpl(ContainerTransaction.class);
50     
51     /**
52      * Copy constructor.
53      */

54     public ContainerTransaction(ContainerTransaction other) {
55     if (other != null) {
56         this.transactionAttribute = other.transactionAttribute;
57         this.setDescription(other.getDescription());
58     }
59     }
60     
61     /**
62      * Create a new transaction descriptor with the given attribute. Throws
63      * an IllegalArgumentException if the attribute is not an allowed type.
64      * The allowed types are enumeration ny this class.
65      * @param the transaction attribute.
66      * @param the description.
67      */

68     public ContainerTransaction(String JavaDoc transactionAttribute,
69                 String JavaDoc description) {
70     super("a Container Transaction", description);
71     boolean isValidAttribute = (NOT_SUPPORTED.equals(transactionAttribute)
72         || SUPPORTS.equals(transactionAttribute)
73         || REQUIRED.equals(transactionAttribute)
74             || REQUIRED.equals(transactionAttribute)
75             || REQUIRES_NEW.equals(transactionAttribute)
76                 || MANDATORY.equals(transactionAttribute)
77                 || NEVER.equals(transactionAttribute) );
78     if (!isValidAttribute && this.isBoundsChecking()) {
79         throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
80             "enterprise.deployment.exceptionunknowncontainertxtype",
81             "Unknown ContainerTransaction type: {0}",
82             new Object JavaDoc[] {transactionAttribute}));
83     } else {
84         this.transactionAttribute = transactionAttribute;
85     }
86     }
87     
88     /**
89      * The transaction attribute that I specify.
90      * @return the transaction attribute.
91      */

92     public String JavaDoc getTransactionAttribute() {
93     return this.transactionAttribute;
94     }
95     
96     /**
97      * Equality iff the other object is another container transaction with the
98      * same transaction attribute.
99      * @return true if the objects are equal, false otherwise.
100      */

101     public boolean equals(Object JavaDoc other) {
102     if (other != null && other instanceof ContainerTransaction) {
103         ContainerTransaction otherContainerTransaction =
104                 (ContainerTransaction) other;
105         if (otherContainerTransaction.getTransactionAttribute().equals(
106                     this.getTransactionAttribute())) {
107         return true;
108         }
109     }
110     return false;
111     }
112     
113     /**
114      * Returns a formatted String representing my state.
115      */

116     public void print(StringBuffer JavaDoc toStringBuffer) {
117     toStringBuffer.append("Container Transaction: ").append(this.getTransactionAttribute()).append("@").append(this.getDescription());
118     }
119 }
120
121
Popular Tags