use of org.apache.camel.spi.ClassResolver in project camel by apache.
the class OsgiClassResolverTest method testResolveClass.
@Test
public void testResolveClass() {
ClassResolver classResolver = getClassResolver();
Class<?> routeBuilder = classResolver.resolveClass("org.apache.camel.core.osgi.test.MyRouteBuilder");
assertNotNull("The class of routeBuilder should not be null.", routeBuilder);
}
use of org.apache.camel.spi.ClassResolver in project camel by apache.
the class DefaultCamelContext method getComponentParameterJsonSchema.
public String getComponentParameterJsonSchema(String componentName) throws IOException {
// use the component factory finder to find the package name of the component class, which is the location
// where the documentation exists as well
FactoryFinder finder = getFactoryFinder(DefaultComponentResolver.RESOURCE_PATH);
try {
Class<?> clazz = null;
try {
clazz = finder.findClass(componentName);
} catch (NoFactoryAvailableException e) {
// ignore, i.e. if a component is an auto-configured spring-boot
// component
}
if (clazz == null) {
// fallback and find existing component
Component existing = hasComponent(componentName);
if (existing != null) {
clazz = existing.getClass();
} else {
return null;
}
}
String packageName = clazz.getPackage().getName();
packageName = packageName.replace('.', '/');
String path = packageName + "/" + componentName + ".json";
ClassResolver resolver = getClassResolver();
InputStream inputStream = resolver.loadResourceAsStream(path);
log.debug("Loading component JSON Schema for: {} using class resolver: {} -> {}", new Object[] { componentName, resolver, inputStream });
if (inputStream != null) {
try {
return IOHelper.loadText(inputStream);
} finally {
IOHelper.close(inputStream);
}
}
// special for ActiveMQ as it is really just JMS
if ("ActiveMQComponent".equals(clazz.getSimpleName())) {
return getComponentParameterJsonSchema("jms");
} else {
return null;
}
} catch (ClassNotFoundException e) {
return null;
}
}
use of org.apache.camel.spi.ClassResolver in project camel by apache.
the class DefaultCamelContext method getDataFormatParameterJsonSchema.
public String getDataFormatParameterJsonSchema(String dataFormatName) throws IOException {
// use the dataformat factory finder to find the package name of the dataformat class, which is the location
// where the documentation exists as well
FactoryFinder finder = getFactoryFinder(DefaultDataFormatResolver.DATAFORMAT_RESOURCE_PATH);
try {
Class<?> clazz = null;
try {
clazz = finder.findClass(dataFormatName);
} catch (NoFactoryAvailableException e) {
// ignore, i.e. if a component is an auto-configured spring-boot
// data-formats
}
if (clazz == null) {
return null;
}
String packageName = clazz.getPackage().getName();
packageName = packageName.replace('.', '/');
String path = packageName + "/" + dataFormatName + ".json";
ClassResolver resolver = getClassResolver();
InputStream inputStream = resolver.loadResourceAsStream(path);
log.debug("Loading dataformat JSON Schema for: {} using class resolver: {} -> {}", new Object[] { dataFormatName, resolver, inputStream });
if (inputStream != null) {
try {
return IOHelper.loadText(inputStream);
} finally {
IOHelper.close(inputStream);
}
}
return null;
} catch (ClassNotFoundException e) {
return null;
}
}
use of org.apache.camel.spi.ClassResolver in project camel by apache.
the class DefaultCamelContext method getLanguageParameterJsonSchema.
public String getLanguageParameterJsonSchema(String languageName) throws IOException {
// use the language factory finder to find the package name of the language class, which is the location
// where the documentation exists as well
FactoryFinder finder = getFactoryFinder(DefaultLanguageResolver.LANGUAGE_RESOURCE_PATH);
try {
Class<?> clazz = null;
try {
clazz = finder.findClass(languageName);
} catch (NoFactoryAvailableException e) {
// ignore, i.e. if a component is an auto-configured spring-boot
// languages
}
if (clazz == null) {
return null;
}
String packageName = clazz.getPackage().getName();
packageName = packageName.replace('.', '/');
String path = packageName + "/" + languageName + ".json";
ClassResolver resolver = getClassResolver();
InputStream inputStream = resolver.loadResourceAsStream(path);
log.debug("Loading language JSON Schema for: {} using class resolver: {} -> {}", new Object[] { languageName, resolver, inputStream });
if (inputStream != null) {
try {
return IOHelper.loadText(inputStream);
} finally {
IOHelper.close(inputStream);
}
}
return null;
} catch (ClassNotFoundException e) {
return null;
}
}
use of org.apache.camel.spi.ClassResolver 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);
}
Aggregations