public static <T> Class getObjectFactory(CamelContext camelContext, Class<T> type) { if (camelContext == null) { return null; } if (type.getPackage() != null) { String objectFactoryClassName = type.getPackage().getName() + ".ObjectFactory"; return camelContext.getClassResolver().resolveClass(objectFactoryClassName); } return null; }
private Source[] getSources() throws FileNotFoundException, MalformedURLException { // we support multiple schema by delimiting they by ',' String[] schemas = schema.split(","); Source[] sources = new Source[schemas.length]; for (int i = 0; i < schemas.length; i++) { URL schemaUrl = ResourceHelper.resolveMandatoryResourceAsUrl(camelContext.getClassResolver(), schemas[i]); sources[i] = new StreamSource(schemaUrl.toExternalForm()); } return sources; }
private ComponentProxyCustomizer resolveCustomizer(CamelContext context, String customizerType) { Class<ComponentProxyCustomizer> type = context.getClassResolver().resolveClass(customizerType, ComponentProxyCustomizer.class); if (type == null) { throw new IllegalArgumentException("Unable to resolve a ComponentProxyCustomizer of type: " + customizerType); } final ComponentProxyCustomizer customizer = context.getInjector().newInstance(type); if (customizer == null) { throw new IllegalArgumentException("Unable to instantiate a ComponentProxyCustomizer of type: " + customizerType); } return customizer; } }
@SuppressWarnings("rawtypes") protected TBase loadDefaultInstance(final String className, final CamelContext context) throws CamelException, ClassNotFoundException { Class<?> instanceClass = context.getClassResolver().resolveMandatoryClass(className); if (TBase.class.isAssignableFrom(instanceClass)) { try { return (TBase)instanceClass.newInstance(); } catch (final Exception ex) { throw new CamelException("Can't set the defaultInstance of ThriftDataFormat with " + className + ", caused by " + ex); } } else { throw new CamelException("Can't set the defaultInstance of ThriftDataFormat with " + className + ", as the class is not a subClass of org.apache.thrift.TBase"); } }
private static ComponentCustomizer<Component> resolveCustomizer(final CamelContext context, final String customizerType) { @SuppressWarnings("rawtypes") final Class<ComponentCustomizer> type = context.getClassResolver().resolveClass(customizerType, ComponentCustomizer.class); if (type == null) { throw new IllegalArgumentException("Unable to resolve a ComponentProxyCustomizer of type: " + customizerType); } @SuppressWarnings("unchecked") final ComponentCustomizer<Component> customizer = context.getInjector().newInstance(type); if (customizer == null) { throw new IllegalArgumentException("Unable to instantiate a ComponentProxyCustomizer of type: " + customizerType); } return customizer; } }
/** * Resolves the XStream instance to be used by this data format. If XStream is not explicitly set, new instance will * be created and cached. * * @param context to be used during a configuration of the XStream instance * @return XStream instance used by this data format. */ public XStream getXStream(CamelContext context) { if (xstream == null) { xstream = createXStream(context.getClassResolver(), context.getApplicationContextClassLoader()); } return xstream; }
private ComponentProxyCustomizer resolveCustomizer(CamelContext context, String customizerType) { final ComponentProxyCustomizer customizer; Class<ComponentProxyCustomizer> type = context.getClassResolver().resolveClass(customizerType, ComponentProxyCustomizer.class); if (type == null) { throw new IllegalArgumentException("Unable to resolve a ComponentProxyCustomizer of type: " + customizerType); } customizer = context.getInjector().newInstance(type); if (customizer == null) { throw new IllegalArgumentException("Unable to instantiate a ComponentProxyCustomizer of type: " + customizerType); } return customizer; } }
public UnmarshallProcessor(final DataShape dataShape) { if (dataShape.getKind() == DataShapeKinds.JAVA) { type = camelContext.getClassResolver().resolveClass(dataShape.getType()); if (type == null) { throw new IllegalArgumentException("The specified class for shape `" + dataShape + "` cannot be found"); } } else { type = null; } }
static JaxbNamespacePrefixMapper newNamespacePrefixMapper(CamelContext camelContext, Map<String, String> namespaces) { // try to load the Sun JAXB 2.1 based Class<?> clazz = camelContext.getClassResolver().resolveClass(SUN_JAXB_21_MAPPER); if (clazz != null) { JaxbNamespacePrefixMapper mapper = (JaxbNamespacePrefixMapper) camelContext.getInjector().newInstance(clazz); mapper.setNamespaces(namespaces); return mapper; } throw new IllegalStateException("Cannot load CamelNamespacePrefixMapper class"); } }
@Override protected void doStart() throws Exception { ObjectHelper.notNull(camelContext, "camelContext"); // initialize xstream if (xstream == null) { xstream = createXStream(camelContext.getClassResolver(), camelContext.getApplicationContextClassLoader()); } }
private void createTransformerFactory() throws ClassNotFoundException { // provide the class loader of this component to work in OSGi environments Class<TransformerFactory> factoryClass = getCamelContext().getClassResolver().resolveMandatoryClass(SAXON_TRANSFORMER_FACTORY_CLASS_NAME, TransformerFactory.class, SchematronComponent.class.getClassLoader()); LOG.debug("Using TransformerFactoryClass {}", factoryClass); transformerFactory = getCamelContext().getInjector().newInstance(factoryClass); transformerFactory.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR, this.uriResolver)); transformerFactory.setAttribute(LINE_NUMBERING, true); }
@Override protected void doStart() throws Exception { if (xmlContext == null) { xmlContext = createXMLContext(getCamelContext().getClassResolver(), getCamelContext().getApplicationContextClassLoader()); } }
public final PGConnection initJdbc() throws Exception { PGConnection conn; if (this.getDatasource() != null) { conn = PgEventHelper.toPGConnection(this.getDatasource().getConnection()); } else { // ensure we can load the class ClassResolver classResolver = getCamelContext().getClassResolver(); classResolver.resolveMandatoryClass(PGDriver.class.getName(), PgEventComponent.class.getClassLoader()); conn = (PGConnection) DriverManager.getConnection("jdbc:pgsql://" + this.getHost() + ":" + this.getPort() + "/" + this.getDatabase(), this.getUser(), this.getPass()); } return conn; }
public DozerEndpoint(String endpointUri, Component component, DozerConfiguration configuration) throws Exception { super(endpointUri, component); this.configuration = configuration; variableMapper = new VariableMapper(); customMapper = new CustomMapper(getCamelContext().getClassResolver()); expressionMapper = new ExpressionMapper(); }
protected FTPClient createFtpClient() throws Exception { FTPClient client = new FTPClient(); // If we're in an OSGI environment, set the parser factory to // OsgiParserFactory, because commons-net uses Class.forName in their // default ParserFactory if (isOsgi()) { ClassResolver cr = getCamelContext().getClassResolver(); OsgiParserFactory opf = new OsgiParserFactory(cr); client.setParserFactory(opf); } return client; }
@Override protected void doStart() throws Exception { this.wrapperFactory = new CallableStatementWrapperFactory(jdbcTemplate, new TemplateParser(getCamelContext().getClassResolver()), isFunction()); super.doStart(); }
@SuppressWarnings("unchecked") public ResultSetIterator queryForStreamList(Connection connection, Statement statement, ResultSet rs) throws SQLException { if (outputClass == null) { RowMapper rowMapper = new ColumnMapRowMapper(); return new ResultSetIterator(connection, statement, rs, rowMapper); } else { Class<?> outputClzz = getCamelContext().getClassResolver().resolveClass(outputClass); RowMapper rowMapper = new BeanPropertyRowMapper(outputClzz); return new ResultSetIterator(connection, statement, rs, rowMapper); } }
@Override protected void doStart() throws Exception { super.doStart(); Processor target; if (EndpointHelper.isReferenceParameter(contentHandlerClass)) { ContentHandler handler = EndpointHelper.resolveReferenceParameter(getCamelContext(), contentHandlerClass.substring(1), ContentHandler.class, true); target = new StAXProcessor(handler); } else { Class<ContentHandler> clazz = getCamelContext().getClassResolver().resolveMandatoryClass(contentHandlerClass, ContentHandler.class); target = new StAXProcessor(clazz); } setProcessor(target); }
public TalendJob getJobInstance(boolean isMandatory) throws Exception { final JobResolver jobResolver = JobResolverHolder.getJobResolver(); if (null != jobResolver) { TalendESBJobFactory talendESBJobFactory = jobResolver.getJobService(owner, clazz, isMandatory); if (null != talendESBJobFactory) { return talendESBJobFactory.newTalendESBJob(); } if (!isMandatory) { return null; } } Class<?> jobType = this.getCamelContext().getClassResolver().resolveMandatoryClass(clazz); return (TalendJob) getCamelContext().getInjector().newInstance(jobType); }
public <T> T evaluate(Exchange exchange, Class<T> tClass) { OgnlContext oglContext = new OgnlContext(); // setup the class resolver from camel oglContext.setClassResolver(new CamelClassResolver(exchange.getContext().getClassResolver())); try { Object value = Ognl.getValue(expression, oglContext, new RootObject(exchange)); return exchange.getContext().getTypeConverter().convertTo(tClass, value); } catch (OgnlException e) { throw new ExpressionEvaluationException(this, exchange, e); } }