Search in sources :

Example 11 with WadlGenerator

use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.

the class WadlGeneratorLoader method loadWadlGenerator.

private static WadlGeneratorControl loadWadlGenerator(InjectionManager injectionManager, WadlGeneratorDescription wadlGeneratorDescription, WadlGenerator wadlGeneratorDelegate) throws Exception {
    LOGGER.info("Loading wadlGenerator " + wadlGeneratorDescription.getGeneratorClass().getName());
    final WadlGenerator generator = Injections.getOrCreate(injectionManager, wadlGeneratorDescription.getGeneratorClass());
    generator.setWadlGeneratorDelegate(wadlGeneratorDelegate);
    CallbackList callbacks = null;
    if (wadlGeneratorDescription.getProperties() != null && !wadlGeneratorDescription.getProperties().isEmpty()) {
        callbacks = new CallbackList();
        final Properties wadlGeneratorProperties = wadlGeneratorDescription.getProperties();
        Class<?> osgiConfiguratorClass = wadlGeneratorDescription.getConfiguratorClass();
        for (Entry<Object, Object> entry : wadlGeneratorProperties.entrySet()) {
            final Callback callback = setProperty(generator, entry.getKey().toString(), entry.getValue(), osgiConfiguratorClass);
            callbacks.add(callback);
        }
    }
    return new WadlGeneratorControl(generator, callbacks);
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) Properties(java.util.Properties)

Example 12 with WadlGenerator

use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.

the class WadlGeneratorLoader method loadWadlGeneratorDescriptions.

static WadlGenerator loadWadlGeneratorDescriptions(InjectionManager injectionManager, List<WadlGeneratorDescription> wadlGeneratorDescriptions) throws Exception {
    WadlGenerator wadlGenerator = new WadlGeneratorJAXBGrammarGenerator();
    final CallbackList callbacks = new CallbackList();
    try {
        if (wadlGeneratorDescriptions != null && !wadlGeneratorDescriptions.isEmpty()) {
            for (WadlGeneratorDescription wadlGeneratorDescription : wadlGeneratorDescriptions) {
                final WadlGeneratorControl control = loadWadlGenerator(injectionManager, wadlGeneratorDescription, wadlGenerator);
                wadlGenerator = control.wadlGenerator;
                callbacks.add(control.callback);
            }
        }
        wadlGenerator.init();
    } finally {
        callbacks.callback();
    }
    return wadlGenerator;
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) WadlGeneratorJAXBGrammarGenerator(org.glassfish.jersey.server.wadl.internal.generators.WadlGeneratorJAXBGrammarGenerator)

Example 13 with WadlGenerator

use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.

the class WadlGeneratorConfigTest method testBuildWadlGeneratorFromDescriptionsWithTypes.

@Test
public void testBuildWadlGeneratorFromDescriptionsWithTypes() {
    WadlGeneratorConfig config = WadlGeneratorConfig.generator(MyWadlGenerator3.class).prop("foo", "string").prop("bar", new Bar()).build();
    final InjectionManager locator = InjectionManagerFactory.createInjectionManager();
    WadlGenerator wadlGenerator = config.createWadlGenerator(locator);
    Assert.assertEquals(MyWadlGenerator3.class, wadlGenerator.getClass());
    MyWadlGenerator3 g = (MyWadlGenerator3) wadlGenerator;
    Assert.assertNotNull(g.foo);
    Assert.assertEquals(g.foo.s, "string");
    Assert.assertNotNull(g.bar);
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 14 with WadlGenerator

use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.

the class WadlGeneratorConfigTest method testCustomWadlGeneratorConfig.

@Test
public void testCustomWadlGeneratorConfig() {
    final String propValue = "someValue";
    final String propValue2 = "baz";
    class MyWadlGeneratorConfig extends WadlGeneratorConfig {

        @Override
        public List<WadlGeneratorDescription> configure() {
            return generator(MyWadlGenerator.class).prop("foo", propValue).generator(MyWadlGenerator2.class).prop("bar", propValue2).descriptions();
        }
    }
    final InjectionManager locator = InjectionManagerFactory.createInjectionManager();
    WadlGeneratorConfig config = new MyWadlGeneratorConfig();
    WadlGenerator wadlGenerator = config.createWadlGenerator(locator);
    Assert.assertEquals(MyWadlGenerator2.class, wadlGenerator.getClass());
    final MyWadlGenerator2 wadlGenerator2 = (MyWadlGenerator2) wadlGenerator;
    Assert.assertEquals(wadlGenerator2.getBar(), propValue2);
    Assert.assertEquals(MyWadlGenerator.class, wadlGenerator2.getDelegate().getClass());
    Assert.assertEquals(((MyWadlGenerator) wadlGenerator2.getDelegate()).getFoo(), propValue);
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 15 with WadlGenerator

use of org.glassfish.jersey.server.wadl.WadlGenerator in project jersey by jersey.

the class WadlGeneratorConfigTest method testBuildWadlGeneratorFromGenerators.

@Test
public void testBuildWadlGeneratorFromGenerators() {
    final Class<MyWadlGenerator> generator = MyWadlGenerator.class;
    final Class<MyWadlGenerator2> generator2 = MyWadlGenerator2.class;
    WadlGeneratorConfig config = WadlGeneratorConfig.generator(generator).generator(generator2).build();
    final InjectionManager locator = InjectionManagerFactory.createInjectionManager();
    WadlGenerator wadlGenerator = config.createWadlGenerator(locator);
    Assert.assertEquals(MyWadlGenerator2.class, wadlGenerator.getClass());
    Assert.assertEquals(MyWadlGenerator.class, ((MyWadlGenerator2) wadlGenerator).getDelegate().getClass());
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Aggregations

WadlGenerator (org.glassfish.jersey.server.wadl.WadlGenerator)16 Test (org.junit.Test)11 InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)10 Properties (java.util.Properties)5 File (java.io.File)4 URL (java.net.URL)4 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)2 WadlGeneratorJAXBGrammarGenerator (org.glassfish.jersey.server.wadl.internal.generators.WadlGeneratorJAXBGrammarGenerator)2 Application (com.sun.research.ws.wadl.Application)1 Resource (com.sun.research.ws.wadl.Resource)1 Resources (com.sun.research.ws.wadl.Resources)1 StringWriter (java.io.StringWriter)1 ProcessingException (javax.ws.rs.ProcessingException)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 Resource (org.glassfish.jersey.server.model.Resource)1 ApplicationDescription (org.glassfish.jersey.server.wadl.internal.ApplicationDescription)1 WadlBuilder (org.glassfish.jersey.server.wadl.internal.WadlBuilder)1 WadlGeneratorImpl (org.glassfish.jersey.server.wadl.internal.WadlGeneratorImpl)1 WadlGeneratorResourceDocSupport (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.WadlGeneratorResourceDocSupport)1