Package org.osgi.framework

Examples of org.osgi.framework.BundleContext


        };

        final ServiceTracker tracker = mock(ServiceTracker.class);
        when(tracker.getService()).thenReturn(mockEA);

        final BundleContext bundleContext = mock(BundleContext.class);
        when(bundleContext.createFilter(any(String.class))).thenReturn(null);
        when(bundleContext.getServiceReference(any(String.class))).thenReturn(null);
        when(bundleContext.getService(null)).thenReturn(mockEA);

        this.listener = new SynchronousJcrResourceListener(RepositoryUtil.getRepository(),
                        bundleContext, resolver, tracker);
    }
View Full Code Here


    /**
     * Bind a new repository.
     */
    protected void bindRepository(final Repository repo, final Map<String, Object> props) {
        final BundleContext processContext;
        synchronized ( pendingServices ) {
            processContext = this.bundleContext;
            if ( processContext == null ) {
                this.pendingServices.add(new PendingService(repo, props));
            }
View Full Code Here

  }

  @Override
  public void init(ExtendedProperties arg0) {
    Bundle bundle = FrameworkUtil.getBundle( VelocityScriptEngineService.class );
    BundleContext bundleContext = bundle.getBundleContext();
    ServiceReference serviceRef = bundleContext.getServiceReference( VelocityScriptEngineService.class.getName() );
   
    if ( serviceRef != null )
    {
      velocityScriptEngineService = (VelocityScriptEngineService) bundleContext.getService( serviceRef );
      if ( velocityScriptEngineService != null )
      {
        resourceResolver = velocityScriptEngineService.getResourceResolver();
      }
    }
View Full Code Here

        final File root = new File("bundle999").getAbsoluteFile();
        final SlingHomeAction slingHome = new SlingHomeAction();
        slingHome.setSlingHome(new File("sling").getAbsolutePath());

        Mockery context = new Mockery();
        final BundleContext bundleContext = context.mock(BundleContext.class);

        context.checking(new Expectations() {
            {
                // mock access to sling.home framework property
                allowing(bundleContext).getProperty("sling.home");
View Full Code Here

    public boolean canAddUser(Session jcrSession) {
        try {
            //if self-registration is enabled, then anyone can create a user
            if (componentContext != null) {
                String filter = "(&(sling.servlet.resourceTypes=sling/users)(|(sling.servlet.methods=POST)(sling.servlet.selectors=create)))";
                BundleContext bundleContext = componentContext.getBundleContext();
                ServiceReference[] serviceReferences = bundleContext.getServiceReferences(Servlet.class.getName(), filter);
                if (serviceReferences != null) {
                    String propName = "self.registration.enabled";
                    for (ServiceReference serviceReference : serviceReferences) {
                        Object propValue = serviceReference.getProperty(propName);
                        if (propValue != null) {
View Full Code Here

        this.enableOptimizeAliasResolution = PropertiesUtil.toBoolean(properties.get(PROP_ENABLE_OPTIMIZE_ALIAS_RESOLUTION), DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION);

        this.vanityPathPrecedence = PropertiesUtil.toBoolean(properties.get(PROP_VANITY_PATH_PRECEDENCE), DEFAULT_VANITY_PATH_PRECEDENCE);
       
        final BundleContext bc = componentContext.getBundleContext();

        // check for required property
        final String[] required = PropertiesUtil.toStringArray(properties.get(PROP_REQUIRED_PROVIDERS));
        this.preconds.activate(bc, required);
        this.checkFactoryPreconditions();
View Full Code Here

                        final String subServiceName = (authenticationInfo.get(ResourceResolverFactory.SUBSERVICE) instanceof String)
                                ? (String) authenticationInfo.get(ResourceResolverFactory.SUBSERVICE)
                                : null;

                        final BundleContext bc = ((Bundle) serviceBundleObject).getBundleContext();

                        final SlingRepository repo = (SlingRepository) bc.getService(repositoryReference);
                        if (repo == null) {
                            log.warn(
                                "getResourceProviderInternal: Cannot login service because cannot get SlingRepository on behalf of bundle {} ({})",
                                bc.getBundle().getSymbolicName(), bc.getBundle().getBundleId());
                            throw new LoginException(); // TODO: correct ??
                        }

                        try {
                            session = repo.loginService(subServiceName, workspace);
                            holder.setRepositoryReference(bc, repositoryReference);
                            holder.setSession(session);
                        } finally {
                            // unget the repository if the service cannot
                            // login to it, otherwise the repository service
                            // is let go off when the resource resolver is
                            // closed and the session logged out
                            if (session == null) {
                                bc.ungetService(repositoryReference);
                            }
                        }

                    } else {
View Full Code Here

    public void run(IProgressMonitor monitor) {

        MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, Messages.ResolveOperation_errorOverview, null);

        // Start a coordination
        BundleContext bc = Plugin.getDefault().getBundleContext();
        ServiceReference<Coordinator> coordSvcRef = bc.getServiceReference(Coordinator.class);
        Coordinator coordinator = coordSvcRef != null ? (Coordinator) bc.getService(coordSvcRef) : null;
        Coordination coordination = coordinator != null ? coordinator.begin(ResolveOperation.class.getName(), 0) : null;

        // Begin resolve
        ResolveProcess resolve = new ResolveProcess();
        ResolverLogger logger = new ResolverLogger();
        try {
            BndResolver bndResolver = new BndResolver(logger);

            //
            // Make sure we do macro expansion properly
            //

            File resource = model.getBndResource();
            if (model.isProjectFile()) {
                Project project = Central.getProject(resource.getParentFile());
                //
                // run's in projects are based on the project
                // and implicitly the ws
                //
                model.setProject(project);
            } else {
                //
                // run's in bndrun files are the bndrun + workspace
                //
                Run run = new Run(Central.getWorkspace(), resource.getParentFile(), resource);
                model.setProject(run);
            }

            ReporterLogService log = new ReporterLogService(Central.getWorkspace());
            Map<Resource,List<Wire>> wirings = resolve.resolveRequired(model, Central.getWorkspace(), bndResolver, callbacks, log);
            result = new ResolutionResult(Outcome.Resolved, wirings, null, status, logger.getLog());
            if (coordination != null)
                coordination.end();
        } catch (ResolveCancelledException e) {
            result = new ResolutionResult(Outcome.Cancelled, null, null, status, logger.getLog());

            if (coordination != null)
                coordination.fail(e);
        } catch (ResolutionException e) {
            status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e));
            result = new ResolutionResult(Outcome.Unresolved, null, e, status, logger.getLog());

            if (coordination != null)
                coordination.fail(e);
        } catch (Exception e) {
            status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Exception during resolution.", e));
            result = new ResolutionResult(Outcome.Error, null, null, status, logger.getLog());

            if (coordination != null)
                coordination.fail(e);
        } finally {
            if (coordinator != null)
                bc.ungetService(coordSvcRef);
        }
    }
View Full Code Here

   
    @Override
    public void execute(CrankstartContext crankstartContext, CrankstartCommandLine commandLine) throws Exception {
        final String bundleRef = commandLine.getQualifier();
        final URL url = new URL(bundleRef);
        final BundleContext ctx = crankstartContext.getOsgiFramework().getBundleContext();
        final InputStream bundleStream = url.openStream();
        try {
            final Bundle b = ctx.installBundle(bundleRef, url.openStream());
           
            final int level = getStartLevel(crankstartContext);
            if(level > 0) {
                final BundleStartLevel bsl = (BundleStartLevel)b.adapt(BundleStartLevel.class);
                if(bsl == null) {
View Full Code Here

     * This method tests the dynamic class loading through the package admin.
     * The returned class changes from map to array list.
     */
    @Test public void testLoading() throws Exception {
        final Sequence sequence = this.context.sequence("load-sequence");
        final BundleContext bundleContext = this.context.mock(BundleContext.class);
        final PackageAdmin packageAdmin = this.context.mock(PackageAdmin.class);
        final ExportedPackage ep = this.context.mock(ExportedPackage.class);
        final Bundle bundle = this.context.mock(Bundle.class);
        this.context.checking(new Expectations() {{
            allowing(bundleContext).createFilter(with(any(String.class)));
View Full Code Here

TOP

Related Classes of org.osgi.framework.BundleContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.