001: //
002: // This file is part of the prose package.
003: //
004: // The contents of this file are subject to the Mozilla Public License
005: // Version 1.1 (the "License"); you may not use this file except in
006: // compliance with the License. You may obtain a copy of the License at
007: // http://www.mozilla.org/MPL/
008: //
009: // Software distributed under the License is distributed on an "AS IS" basis,
010: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: // for the specific language governing rights and limitations under the
012: // License.
013: //
014: // The Original Code is prose.
015: //
016: // The Initial Developer of the Original Code is Angela Nicoara. Portions
017: // created by Angela Nicoara are Copyright (C) 2002 Angela Nicoara.
018: // All Rights Reserved.
019: //
020: // Contributor(s):
021: // $Id$
022: // =====================================================================
023: //
024: // (history at end)
025: //
026:
027: package ch.ethz.prose.crosscut;
028:
029: // used packages
030: import ch.ethz.jvmai.ExceptionCatchJoinPoint;
031:
032: /**
033: * Class CatchCut represents a crosscut which cuts across <em>all</em>
034: * points belonging to <em>all</em> classes in the local VM where exceptions
035: * are catch.
036: *
037: * There are two ways of using this crosscut:
038: * <ol>
039: * <li> override the <em>convenience</em> methods <code>exceptionThrowAdvice</code>
040: * and <code>exceptionCatchAdvice</code> if you do not want to deal with the
041: * reflective part of join-points.
042: * <li> override the <code>joinPointAdvice</code> methods and define void-bodies
043: * for <code>exceptionThrowAdvice</code> and <code>exceptionCatchAdvice</code>.
044: * This second case is recomended only if you need the last bit of speed out
045: * of the system.
046: * </ol>
047: *
048: * @version $Revision: 1.1.1.1 $
049: * @author Philippe Schoch
050: */
051: public abstract class CatchCut extends AbstractCrosscut implements
052: java.io.Serializable {
053:
054: private transient CatchHandleSignaturePattern advicePattern;
055:
056: // Caching variable for Class Object Throwable
057: private static Class throwableClass;
058:
059: /**
060: * Constructor
061: */
062: protected CatchCut() {
063: initState();
064: }
065:
066: public void insertionAction(boolean isBeforeInsertion) {
067: if (isBeforeInsertion)
068: initState();
069: }
070:
071: private void initState() {
072: if (advicePattern == null) {
073: advicePattern = new CatchHandleSignaturePattern(this );
074: }
075: }
076:
077: /** This method must be defined by subclasses. It will be called
078: * each time one of the selected exceptions is catch.
079: */
080: public void CATCH_ARGS() {
081: }
082:
083: /** Advice action of Exceptions*/
084: protected void joinPointAction(ExceptionCatchJoinPoint ecjp)
085: throws IllegalAccessException {
086:
087: try {
088: switch (advicePattern.signatureCathegory
089: & (SignaturePattern.WILDCARD_1
090: | SignaturePattern.CONCRETE_1 | SignaturePattern.SIGNATURE__EMPTY)) {
091: case SignaturePattern.SIGNATURE__EMPTY:
092: CATCH_ARGS();
093: break;
094: case SignaturePattern.WILDCARD_1:
095: ANY x = new ANY();
096: x.setObject(ecjp.getException());
097: advicePattern.methodObj
098: .invoke(this , new Object[] { x });
099: break;
100: case SignaturePattern.CONCRETE_1:
101: advicePattern.methodObj.invoke(this ,
102: new Object[] { ecjp.getException() });
103: break;
104: default:
105: throw new Error(
106: "CatchCut.joinPointAction: illegal signature pattern");
107: }
108: } catch (java.lang.reflect.InvocationTargetException e) {
109: throw new Error(
110: "CatchCut.joinPointAction: wrong arguments; static check failure:"
111: + e);
112: }
113:
114: }
115:
116: /**
117: * Only a class of supertype 'Throwable' is a potential Exception Catch Crosscut Class
118: */
119: protected boolean isPotentialCrosscutClass(Class c) {
120: return Throwable.class.isAssignableFrom(c);
121: }
122:
123: /**
124: * Create a new CrosscutRequest consisting of ExceptionCatchRequests
125: * for each catch exception in each method declared in class <code>cls</code>.
126: * Only one ExceptionCatchRequest per exception class is
127: * generated for a specific CatchCut.
128: */
129: protected CrosscutRequest doCreateRequest(Class cls) {
130: CrosscutRequest result = new CrosscutRequest();
131: if ((advicePattern.signatureCathegory & (SignaturePattern.CONCRETE_1)) != 0
132: && (!advicePattern.signature[0].isAssignableFrom(cls)))
133: return result;
134:
135: result.add(requestFactory.createJoinPointRequest(
136: ExceptionCatchJoinPoint.KIND, cls));
137:
138: return result;
139: }
140:
141: /**
142: *
143: */
144: public String toString() {
145: return "Crosscut 'CatchCut' [class '" + getClass().getName()
146: + "'] specialized with [" + getSpecializer() + "]";
147: }
148:
149: }
150:
151: //======================================================================
152: //
153: // $Log$
154: //
|