Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] @DeclareMixin and access to mixxed in object properties

Hi Jirka,

It looks to me like you are doing the right thing. Yes it is much more
long-winded when using annotation style for declare parents.

> is there a better way (eg. make WithProperties2XmlImpl extending the Item)?

Having the Impl extend the Item, hmmm - I suppose that could produce
something like this:

@Aspect
public class Item2Xml {

@DeclareMixin // target inferred from supertype
public static class WithProperties2XmlImpl extends Item {

public void preXmlMarschalCheck() {
if (this.getXmlDescription() == null) throw new
DARequiredException(REQUIRED_ERROR, new
ObjectProperties(Item.class.getName(), "xmlDescription"));
}

}

}

and then code that wants to use the preXmlMarshalCheck() would have to
cast item to WithProperties2XmlImpl :

  Item item;
  ((WithProperties2XmlImpl)item)preXmlMarschalCheck()

(since casts are required when using annotation style, so javac can
build the code).

I worry there are some downsides to it (something that makes it
infeasible), but I'd need to spend more time thinking about it.  Could
be worth an enhancement request against AJ.

cheers
Andy

On 24 January 2011 04:19,  <jiramares@xxxxxxxxx> wrote:
> Hallo,
>
> I'm using annotations to create aspects and I would like to make same thing
> as :
>
> public aspect Item2Xml {
>
> public void Item.preXmlMarschalCheck() {
> if (this.getXmlDescription() == null)
> throw new DARequiredException(DAExceptionType.REQUIRED_ERROR, new
> ObjectProperties(Item.class.getName(), "xmlDescription"));
> }
>
> }
>
> So I add method to the class Item where I access the local method
> getXmlDescription() ......
>
> But using the @DeclareMixin the only way how to make this is (as I know):
>
> @Aspect
> public class Item2Xml {
>
> public interface WithProperties2Xml {
> void preXmlMarschalCheck();
> }
>
> public static class WithProperties2XmlImpl implements WithProperties2Xml {
> private Item item;
>
> protected WithProperties2XmlImpl(Item item) {
> super();
> this.item = item;
> }
>
> public void preXmlMarschalCheck() {
> if (item.getXmlDescription() == null) throw new
> DARequiredException(REQUIRED_ERROR, new
> ObjectProperties(Item.class.getName(), "xmlDescription"));
> }
>
> }
>
> @DeclareMixin("cz.svt.dao.hibernate.Item")
> public static WithProperties2Xml createWithProperties2Xml(Item item) {
> return new WithProperties2XmlImpl(item);
> }
>
> }
>
> This looks more complicated than it should be ... is there a better way (eg.
> make WithProperties2XmlImpl extending the Item)?
>
> Thanks for help
>
> Jirka
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top