@Override
    public ResourceBundle addingService(ServiceReference<ResourceBundle> serviceReference) {

      Registry registry = RegistryUtil.getRegistry();

      ResourceBundle resourceBundle = registry.getService(serviceReference);

      String languageId =
          GetterUtil.getString(serviceReference.getProperty("language.id"), StringPool.BLANK);
      Map<String, String> languageMap = new HashMap<>();
      Locale locale = null;

      if (Validator.isNotNull(languageId)) {
        locale = LocaleUtil.fromLanguageId(languageId, true);
      } else {
        locale = new Locale(StringPool.BLANK);
      }

      Enumeration<String> keys = resourceBundle.getKeys();

      while (keys.hasMoreElements()) {
        String key = keys.nextElement();

        String value = ResourceBundleUtil.getString(resourceBundle, key);

        languageMap.put(key, value);
      }

      Map<String, String> oldLanguageMap = _putLanguageMap(locale, languageMap);

      _oldLanguageMaps.put(serviceReference, oldLanguageMap);

      return resourceBundle;
    }
  @Test
  public void testMBeanBySuffix() throws Exception {
    Registry registry = RegistryUtil.getRegistry();

    MBeanServer mBeanServer = registry.getService(MBeanServer.class);

    ObjectName objectName = new ObjectName(JMXWhiteboardByInterfaceMBean.OBJECT_NAME);

    MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(objectName);

    Assert.assertNotNull(mBeanInfo);

    MBeanOperationInfo[] operations = mBeanInfo.getOperations();

    MBeanOperationInfo mBeanOperationInfo = operations[0];

    MBeanParameterInfo[] signatureParameters = mBeanOperationInfo.getSignature();

    String[] sinature = new String[signatureParameters.length];

    for (int i = 0; i < signatureParameters.length; i++) {
      MBeanParameterInfo mBeanParameterInfo = signatureParameters[i];

      sinature[i] = mBeanParameterInfo.getType();
    }

    Object result =
        mBeanServer.invoke(
            objectName, mBeanOperationInfo.getName(), new Object[] {"Hello!"}, sinature);

    Assert.assertEquals("{Hello!}", result);
  }
    @Override
    public SchedulerEntry addingService(ServiceReference<SchedulerEntry> serviceReference) {

      Registry registry = RegistryUtil.getRegistry();

      SchedulerEntry schedulerEntry = registry.getService(serviceReference);

      StorageType storageType = StorageType.MEMORY_CLUSTERED;

      if (schedulerEntry instanceof StorageTypeAware) {
        StorageTypeAware storageTypeAware = (StorageTypeAware) schedulerEntry;

        storageType = storageTypeAware.getStorageType();
      }

      addTrigger(schedulerEntry, serviceReference);

      String portletId = (String) serviceReference.getProperty("javax.portlet.name");

      try {
        SchedulerEngineHelperUtil.schedule(schedulerEntry, storageType, portletId, 0);

        return schedulerEntry;
      } catch (SchedulerException e) {
        _log.error(e, e);
      }

      return null;
    }
    @Override
    public IndexerPostProcessor addingService(
        ServiceReference<IndexerPostProcessor> serviceReference) {

      Registry registry = RegistryUtil.getRegistry();

      IndexerPostProcessor indexerPostProcessor = registry.getService(serviceReference);

      List<String> indexerClassNames =
          StringPlus.asList(serviceReference.getProperty("indexer.class.name"));

      for (String indexerClassName : indexerClassNames) {
        Indexer indexer = IndexerRegistryUtil.getIndexer(indexerClassName);

        if (indexer == null) {
          _log.error("No indexer for " + indexerClassName + " was found");

          continue;
        }

        indexer.registerIndexerPostProcessor(indexerPostProcessor);
      }

      return indexerPostProcessor;
    }
  @BeforeClass
  public static void setUpClass() throws Exception {
    RegistryUtil.setRegistry(new BasicRegistryImpl());

    MultiVMPoolUtil multiVMPoolUtil = new MultiVMPoolUtil();

    MultiVMPoolImpl multiVMPoolImpl = new MultiVMPoolImpl();

    multiVMPoolImpl.setPortalCacheManager(
        MemoryPortalCacheManager.<Serializable, Serializable>createMemoryPortalCacheManager(
            "multi.vm.pool"));

    multiVMPoolUtil.setMultiVMPool(multiVMPoolImpl);

    SingleVMPoolUtil singleVMPoolUtil = new SingleVMPoolUtil();

    SingleVMPoolImpl singleVMPoolImpl = new SingleVMPoolImpl();

    singleVMPoolImpl.setPortalCacheManager(
        MemoryPortalCacheManager.createMemoryPortalCacheManager("single.vm.pool"));

    singleVMPoolUtil.setSingleVMPool(singleVMPoolImpl);

    _templateResourceLoader = new MockTemplateResourceLoader();

    _templateResourceLoader.activate(Collections.<String, Object>emptyMap());

    Registry registry = RegistryUtil.getRegistry();

    _serviceRegistration =
        registry.registerService(TemplateResourceLoader.class, _templateResourceLoader);
  }
  private AccessControlUtil() {
    Registry registry = RegistryUtil.getRegistry();

    _serviceTracker = registry.trackServices(AccessControl.class);

    _serviceTracker.open();
  }
            @Override
            public void map(
                ServiceReference<ModelAdapterBuilder> serviceReference, Emitter<String> emitter) {

              Registry registry = RegistryUtil.getRegistry();

              ModelAdapterBuilder modelAdapterBuilder = registry.getService(serviceReference);

              Type genericInterface =
                  ReflectionUtil.getGenericInterface(
                      modelAdapterBuilder, ModelAdapterBuilder.class);

              if ((genericInterface == null) || !(genericInterface instanceof ParameterizedType)) {

                return;
              }

              ParameterizedType parameterizedType = (ParameterizedType) genericInterface;

              Type[] typeArguments = parameterizedType.getActualTypeArguments();

              if (ArrayUtil.isEmpty(typeArguments) || (typeArguments.length != 2)) {

                return;
              }

              try {
                Class adapteeModelClass = (Class) typeArguments[0];
                Class adaptedModelClass = (Class) typeArguments[1];

                emitter.emit(getKey(adapteeModelClass, adaptedModelClass));
              } catch (ClassCastException cce) {
                return;
              }
            }
Example #8
0
  private WebDAVUtil() {
    Registry registry = RegistryUtil.getRegistry();

    _serviceTracker =
        registry.trackServices(WebDAVStorage.class, new WebDAVStorageServiceTrackerCustomizer());

    _serviceTracker.open();
  }
Example #9
0
  private void _addStorage(WebDAVStorage storage) {
    Registry registry = RegistryUtil.getRegistry();

    ServiceRegistration<WebDAVStorage> serviceRegistration =
        registry.registerService(WebDAVStorage.class, storage);

    _serviceRegistrations.put(storage, serviceRegistration);
  }
  private XStreamAliasRegistryUtil() {
    Registry registry = RegistryUtil.getRegistry();

    _serviceTracker =
        registry.trackServices(XStreamAlias.class, new XStreamAliasServiceTrackerCustomizer());

    _serviceTracker.open();
  }
  @Override
  public void register(Indexer<?> indexer) {
    Registry registry = RegistryUtil.getRegistry();

    ServiceRegistration<Indexer<?>> serviceRegistration =
        registry.registerService((Class<Indexer<?>>) (Class<?>) Indexer.class, indexer);

    _serviceRegistrations.put(indexer.getClassName(), serviceRegistration);
  }
  public TestIndexerRegistry() {
    Registry registry = RegistryUtil.getRegistry();

    _serviceTracker =
        registry.trackServices(
            (Class<Indexer<?>>) (Class<?>) Indexer.class, new IndexerServiceTrackerCustomizer());

    _serviceTracker.open();
  }
            @Override
            public void map(ServiceReference<Editor> serviceReference, Emitter<String> emitter) {

              Registry registry = RegistryUtil.getRegistry();

              Editor editor = registry.getService(serviceReference);

              emitter.emit(editor.getName());
            }
    @Override
    public void removedService(
        ServiceReference<XStreamAlias> serviceReference, XStreamAlias xStreamAlias) {

      Registry registry = RegistryUtil.getRegistry();

      registry.ungetService(serviceReference);

      _xstreamAliases.remove(xStreamAlias.getClazz());
    }
Example #15
0
    @Override
    public void removedService(
        ServiceReference<WebDAVStorage> serviceReference, WebDAVStorage webDAVStorage) {

      Registry registry = RegistryUtil.getRegistry();

      registry.ungetService(serviceReference);

      _storageMap.remove(webDAVStorage.getToken());
    }
  private AtomCollectionAdapterRegistryUtil() {
    Registry registry = RegistryUtil.getRegistry();

    _serviceTracker =
        registry.trackServices(
            (Class<AtomCollectionAdapter<?>>) (Class<?>) AtomCollectionAdapter.class,
            new AtomCollectionAdapterServiceTrackerCustomizer());

    _serviceTracker.open();
  }
  private void _register(AtomCollectionAdapter<?> atomCollectionAdapter) {
    Registry registry = RegistryUtil.getRegistry();

    ServiceRegistration<AtomCollectionAdapter<?>> serviceRegistration =
        registry.registerService(
            (Class<AtomCollectionAdapter<?>>) (Class<?>) AtomCollectionAdapter.class,
            atomCollectionAdapter);

    _serviceRegistrations.put(atomCollectionAdapter, serviceRegistration);
  }
  private void _register(Class<?> clazz, String name) {
    XStreamAlias xStreamAlias = new XStreamAlias(clazz, name);

    Registry registry = RegistryUtil.getRegistry();

    ServiceRegistration<XStreamAlias> serviceRegistration =
        registry.registerService(XStreamAlias.class, xStreamAlias);

    _serviceRegistrations.put(xStreamAlias, serviceRegistration);
  }
    @Override
    public Object addingService(ServiceReference<Object> serviceReference) {
      List<String> authTokenIgnoreActions =
          StringPlus.asList(serviceReference.getProperty(PropsKeys.AUTH_TOKEN_IGNORE_ACTIONS));

      _portletCSRFWhitelistActions.addAll(authTokenIgnoreActions);

      Registry registry = RegistryUtil.getRegistry();

      return registry.getService(serviceReference);
    }
    @Override
    public void removedService(
        ServiceReference<AtomCollectionAdapter<?>> serviceReference,
        AtomCollectionAdapter<?> atomCollectionAdapter) {

      Registry registry = RegistryUtil.getRegistry();

      registry.ungetService(serviceReference);

      _atomCollectionAdapters.remove(atomCollectionAdapter.getCollectionName());
    }
  public BaseDisplayContextProvider(Class<T> displayContextFactoryClass) {
    Registry registry = RegistryUtil.getRegistry();

    Filter filter =
        registry.getFilter("(objectClass=" + displayContextFactoryClass.getName() + ")");

    _serviceTracker =
        registry.trackServices(filter, new DisplayContextFactoryServiceTrackerCustomizer());

    _serviceTracker.open();
  }
  public PortletInstanceFactoryImpl() {
    _pool = new ConcurrentHashMap<>();

    Registry registry = RegistryUtil.getRegistry();

    _serviceTracker =
        registry.trackServices(
            InvokerPortletFactory.class, new InvokerPortletFactoryTrackerCustomizer());

    _serviceTracker.open();
  }
    @Override
    public XStreamAlias addingService(ServiceReference<XStreamAlias> serviceReference) {

      Registry registry = RegistryUtil.getRegistry();

      XStreamAlias xStreamAlias = registry.getService(serviceReference);

      _xstreamAliases.put(xStreamAlias.getClazz(), xStreamAlias.getName());

      return xStreamAlias;
    }
    @Override
    public void removedService(
        ServiceReference<ResourceBundle> serviceReference, ResourceBundle resourceBundle) {

      Registry registry = RegistryUtil.getRegistry();

      registry.ungetService(serviceReference);

      String languageId = (String) serviceReference.getProperty("language.id");

      _resourceBundles.remove(languageId);
    }
  private CustomJspBagRegistryUtil() {
    Registry registry = RegistryUtil.getRegistry();

    Filter filter =
        registry.getFilter(
            "(&(context.id=*)(context.name=*)(objectClass=" + CustomJspBag.class.getName() + "))");

    _serviceTracker =
        registry.trackServices(filter, new CustomJspBagRegistryUtilServiceTrackerCustomizer());

    _serviceTracker.open();
  }
  protected void reconfigureCaches(ClassLoader classLoader) throws Exception {
    Configuration configuration = null;

    try {
      configuration = ConfigurationFactoryUtil.getConfiguration(classLoader, "portlet");
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug("Unable to read portlet.properties");
      }

      return;
    }

    String singleVMConfigurationLocation =
        configuration.get(PropsKeys.EHCACHE_SINGLE_VM_CONFIG_LOCATION);
    String multiVMConfigurationLocation =
        configuration.get(PropsKeys.EHCACHE_MULTI_VM_CONFIG_LOCATION);

    if (Validator.isNull(singleVMConfigurationLocation)
        && Validator.isNull(multiVMConfigurationLocation)) {

      return;
    }

    if (_serviceRegistrar == null) {
      Registry registry = RegistryUtil.getRegistry();

      _serviceRegistrar = registry.getServiceRegistrar(PortalCacheConfiguratorSettings.class);
    }

    if (Validator.isNotNull(singleVMConfigurationLocation)) {
      Map<String, Object> properties = new HashMap<>();

      properties.put("portal.cache.manager.name", PortalCacheManagerNames.SINGLE_VM);

      _serviceRegistrar.registerService(
          PortalCacheConfiguratorSettings.class,
          new PortalCacheConfiguratorSettings(classLoader, singleVMConfigurationLocation),
          properties);
    }

    if (Validator.isNotNull(multiVMConfigurationLocation)) {
      Map<String, Object> properties = new HashMap<>();

      properties.put("portal.cache.manager.name", PortalCacheManagerNames.MULTI_VM);

      _serviceRegistrar.registerService(
          PortalCacheConfiguratorSettings.class,
          new PortalCacheConfiguratorSettings(classLoader, multiVMConfigurationLocation),
          properties);
    }
  }
  public void register(String languageId, ResourceBundle resourceBundle) {
    Registry registry = RegistryUtil.getRegistry();

    Map<String, Object> properties = new HashMap<String, Object>();

    properties.put("javax.portlet.name", _portletId);
    properties.put("language.id", languageId);

    ServiceRegistration<ResourceBundle> serviceRegistration =
        registry.registerService(ResourceBundle.class, resourceBundle, properties);

    _serviceRegistrations.put(languageId, serviceRegistration);
  }
    @Override
    public void removedService(ServiceReference<Indexer<?>> serviceReference, Indexer<?> indexer) {

      Registry registry = RegistryUtil.getRegistry();

      registry.ungetService(serviceReference);

      Class<?> clazz = indexer.getClass();

      _indexers.remove(clazz.getName());

      _indexers.remove(indexer.getClassName());
    }
  protected void setUpRegistryUtil() {
    Registry registry = mock(Registry.class);

    when(registry.getRegistry()).thenReturn(registry);

    when(registry.setRegistry(registry)).thenReturn(registry);

    when(registry.trackServices((com.liferay.registry.Filter) Matchers.any()))
        .thenReturn(_serviceTracker);

    RegistryUtil.setRegistry(null);
    RegistryUtil.setRegistry(registry);
  }
  public IndexerPostProcessorRegistry() {
    Registry registry = RegistryUtil.getRegistry();

    Filter indexerPostProcessorFilter =
        registry.getFilter(
            "(&(indexer.class.name=*)(objectClass=" + IndexerPostProcessor.class.getName() + "))");

    _serviceTracker =
        registry.trackServices(
            indexerPostProcessorFilter, new IndexerPostProcessorServiceTrackerCustomizer());

    _serviceTracker.open();
  }