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.jvmai.jikesrvm.advice_weaver;
028:
029: import java.lang.reflect.Method;
030: import java.util.*;
031:
032: import ch.ethz.prose.crosscut.MethodRedefineCut;
033: import ch.ethz.prose.engine.MethodRedefineRequest;
034:
035: /**
036: * Weave and unweave method redefine requests.
037: *
038: * @version $Revision$
039: * @author Johann Gyger
040: * @author Angela Nicoara
041: */
042: public class RedefineWeaver {
043:
044: /**
045: * Mapping from a crosscut (key) to a collection of method redefine requests
046: * (value).
047: */
048: protected Map requests = new HashMap();
049:
050: /**
051: * Weave a method redefinition.
052: *
053: * @param cut crosscut that contains advice method
054: * @param request
055: */
056: public void weaveMethodRedefineCut(MethodRedefineCut cut,
057: MethodRedefineRequest request) {
058: Method advice_method = cut.getMethod();
059: Method target_method = request.getMethod();
060: MethodWeaver weaver = MethodWeaver.getWeaver(target_method);
061:
062: weaver.setRedefineAdvice(advice_method);
063: getRequests(cut).add(request);
064: }
065:
066: /**
067: * Unweave a method redefinition.
068: *
069: * @param cut crosscut which should be unwoven.
070: */
071: public void unweaveMethodRedefineCut(MethodRedefineCut cut) {
072: Iterator it = getRequests(cut).iterator();
073:
074: while (it.hasNext()) {
075: Method target_method = ((MethodRedefineRequest) it.next())
076: .getMethod();
077: MethodWeaver weaver = MethodWeaver.getWeaver(target_method);
078:
079: weaver.setRedefineAdvice(null);
080: }
081:
082: requests.remove(cut);
083: }
084:
085: /**
086: * Get requests for `cut'.
087: *
088: * @param cut crosscut whose requests are returned
089: * @return requests for `cut'
090: */
091: protected Collection getRequests(MethodRedefineCut cut) {
092: Collection c = (Collection) requests.get(cut);
093: if (c == null) {
094: c = new LinkedList();
095: requests.put(cut, c);
096: }
097: return c;
098: }
099:
100: }
101:
102: //======================================================================
103: //
104: // $Log$
105: //
|