Search in sources :

Example 1 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project jersey by jersey.

the class Hk2Helper method bindBinding.

/**
     * Binds the single descriptor using an external {@link DynamicConfiguration}.
     *
     * @param locator HK2 injection manager.
     * @param dc      HK2 Dynamic configuration to bind the object.
     * @param binding Jersey descriptor as a holder of information about an injection point.
     */
private static void bindBinding(ServiceLocator locator, DynamicConfiguration dc, Binding<?, ?> binding) {
    if (ClassBinding.class.isAssignableFrom(binding.getClass())) {
        ActiveDescriptor<?> activeDescriptor = translateToActiveDescriptor((ClassBinding<?>) binding);
        bindBinding(locator, dc, activeDescriptor, binding.getAliases());
    } else if (InstanceBinding.class.isAssignableFrom(binding.getClass())) {
        ActiveDescriptor<?> activeDescriptor = translateToActiveDescriptor((InstanceBinding<?>) binding);
        bindBinding(locator, dc, activeDescriptor, binding.getAliases());
    } else if (InjectionResolverBinding.class.isAssignableFrom(binding.getClass())) {
        InjectionResolverBinding resolverDescriptor = (InjectionResolverBinding) binding;
        bindBinding(locator, dc, wrapInjectionResolver(resolverDescriptor), binding.getAliases());
        bindBinding(locator, dc, translateToActiveDescriptor(resolverDescriptor), binding.getAliases());
    } else if (SupplierClassBinding.class.isAssignableFrom(binding.getClass())) {
        bindSupplierClassBinding(locator, (SupplierClassBinding<?>) binding);
    } else if (SupplierInstanceBinding.class.isAssignableFrom(binding.getClass())) {
        bindSupplierInstanceBinding(locator, (SupplierInstanceBinding<?>) binding);
    } else {
        throw new RuntimeException(LocalizationMessages.UNKNOWN_DESCRIPTOR_TYPE(binding.getClass().getSimpleName()));
    }
}
Also used : InstanceBinding(org.glassfish.jersey.internal.inject.InstanceBinding) SupplierInstanceBinding(org.glassfish.jersey.internal.inject.SupplierInstanceBinding) InjectionResolverBinding(org.glassfish.jersey.internal.inject.InjectionResolverBinding) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) AbstractActiveDescriptor(org.glassfish.hk2.utilities.AbstractActiveDescriptor) SupplierClassBinding(org.glassfish.jersey.internal.inject.SupplierClassBinding)

Example 2 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project jersey by jersey.

the class Hk2Helper method bindBinding.

/**
     * Binds the single descriptor using a single {@link DynamicConfiguration}.
     *
     * @param locator HK2 injection manager.
     * @param binding Jersey descriptor as a holder of information about an injection point.
     */
private static void bindBinding(ServiceLocator locator, Binding<?, ?> binding) {
    DynamicConfiguration dc = getDynamicConfiguration(locator);
    bindBinding(locator, dc, binding);
    dc.commit();
}
Also used : DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration)

Example 3 with Descriptor

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

the class WeldUtils method getCDIEnablingAnnotations.

/**
 * Get the names of any annotation types that are applied to beans, which should enable CDI
 * processing even in the absence of a beans.xml descriptor.
 *
 * @param context The DeploymentContext
 *
 * @return An array of annotation type names; The array could be empty if none are found.
 */
public static String[] getCDIEnablingAnnotations(DeploymentContext context) {
    List<String> result = new ArrayList<String>();
    Types types = getTypes(context);
    if (types != null) {
        Iterator<Type> typesIter = types.getAllTypes().iterator();
        while (typesIter.hasNext()) {
            Type type = typesIter.next();
            if (!(type instanceof AnnotationType)) {
                Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
                while (annotations.hasNext()) {
                    AnnotationModel am = annotations.next();
                    AnnotationType at = am.getType();
                    if (isCDIEnablingAnnotation(at)) {
                        if (!result.contains(at.getName())) {
                            result.add(at.getName());
                        }
                    }
                }
            }
        }
    }
    return result.toArray(new String[result.size()]);
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) Type(org.glassfish.hk2.classmodel.reflect.Type) ArrayList(java.util.ArrayList) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType)

Example 4 with Descriptor

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

the class DOLUtils method getComponentEnvId.

/**
 * Generate a unique id name for each J2EE component.
 * @param env
 * @return
 */
public static String getComponentEnvId(JndiNameEnvironment env) {
    String id = null;
    if (env instanceof EjbDescriptor) {
        // EJB component
        EjbDescriptor ejbEnv = (EjbDescriptor) env;
        // Make jndi name flat so it won't result in the creation of
        // a bunch of sub-contexts.
        String flattedJndiName = ejbEnv.getJndiName().replace('/', '.');
        EjbBundleDescriptor ejbBundle = ejbEnv.getEjbBundleDescriptor();
        Descriptor d = ejbBundle.getModuleDescriptor().getDescriptor();
        // as the web bundle, because they share the same JNDI namespace
        if (d instanceof WebBundleDescriptor) {
            // copy of code below
            WebBundleDescriptor webEnv = (WebBundleDescriptor) d;
            id = webEnv.getApplication().getName() + ID_SEPARATOR + webEnv.getContextRoot();
            if (deplLogger.isLoggable(Level.FINER)) {
                deplLogger.log(Level.FINER, CONVERT_EJB_TO_WEB_ID, id);
            }
        } else {
            id = ejbEnv.getApplication().getName() + ID_SEPARATOR + ejbBundle.getModuleDescriptor().getArchiveUri() + ID_SEPARATOR + ejbEnv.getName() + ID_SEPARATOR + flattedJndiName + ejbEnv.getUniqueId();
        }
    } else if (env instanceof WebBundleDescriptor) {
        WebBundleDescriptor webEnv = (WebBundleDescriptor) env;
        id = webEnv.getApplication().getName() + ID_SEPARATOR + webEnv.getContextRoot();
    } else if (env instanceof ApplicationClientDescriptor) {
        ApplicationClientDescriptor appEnv = (ApplicationClientDescriptor) env;
        id = "client" + ID_SEPARATOR + appEnv.getName() + ID_SEPARATOR + appEnv.getMainClassName();
    } else if (env instanceof ManagedBeanDescriptor) {
        id = ((ManagedBeanDescriptor) env).getGlobalJndiName();
    } else if (env instanceof EjbBundleDescriptor) {
        EjbBundleDescriptor ejbBundle = (EjbBundleDescriptor) env;
        id = "__ejbBundle__" + ID_SEPARATOR + ejbBundle.getApplication().getName() + ID_SEPARATOR + ejbBundle.getModuleName();
    }
    return id;
}
Also used : EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) Descriptor(org.glassfish.deployment.common.Descriptor) ManagedBeanDescriptor(com.sun.enterprise.deployment.ManagedBeanDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) RootDeploymentDescriptor(org.glassfish.deployment.common.RootDeploymentDescriptor) ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) ManagedBeanDescriptor(com.sun.enterprise.deployment.ManagedBeanDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Example 5 with Descriptor

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

the class Archivist method processAnnotations.

/**
 * Process annotations in a bundle descriptor, the annoation processing
 * is dependent on the type of descriptor being passed.
 */
protected ProcessingResult processAnnotations(RootDeploymentDescriptor bundleDesc, ModuleScanner scanner, ReadableArchive archive) throws AnnotationProcessorException, IOException {
    if (scanner == null) {
        return null;
    }
    AnnotatedElementHandler aeHandler = AnnotatedElementHandlerFactory.createAnnotatedElementHandler(bundleDesc);
    if (aeHandler == null) {
        return null;
    }
    Parser parser = null;
    if (archive.getParentArchive() != null) {
        parser = archive.getParentArchive().getExtraData(Parser.class);
    } else {
        parser = archive.getExtraData(Parser.class);
    }
    scanner.process(archive, bundleDesc, classLoader, parser);
    if (!scanner.getElements().isEmpty()) {
        if (((BundleDescriptor) bundleDesc).isDDWithNoAnnotationAllowed()) {
            // if we come into this block, it means an old version
            // of deployment descriptor has annotation which is not correct
            // throw exception in this case
            String ddName = getStandardDDFile().getDeploymentDescriptorPath();
            String explodedArchiveName = new File(archive.getURI()).getName();
            String archiveName = FileUtils.revertFriendlyFilenameExtension(explodedArchiveName);
            throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.oldDDwithAnnotation", "{0} in archive {1} is of version {2}, which cannot support annotations in an application.  Please upgrade the deployment descriptor to be a version supported by Java EE 5.0 (or later).", new Object[] { ddName, archiveName, bundleDesc.getSpecVersion() }));
        }
        boolean isFullAttribute = false;
        if (bundleDesc instanceof BundleDescriptor) {
            isFullAttribute = ((BundleDescriptor) bundleDesc).isFullAttribute();
        }
        AnnotationProcessor ap = annotationFactory.getAnnotationProcessor(isFullAttribute);
        ProcessingContext ctx = ap.createContext();
        ctx.setArchive(archive);
        if (annotationErrorHandler != null) {
            ctx.setErrorHandler(annotationErrorHandler);
        }
        ctx.setProcessingInput(scanner);
        ctx.pushHandler(aeHandler);
        // Make sure there is a classloader available on the descriptor
        // during annotation processing.
        ClassLoader originalBundleClassLoader = null;
        try {
            originalBundleClassLoader = bundleDesc.getClassLoader();
        } catch (Exception e) {
        // getClassLoader can throw exception if not available
        }
        // Only set classloader if it's not already set.
        if (originalBundleClassLoader == null) {
            bundleDesc.setClassLoader(classLoader);
        }
        try {
            return ap.process(ctx);
        } finally {
            if (originalBundleClassLoader == null) {
                bundleDesc.setClassLoader(null);
            }
        }
    }
    return null;
}
Also used : DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) JarFile(java.util.jar.JarFile) ConfigurationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile) SAXParseException(org.xml.sax.SAXParseException) MultiException(org.glassfish.hk2.api.MultiException)

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