The Artima Developer Community
Sponsored Link

Java Buzz Forum
Hard AOP questions and ideas

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Carlos Villela

Posts: 116
Nickname: cvillela
Registered: Jun, 2003

Carlos Villela is a Java developer working mostly with web technologies and AOP.
Hard AOP questions and ideas Posted: Jun 26, 2003 12:51 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Carlos Villela.
Original Post: Hard AOP questions and ideas
Feed Title: That's sooo '82!
Feed URL: http://www.jroller.com/rss/cv?catname=Technical
Feed Description: Carlos Villela's weblog. Everyday life, everyday software development, everyday musings.
Latest Java Buzz Posts
Latest Java Buzz Posts by Carlos Villela
Latest Posts From That's sooo '82!

Advertisement
In a previous post, I blogged about my works in a CMS system using AOP, and the problem of implementing security in a 100% AOP system, and then I realized I hadn't yet said anything about it in my blogs. Sorry fellas, here it goes. :)

One of the really weird things about having a 100% AOP system is that you end up using composition, with introductions, to create your objects. I started doing this in order to put some stress on Jonas' transparent persistence for aspects, and then I realized it actually gives me a very good level of flexibility and abstraction. In a Content Management System, you'd expect to see either a very flexible or very complicated Content class. Without any further ado, here's mine:

public class Content {
}

That's it: one line of code. You're probably thinking now: "Yeah, Carlos, so what? Are you just trying to create unreadable code or are you actually doing something useful?". I'm sorry I can't answer that question, but bear with me, I'm doing quite of an exercise here. Time will tell if it's any good or if it's readable or not.

All the fun going on with that Content class goes into AspectWerkz and its definition file, where I compose the Content object with the properties, or, as I'd like to call, atoms, I like to see in those objects:

    <introduction-def name="core/hasName"
                      interface="core.atoms.HasName"
                      implementation="core.atoms.HasNameImpl"
                      deployment-model="perInstance"
                      persistent="true"/>

    <introduction-def name="core/hasText"
                      interface="core.atoms.HasText"
                      implementation="core.atoms.HasTextImpl"
                      deployment-model="perInstance"
                      persistent="true"/>

    <aspect name="core/Content">
        <introduction class="core.model.Content">
            <introduction-ref name="core/hasName"/>
            <introduction-ref name="core/hasText"/>
        </introduction>
    </aspect>

This has two interesting effects: I can now create a second class, HtmlContent, and have it composed with the hasName atom, but using a different atom for the actual content:

    <introduction-def name="core/hasHtmlText"
                      interface="core.atoms.HasHtmlText"
                      implementation="core.atoms.HasHtmlTextImpl"
                      deployment-model="perInstance"
                      persistent="true"/>

    <aspect name="core/HtmlContent">
        <introduction class="core.model.HtmlContent">
            <introduction-ref name="core/hasName"/>
            <introduction-ref name="core/hasHtmlText"/>
        </introduction>
    </aspect>

This way, I'm reusing the hasName atom throughout different objects in the system. Then, I'm handling a cross-cutting concern, that is to have a property that defines the name of a given object, using an introduction. The code for this particular introduction is not really interesting, and you probably figured it out yourself at this time, but anyway, here it goes:

package core.atoms;

public interface HasName extends Serializable {
    void setName(String name);
    String getName();
}

public class HasNameImpl implements HasName {
    private String name = "";
    public void setName(String name) { this.name = name; }
    public String getName() { return name; }
}

As you can see from these code and XML snippets, my "business objects" aren't really any interesting until I run them through AspectWerkz, and then things start to make sense. Persistence, for example, is handled transparently by AspectWerkz in this case, using Prevayler. Awesome! :)

Now, the problem is: how do I keep those objects safe from unwanted users? By implementing two simple atoms, hasOwner and hasPermissions, I can now manage my object's ownership and permissions. But who's going to enforce them? I hear you scream "advices!" already. Cool, advices fit perfectly in this description, but there's a big problem here: how can I let an advice know who is trying to fiddle with a given object? The advice would need to actually ask the Servlet Container for an object in the HttpSession that holds the currently logged-on User reference (User is also a composed object, like Content, above). Given that I'm manipulating those objects using WebWork 1.x actions, what are my choices?

More thougts on this later, as the clouds in my head disappear. :)

Read: Hard AOP questions and ideas

Topic: Digging a Hole Previous Topic   Next Topic Topic: Lame Programmers and Credit-Card Numbers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use