コード例 #1
0
    @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;
    }
コード例 #2
0
  @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);
  }
コード例 #3
0
    @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;
    }
コード例 #4
0
    @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;
    }
コード例 #5
0
  @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);
  }
コード例 #6
0
  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;
              }
            }
コード例 #8
0
  private WebDAVUtil() {
    Registry registry = RegistryUtil.getRegistry();

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

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

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

    _serviceRegistrations.put(storage, serviceRegistration);
  }
コード例 #10
0
  private XStreamAliasRegistryUtil() {
    Registry registry = RegistryUtil.getRegistry();

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

    _serviceTracker.open();
  }
コード例 #11
0
  @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);
  }
コード例 #12
0
  public TestIndexerRegistry() {
    Registry registry = RegistryUtil.getRegistry();

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

    _serviceTracker.open();
  }
コード例 #13
0
            @Override
            public void map(ServiceReference<Editor> serviceReference, Emitter<String> emitter) {

              Registry registry = RegistryUtil.getRegistry();

              Editor editor = registry.getService(serviceReference);

              emitter.emit(editor.getName());
            }
コード例 #14
0
    @Override
    public void removedService(
        ServiceReference<XStreamAlias> serviceReference, XStreamAlias xStreamAlias) {

      Registry registry = RegistryUtil.getRegistry();

      registry.ungetService(serviceReference);

      _xstreamAliases.remove(xStreamAlias.getClazz());
    }
コード例 #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);
  }
コード例 #18
0
  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);
  }
コード例 #19
0
    @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());
    }
コード例 #21
0
  public BaseDisplayContextProvider(Class<T> displayContextFactoryClass) {
    Registry registry = RegistryUtil.getRegistry();

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

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

    _serviceTracker.open();
  }
コード例 #22
0
  public PortletInstanceFactoryImpl() {
    _pool = new ConcurrentHashMap<>();

    Registry registry = RegistryUtil.getRegistry();

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

    _serviceTracker.open();
  }
コード例 #23
0
    @Override
    public XStreamAlias addingService(ServiceReference<XStreamAlias> serviceReference) {

      Registry registry = RegistryUtil.getRegistry();

      XStreamAlias xStreamAlias = registry.getService(serviceReference);

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

      return xStreamAlias;
    }
コード例 #24
0
    @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);
    }
コード例 #25
0
  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();
  }
コード例 #26
0
  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);
    }
  }
コード例 #27
0
  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);
  }
コード例 #28
0
    @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());
    }
コード例 #29
0
  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);
  }
コード例 #30
0
  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();
  }