Search in sources :

Example 1 with JMS2CDIExtension

use of org.apache.openejb.resource.activemq.jms2.cdi.JMS2CDIExtension in project tomee by apache.

the class OptimizedLoaderService method loadExtensions.

protected List<? extends Extension> loadExtensions(final ClassLoader classLoader) {
    final List<Extension> list = loaderService.load(Extension.class, classLoader);
    final Collection<String> additional = ADDITIONAL_EXTENSIONS.get();
    if (additional != null) {
        for (final String name : additional) {
            try {
                list.add(Extension.class.cast(classLoader.loadClass(name).newInstance()));
            } catch (final Exception ignored) {
            // no-op
            }
        }
    }
    if (hasJms()) {
        list.add(new JMS2CDIExtension());
    }
    final Collection<Extension> extensionCopy = new ArrayList<>(list);
    final Iterator<Extension> it = list.iterator();
    while (it.hasNext()) {
        if (it.hasNext()) {
            if (isFiltered(extensionCopy, it.next())) {
                it.remove();
            }
        }
    }
    if ("true".equals(OptimizedLoaderService.this.config.getProperty("openejb.cdi.extensions.sorted", SystemInstance.get().getProperty("openejb.cdi.extensions.sorted")))) {
        Collections.sort(list, new Comparator<Extension>() {

            @Override
            public int compare(final Extension o1, final Extension o2) {
                final int val1 = getVal(o1);
                final int val2 = getVal(o1);
                if (val1 == val2) {
                    return o1.getClass().getName().compareTo(o2.getClass().getName());
                }
                return val1 - val2;
            }

            private int getVal(final Extension o1) {
                final String key = "openejb.cdi.extensions." + o1.getClass().getName() + ".ordinal";
                final String config = OptimizedLoaderService.this.config.getProperty(key, SystemInstance.get().getProperty(key));
                return config == null ? 0 : Integer.parseInt(config.trim());
            }
        });
    }
    return list;
}
Also used : Extension(javax.enterprise.inject.spi.Extension) JMS2CDIExtension(org.apache.openejb.resource.activemq.jms2.cdi.JMS2CDIExtension) ArrayList(java.util.ArrayList) JMS2CDIExtension(org.apache.openejb.resource.activemq.jms2.cdi.JMS2CDIExtension)

Aggregations

ArrayList (java.util.ArrayList)1 Extension (javax.enterprise.inject.spi.Extension)1 JMS2CDIExtension (org.apache.openejb.resource.activemq.jms2.cdi.JMS2CDIExtension)1