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);
}
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;
}
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);
}
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);
}
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());
}
Aggregations