The idea of adding annotations for JESS goes back several years, so I
don't think anyone questions the value of using it. The question is
really about backward compatability for those stuck with jdk1.4.2.
a few years back I ported JESS to .NET and added support for
attributes, which is the .NET version of annotation. Actually
attributes came before java annotation. The attributes I created made
it easier to scan a library and declare all classes with the proper
attribute. Here is a short list of the attributes I used.
declare class - true/false
slot - name, true/false
static fact - true/false
For example, I made it so that I could load all classes in a library
except for classes marked declare false. by default, it would only
declare classes with declare true. The same with slots, users could
explicitly include or exclude object fields from the deftemplate.
the static fact attribute made it easy to figure out if a classes
should be asserted as static.
You can go even further and give the rule compiler hints on how the
slots are used. For example, you could annotate a numeric field as
"mutually exclusive" or as "value ranges". Another example is you can
annotate string fields to indicate the rules use regular expression
for the slot.
you could even add annotations to make it easier to test a rule.
peter
On Thu, Jul 17, 2008 at 3:48 AM, Wolfgang Laun
<[EMAIL PROTECTED]> wrote:
> I've tried to think up a few annotations as an alternative to the Bean
> introspection for deriving Jess templates from Java classes.
>
> Given that you can use BeanInfo and/or write your own extension of
> ReflectionClassResearcher I'd say that the extra effort isn't really
> worth it - unless you could add some additional features. These,
> however, would require supporting extensions to classes in jess (and,
> therefore, could not be implemented by a mere userfunction).
>
> Here is what I've come up with. Perhaps interesting, but no "killer
> application" as far as I can see. (I guess that the JessProperty is just
> syntactic sugar,
> because you could call such methods with a test CE.)
>
> JessTemplate( name=<template-name>,
> module=<module-name>,
> isSlotSpecific=<boolean>,
> isBackchainReactive=<boolean>,
> factoryClass=<class>,
> factoryMethod=<method-name> )
>
> factoryClass and factoryMethod can be used to create the Java object behind
> the shadow fact from Jess' assert.
>
>
> JessSlot( name=<slot-name>,
> defaultMethod=<method-name>,
> defaultClass=<class> )
>
> May be on a field or a method. defaultClass/defaultMethod may be used to
> produce the default value.
>
>
> JessPreModify()
>
> Method in the template class, to be called before an update from Jess.
>
> JessPostModify()
>
> Method in the template class, called after an update from Jess.
> It is possible for this method to send a PropertyChangeEvent,
> so this may be omitted from the set methods for individual slots.
>
> JessProperty()
>
> A boolean method with this annotation acts as a property
> that can be used in a conditional element as a "fact-level
> predicate constraint" (Jess extension).
>
> Example: Define a fact predicate constraint.
>
> //Example: Code fragment
> @JessTemplate
> public class Car {
> @JessSlot
> protected int seat;
> @JessSlot
> protected int price;
> //...
> @JessProperty
> public boolean eligible(){
> return seat >= 5 && price <= 10000;
> }
> }
>
> A rule about a Car could now contain
>
> (defrule buyCar
> ?car <- (Car :eligible)
> =>
> (printout t "buy: " ?car.id crlf)
> )
>
> Cheers
> Wolfgang
>
>
> Skeptic 2000 wrote:
>
>>
>> Yeah, I knew about BeanInfo classes, but after using them for a while,
>> I'm not too satisfied (usability).
>>
>> Of course I could write some code that produce a Deftemplate, but what
>> I'm interested in is a solution that include JessDE working accordingly.
>>
>> That's why I was thinking about replacing the default Bean
>> introspection mechanism, but I'm not even sure it would work for JessDE.
>>
>> Thanks again.
>>
>>
>> ------------------------------------------------------------------------
>>
>> > From: [EMAIL PROTECTED]
>> > To: [email protected]
>> > Subject: Re: JESS: using annotations
>> > Date: Wed, 16 Jul 2008 10:04:27 -0400
>> >
>> > Jess 7.1 still supports JDK 1.4, so annotations aren't available.
>> > Future Jess versions will support Java 5+ .
>> >
>> > I like the fact that Jess supports the JavaBeans spec; it's nice to be
>> > able to refer people to that for details. It's one less "invention"
>> > that needs to be maintained by us.
>> >
>> > It's not true, of course, that you're restricted to following naming
>> > conventions, as JavaBeans includes the BeanInfo concept for describing
>> > variances from the conventions.
>> >
>> > In any case, the jess.Deftemplate class has a complete public API;
>> > you should be able write a Userfunction in Java which turned classes
>> > into Deftemplates following annotations using whatever scheme you
>> > like. If you do this, and describe it in our Wiki, then other people
>> > could use it too!
>> >
>> >
>> > On Jul 15, 2008, at 11:54 PM, Skeptic 2000 wrote:
>> >
>> > >
>> > > Hi,
>> > >
>> > > Have you considered using annotations instead of naming scheme to
>> > > create deftemplates associated to shadow facts ?
>> > >
>> > > Do you think it would be difficult thing to "hack" ?
>> > >
>> > > Thanks.
>> > >
>> > >
>> >
>> > ---------------------------------------------------------
>> > Ernest Friedman-Hill
>> > Informatics & Decision Sciences, Sandia National Laboratories
>> > PO Box 969, MS 9012, Livermore, CA 94550
>> > http://www.jessrules.com
>> >
>> >
>> >
>> >
>> >
>> >
>> > --------------------------------------------------------------------
>> > To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
>> > in the BODY of a message to [EMAIL PROTECTED], NOT to the list
>> > (use your own address!) List problems? Notify
>> [EMAIL PROTECTED]
>> > --------------------------------------------------------------------
>> >
>>
>>
>> ------------------------------------------------------------------------
>
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the list
> (use your own address!) List problems? Notify [EMAIL PROTECTED]
> --------------------------------------------------------------------
>
>
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------