If I'm correct you can do you entire confiuration in Java code. As a
matter of fact, I'm pretty sure the XML configuration is converted to
a Java file and compiled at runtime. However, I like you setup, seems
logical to me. Thanks for sharing it.

Cheers,
 Tyler

On 6/27/06, Steven Grimm <[EMAIL PROTECTED]> wrote:
I realize the annotation support is new enough that there hasn't been
time for a set of recommended practices to evolve, but I thought I'd
share the system I've been using to see what other people think and to
maybe get a discussion going about what makes sense to put where.
Obviously I'm still a RIFE newbie so it is entirely possible I'm being
stupid about this.

The basic principle is that I keep the site structure -- that is,
information about the linkages between elements -- in the XML files but
keep the specifics of an element in its annotations.

So, for example, on a restaurant review site I might have this element
declaration:

<element id="PostReview"
         implementation="com.foo.PostReview"
         url="postReview">
    <flowlink srcexit="showReview" destid="ShowReview" />
    <datalink srcoutbean="review" destid="ShowReview" destinbean="review" />
</element>

And this set of annotations:

@Elem(
    submissions = {
        @Submission(
                name="saveReview",
                [EMAIL PROTECTED](beanclass=Review.class)},
                [EMAIL PROTECTED](name="tags")}
            )
    },
    exits = {
        @Exit(name=PostReview.EXIT_SHOW_REVIEW)
    }
)
public class PostReview extends Element {
    @InputProperty
    public void setRestaurantId(int id) { this.restaurantId = id; }
    @OutputBean
    public Review getReview() { return this.review; }
    public static final String EXIT_SHOW_REVIEW = "showReview";
    ...
    public void processElement() {
        ...
        exit(EXIT_SHOW_REVIEW);
    }
}


I've arrived at this arrangement by trying to (a) keep the information
as close as possible to where I'm using it most often and (b) avoid
repeating information. The input and output properties are a good
example of the latter; if you use XML you have to declare them in the
XML and then make sure you use the same names in the Java code.

Flowlinks and datalinks need to refer to two elements at the same time,
so they go in the XML where both of the element names are close at hand.

Submissions seem like the biggest no-brainer for using annotations. They
are completely private to a particular element; no outside element can
get at them or needs to know anything about them. (As far as I can tell,
anyway -- is that correct?)

The URL is in the XML because the element doesn't need to know anything
about it. On the other hand, neither do other elements, so that one
could easily go either way -- but to me it seemed more like "site
structure" than "element details."

Exits are in annotations even though other elements need them because
code needs them too, and the ability to use compiler-checked string
constants for both the element declaration and my exit() calls seems
helpful to me.

If I wanted my flowlinks and datalinks in annotations, I'd use an
approach like that for them as well so that I'd get compile-time
checking and IDE autocompletion and the like. Of course, that would
remove some of the "rewire the site without touching Java code" benefit
of RIFE, but I wonder if that actually happens very much in anything but
simple test projects. I'd probably almost always need to touch the Java
code anyway to account for the different context in which it's being
used. So updating the annotations at the same time wouldn't be a big
problem.

Comments? How are other people actually using annotations?

Once I started using string constants as above, I started wondering if
it would eventually be possible to get rid of the XML and use
annotations and/or regular Java code to do the entire site declaration.
Just point RIFE at a bootstrap class and it takes it from there. You'd
get compile-time sanity checking and IDE support from top to bottom. No
more need to spell out your fully-qualified class names in XML files --
just refer to the Class objects. Not sure if I actually think that's a
good idea, or for that matter if it's even possible as things stand now,
but the idea of reducing repetition and pushing stuff into Java code
seems very RIFE-like in theory.

-Steve
_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users

_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users

Reply via email to