[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Static crosscutting
|
Eric,
All you need to do is to add those methods to your interface too. E.g.,
public interface BeanSupport {
void addPropertyChangeListener(PropertyChangeListener listener);
void removePropertyChangeListener(PropertyChangeListener listener);
void firePropertyChange(String name, Object original, Object modified);
}
with your same aspect as posted still providing the inter-type declarations to implement them. The interface acts a bit like a .h file and the inter-type decl implementation like a .C (I know, scary analogy).
Ron Bodkin
Chief Technology Officer
New Aspects of Security
m: (415) 509-2895
> ------------Original Message-------------
> From: "Eric Jain" <Eric.Jain@xxxxxxxxxx>
> To: "aspectj-users" <aspectj-users@xxxxxxxxxxx>
> Date: Sat, Sep-27-2003 9:15 AM
> Subject: Re: [aspectj-users] Static crosscutting
>
> > For a reusable version of bean support, please look at
> > a solution that I posted to a JavaRanch forum:
> >
> >
> http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=14&t=000304
>
>
> Thanks. I had a look at your code and implemented a similar solution,
> which unfortunately doesn't quite work. One of my requirements is that
> the interface that allows addition of listeners must be useable from
> editors that are not aspect-aware. Therefore, after adding the
> possibility to register change listeners to a class called Taxon, I
> can't require developers to write:
>
> taxon.addPropertyChangeListener(...);
>
> because this would only compile with ajc. Or this:
>
> taxon.ajc$...$pcs.addPropertyChangeListener(...);
>
> not only because it is way too ugly, but it would also fail if the
> imported library happens to not be postprocessed. On the other hand
> everybody could do this:
>
> if (object instanceof BeanSupport)
> ((BeanSupport) taxon).addPropertyChangeListener(...);
>
> Any suggestions how to accomplish this? Here is my approach, which works
> except that after applying it I get a compile time error ("The method
> addPropertyChangeListener is undefined for the type BeanSupport"). The
> BeanSupport interface is a normal interface that declares methods such
> as addPropertyChangeListener.
>
> package org.expasy.aspects;
>
> import java.beans.PropertyChangeEvent;
> import java.beans.PropertyChangeListener;
> import java.beans.PropertyChangeSupport;
> import org.expasy.models.util.BeanSupport;
> import org.expasy.models.taxonomy.Taxon;
>
> public aspect PropertyChange
> {
> declare parents: Taxon implements BeanSupport;
>
> private PropertyChangeSupport BeanSupport.pcs =
> new PropertyChangeSupport(this);
>
> pointcut setter(BeanSupport source, Object value):
> execution(void BeanSupport+.set*(*))
> && target(source) && args(value);
>
> after(BeanSupport source, Object value): setter(source, value)
> {
> String property = thisJoinPointStaticPart.getSignature()
> .getName().substring(3).toLowerCase();
> source.firePropertyChange(property, null, value);
> }
>
> public void
> BeanSupport.addPropertyChangeListener(PropertyChangeListener listener)
> {
> pcs.addPropertyChangeListener(listener);
> }
>
> public void
> BeanSupport.removePropertyChangeListener(PropertyChangeListener
> listener)
> {
> pcs.removePropertyChangeListener(listener);
> }
>
> public void BeanSupport.firePropertyChange(String name, Object
> original, Object modified)
> {
> pcs.firePropertyChange(name, original, modified);
> }
> }
>
>
> --
> Eric Jain
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>