本文整理汇总了Java中com.thoughtworks.xstream.converters.ConversionException.add方法的典型用法代码示例。如果您正苦于以下问题:Java ConversionException.add方法的具体用法?Java ConversionException.add怎么用?Java ConversionException.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thoughtworks.xstream.converters.ConversionException
的用法示例。
在下文中一共展示了ConversionException.add方法的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));
}
示例2: 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));
}
示例3: 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;
}
示例4: accept
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
@Override
public int accept(final Method method) {
if (!callbackIndexMap.containsKey(method)) {
final ConversionException exception = new ConversionException(
"CGLIB callback not detected in reverse engineering");
exception.add("CGLIB callback", method.toString());
throw exception;
}
return callbackIndexMap.get(method).intValue();
}
示例5: unmarshal
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
/**
* Deserialize an object from a hierarchical data structure (such as XML).
*
* @param root If present, the passed in object will have its fields populated, as opposed to XStream creating a new
* instance. Note, that this is a special use case! With the ReflectionConverter XStream will write
* directly into the raw memory area of the existing object. Use with care!
* @param dataHolder Extra data you can use to pass to your converters. Use this as you want. If not present,
* XStream shall create one lazily as needed.
* @throws XStreamException if the object cannot be deserialized
*/
public <T> T unmarshal(final HierarchicalStreamReader reader, final T root, final DataHolder dataHolder) {
try {
@SuppressWarnings("unchecked")
final T t = (T)marshallingStrategy.unmarshal(root, reader, dataHolder, converterLookup, mapper);
return t;
} catch (final ConversionException e) {
final Package pkg = getClass().getPackage();
final String version = pkg != null ? pkg.getImplementationVersion() : null;
e.add("version", version != null ? version : "not available");
throw e;
}
}
示例6: convertAnother
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
@Override
public Object convertAnother(final Object parent, Class<?> type, Converter converter) {
type = mapper.defaultImplementationOf(type);
if (converter == null) {
converter = converterLookup.lookupConverterForType(type);
} else {
if (!converter.canConvert(type)) {
final ConversionException e = new ConversionException("Explicit selected converter cannot handle type");
e.add("item-type", type.getName());
e.add("converter-type", converter.getClass().getName());
throw e;
}
}
return convert(parent, type, converter);
}
示例7: convert
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
@Override
protected Object convert(final Object parent, final Class<?> type, final Converter converter) {
if (parentStack.size() > 0) { // handles circular references
final R parentReferenceKey = parentStack.peek();
if (parentReferenceKey != null) {
// see AbstractCircularReferenceTest.testWeirdCircularReference()
if (!values.containsKey(parentReferenceKey)) {
values.put(parentReferenceKey, parent);
}
}
}
final Object result;
final String attributeName = getMapper().aliasForSystemAttribute("reference");
final String reference = attributeName == null ? null : reader.getAttribute(attributeName);
if (reference != null) {
final Object cache = values.get(getReferenceKey(reference));
if (cache == null) {
final ConversionException ex = new ConversionException("Invalid reference");
ex.add("reference", reference);
throw ex;
}
result = cache == NULL ? null : cache;
} else {
final R currentReferenceKey = getCurrentReferenceKey();
parentStack.push(currentReferenceKey);
result = super.convert(parent, type, converter);
if (currentReferenceKey != null) {
values.put(currentReferenceKey, result == null ? NULL : result);
}
parentStack.popSilently();
}
return result;
}
示例8: convertAnother
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
@Override
public void convertAnother(final Object item, Converter converter) {
if (converter == null) {
converter = converterLookup.lookupConverterForType(item.getClass());
} else {
if (!converter.canConvert(item.getClass())) {
final ConversionException e = new ConversionException("Explicit selected converter cannot handle item");
e.add("item-type", item.getClass().getName());
e.add("converter-type", converter.getClass().getName());
throw e;
}
}
convert(item, converter);
}
示例9: convert
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
protected void convert(final Object item, final Converter converter) {
if (parentObjects.containsId(item)) {
final ConversionException e = new CircularReferenceException("Recursive reference to parent object");
e.add("item-type", item.getClass().getName());
e.add("converter-type", converter.getClass().getName());
throw e;
}
parentObjects.associateId(item, "");
converter.marshal(item, writer, this);
parentObjects.removeId(item);
}
示例10: createConversionException
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
private ConversionException createConversionException(Throwable e) {
final ConversionException conversionException = new ConversionException(e);
StackTraceElement[] ste = e.getStackTrace();
if (ste!=null){
for(StackTraceElement top : ste){
String className=top.getClassName();
if (className.startsWith("org.apache.jmeter.")){
conversionException.add("first-jmeter-class", top.toString());
break;
}
}
}
return conversionException;
}
示例11: accept
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
@Override
public int accept(final Method method) {
if (!callbackIndexMap.containsKey(method)) {
final ConversionException exception = new ConversionException(
"CGLIB callback not detected in reverse engineering");
exception.add("CGLIB-callback", method.toString());
throw exception;
}
return callbackIndexMap.get(method).intValue();
}
示例12: add
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
@Override
public boolean add(final Object object) {
if (object == null) {
final boolean containsNull = !map.containsKey(null);
map.put(null, null);
return containsNull;
}
final Class<?> itemType = object.getClass();
if (keyFieldName != null) {
Field field = fieldCache.get(itemType);
if (field == null) {
field = reflectionProvider.getField(itemType, keyFieldName);
fieldCache.put(itemType, field);
}
if (field != null) {
final Object key = Fields.read(field, object);
return map.put(key, object) == null;
}
} else if (object instanceof Map.Entry) {
@SuppressWarnings("unchecked")
final Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>)object;
return map.put(entry.getKey(), entry.getValue()) == null;
}
final ConversionException exception = new ConversionException(
"Element is not defined as entry for implicit map");
exception.add("map-type", map.getClass().getName());
exception.add("element-type", object.getClass().getName());
throw exception;
}
示例13: fromString
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
@Override
public Object fromString(final String str) {
if (attributeMap.containsKey(str)) {
return attributeMap.get(str);
}
final ConversionException exception = new ConversionException("Cannot find attribute");
exception.add("attribute-type", type.getName());
exception.add("attribute-name", str);
throw exception;
}
示例14: fromString
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
@Override
public Year fromString(final String str) {
try {
return Year.of(Integer.parseInt(str));
} catch (final NumberFormatException ex) {
final ConversionException exception = new ConversionException("Cannot parse value as year", ex);
exception.add("value", str);
throw exception;
}
}
示例15: fromString
import com.thoughtworks.xstream.converters.ConversionException; //导入方法依赖的package包/类
@Override
public Object fromString(final String str) {
try {
return LocalDateTime.parse(str);
} catch (final DateTimeParseException e) {
final ConversionException exception = new ConversionException("Cannot parse value as local date time", e);
exception.add("value", str);
throw exception;
}
}