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 Andrei Popovici. Portions
017: // created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
018: // All Rights Reserved.
019: //
020: // Contributor(s):
021: // $Id: DefaultAspect.java,v 1.1.1.1 2003/07/02 15:30:50 apopovic Exp $
022: // =====================================================================
023: //
024: // (history at end)
025: //
026:
027: package ch.ethz.prose;
028:
029: // used packages
030: import java.lang.reflect.Field;
031: import java.util.Vector;
032:
033: import ch.ethz.prose.crosscut.Crosscut;
034: import ch.ethz.inf.util.Logger;
035:
036: /**
037: * Class DefaultAspect provides a declarative way to define
038: * an extension. For example, the following code
039: * <blockquote><pre>
040: * class MyExtension extends DefaultAspect
041: * {
042: * Crosscut c1 = new MethodCut()
043: * {
044: * public void METHOD_ARGS(ANY thisO,REST params) {}
045: * }
046: * Crosscut c2 = new MethodCut{}
047: * {
048: * public void adviceMethod(Object thisO, Object[] parms){}
049: * }.specializeWith( ( MethodS.BEFORE1) .AND
050: * ( MethodS.named("Foo")) );
051: *
052: * }
053: *
054: * </pre></blockquote>
055: * would produce an extension which returns a list of two crosscuts
056: * <code>c1</code> and <code>c2</code>.
057: *
058: *
059: * @version $Revision: 1.1.1.1 $
060: * @author Andrei Popovici
061: */
062: public abstract class DefaultAspect extends Aspect {
063:
064: protected Crosscut[] crosscuts() {
065: Vector theCrosscuts = null;
066: try {
067: theCrosscuts = new Vector();
068: Field[] declFields = getClass().getDeclaredFields();
069: for (int i = 0; i < declFields.length; i++) {
070: if (Crosscut.class.isAssignableFrom(declFields[i]
071: .getType())
072: && (declFields[i].get(this ) != null))
073: theCrosscuts.add(declFields[i].get(this ));
074: }
075: } catch (IllegalAccessException probablyPrivate) {
076: Logger.error("Probably private definition:",
077: probablyPrivate);
078: throw new IllegalAspectException(
079: " Probably private crosscut definitions:"
080: + probablyPrivate.toString());
081: }
082:
083: return (Crosscut[]) (theCrosscuts.toArray(new Crosscut[] {}));
084: }
085:
086: }
087:
088: //======================================================================
089: //
090: // $Log: DefaultAspect.java,v $
091: // Revision 1.1.1.1 2003/07/02 15:30:50 apopovic
092: // Imported from ETH Zurich
093: //
094: // Revision 1.2 2003/05/26 13:28:49 popovici
095: // Documentation Improvements
096: //
097: // Revision 1.1 2003/05/05 13:58:31 popovici
098: // renaming from runes to prose
099: //
100: // Revision 1.4 2003/04/29 12:41:04 popovici
101: // Feature added:
102: // - the 'setPriority' in class insertable allows now Aspects and Crosscuts to have a priority.
103: // Notitification is done from low int priorities to high int priorities.
104: // - the 'setAspectID' introduced to replace constuctor; used to be cumberstone for subclasses
105: //
106: // Revision 1.3 2003/04/27 13:21:32 popovici
107: // Aspects now have identities. Equality is based
108: // either on an ad-hoc identity, or on a specific
109: // name given by the user
110: //
111: // Revision 1.2 2003/04/17 15:43:45 popovici
112: // crosscuts renamed to 'getCrosscuts'
113: // createCrosscuts renamed to 'crosscuts'
114: //
115: // Revision 1.1 2003/04/17 15:15:12 popovici
116: // Extension->Aspect renaming
117: //
118: // Revision 1.8 2003/04/17 13:54:35 popovici
119: // Refactorization of 'ExecutionS' into 'Within' and 'Executions'.
120: // Method names refer now to 'types'
121: //
122: // Revision 1.7 2003/04/17 12:49:41 popovici
123: // Refactoring of the crosscut package
124: // ExceptionCut renamed to ThrowCut
125: // McutSignature is now SignaturePattern
126: //
127: // Revision 1.6 2003/04/17 08:47:12 popovici
128: // Important functionality additions
129: // - Cflow specializers
130: // - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
131: // - Transactional capabilities
132: // - Total refactoring of Specializer evaluation, which permits fine-grained distinction
133: // between static and dynamic specializers.
134: // - Functionality pulled up in abstract classes
135: // - Uniformization of advice methods patterns and names
136: //
137: // Revision 1.5 2003/03/04 18:36:37 popovici
138: // Organization of imprts
139: //
140: // Revision 1.4 2002/06/07 15:30:49 popovici
141: // Documentation updates of FunctionalCrosscut/ClasseS refactorings
142: //
143: // Revision 1.3 2002/03/28 13:48:33 popovici
144: // Mozilla-ified
145: //
146: // Revision 1.2 2002/02/05 10:17:22 smarkwal
147: // JVMDI-specific code replaced by JVMAI. Implementation-classes and reflection-package removed.
148: //
149: // Revision 1.1.1.1 2001/11/29 18:13:14 popovici
150: // Sources from runes
151: //
152: // Revision 1.1.2.7 2001/06/01 11:29:04 popovici
153: // Generation of birthdaykookie changed, in order to avoid collsions of
154: // extensions created one after the other. A sequence number is now
155: // included in the cookie.
156: //
157: // Revision 1.1.2.6 2001/02/21 16:43:46 popovici
158: // Methods 'equals' and 'hashCode' added.
159: //
160: // Revision 1.1.2.5 2001/02/21 13:24:25 popovici
161: // Logging messages added.
162: //
163: // Revision 1.1.2.4 2001/02/15 10:21:55 popovici
164: // The mapping threads to maps is now transient.
165: //
166: // Revision 1.1.2.3 2001/02/07 11:46:31 popovici
167: // Void method 'insertionAction' and 'withdrawalAction' added.
168: //
169: // Revision 1.1.2.2 2000/11/13 19:00:20 popovici
170: // More explicit IllegalExtension exception
171: //
172: // Revision 1.1.2.1 2000/10/24 17:47:59 popovici
173: // Initial Revision
174: //
|