当前位置: 首页>>代码示例>>Java>>正文


Java TypeConverter.mandatoryConvertTo方法代码示例

本文整理汇总了Java中org.apache.camel.TypeConverter.mandatoryConvertTo方法的典型用法代码示例。如果您正苦于以下问题:Java TypeConverter.mandatoryConvertTo方法的具体用法?Java TypeConverter.mandatoryConvertTo怎么用?Java TypeConverter.mandatoryConvertTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.camel.TypeConverter的用法示例。


在下文中一共展示了TypeConverter.mandatoryConvertTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convert

import org.apache.camel.TypeConverter; //导入方法依赖的package包/类
private static Object convert(TypeConverter typeConverter, Class<?> type, Object value)
    throws URISyntaxException, NoTypeConversionAvailableException {
    if (typeConverter != null) {
        return typeConverter.mandatoryConvertTo(type, value);
    }
    if (type == URI.class) {
        return new URI(value.toString());
    }
    PropertyEditor editor = PropertyEditorManager.findEditor(type);
    if (editor != null) {
        // property editor is not thread safe, so we need to lock
        Object answer;
        synchronized (LOCK) {
            editor.setAsText(value.toString());
            answer = editor.getValue();
        }
        return answer;
    }
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:IntrospectionSupport.java

示例2: getMandatoryBody

import org.apache.camel.TypeConverter; //导入方法依赖的package包/类
public <T> T getMandatoryBody(Class<T> type) throws InvalidPayloadException {
    // eager same instance type test to avoid the overhead of invoking the type converter
    // if already same type
    if (type.isInstance(body)) {
        return type.cast(body);
    }

    Exchange e = getExchange();
    if (e != null) {
        TypeConverter converter = e.getContext().getTypeConverter();
        try {
            return converter.mandatoryConvertTo(type, e, getBody());
        } catch (Exception cause) {
            throw new InvalidPayloadException(e, type, this, cause);
        }
    }
    throw new InvalidPayloadException(e, type, this);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:MessageSupport.java

示例3: extractOffset

import org.apache.camel.TypeConverter; //导入方法依赖的package包/类
private static long extractOffset(String now, TypeConverter typeConverter) throws NoTypeConversionAvailableException {
    Matcher matcher = NOW_PATTERN.matcher(now);
    if (matcher.matches()) {
        String op = matcher.group(1);
        String remainder = matcher.group(2);

        // convert remainder to a time millis (eg we have a String -> long converter that supports
        // syntax with hours, days, minutes: eg 5h30m for 5 hours and 30 minutes).
        long offset = typeConverter.mandatoryConvertTo(long.class, remainder);

        if ("+".equals(op)) {
            return offset;
        } else {
            return -1 * offset;
        }
    }

    return 0;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:MailConverters.java

示例4: asBeanParameter

import org.apache.camel.TypeConverter; //导入方法依赖的package包/类
private String asBeanParameter(TypeConverter converter, Map.Entry<String, Object> entry) {
    try {
        return "bean." + entry.getKey() + "=" + converter.mandatoryConvertTo(String.class, entry.getValue());
    } catch (NoTypeConversionAvailableException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:8,代码来源:FunctionHandler.java

示例5: consumeOption

import org.apache.camel.TypeConverter; //导入方法依赖的package包/类
private <T> void consumeOption(String name, Class<T> type, Consumer<T> consumer) throws NoTypeConversionAvailableException {
    final TypeConverter converter = getCamelContext().getTypeConverter();
    final Object val = getOptions().get(name);
    final T result = converter.mandatoryConvertTo(type, val);

    consumer.accept(result);

    LOGGER.debug("Consume option {}", name);
    getOptions().remove(name);
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:11,代码来源:SqlStartConnectorComponent.java

示例6: convertToMandatoryType

import org.apache.camel.TypeConverter; //导入方法依赖的package包/类
/**
 * Converts the value to the given expected type or throws an exception
 *
 * @return the converted value
 * @throws TypeConversionException is thrown if error during type conversion
 * @throws NoTypeConversionAvailableException} if no type converters exists to convert to the given type
 */
public static <T> T convertToMandatoryType(Exchange exchange, Class<T> type, Object value)
    throws TypeConversionException, NoTypeConversionAvailableException {
    CamelContext camelContext = exchange.getContext();
    ObjectHelper.notNull(camelContext, "CamelContext of Exchange");
    TypeConverter converter = camelContext.getTypeConverter();
    if (converter != null) {
        return converter.mandatoryConvertTo(type, exchange, value);
    }
    throw new NoTypeConversionAvailableException(value, type);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:ExchangeHelper.java

示例7: attemptConvertToList

import org.apache.camel.TypeConverter; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private List<DBObject> attemptConvertToList(List insertList, Exchange exchange) throws CamelMongoDbException {
    List<DBObject> dbObjectList = new ArrayList<DBObject>(insertList.size());
    TypeConverter converter = exchange.getContext().getTypeConverter();
    for (Object item : insertList) {
        try {
            DBObject dbObject = converter.mandatoryConvertTo(DBObject.class, item);
            dbObjectList.add(dbObject);
        } catch (Exception e) {
            throw new CamelMongoDbException("MongoDB operation = insert, Assuming List variant of MongoDB insert operation, but List contains non-DBObject items", e);
        }
    }
    return dbObjectList;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:MongoDbProducer.java

示例8: convertWithTypeConverter

import org.apache.camel.TypeConverter; //导入方法依赖的package包/类
@Test
public void convertWithTypeConverter(TypeConverter converter) throws NoTypeConversionAvailableException {
    TypeConverterInput input = new TypeConverterInput();
    input.setProperty("property value is [{{property2}}]");

    TypeConverterOutput output = converter.mandatoryConvertTo(TypeConverterOutput.class, input);

    assertThat(output.getProperty(), is(equalTo("property value is [value 2]")));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:InjectedTypeConverterTest.java


注:本文中的org.apache.camel.TypeConverter.mandatoryConvertTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。