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]

Reply via email to