//
// This file is part of the prose package.
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// The Original Code is prose.
//
// The Initial Developer of the Original Code is Angela Nicoara. Portions
// created by Angela Nicoara are Copyright (C) 2004 Angela Nicoara.
// All Rights Reserved.
//
// Contributor(s):
// $Id: HotSwapFieldJoinPointImpl.java,v 1.2 2008/11/18 11:09:31 anicoara Exp $
// =====================================================================
//
package ch.ethz.inf.iks.jvmai.jvmdi;
import java.lang.reflect.Field;
import ch.ethz.jvmai.JVMAIRuntimeException;
import ch.ethz.jvmai.FieldJoinPoint;
/**
* Concrete implementation of a CodeJoinPoint for the Jikes RVM.
*
* @author Angela Nicoara
* @author Johann Gyger
* @version $Revision: 1.2 $
*/
public class HotSwapFieldJoinPointImpl extends HotSwapJoinPointImpl implements FieldJoinPoint {
/**
* Field identifier to which this join point belongs.
*/
public int fieldId;
/**
* Field to which this join point belongs.
*/
public Field field;
/**
* Owner of `field'.
*/
public Object owner;
/**
* Field value for `owner';
*/
public Object value;
/**
* Constructs an uninitialized instance.
* To use it {@link #init} must be called
* after construction.
*/
HotSwapFieldJoinPointImpl() {
super();
}
/**
* Constructs an initialized instance.
* @param tag AOP tag associated with this join point.
* @param fieldId unique numerical identifier for the target field.
* @param owner Object owning the field.
*/
HotSwapFieldJoinPointImpl( Object tag, int fieldId, Object owner ) {
super( tag, 0 );
this.fieldId = fieldId;
this.owner = owner;
}
/**
* Initializes this instance.
* @param tag AOP tag associated with this join point.
* @param fieldId unique numerical identifier for the target field.
* @param owner Object owning the field.
*/
public void init( Object tag, int fieldId, Object owner) {
init( tag );
this.fieldId = fieldId;
field = null;
this.owner = owner;
value = null;
}
/**
* The target of a field join point differs from the target of a code join
* point: It is actually the owner of the field.
*/
public Object getTarget() {
return owner;
}
public Field getField() {
if (field == null)
field = HotSwapFieldWeaver.idToField( fieldId );
return field;
}
public Object getValue() {
if (value == null) {
Field f = getField();
// Make the field accessible if it's private or protected.
// There's no reset after access, because repeated
// accessses to this field are very likely.
if( ! f.isAccessible() );
f.setAccessible( true );
try { value = f.get( owner ); }
// If this handler is reached, something went wrong at
// the f.isAccessible() or f.setAccessible() call above.
catch( IllegalAccessException e ) { throw new JVMAIRuntimeException("Illigal field access: this should never happen"); }
}
return value;
}
public String getKind() {
return FieldJoinPoint.KIND;
}
public int getMask() {
return MASK_CODE_JP | MASK_FIELD_JP;
}
/**
* @deprecated use getField().getDeclaringClass() instead
*/
public Class getTargetClass() {
return getField().getDeclaringClass();
}
}