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


Java ConversionException类代码示例

本文整理汇总了Java中com.thoughtworks.xstream.converters.ConversionException的典型用法代码示例。如果您正苦于以下问题:Java ConversionException类的具体用法?Java ConversionException怎么用?Java ConversionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createReverseEngineeredCallbackOfProperType

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
private Callback createReverseEngineeredCallbackOfProperType(final Callback callback, final int index,
        final Map<? super Object, ? super Object> callbackIndexMap) {
    Class<?> iface = null;
    Class<?>[] interfaces = callback.getClass().getInterfaces();
    for (int i = 0; i < interfaces.length; i++) {
        if (Callback.class.isAssignableFrom(interfaces[i])) {
            iface = interfaces[i];
            if (iface == Callback.class) {
                final ConversionException exception = new ConversionException("Cannot handle CGLIB callback");
                exception.add("CGLIB callback type", callback.getClass().getName());
                throw exception;
            }
            interfaces = iface.getInterfaces();
            if (Arrays.asList(interfaces).contains(Callback.class)) {
                break;
            }
            i = -1;
        }
    }
    return (Callback)Proxy.newProxyInstance(iface.getClassLoader(), new Class[]{iface},
        new ReverseEngineeringInvocationHandler(index, callbackIndexMap));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:CGLIBEnhancedConverter.java

示例2: unmarshal

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    String methodName = null;
    String declaringClassName = null;

    while ((methodName == null || declaringClassName == null) && reader.hasMoreChildren()) {
        reader.moveDown();

        if (reader.getNodeName().equals("name")) {
            methodName = reader.getValue();
        } else if (reader.getNodeName().equals("clazz")) {
            declaringClassName = reader.getValue();
        }
        reader.moveUp();
    }

    final Class<?> declaringClass = (Class<?>)javaClassConverter.fromString(declaringClassName);
    try {
        return declaringClass.getDeclaredField(mapper.realMember(declaringClass, methodName));
    } catch (final NoSuchFieldException e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:JavaFieldConverter.java

示例3: fromString

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
@Override
public Object fromString(final String str) {
    final Matcher matcher = PATTERN.matcher(str);
    if (matcher.matches()) {
        final String declaringClass = matcher.group(1);
        final String methodName = matcher.group(2);
        final String fileName = matcher.group(3);
        if (fileName.equals("Unknown Source")) {
            return FACTORY.unknownSourceElement(declaringClass, methodName);
        } else if (fileName.equals("Native Method")) {
            return FACTORY.nativeMethodElement(declaringClass, methodName);
        } else {
            if (matcher.group(4) != null) {
                final int lineNumber = Integer.parseInt(matcher.group(5));
                return FACTORY.element(declaringClass, methodName, fileName, lineNumber);
            } else {
                return FACTORY.element(declaringClass, methodName, fileName);
            }
        }
    } else {
        throw new ConversionException("Could not parse StackTraceElement : " + str);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:StackTraceElementConverter.java

示例4: convertXStreamException

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
/**
    * Convert the given XStream exception to an appropriate exception from the
    * {@code org.springframework.oxm} hierarchy.
    * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
    * unmarshalling, since XStream itself does not make this distinction in its exception hierarchy.
    * @param ex XStream exception that occurred
    * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
    * or unmarshalling ({@code false})
    * @return the corresponding {@code XmlMappingException}
    */
protected XmlMappingException convertXStreamException(Exception ex, boolean marshalling) {
	if (ex instanceof StreamException || ex instanceof CannotResolveClassException ||
			ex instanceof ConversionException) {
		if (marshalling) {
			return new MarshallingFailureException("XStream marshalling exception",  ex);
		}
		else {
			return new UnmarshallingFailureException("XStream unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown XStream exception", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:XStreamMarshaller.java

示例5: marshal

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
@Override
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext context) {
    // get Picklist enum element class from array class
    Class<?> arrayClass = o.getClass();
    final Class<?> aClass = arrayClass.getComponentType();

    try {
        Method getterMethod = aClass.getMethod("value");
        final int length = Array.getLength(o);

        // construct a string of form value1;value2;...
        final StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < length; i++) {
            buffer.append((String) getterMethod.invoke(Array.get(o, i)));
            if (i < (length - 1)) {
                buffer.append(';');
            }
        }
        writer.setValue(buffer.toString());
    } catch (Exception e) {
        throw new ConversionException(
                String.format("Exception writing pick list value %s of type %s: %s",
                        o, o.getClass().getName(), e.getMessage()), e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:MultiSelectPicklistConverter.java

示例6: unmarshal

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    final String listValue = reader.getValue();
    // get Picklist enum element class from array class
    final Class<?> requiredArrayType = context.getRequiredType();
    final Class<?> requiredType = requiredArrayType.getComponentType();

    try {
        Method factoryMethod = requiredType.getMethod(FACTORY_METHOD, String.class);

        // parse the string of the form value1;value2;...
        final String[] value = listValue.split(";");
        final int length = value.length;
        final Object resultArray = Array.newInstance(requiredType, length);
        for (int i = 0; i < length; i++) {
            // use factory method to create object
            Array.set(resultArray, i, factoryMethod.invoke(null, value[i].trim()));
        }
        return resultArray;
    } catch (Exception e) {
        throw new ConversionException(
                String.format("Exception reading pick list value %s of type %s: %s",
                        listValue, requiredArrayType.getName(), e.getMessage()), e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:MultiSelectPicklistConverter.java

示例7: fromString

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
@Override
public Object fromString(String marshaledData)
{
   	String[] rows = marshaledData.split(";");
   	boolean[][] data = new boolean[rows.length][];
   	for(int i=0;i<rows.length;i++)
   	{
   		String[] columns = rows[i].split(",");
   		data[i] = new boolean[columns.length];
   		for(int j=0; j<columns.length; j++)
   		{
   			try
   			{
   				data[i][j] = Integer.parseInt(columns[j].trim()) > 0;
   			}
   			catch(NumberFormatException e)
   			{
   				throw new ConversionException("Element \"" + columns[j].trim() + "\" in row " + Integer.toString(i+1) + ", column " + Integer.toString(j+1) + " is not 1 or 0.", e); 
   			}
   		}
   	}
   	
       return data;
   }
 
开发者ID:langmo,项目名称:youscope,代码行数:25,代码来源:MeasuredWellsAndPositionsConverter.java

示例8: parseDate

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
public static Date parseDate(String value) {
	DateFormat formatter = new SimpleDateFormat(VISTA_DATE_FORMAT);
	Date date = null;
	if (value != null && !value.equals("")) {
		try {
			double dateTimeNumber = Double.parseDouble(value);
			DecimalFormat paddingFormatter = new DecimalFormat(
					"00000000.000000");
			value = paddingFormatter.format(dateTimeNumber);
			date = formatter.parse(value);
		} catch (ParseException e) {
			String msg = "can't parse \"" + value + "\" into a Date";
			throw new ConversionException(msg, e);
		}
	}
	return date;
}
 
开发者ID:VHAINNOVATIONS,项目名称:Telepathology,代码行数:18,代码来源:VistaDateConverter.java

示例9: getName

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
/**
 * Given a key, the escape method returns the filename which shall be used.
 *
 * @param key the key
 * @return the desired and escaped filename
 */
@Override
protected String getName(final Object key) {
    if (key == null) {
        return "[email protected]";
    }
    final Class<?> type = key.getClass();
    final Converter converter = getConverterLookup().lookupConverterForType(type);
    if (converter instanceof SingleValueConverter) {
        final SingleValueConverter svConverter = (SingleValueConverter)converter;
        return getMapper().serializedClass(type) + '@' + escape(svConverter.toString(key)) + ".xml";
    } else {
        final ConversionException exception = new ConversionException(
            "No SingleValueConverter available for key type");
        exception.add("key-type", type.getName());
        throw exception;
    }
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:24,代码来源:FilePersistenceStrategy.java

示例10: createReverseEngineeredCallbackOfProperType

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
private Callback createReverseEngineeredCallbackOfProperType(final Callback callback, final int index,
        final Map<? super Object, ? super Object> callbackIndexMap) {
    Class<?> iface = null;
    Class<?>[] interfaces = callback.getClass().getInterfaces();
    for (int i = 0; i < interfaces.length; i++) {
        if (Callback.class.isAssignableFrom(interfaces[i])) {
            iface = interfaces[i];
            if (iface == Callback.class) {
                final ConversionException exception = new ConversionException("Cannot handle CGLIB callback");
                exception.add("CGLIB-callback-type", callback.getClass().getName());
                throw exception;
            }
            interfaces = iface.getInterfaces();
            if (Arrays.asList(interfaces).contains(Callback.class)) {
                break;
            }
            i = -1;
        }
    }
    return (Callback)Proxy.newProxyInstance(iface.getClassLoader(), new Class[]{iface},
        new ReverseEngineeringInvocationHandler(index, callbackIndexMap));
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:23,代码来源:CGLIBEnhancedConverter.java

示例11: compare

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
private int compare(final String first, final String second) {
    int firstPosition = -1, secondPosition = -1;
    for (int i = 0; i < fieldOrder.length; i++) {
        if (fieldOrder[i].equals(first)) {
            firstPosition = i;
        }
        if (fieldOrder[i].equals(second)) {
            secondPosition = i;
        }
    }
    if (firstPosition == -1 || secondPosition == -1) {
        // field not defined!!!
        final ConversionException exception = new ConversionException(
            "Incomplete list of serialized fields for type");
        exception.add("sort-type", type.getName());
        throw exception;
    }
    return firstPosition - secondPosition;
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:20,代码来源:SortableFieldKeySorter.java

示例12: testUnmarshallerThrowsExceptionWithDebuggingInfo

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
public void testUnmarshallerThrowsExceptionWithDebuggingInfo() {
    try {
        xstream.fromXML(""
            + "<thing>\n" 
            + "  <one>string 1</one>\n" 
            + "  <two>another string</two>\n" 
            + "</thing>");
        fail("Error expected");
    } catch (ConversionException e) {
        assertEquals("java.lang.NumberFormatException",
                e.get("cause-exception"));
        assertEquals("For input string: \"another string\"",
                e.get("cause-message"));
        assertEquals(Integer.class.getName(),
                e.get("class"));
        assertEquals("/thing/two",
                e.get("path"));
        assertEquals("3",
                e.get("line number"));
        assertEquals("java.lang.Integer",
                e.get("required-type"));
        assertEquals(Thing.class.getName(),
            e.get("class[1]"));
    }
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:26,代码来源:ErrorTest.java

示例13: testInvalidXml

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
public void testInvalidXml() {
    try {
        xstream.fromXML(""
            + "<thing>\n" 
            + "  <one>string 1</one>\n" 
            + "  <two><<\n" 
            + "</thing>");
        fail("Error expected");
    } catch (ConversionException e) {
        assertEquals(StreamException.class.getName(),
                e.get("cause-exception"));
        assertNotNull(e.get("cause-message")); // depends on parser
        assertEquals("/thing/two",
                e.get("path"));
        assertEquals("3",
                e.get("line number"));
    }
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:19,代码来源:ErrorTest.java

示例14: testNonExistingMember

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
public void testNonExistingMember() {
    try {
        xstream.fromXML("" 
            + "<thing>\n" 
            + "  <one>string 1</one>\n" 
            + "  <three>3</three>\n" 
            + "</thing>");
        fail("Error expected");
    } catch (ConversionException e) {
        assertEquals("three",
                e.get("field"));
        assertEquals("/thing/three",
                e.get("path"));
        assertEquals("3",
                e.get("line number"));
    }
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:18,代码来源:ErrorTest.java

示例15: testThrowsForInvalidReference

import com.thoughtworks.xstream.converters.ConversionException; //导入依赖的package包/类
public void testThrowsForInvalidReference() {
    String xml = "" //
        + "<list>\n"
        + "  <thing>\n"
        + "    <field>Hello</field>\n"
        + "  </thing>\n"
        + "  <thing reference=\"foo\">\n"
        + "</list>";

    try {
        xstream.fromXML(xml);
        fail("Thrown " + ConversionException.class.getName() + " expected");
    } catch (final ConversionException e) {
        assertEquals("foo", e.get("reference"));
    }
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:17,代码来源:AbstractReferenceTest.java


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