KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > crosscut > SetGetSignaturePattern


1 //
2
// This file is part of the prose package.
3
//
4
// The contents of this file are subject to the Mozilla Public License
5
// Version 1.1 (the "License"); you may not use this file except in
6
// compliance with the License. You may obtain a copy of the License at
7
// http://www.mozilla.org/MPL/
8
//
9
// Software distributed under the License is distributed on an "AS IS" basis,
10
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
// for the specific language governing rights and limitations under the
12
// License.
13
//
14
// The Original Code is prose.
15
//
16
// The Initial Developer of the Original Code is Andrei Popovici. Portions
17
// created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
18
// All Rights Reserved.
19
//
20
// Contributor(s):
21
package ch.ethz.prose.crosscut;
22 import java.lang.IllegalAccessException JavaDoc;
23 import java.io.Serializable JavaDoc;
24 import java.lang.InstantiationException JavaDoc;
25 import java.lang.reflect.Field JavaDoc;
26 import java.lang.Error JavaDoc;
27 import java.lang.Class JavaDoc;
28 import ch.ethz.inf.util.Logger;
29 import java.lang.SecurityException JavaDoc;
30 import java.lang.ArrayIndexOutOfBoundsException JavaDoc;
31
32   class SetGetSignaturePattern extends SignaturePattern implements Serializable JavaDoc
33   {
34     private final AbstractCrosscut crosscut;
35
36
37
38     /**
39      * Create an <code>UserDefinedMCSignature</code> that encapsulates the
40      * method to be executed.
41      * <p>
42      * Postcondition: methodObj is properly initialized
43      * <p>
44      * Implementation:
45      * <ul>
46      * <li> if <code>crsc</code> (i.e., a subclass of FunctionalCrossscut)
47      * <em>defines</em> exaclty one method, this method is
48      * the advice method.
49      *
50      * <li> If <code>crsc</code> defines several methods, the one whose
51      * name corresponds to <code>crsc.ADVICE_NAME()</code> is the advice method
52      * </ul>
53      * @throws MissingInformationExeception crsc does not define a method at all,
54      * or if it defines several, none of them matches <code>crsc.ADVICE_NAME()</code>.
55      *
56      */

57     protected SetGetSignaturePattern(SetCut crsc) throws MissingInformationException
58       {
59     this.crosscut = crsc;
60     initFromMethod(crsc.getClass(),"SET_ARGS",ANY.class,SetCut.class);
61       }
62
63
64
65     protected SetGetSignaturePattern(GetCut crsc) throws MissingInformationException
66       {
67     this.crosscut = crsc;
68     initFromMethod(crsc.getClass(),"GET_ARGS",ANY.class,GetCut.class);
69       }
70
71
72
73     /** Returns <code>true</code> if the signature of
74      * <code>methoObj</code>, seen as a pattern,
75      * matches the signature (the parameter types) for
76      * <code>actualMehtod</code>.
77      */

78      protected boolean matchesOperationOnField(Field JavaDoc field)
79       {
80       if (signatureCathegory == SIGNATURE__EMPTY)
81           return true;
82       else
83           {
84           return getLength() == 2 && // must have the format (Receiver,TYPE)
85
matchesTarget(field.getDeclaringClass()) &&
86           isAssignable(field.getType(),signature[1]);
87           }
88       }
89
90
91
92     public String JavaDoc toString()
93       {
94     return methodObj.toString();
95       }
96   }
97
Popular Tags