Search in sources :

Example 11 with Descriptor

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

the class BeanParamMemoryLeakTest method testBeanParam.

@Test
public void testBeanParam() throws Exception {
    initiateWebApplication(BeanParamInjectionResource.class);
    final InjectionManager injectionManager = app().getInjectionManager();
    if (!(injectionManager instanceof HK2InjectionManager)) {
        throw new RuntimeException("Bean Manager is not an injection manager");
    }
    HK2InjectionManager hk2BeanManager = (HK2InjectionManager) injectionManager;
    ServiceLocator serviceLocator = hk2BeanManager.getServiceLocator();
    // we do not expect any descriptor registered yet
    assertEquals(0, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
    // now make one registered via this call
    assertEquals("one", resource("/jaxrs?q=one").getEntity());
    // make sure it got registered
    assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
    // make another call
    assertEquals("two", resource("/jaxrs?q=two").getEntity());
    assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
    // and some more
    for (int i = 0; i < 20; i++) {
        assertEquals(Integer.toString(i), resource("/jaxrs?q=" + i).getEntity());
        assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) HK2InjectionManager(org.glassfish.jersey.hk2.HK2InjectionManager) HK2InjectionManager(org.glassfish.jersey.hk2.HK2InjectionManager) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 12 with Descriptor

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

the class SJSASFactory method postConstruct.

@SuppressWarnings({ "unused", "unchecked" })
@PostConstruct
private void postConstruct() {
    if (systemProcessor != null && systemProcessorMetaDataComplete != null)
        return;
    // initialize our system annotation processor...
    systemProcessor = new AnnotationProcessorImpl();
    systemProcessorMetaDataComplete = new AnnotationProcessorImpl();
    for (ActiveDescriptor<?> i : locator.getDescriptors(BuilderHelper.createContractFilter(AnnotationHandler.class.getName()))) {
        ActiveDescriptor<AnnotationHandler> descriptor = (ActiveDescriptor<AnnotationHandler>) i;
        String annotationTypeName = getAnnotationHandlerForStringValue(descriptor);
        if (annotationTypeName == null)
            continue;
        systemProcessor.pushAnnotationHandler(annotationTypeName, new LazyAnnotationHandler(descriptor));
        annotationClassNames.add("L" + annotationTypeName.replace('.', '/') + ";");
        // falling in this category in the future, add them to this list
        if (annotationTypeName.equals("javax.annotation.ManagedBean")) {
            systemProcessorMetaDataComplete.pushAnnotationHandler(annotationTypeName, new LazyAnnotationHandler(descriptor));
            annotationClassNamesMetaDataComplete.add("L" + annotationTypeName.replace('.', '/') + ";");
        }
    }
}
Also used : ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) AnnotationHandler(org.glassfish.apf.AnnotationHandler) AnnotationProcessorImpl(org.glassfish.apf.impl.AnnotationProcessorImpl) PostConstruct(javax.annotation.PostConstruct)

Example 13 with Descriptor

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

the class WeldUtils method hasCDIEnablingAnnotations.

/**
 * Determine whether there are any beans annotated with annotations that should enable CDI
 * processing even in the absence of a beans.xml descriptor.
 *
 * @param context The DeploymentContext
 * @param paths   The paths to check for annotated beans
 *
 * @return true, if there is at least one bean annotated with a qualified annotation in the specified paths
 */
public static boolean hasCDIEnablingAnnotations(DeploymentContext context, Collection<URI> paths) {
    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) && type.wasDefinedIn(paths)) {
                        if (!result.contains(at.getName())) {
                            result.add(at.getName());
                        }
                    }
                }
            }
        }
    }
    return !(result.isEmpty());
}
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 14 with Descriptor

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

the class WeldUtils method getCDIAnnotatedClassNames.

/**
 * Get the names of any classes that are annotated with bean-defining annotations, which should
 * enable CDI processing even in the absence of a beans.xml descriptor.
 *
 * @param context The DeploymentContext
 *
 * @return A collection of class names; The collection could be empty if none are found.
 */
public static Collection<String> getCDIAnnotatedClassNames(DeploymentContext context) {
    Set<String> result = new HashSet<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(type.getName());
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) Type(org.glassfish.hk2.classmodel.reflect.Type) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) HashSet(java.util.HashSet)

Example 15 with Descriptor

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

the class TransactionLifecycleService method postConstruct.

@Override
public void postConstruct() {
    EventListener glassfishEventListener = new EventListener() {

        @Override
        public void event(Event event) {
            if (event.is(EventTypes.SERVER_READY)) {
                _logger.fine("TM LIFECYCLE SERVICE - ON READY");
                onReady();
            } else if (event.is(EventTypes.PREPARE_SHUTDOWN)) {
                _logger.fine("TM LIFECYCLE SERVICE - ON SHUTDOWN");
                onShutdown();
            }
        }
    };
    events.register(glassfishEventListener);
    if (nm != null) {
        try {
            nm.publishObject(USER_TX_NO_JAVA_COMP, new NamingObjectProxy.InitializationNamingObjectProxy() {

                @Override
                public Object create(Context ic) throws NamingException {
                    ActiveDescriptor<?> descriptor = habitat.getBestDescriptor(BuilderHelper.createContractFilter("javax.transaction.UserTransaction"));
                    if (descriptor == null)
                        return null;
                    return habitat.getServiceHandle(descriptor).getService();
                }
            }, false);
        } catch (NamingException e) {
            _logger.warning("Can't bind \"UserTransaction\" in JNDI");
        }
    }
}
Also used : Context(javax.naming.Context) NamingObjectProxy(org.glassfish.api.naming.NamingObjectProxy) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) NamingException(javax.naming.NamingException) EventListener(org.glassfish.api.event.EventListener)

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