001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JApplicationException.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.deployment.annotations.impl;
025:
026: import java.lang.annotation.Annotation;
027:
028: import javax.ejb.ApplicationException;
029:
030: /**
031: * Acts as an implementation of @{@link javax.ejb.ApplicationException}
032: * annotation.
033: * @author Florent Benoit
034: */
035: public class JApplicationException implements ApplicationException {
036:
037: /**
038: * Name of this element (Deployment desc).
039: */
040: public static final String NAME = "application-exception";
041:
042: /**
043: * Container rollback the transaction ? if an exception is thrown.
044: */
045: private boolean rollback = false;
046:
047: /**
048: * Name of the class that is flagged as ApplicationException.
049: */
050: private String className = null;
051:
052: /**
053: * Build an object which represents @{@link javax.ejb.ApplicationException}
054: * annotation.<br>
055: * Default value for rollback is false.
056: */
057: public JApplicationException() {
058: this (false);
059: }
060:
061: /**
062: * Build an object which represents @{@link javax.ejb.ApplicationException}
063: * annotation with a given boolean.<br>
064: * @param rollback true/false (false is a default value)
065: */
066: public JApplicationException(final boolean rollback) {
067: this (null, rollback);
068: }
069:
070: /**
071: * Build an object which represents @{@link javax.ejb.ApplicationException}
072: * annotation with a given boolean.<br>
073: * @param className the name of the class which is the application
074: * exception.
075: * @param rollback true/false (false is a default value)
076: */
077: public JApplicationException(final String className,
078: final boolean rollback) {
079: this .className = className;
080: this .rollback = rollback;
081: }
082:
083: /**
084: * @return the retainIfException value (true/false)
085: */
086: public boolean rollback() {
087: return rollback;
088: }
089:
090: /**
091: * @return the class name.
092: */
093: public String getClassName() {
094: return className;
095: }
096:
097: /**
098: * @return annotation type
099: */
100: public Class<? extends Annotation> annotationType() {
101: return ApplicationException.class;
102: }
103:
104: /**
105: * @return string representation
106: */
107: @Override
108: public String toString() {
109: StringBuilder sb = new StringBuilder();
110: // classname
111: sb.append(this .getClass().getName().substring(
112: this .getClass().getPackage().getName().length() + 1));
113: // rollback
114: sb.append("[rollback=");
115: sb.append(rollback);
116: if (className != null) {
117: sb.append(",className=");
118: sb.append(className);
119: }
120: sb.append("]");
121: return sb.toString();
122: }
123: }
|