2 Replies Latest reply on Mar 28, 2013 1:17 AM by maruthid

    How to Access CRX Node from a JAVA file?

    sachin_solutions

      Hi All,

       

      If my developing a class to be used in OSGi service,  what should i do a class to be used as OSGI serive?

       

      Thanks !


        • 1. Re: How to Access CRX Node from a JAVA file?
          Veena_07 Level 3

          Hi Sachin

           

               Sorry but your question is not clear. Can you please clearly say what is ur requirement

           

           

          Thanks

           

          Veena

          • 2. Re: How to Access CRX Node from a JAVA file?
            maruthid Level 1

            To make your class as service use annotations. like

             

            @Component(label = "This will show up as lebel in osgi console", description = "description of the service", metatype = true, immediate = true)

            @Service

            public class NameofImplementationclass {

             

            //Below are 2 default method implementaions which will help to get admin session on activation and logging out on deactivation

              @Activate

              @Modified

                      protected void activate(ComponentContext componentContext) {

                                try {

              adminSession = repository.loginAdministrative(repository

                                                              .getDefaultWorkspace());

                                } catch (Exception e) {

              log.error("exception in service activation", e.getMessage);

                                }

                      }

             

              @Deactivate

                      protected void deactivate(ComponentContext componentContext) {

              if (adminSession != null) {

                                          adminSession.logout();

              log.info("service is deactivated admis session logged out");

                                }

                      }

             

             

            }

             

            For accessing node

            get the admin session in your service on activation of the service. Activation method will be called once this service is activated in osgi as shown in above code

            adminSession = repository.loginAdministrative(repository

                                                              .getDefaultWorkspace());

             

            Get resource resolver

             

            ResourceResolver rr = resolverFactory.getResourceResolver(session);

             

            By using this resolver you resolve paths to resources etc like

             

            rr.getResource("path");