Hi,

The easiest use is in the class comment as a name value pair:

        /**
         * @scr.property name="theName" value="theValue"
         */

Alternatively, you can apply the annotation to a string constant (static
final String) and omit the name attribute, in which case the value of
the string constant is used as the name:

        /** @scr.property value="someValue" */
        private static final String PROP_SAMPLE = "sample";

This defines a property with name "sample". The advantage of the second
method is, that you only write the property name once (as the constant
value) and use it twice: as the component property's name and as the
value of the constant, which may be used in your code to refer to the
property. This proves very usefull when trying to solve property related
issues.

Further options are available setting the property, refer to the
respective page for more information. And then, you will find a lot of
these annotation uses in the Apache Sling project, most notably in the
core module.

Regards
Felix

Am Freitag, den 21.09.2007, 19:16 -0300 schrieb Rodrigo Madera:
> Felix,
> 
> Can you give a brief example of how to use the property annotation?
> 
> Thank you,
> Rodrigo
> 
> On 9/21/07, Felix Meschberger <[EMAIL PROTECTED]> wrote:
> >
> > Hi Rodrigo,
> >
> > The simplest of all possible examples might be:
> >
> >         package some.package;
> >         /**
> >          * @scr.component
> >          */
> >         public class Client {
> >             /** @scr.reference */
> >             private org.osgi.service.log.LogService log;
> >         }
> >
> > This would create a reference with static policy (policy="static") and
> > unary cardinality (cardinality="1..1") plus the plugin automatically
> > generates the bind and unbind methods like this by byte-code
> > manipulation in the class file:
> >
> >         protected void bindLog(LogService logService) {
> >             this.logService = logService
> >         }
> >         protected void unbindLog(LogService logService) {
> >             if (this.logService == logService) {
> >                 this.logService = null;
> >             }
> >         }
> >
> > (The check is necessary as rebinding the log service will first bind the
> > new service and then unbind the old service, without the check, the new
> > service just set would be removed again)
> >
> > Starting from this example you can go great length by specififying more
> > attributes to the @scr.reference tag, such as
> >
> >         @scr.reference policy="dynamic"
> > or     @scr.reference policy="dynamic" cardinality="0..1"
> > or     @scr.reference bind="someBindMethod"
> >
> > But please note, that automatic generation of the bind/unbind methods is
> > only implemented for unary cardinality (that is cardinality="0..1" and
> > cardinality="1..1") not for multiple cardinality.
> >
> > Hope this helps.
> >
> > Regards
> > Felix
> >
> > Am Freitag, den 21.09.2007, 02:36 +0100 schrieb Rodrigo Madera:
> > > Hello,
> > >
> > > I am now using the SCR plugin, but I need an example on using
> > scr.reference.
> > > Does anyone have one?
> > >
> > > A full service example (which shouldn't be more than 20 lines) would be
> > > excellent for everyone.
> > >
> > > Thank you,
> > > Rodrigo
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to