Search in sources :

Example 21 with Descriptor

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

the class ConfigTest method testAddClassOfInjector.

/**
 * Ensures that even the non-standard format of metadata from the hk2-config subsystem can
 * be read from the service in addClasses.  addClasses will now read both forms, if the
 * documented form fails, it'll try the hk2-config form
 */
@Test
public void testAddClassOfInjector() {
    ServiceLocator locator = ServiceLocatorFactory.getInstance().create(null);
    List<ActiveDescriptor<?>> added = ServiceLocatorUtilities.addClasses(locator, EjbContainerAvailabilityInjector.class);
    ActiveDescriptor<?> descriptor = added.get(0);
    Assert.assertEquals("org.jvnet.hk2.config.test.EjbContainerAvailability", ServiceLocatorUtilities.getOneMetadataField(descriptor, "target"));
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) Test(org.junit.Test)

Example 22 with Descriptor

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

the class AttributeMethodVisitor method visitAnnotation.

/**
 * Visits an annotation of this method.
 *
 * @param desc the class descriptor of the annotation class.
 * @param visible <tt>true</tt> if the annotation is visible at runtime.
 *
 * @return a visitor to visit the annotation values, or <tt>null</tt> if this visitor is not interested in visiting
 *         this annotation.
 */
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
    duckTyped |= "Lorg/jvnet/hk2/config/DuckTyped;".equals(desc);
    AnnotationVisitor visitor = null;
    if ("Lorg/jvnet/hk2/config/Attribute;".equals(desc) || "Lorg/jvnet/hk2/config/Element;".equals(desc)) {
        try {
            final Class<?> configurable = Thread.currentThread().getContextClassLoader().loadClass(def.getDef());
            final Attribute annotation = configurable.getMethod(name).getAnnotation(Attribute.class);
            def.addAttribute(name, annotation);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    } else if ("Lorg/glassfish/api/admin/config/PropertiesDesc;".equals(desc)) {
        try {
            final Class<?> configurable = Thread.currentThread().getContextClassLoader().loadClass(def.getDef());
            final PropertiesDesc annotation = configurable.getMethod(name).getAnnotation(PropertiesDesc.class);
            final PropertyDesc[] propertyDescs = annotation.props();
            for (PropertyDesc prop : propertyDescs) {
                def.addProperty(prop);
            }
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return visitor;
}
Also used : PropertiesDesc(org.glassfish.api.admin.config.PropertiesDesc) Attribute(org.jvnet.hk2.config.Attribute) AnnotationVisitor(org.glassfish.hk2.external.org.objectweb.asm.AnnotationVisitor) PropertyDesc(org.glassfish.api.admin.config.PropertyDesc)

Example 23 with Descriptor

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

the class AbstractRestResourceProvider method getResourceConfig.

@Override
public ResourceConfig getResourceConfig(Set<Class<?>> classes, final ServerContext sc, final ServiceLocator habitat, final Set<? extends Binder> additionalBinders) throws EndpointRegistrationException {
    final Reloader r = new Reloader();
    ResourceConfig rc = new ResourceConfig(classes);
    rc.property(ServerProperties.MEDIA_TYPE_MAPPINGS, getMimeMappings());
    rc.register(CsrfProtectionFilter.class);
    // TODO - JERSEY2
    // RestConfig restConf = ResourceUtil.getRestConfig(habitat);
    // if (restConf != null) {
    // if (restConf.getLogOutput().equalsIgnoreCase("true")) { //enable output logging
    // rc.getContainerResponseFilters().add(LoggingFilter.class);
    // }
    // if (restConf.getLogInput().equalsIgnoreCase("true")) { //enable input logging
    // rc.getContainerRequestFilters().add(LoggingFilter.class);
    // }
    // if (restConf.getWadlGeneration().equalsIgnoreCase("false")) { //disable WADL
    // rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
    // }
    // }
    // else {
    // rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
    // }
    // 
    rc.register(r);
    rc.register(ReloadResource.class);
    rc.register(new MultiPartFeature());
    // rc.register(getJsonFeature());
    rc.register(new AbstractBinder() {

        @Override
        protected void configure() {
            AbstractActiveDescriptor<Reloader> descriptor = BuilderHelper.createConstantDescriptor(r);
            descriptor.addContractType(Reloader.class);
            bind(descriptor);
            AbstractActiveDescriptor<ServerContext> scDescriptor = BuilderHelper.createConstantDescriptor(sc);
            scDescriptor.addContractType(ServerContext.class);
            bind(scDescriptor);
            LocatorBridge locatorBridge = new LocatorBridge(habitat);
            AbstractActiveDescriptor<LocatorBridge> hDescriptor = BuilderHelper.createConstantDescriptor(locatorBridge);
            bind(hDescriptor);
            RestSessionManager rsm = habitat.getService(RestSessionManager.class);
            AbstractActiveDescriptor<RestSessionManager> rmDescriptor = BuilderHelper.createConstantDescriptor(rsm);
            bind(rmDescriptor);
        }
    });
    for (Binder b : additionalBinders) {
        rc.register(b);
    }
    rc.property(MessageProperties.LEGACY_WORKERS_ORDERING, true);
    return rc;
}
Also used : Binder(org.glassfish.hk2.utilities.Binder) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ServerContext(org.glassfish.internal.api.ServerContext) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) RestSessionManager(org.glassfish.common.util.admin.RestSessionManager) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) AbstractActiveDescriptor(org.glassfish.hk2.utilities.AbstractActiveDescriptor)

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