@Override
 public ClassLoader getClassLoader(
     String componentName, String componentVersion, ComponentReference componentReference) {
   Bundle bundle = getBundle(componentName, componentVersion, componentReference);
   BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
   return bundleWiring.getClassLoader();
 }
  protected void verifyBundleWiring() {
    Bundle bundle = Mockito.verify(_bundle);

    bundle.adapt(BundleWiring.class);

    BundleWiring bundleWiring = Mockito.verify(_bundleWiring);

    bundleWiring.getClassLoader();
  }
  @Activate
  @Modified
  protected void activate(ComponentContext componentContext) {
    _freemarkerEngineConfiguration =
        Configurable.createConfigurable(
            FreeMarkerEngineConfiguration.class, componentContext.getProperties());

    BundleContext bundleContext = componentContext.getBundleContext();

    _bundle = bundleContext.getBundle();

    BundleWiring bundleWiring = _bundle.adapt(BundleWiring.class);

    _classLoader = bundleWiring.getClassLoader();
  }
Пример #4
0
  @Activate
  public void activate(BundleContext context) {
    BundleWiring wiring = context.getBundle().adapt(BundleWiring.class);
    Collection<String> clazzes =
        wiring.listResources(
            "be/iminds/iot/things/api", "*.class", BundleWiring.LISTRESOURCES_RECURSE);
    for (String s : clazzes) {
      String className = s.substring(0, s.length() - 6).replaceAll("/", ".");
      try {
        Class clazz = wiring.getClassLoader().loadClass(className);
        if (Thing.class.isAssignableFrom(clazz) && Thing.class != clazz) {
          // We have a Thing
          String[] packageParts = className.split("\\.");
          String name = packageParts[packageParts.length - 2];
          types.put(name, clazz);
        }

      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      }
    }
  }
  protected ClassLoader getBundleClassLoader(Bundle bundle) {
    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);

    return bundleWiring.getClassLoader();
  }
Пример #6
0
  protected com.liferay.portal.model.Portlet addingPortlet(
      ServiceReference<Portlet> serviceReference,
      Portlet portlet,
      String portletName,
      String portletId) {

    warnPorletProperties(portletName, serviceReference);

    Bundle bundle = serviceReference.getBundle();

    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);

    ServiceRegistrations serviceRegistrations = getServiceRegistrations(bundle);

    BundlePortletApp bundlePortletApp =
        createBundlePortletApp(bundle, bundleWiring.getClassLoader(), serviceRegistrations);

    com.liferay.portal.model.Portlet portletModel = buildPortletModel(bundlePortletApp, portletId);

    portletModel.setPortletName(portletName);

    String displayName =
        GetterUtil.getString(
            serviceReference.getProperty("javax.portlet.display-name"), portletName);

    portletModel.setDisplayName(displayName);

    Class<?> portletClazz = portlet.getClass();

    portletModel.setPortletClass(portletClazz.getName());

    collectJxPortletFeatures(serviceReference, portletModel);
    collectLiferayFeatures(serviceReference, portletModel);

    PortletContextBag portletContextBag =
        new PortletContextBag(bundlePortletApp.getServletContextName());

    PortletContextBagPool.put(bundlePortletApp.getServletContextName(), portletContextBag);

    PortletBagFactory portletBagFactory = new BundlePortletBagFactory(portlet);

    portletBagFactory.setClassLoader(bundleWiring.getClassLoader());
    portletBagFactory.setServletContext(bundlePortletApp.getServletContext());
    portletBagFactory.setWARFile(true);

    try {
      portletBagFactory.create(portletModel);

      checkWebResources(
          bundle.getBundleContext(),
          bundlePortletApp.getServletContextName(),
          bundleWiring.getClassLoader(),
          serviceRegistrations);

      checkResourceBundles(
          bundle.getBundleContext(),
          bundleWiring.getClassLoader(),
          portletModel,
          serviceRegistrations);

      List<Company> companies = _companyLocalService.getCompanies();

      deployPortlet(serviceReference, portletModel, companies);

      checkResources(serviceReference, portletModel, companies);

      portletModel.setReady(true);

      if (_log.isInfoEnabled()) {
        _log.info("Added " + serviceReference);
      }

      serviceRegistrations.addServiceReference(serviceReference);

      return portletModel;
    } catch (Exception e) {
      _log.error("Portlet " + portletId + " from " + bundle + " failed to initialize", e);

      return null;
    }
  }