Search in sources :

Example 6 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project Payara by payara.

the class ArchivistFactory method getExtensionsArchivists.

/**
 * Gets all the classes for processing parts of a specified archive
 * @param sniffers
 * @param moduleType
 * @return
 * @see org.glassfish.webservices.archivist.WebServicesArchivist
 * @see org.glassfish.ejb.deployment.archivist.EjbInWarArchivist
 * @see com.sun.enterprise.deployment.archivist.PersistenceArchivist
 */
@SuppressWarnings("unchecked")
public List<ExtensionsArchivist> getExtensionsArchivists(Collection<Sniffer> sniffers, ArchiveType moduleType) {
    Set<String> containerTypes = new HashSet<String>();
    for (Sniffer sniffer : sniffers) {
        containerTypes.add(sniffer.getModuleType());
    }
    List<ExtensionsArchivist> archivists = new ArrayList<ExtensionsArchivist>();
    for (String containerType : containerTypes) {
        List<ActiveDescriptor<?>> descriptors = habitat.getDescriptors(new ArchivistFilter(containerType, EXTENSION_ARCHIVE_TYPE, ExtensionsArchivist.class));
        for (ActiveDescriptor<?> item : descriptors) {
            ActiveDescriptor<ExtensionsArchivist> descriptor = (ActiveDescriptor<ExtensionsArchivist>) item;
            ServiceHandle<ExtensionsArchivist> handle = habitat.getServiceHandle(descriptor);
            ExtensionsArchivist ea = handle.getService();
            if (ea.supportsModuleType(moduleType)) {
                archivists.add(ea);
            }
        }
    }
    return archivists;
}
Also used : ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) ArrayList(java.util.ArrayList) Sniffer(org.glassfish.api.container.Sniffer) HashSet(java.util.HashSet)

Example 7 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project Payara by payara.

the class CDIExtension method beforeBeanDiscovery.

/**
 * This method will ensure that the file which indicates that the
 * application has shut down properly has been removed and then
 * adds the HK2 service to the system
 *
 * @param beforeBeanDiscovery
 */
@SuppressWarnings("unused")
private void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscovery) {
    File destructoFile = createDestructionFileObject();
    if (destructoFile == null)
        return;
    if (destructoFile.exists()) {
        if (destructoFile.delete() == false)
            return;
    }
    ServiceLocator locator = getServiceLocator();
    if (locator == null)
        return;
    Descriptor d = BuilderHelper.link(HK2ExtensionVerifier.class).in(Singleton.class.getName()).andLoadWith(new HK2LoaderImpl()).build();
    // Just having the service present is enough for the first callback
    ServiceLocatorUtilities.addOneDescriptor(locator, d);
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Singleton(javax.inject.Singleton) Descriptor(org.glassfish.hk2.api.Descriptor) File(java.io.File)

Example 8 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project Payara by payara.

the class ConfigModularityUtils method getAnnotatedConfigBeans.

public List<Class> getAnnotatedConfigBeans(Class annotationType) {
    List<Class> prox = new ArrayList<Class>();
    List<ActiveDescriptor<?>> descriptor = serviceLocator.getDescriptors(BuilderHelper.createContractFilter(ConfigInjector.class.getName()));
    Class<?> clz = null;
    for (ActiveDescriptor desc : descriptor) {
        if (desc.getName() == null) {
            continue;
        }
        ConfigInjector injector = serviceLocator.getService(ConfigInjector.class, desc.getName());
        if (injector != null) {
            String clzName = injector.getClass().getName().substring(0, injector.getClass().getName().length() - 8);
            if (clzName == null) {
                continue;
            }
            try {
                clz = injector.getClass().getClassLoader().loadClass(clzName);
                if (clz == null) {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.log(Level.FINE, "Cannot find the class mapping to:  " + clzName);
                    }
                    continue;
                }
            } catch (Throwable e) {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.log(Level.FINE, "Cannot load the class", e);
                }
                continue;
            }
        }
        if (clz != null) {
            if (clz.isAnnotationPresent(annotationType)) {
                prox.add(clz);
            }
        }
    }
    return prox;
}
Also used : ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) ArrayList(java.util.ArrayList) ConfigInjector(org.jvnet.hk2.config.ConfigInjector)

Example 9 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project Payara by payara.

the class CreateResourceRef method chooseRefContainer.

private RefContainer chooseRefContainer(final AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Class<?>[] allInterfaces = resourceOfInterest.getClass().getInterfaces();
    for (Class<?> resourceInterface : allInterfaces) {
        ResourceConfigCreator resourceConfigCreator = (ResourceConfigCreator) resourceInterface.getAnnotation(ResourceConfigCreator.class);
        if (resourceConfigCreator != null) {
            commandName = resourceConfigCreator.commandName();
        }
    }
    if (commandName != null) {
        List<ServiceHandle<?>> serviceHandles = locator.getAllServiceHandles(new Filter() {

            @Override
            public boolean matches(Descriptor arg0) {
                String name = arg0.getName();
                if (name != null && name.equals(commandName)) {
                    return true;
                }
                return false;
            }
        });
        for (ServiceHandle<?> handle : serviceHandles) {
            ActiveDescriptor<?> descriptor = handle.getActiveDescriptor();
            if (descriptor.getName().equals(commandName)) {
                if (!descriptor.isReified()) {
                    locator.reifyDescriptor(descriptor);
                }
                AdminCommand service = locator.<AdminCommand>getService(descriptor.getImplementationClass());
                if (service != null) {
                    TargetType targetType = descriptor.getImplementationClass().getAnnotation(TargetType.class);
                    targets = targetType.value();
                    break;
                }
            }
        }
        if (!(isTargetValid = validateTarget(target, targets))) {
            return null;
        }
        Config config = domain.getConfigs().getConfigByName(target);
        if (config != null) {
            return config;
        }
        Server server = configBeansUtilities.getServerNamed(target);
        if (server != null) {
            return server;
        }
        DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
        if (dg != null) {
            return dg;
        }
        Cluster cluster = domain.getClusterNamed(target);
        return cluster;
    } else {
        report.setMessage(localStrings.getLocalString("create.resource.ref.failed", "Resource ref {0} creation failed", refName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return null;
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport) Filter(org.glassfish.hk2.api.Filter) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) TargetType(org.glassfish.config.support.TargetType) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) Descriptor(org.glassfish.hk2.api.Descriptor) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 10 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project Payara by payara.

the class ConfigModule method bindInjector.

private void bindInjector(DynamicConfiguration configurator, String elementName, Class contract, final Class clz) {
    DescriptorBuilder db = BuilderHelper.link(clz).to(ConfigInjector.class).to(InjectionTarget.class).to(contract).in(Singleton.class.getName()).qualifiedBy(clz.getAnnotation(InjectionTarget.class)).named(elementName).andLoadWith(new MyHk2Loader(clz.getClassLoader()));
    String metaData = ((Service) clz.getAnnotation(Service.class)).metadata();
    Map<String, List<String>> metaMap = new HashMap<String, List<String>>();
    for (StringTokenizer st = new StringTokenizer(metaData, ","); st.hasMoreTokens(); ) {
        String tok = st.nextToken();
        int index = tok.indexOf('=');
        if (index > 0) {
            String key = tok.substring(0, index);
            String value = tok.substring(index + 1);
            List<String> lst = metaMap.get(key);
            if (lst == null) {
                lst = new LinkedList<String>();
                metaMap.put(key, lst);
            }
            lst.add(value);
        // System.out.println("**     Added Metadata: " + tok.substring(0, index) + "  : " + tok.substring(index+1));
        }
    // db.andLoadWith(new MyHk2Loader(clz.getClassLoader()));
    }
    for (String key : metaMap.keySet()) {
        db.has(key, metaMap.get(key));
    }
    ActiveDescriptor desc = configurator.bind(db.build());
    configurator.bind(new AliasDescriptor(serviceLocator, desc, InjectionTarget.class.getName(), contract.getName()));
    System.out.println("**Successfully bound an alias descriptor for: " + elementName);
}
Also used : ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) Service(org.jvnet.hk2.annotations.Service) DescriptorBuilder(org.glassfish.hk2.utilities.DescriptorBuilder) AliasDescriptor(org.glassfish.hk2.utilities.AliasDescriptor) InjectionTarget(org.jvnet.hk2.config.InjectionTarget)

Aggregations

ActiveDescriptor (org.glassfish.hk2.api.ActiveDescriptor)10 ArrayList (java.util.ArrayList)4 Descriptor (org.glassfish.hk2.api.Descriptor)4 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)3 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)3 AnnotationType (org.glassfish.hk2.classmodel.reflect.AnnotationType)3 Type (org.glassfish.hk2.classmodel.reflect.Type)3 Types (org.glassfish.hk2.classmodel.reflect.Types)3 HashSet (java.util.HashSet)2 Filter (org.glassfish.hk2.api.Filter)2 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)2 Test (org.junit.Test)2 Version (com.sun.appserv.server.util.Version)1 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)1 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 ManagedBeanDescriptor (com.sun.enterprise.deployment.ManagedBeanDescriptor)1