001: // $Id: CrosscutSurrogate.java,v 1.1.1.1 2003/07/02 15:30:52 apopovic Exp $
002: // =====================================================================
003: //
004: // (history at end)
005: //
006:
007: package ch.ethz.prose.query;
008:
009: // used packages
010: import java.util.List;
011: import ch.ethz.prose.crosscut.Crosscut;
012:
013: /**
014: * Class CrosscutSurrogate represents a <code>Class</code> object without the need
015: * that the classe's byte-code is available in the current virtual machine.
016: *
017: * @version $Revision: 1.1.1.1 $
018: * @author Andrei Popovici
019: */
020: public class CrosscutSurrogate implements java.io.Serializable {
021:
022: /**
023: * Serial Version Unique Identifier, used as identifier when serializing
024: * this class. A static final definition like this gains a speed up at
025: * when serializing the class.
026: */
027: private static final long serialVersionUID = 3618696392269575216L;
028:
029: AspectSurrogate ownerSurrogate;
030: int index;
031: String crosscutClassName;
032: String initialToString;
033:
034: /**
035: * Creates a CrosscutSurrogate
036: * @param as surrogate for the aspect defining this crosscut
037: * @param crsc the real crosscut
038: */
039: public CrosscutSurrogate(AspectSurrogate as, Crosscut crsc) {
040: if (as == null || crsc == null)
041: throw new IllegalArgumentException(
042: "CrosscutSurrogate.init: NULL argument");
043:
044: ownerSurrogate = as;
045: crosscutClassName = crsc.getClass().getName();
046: try {
047: List crosscuts = crsc.getOwner().getCrosscuts();
048: index = crosscuts.indexOf(crsc);
049: } catch (NullPointerException e) {
050: index = -1;
051: }
052: initialToString = crsc.toString();
053: }
054:
055: public AspectSurrogate getOwnerSurrogate() {
056: return ownerSurrogate;
057: }
058:
059: public String getCrosscutClassName() {
060: return crosscutClassName;
061: }
062:
063: public int getIndex() {
064: return index;
065: }
066:
067: /**
068: * Indicates whether some other object is "equal to" this one. The
069: * result is <code>true</code> if and only if <code>obj</code> is
070: * not <code>null</code> and is a instance of
071: * <code>CrosscutSurrogate</code> and has equal contents as this
072: * object.
073: * @param obj other object with which to compare
074: * @return <code>true</code> iff <code>obj</code> is equal to this
075: * <code>CrosscutSurrogate</code>
076: */
077: public boolean equals(Object obj) {
078: return obj instanceof CrosscutSurrogate
079: && ownerSurrogate
080: .equals(((CrosscutSurrogate) obj).ownerSurrogate)
081: && index == ((CrosscutSurrogate) obj).index;
082: }
083:
084: /**
085: * Returns a hashcode for this object.
086: * @return hashcode value
087: */
088: public int hashCode() {
089: return ownerSurrogate.hashCode() + index;
090: }
091:
092: public String toString() {
093: return initialToString;
094: }
095:
096: }
097:
098: //======================================================================
099: //
100: // $Log: CrosscutSurrogate.java,v $
101: // Revision 1.1.1.1 2003/07/02 15:30:52 apopovic
102: // Imported from ETH Zurich
103: //
104: // Revision 1.1 2003/05/20 16:05:07 popovici
105: //
106: // New QueryManager replaces functionality in AspectManager (better Soc)
107: // New 'Surrogate' classes for usage in the QueryManager
108: // The 'RemoteAspectManager' and tools modified to use the Surrogates and the QueryManager
109: //
|