@SuppressWarnings("rawtypes") public static Class getServerInterface(String packageName, String serviceName, boolean isSyncInterface, final CamelContext context) { String serverInterfaceName = null; Class serverInterface = null; try { if (isSyncInterface) { serverInterfaceName = packageName + "." + serviceName + "$" + ThriftConstants.THRIFT_SERVER_SYNC_INTERFACE_NAME; } else { serverInterfaceName = packageName + "." + serviceName + "$" + ThriftConstants.THRIFT_SERVER_ASYNC_INTERFACE_NAME; } serverInterface = context.getClassResolver().resolveMandatoryClass(serverInterfaceName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Unable to find server interface implementation for: " + serverInterfaceName); } return serverInterface; }
@SuppressWarnings({"rawtypes", "unchecked"}) public static Object constructClientInstance(String packageName, String serviceName, TTransport transport, ThriftExchangeProtocol exchangeProtocol, final ThriftNegotiationType negotiationType, final ThriftCompressionType compressionType, final CamelContext context) { Object clientInstance = null; Class[] constructorParamTypes = {TProtocol.class}; Object[] constructorParamValues = {constructSyncProtocol(transport, exchangeProtocol, negotiationType, compressionType)}; String clientClassName = packageName + "." + serviceName + "$" + ThriftConstants.THRIFT_SYNC_CLIENT_CLASS_NAME; try { Class clientClass = context.getClassResolver().resolveMandatoryClass(clientClassName); Constructor clientConstructor = clientClass.getConstructor(constructorParamTypes); clientInstance = clientConstructor.newInstance(constructorParamValues); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Thrift client class not found: " + clientClassName); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Thrift client class constructor not found: " + clientClassName); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | SecurityException e) { throw new IllegalArgumentException(e); } return clientInstance; }
@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"); } }
/** * Loading the saxon transformer class * * @param context * @return */ private TransformerFactory getSaxonTransformerFactory(CamelContext context) { final ClassResolver resolver = context.getClassResolver(); try { Class<TransformerFactory> factoryClass = resolver.resolveMandatoryClass( XsltEndpoint.SAXON_TRANSFORMER_FACTORY_CLASS_NAME, TransformerFactory.class, XsltComponent.class.getClassLoader()); if (factoryClass != null) { return ObjectHelper.newInstance(factoryClass); } } catch (ClassNotFoundException e) { throw new RuntimeException("Cannot load the saxon transformer class", e); } return null; }
@SuppressWarnings({"unchecked", "rawtypes"}) public static Object constructServerProcessor(String packageName, String serviceName, Object serverImplementation, boolean isSyncProcessor, final CamelContext context) { String processorClassName = null; Class serverInterface = null; Object processorInstance = null; try { if (isSyncProcessor) { processorClassName = packageName + "." + serviceName + "$" + ThriftConstants.THRIFT_SERVER_SYNC_PROCESSOR_CLASS; serverInterface = getServerInterface(packageName, serviceName, isSyncProcessor, context); } else { processorClassName = packageName + "." + serviceName + "$" + ThriftConstants.THRIFT_SERVER_ASYNC_PROCESSOR_CLASS; serverInterface = getServerInterface(packageName, serviceName, isSyncProcessor, context); } Class processorClass = context.getClassResolver().resolveMandatoryClass(processorClassName); Constructor procesorConstructor = processorClass.getConstructor(new Class[] {serverInterface}); processorInstance = procesorConstructor.newInstance(serverImplementation); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Unable to find server processor for: " + processorClassName); } catch (NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException("Processor class instance not found for: " + processorClassName); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new IllegalArgumentException(e); } return processorInstance; }
@SuppressWarnings({"rawtypes", "unchecked"}) public static Object constructAsyncClientInstance(String packageName, String serviceName, TNonblockingTransport transport, ThriftExchangeProtocol exchangeProtocol, final CamelContext context) { Object asynClientInstance = null; Class[] getterParamTypes = {TNonblockingTransport.class}; Class[] constructorParamTypes = {TAsyncClientManager.class, TProtocolFactory.class}; String clientClassName = packageName + "." + serviceName + "$" + ThriftConstants.THRIFT_ASYNC_CLIENT_CLASS_NAME + "$" + ThriftConstants.THRIFT_ASYNC_CLIENT_FACTORY_NAME; try { Class clientClass = context.getClassResolver().resolveMandatoryClass(clientClassName); Constructor factoryConstructor = clientClass.getConstructor(constructorParamTypes); Object factoryInstance = factoryConstructor.newInstance(new TAsyncClientManager(), constructAsyncProtocol(exchangeProtocol)); Method asyncClientGetter = ReflectionHelper.findMethod(clientClass, ThriftConstants.THRIFT_ASYNC_CLIENT_GETTER_NAME, getterParamTypes); if (asyncClientGetter == null) { throw new IllegalArgumentException("Thrift async client getter not found: " + clientClassName + "." + ThriftConstants.THRIFT_ASYNC_CLIENT_GETTER_NAME); } asynClientInstance = ObjectHelper.invokeMethod(asyncClientGetter, factoryInstance, transport); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Thrift sync client class not found: " + clientClassName); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Thrift sync client factory class not found: " + clientClassName); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | IOException | SecurityException e) { throw new IllegalArgumentException(e); } return asynClientInstance; }
public static int parseSqlType(Token sqlTypeToken, ClassResolver classResolver) { String sqlType = sqlTypeToken.toString(); //if number then use it(probably Vendor spesific SQL-type) if (sqlTypeToken.kind == SSPTParserConstants.NUMBER) { return Integer.valueOf(sqlType); } //if contains . if (sqlType.contains(".")) { String className; String fieldName; try { className = sqlType.substring(0, sqlType.lastIndexOf(".")); fieldName = sqlType.substring(sqlType.lastIndexOf(".") + 1); } catch (Exception ex) { throw new ParseRuntimeException("Failed to parse class.field:" + sqlType); } try { Class clazz = classResolver.resolveMandatoryClass(className); return getFieldInt(clazz, fieldName); } catch (ClassNotFoundException e) { throw new ParseRuntimeException("Class for " + className + " not found", e); } } //Loop-up from "Standard" types return getFieldInt(Types.class, sqlType); }
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); }
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; }
partialClass = camelContext.getClassResolver().resolveMandatoryClass(partClassFromHeader, Object.class); } catch (ClassNotFoundException e) { throw new JAXBException(e);
clazz = (Class<T>) exchange.getContext().getClassResolver().resolveMandatoryClass(handledName);
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { if (usingIterator) { if (clazzName != null) { Class<?> clazz = exchange.getContext().getClassResolver().resolveMandatoryClass(clazzName); ASN1GenericIterator asn1GenericIterator = new ASN1GenericIterator(clazz, stream); return asn1GenericIterator; } ASN1MessageIterator asn1MessageIterator = new ASN1MessageIterator(exchange, stream); return asn1MessageIterator; } else { ASN1Primitive asn1Record = null; byte[] asn1Bytes; try (ASN1InputStream ais = new ASN1InputStream(stream); ByteArrayOutputStream asn1Out = new ByteArrayOutputStream();) { while (ais.available() > 0) { asn1Record = ais.readObject(); asn1Out.write(asn1Record.getEncoded()); } asn1Bytes = asn1Out.toByteArray(); } return asn1Bytes; } }
@Override public Optional<ProcessorDefinition> handle(Extension step, ProcessorDefinition route, SyndesisRouteBuilder routeBuilder) { final CamelContext context = routeBuilder.getContext(); final TypeConverter converter = context.getTypeConverter(); final String target = step.getName(); if (!Strings.isEmpty(target)) { try { final Class<SyndesisStepExtension> clazz = context.getClassResolver().resolveMandatoryClass(target, SyndesisStepExtension.class); final SyndesisStepExtension stepExtension = context.getInjector().newInstance(clazz); final Map<String, Object> props = new HashMap<>(step.getProperties()); try { IntrospectionSupport.setProperties(context, converter, stepExtension, props); } catch (Exception e) { throw new IllegalStateException(e); } return stepExtension.configure(context, route, props); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } } return Optional.of(route); } }
@Override public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { InputStream berOut = null; if (usingIterator) { if (clazzName != null) { Class<?> clazz = exchange.getContext().getClassResolver().resolveMandatoryClass(clazzName); encodeGenericTypeObject(exchange, clazz, stream); return; } Object record = exchange.getIn().getBody(); if (record instanceof ASN1Primitive) { ASN1Primitive asn1Primitive = ObjectHelper.cast(ASN1Primitive.class, record); berOut = new ByteArrayInputStream(asn1Primitive.getEncoded()); } else if (record instanceof byte[]) { berOut = new ByteArrayInputStream(ObjectHelper.cast(byte[].class, record)); } } else { byte[] byteInput = exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class, exchange, graph); berOut = new ByteArrayInputStream(byteInput); } try { IOHelper.copy(berOut, stream); } finally { IOHelper.close(berOut, stream); } }
@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); }
Class<?> clazz = getCamelContext().getClassResolver().resolveMandatoryClass(resourceClass); answer.addResourceClass(clazz); while (it.hasNext()) { String name = (String) it.next(); Class<?> clazz = getCamelContext().getClassResolver().resolveMandatoryClass(name); answer.addResourceClass(clazz);
@Override @SuppressWarnings("unchecked") protected void doStart() throws Exception { ObjectHelper.notNull(camelContext, "CamelContext"); if (context == null) { // if context not injected, create one and resolve partial class up front so they are ready to be used context = createContext(); } introspector = context.createJAXBIntrospector(); if (partClass != null) { partialClass = camelContext.getClassResolver().resolveMandatoryClass(partClass, Object.class); } if (namespacePrefixRef != null) { namespacePrefix = CamelContextHelper.mandatoryLookup(camelContext, namespacePrefixRef, Map.class); } if (namespacePrefix != null) { namespacePrefixMapper = NamespacePrefixMapperFactory.newNamespacePrefixMapper(camelContext, namespacePrefix); } typeConverter = camelContext.getTypeConverter(); if (schema != null) { cachedSchema = createSchema(getSources()); } LOG.debug("JaxbDataFormat [prettyPrint={}, objectFactory={}]", prettyPrint, objectFactory); }
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 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); }
Class<?> targetModel = endpoint.getCamelContext().getClassResolver().resolveMandatoryClass( endpoint.getConfiguration().getTargetModel());