Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Basic AspectJ question

Hi,

I've got the following problem (I've got JDK 1.5 + AspectJ 1.5.3). There's a class for which I can't modify the source however I've got to have an extra field which should be updated whenever an certain other field is set. I tried to create a small aspect for that without any success. Could please someone show me how to do it? I'd like to have this modification in the class file since it's part of a JAR used in several projects so the solutions should be portable. The field in question is only set in the constructor and it's setter method. Both fields have setter and getter methods.

The relevant source is the following:

...

/** @author Hibernate CodeGenerator */
public class PathChanInst implements Serializable {

...
    /** This is the source field, it should be monitored. */
    private CircPathInst parentPathInst;

/** The extra field, it should be updated whenever parentPathInst is changed */
    private String parentPathHumid;
...

    /** full constructor */
    public PathChanInst(...) {
...
// Here's the first occasion, after that should parentPathHumid set.
        this.parentPathInst = parentPathInst;
...
    }

...

    public void setParentPathInst(CircPathInst parentPathInst) {

// Here's the second occasion, after that should parentPathHumid set.
        this.parentPathInst = parentPathInst;
    }
}

The aspect I did:

aspect PathChannelHack {

after(PathChanInst pathchannel) : set(private CircPathInst parentPathInst) { pathchannel .setParentPathHumid(pathchannel.getParentPathInst().getPathHumId());
	}
}


Thanks in advance,

Zoltan



Back to the top