use of org.apache.camel.spi.Injector in project camel by apache.
the class XsltEndpoint method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
final CamelContext ctx = getCamelContext();
final ClassResolver resolver = ctx.getClassResolver();
final Injector injector = ctx.getInjector();
LOG.debug("{} using schema resource: {}", this, resourceUri);
this.xslt = injector.newInstance(XsltBuilder.class);
if (converter != null) {
xslt.setConverter(converter);
}
boolean useSaxon = false;
if (transformerFactoryClass == null && (saxon || saxonExtensionFunctions != null)) {
useSaxon = true;
transformerFactoryClass = SAXON_TRANSFORMER_FACTORY_CLASS_NAME;
}
TransformerFactory factory = transformerFactory;
if (factory == null && transformerFactoryClass != null) {
// provide the class loader of this component to work in OSGi environments
Class<TransformerFactory> factoryClass = resolver.resolveMandatoryClass(transformerFactoryClass, TransformerFactory.class, XsltComponent.class.getClassLoader());
LOG.debug("Using TransformerFactoryClass {}", factoryClass);
factory = injector.newInstance(factoryClass);
if (useSaxon) {
XsltHelper.registerSaxonConfiguration(ctx, factoryClass, factory, saxonConfiguration);
XsltHelper.registerSaxonConfigurationProperties(ctx, factoryClass, factory, saxonConfigurationProperties);
XsltHelper.registerSaxonExtensionFunctions(ctx, factoryClass, factory, saxonExtensionFunctions);
}
}
if (factory != null) {
LOG.debug("Using TransformerFactory {}", factory);
xslt.getConverter().setTransformerFactory(factory);
}
if (resultHandlerFactory != null) {
xslt.setResultHandlerFactory(resultHandlerFactory);
}
if (errorListener != null) {
xslt.errorListener(errorListener);
}
xslt.setFailOnNullBody(failOnNullBody);
xslt.transformerCacheSize(transformerCacheSize);
xslt.setUriResolver(uriResolver);
xslt.setEntityResolver(entityResolver);
xslt.setAllowStAX(allowStAX);
xslt.setDeleteOutputFile(deleteOutputFile);
configureOutput(xslt, output.name());
// any additional transformer parameters then make a copy to avoid side-effects
if (parameters != null) {
Map<String, Object> copy = new HashMap<String, Object>(parameters);
xslt.setParameters(copy);
}
// must load resource first which sets a template and do a stylesheet compilation to catch errors early
loadResource(resourceUri);
// the processor is the xslt builder
setProcessor(xslt);
}
use of org.apache.camel.spi.Injector in project camel by apache.
the class InjectorDefaultsTest method testInjectorIsDefaultByDefault.
public void testInjectorIsDefaultByDefault() throws Exception {
Injector injector = context.getInjector();
assertIsInstanceOf(DefaultInjector.class, injector);
}
use of org.apache.camel.spi.Injector in project camel by apache.
the class InjectorDefaultsTest method testNewInstance.
public void testNewInstance() throws Exception {
Injector injector = context.getInjector();
MyFoo foo = injector.newInstance(MyFoo.class);
foo.setName("Claus");
MyFoo foo2 = injector.newInstance(MyFoo.class);
assertNotSame(foo, foo2);
assertEquals("Claus", foo.getName());
assertNull(foo2.getName());
}
use of org.apache.camel.spi.Injector in project camel by apache.
the class DefaultFactoryFinderTest method shouldComplainIfInstanceTypeIsNotAsExpected.
@Test
public void shouldComplainIfInstanceTypeIsNotAsExpected() throws ClassNotFoundException, IOException {
final Injector injector = createMock(Injector.class);
final TestImplA expected = new TestImplA();
expect(injector.newInstance(TestImplA.class)).andReturn(expected);
replay(injector);
try {
factoryFinder.newInstances("TestImplA", injector, TestImplB.class);
fail("ClassCastException should have been thrown");
} catch (final ClassCastException e) {
final String message = e.getMessage();
assertThat(message, matchesPattern("Not instanceof org\\.apache\\.camel\\.impl\\.DefaultFactoryFinderTest\\$TestImplB " + "value: org\\.apache\\.camel\\.impl\\.DefaultFactoryFinderTest\\$TestImplA.*"));
}
}
use of org.apache.camel.spi.Injector in project camel by apache.
the class InjectorDefaultsTest method testSharedInstance.
public void testSharedInstance() throws Exception {
Injector injector = context.getInjector();
MyBarSingleton bar = injector.newInstance(MyBarSingleton.class, new MyBarSingleton());
bar.setName("Claus");
MyBarSingleton bar2 = injector.newInstance(MyBarSingleton.class, bar);
assertSame(bar, bar2);
assertEquals("Claus", bar.getName());
assertEquals("Claus", bar2.getName());
}
Aggregations