com.thoughtworks.xstream.mapper.Mapper.realClass()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(315)

本文整理了Java中com.thoughtworks.xstream.mapper.Mapper.realClass()方法的一些代码示例,展示了Mapper.realClass()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mapper.realClass()方法的具体详情如下:
包路径:com.thoughtworks.xstream.mapper.Mapper
类名称:Mapper
方法名:realClass

Mapper.realClass介绍

[英]How a serialized class representation should be mapped back to a real class.
[中]序列化类表示应该如何映射回真实类。

代码示例

代码示例来源:origin: jenkinsci/jenkins

public Class realClass(String elementName) {
  return delegate.realClass(elementName);
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public Class realClass(String elementName) {
  return realClassMapper.realClass(elementName);
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public static Class readClassType(HierarchicalStreamReader reader, Mapper mapper) {
  String classAttribute = readClassAttribute(reader, mapper);
  Class type;
  if (classAttribute == null) {
    type = mapper.realClass(reader.getNodeName());
  } else {
    type = mapper.realClass(classAttribute);
  }
  return type;
}

代码示例来源:origin: jenkinsci/jenkins

private Class determineWhichClassDefinesField(HierarchicalStreamReader reader) {
  String definedIn = reader.getAttribute(mapper.aliasForAttribute("defined-in"));
  return definedIn == null ? null : mapper.realClass(definedIn);
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

private void readCallback(HierarchicalStreamReader reader, UnmarshallingContext context,
  List callbacksToEnhance, List callbacks) {
  Callback callback = (Callback)context.convertAnother(null, mapper.realClass(reader
    .getNodeName()));
  callbacks.add(callback);
  if (callback == null) {
    callbacksToEnhance.add(NoOp.INSTANCE);
  } else {
    callbacksToEnhance.add(callback);
  }
}

代码示例来源:origin: jenkinsci/jenkins

private Class determineType(HierarchicalStreamReader reader, boolean validField, Object result, String fieldName, Class definedInCls) {
  String classAttribute = reader.getAttribute(mapper.aliasForAttribute("class"));
  Class fieldType = reflectionProvider.getFieldType(result, fieldName, definedInCls);
  if (classAttribute != null) {
    Class specifiedType = mapper.realClass(classAttribute);
    if(fieldType.isAssignableFrom(specifiedType))
      // make sure that the specified type in XML is compatible with the field type.
      // this allows the code to evolve in more flexible way.
      return specifiedType;
  }
  if (!validField) {
    Class itemType = mapper.getItemTypeForItemFieldName(result.getClass(), fieldName);
    if (itemType != null) {
      return itemType;
    } else {
      return mapper.realClass(reader.getNodeName());
    }
  } else {
    return mapper.defaultImplementationOf(fieldType);
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

private Class readDeclaringClass(HierarchicalStreamReader reader) {
  String attributeName = mapper.aliasForSystemAttribute("defined-in");
  String definedIn = attributeName == null ? null : reader.getAttribute(attributeName);
  return definedIn == null ? null : mapper.realClass(definedIn);
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public Object fromString(String str) {
    try {
      return mapper.realClass(str);
    } catch (CannotResolveClassException e) {
      throw new ConversionException("Cannot load java class " + str, e.getCause());
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

protected Object instantiateNewInstance(HierarchicalStreamReader reader, UnmarshallingContext context) {
  String readResolveValue = reader.getAttribute(mapper.aliasForAttribute("resolves-to"));
  Class type = readResolveValue != null ? mapper.realClass(readResolveValue) : context.getRequiredType();
  Object currentObject = context.currentObject();
  if (currentObject != null) {
    if (type.isInstance(currentObject))
      return currentObject;
  }
  return reflectionProvider.newInstance(type);
}

代码示例来源:origin: AxonFramework/AxonFramework

@Override
public Class classForType(SerializedType type) {
  if (SerializedType.emptyType().equals(type)) {
    return Void.class;
  }
  try {
    return xStream.getMapper().realClass(type.getName());
  } catch (CannotResolveClassException e) {
    return UnknownSerializedType.class;
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
  final List list = new ArrayList();
  while (reader.hasMoreChildren()) {
    reader.moveDown();
    final Object item;
    final String className = HierarchicalStreams.readClassAttribute(reader, mapper);
    final Class itemType = className == null ? arrayType.getComponentType() : mapper.realClass(className);
    if (Mapper.Null.class.equals(itemType)) {
      item = null;
    } else {
      item = context.convertAnother(null, itemType);
    }
    list.add(item);
    reader.moveUp();
  }
  final Object array = Array.newInstance(arrayType.getComponentType(), list.size());
  for (int i = 0; i < list.size(); ++i) {
    Array.set(array, i, list.get(i));
  }
  return array;
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

@SuppressWarnings("unchecked")
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
  String attributeName = mapper.aliasForSystemAttribute("enum-type");
  if (attributeName == null) {
    throw new ConversionException("No EnumType specified for EnumSet");
  }
  Class enumTypeForSet = mapper.realClass(reader.getAttribute(attributeName));
  EnumSet set = EnumSet.noneOf(enumTypeForSet);
  String[] enumValues = reader.getValue().split(",");
  for (int i = 0; i < enumValues.length; i++) {
    String enumValue = enumValues[i];
    if(enumValue.length() > 0) {
      set.add(Enum.valueOf(enumTypeForSet, enumValue));
    }
  }
  return set;
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

protected Object readBareItem(final HierarchicalStreamReader reader, final UnmarshallingContext context,
      final Object current) {
    final String className = HierarchicalStreams.readClassAttribute(reader, mapper());
    final Class itemType = className == null ? type : mapper().realClass(className);
    if (Mapper.Null.class.equals(itemType)) {
      return null;
    } else {
      return context.convertAnother(current, itemType);
    }
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

protected Object readItem(Class type, HierarchicalStreamReader reader,
    UnmarshallingContext context, Object current) {
    String className = HierarchicalStreams.readClassAttribute(reader, mapper());
    Class itemType = className == null ? type : mapper().realClass(className);
    if (Mapper.Null.class.equals(itemType)) {
      return null;
    } else {
      return context.convertAnother(current, itemType);
    }
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

private Class determineType(HierarchicalStreamReader reader, Object result, String fieldName) {
  final String classAttributeName = classAttributeIdentifier != null ? classAttributeIdentifier : mapper.aliasForSystemAttribute("class");
  String classAttribute = classAttributeName == null ? null : reader.getAttribute(classAttributeName);
  if (classAttribute != null) {
    return mapper.realClass(classAttribute);
  } else {
    return mapper.defaultImplementationOf(beanProvider.getPropertyType(result, fieldName));
  }
}

代码示例来源:origin: geoserver/geoserver

@Override
  protected Object readItem(
      HierarchicalStreamReader reader, UnmarshallingContext context, Object current) {
    Class theClass = clazz;
    if (subclasses != null) {
      String attribute = reader.getAttribute("type");
      if (attribute != null) {
        theClass = mapper().realClass(attribute);
      }
    }
    return context.convertAnother(current, theClass, new ReferenceConverter(theClass));
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

@SuppressWarnings("unchecked")
  public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String attributeName = mapper().aliasForSystemAttribute("enum-type");
    if (attributeName == null) {
      throw new ConversionException("No EnumType specified for EnumMap");
    }
    Class type = mapper().realClass(reader.getAttribute(attributeName));
    EnumMap map = new EnumMap(type);
    populateMap(reader, context, map);
    return map;
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

/**
 * Given a filename, the unescape method returns the key which originated it.
 *
 * @param name the filename
 * @return the original key
 */
protected Object extractKey(final String name) {
  final String key = unescape(name.substring(0, name.length() - 4));
  if ("null@null".equals(key)) {
    return null;
  }
  final int idx = key.indexOf('@');
  if (idx < 0) {
    final ConversionException exception = new ConversionException("No valid key");
    exception.add("key", key);
    throw exception;
  }
  final Class type = getMapper().realClass(key.substring(0, idx));
  final Converter converter = getConverterLookup().lookupConverterForType(type);
  if (converter instanceof SingleValueConverter) {
    final SingleValueConverter svConverter = (SingleValueConverter)converter;
    return svConverter.fromString(key.substring(idx + 1));
  } else {
    final ConversionException exception = new ConversionException(
      "No SingleValueConverter available for key type");
    exception.add("key-type", type.getName());
    throw exception;
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

protected Object instantiateNewInstance(HierarchicalStreamReader reader,
  UnmarshallingContext context) {
  String attributeName = mapper.aliasForSystemAttribute("resolves-to");
  String readResolveValue = attributeName == null ? null : reader
    .getAttribute(attributeName);
  Object currentObject = context.currentObject();
  if (currentObject != null) {
    return currentObject;
  } else if (readResolveValue != null) {
    return reflectionProvider.newInstance(mapper.realClass(readResolveValue));
  } else {
    return reflectionProvider.newInstance(context.getRequiredType());
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public void defaultReadObject() {
  if (serializationMembers.getSerializablePersistentFields(currentType[0]) != null) {
    readFieldsFromStream();
    return;
  }
  if (!reader.hasMoreChildren()) {
    return;
  }
  reader.moveDown();
  if (!reader.getNodeName().equals(ELEMENT_DEFAULT)) {
    throw new ConversionException("Expected <" + ELEMENT_DEFAULT + "/> element in readObject() stream");
  }
  while (reader.hasMoreChildren()) {
    reader.moveDown();
    String fieldName = mapper.realMember(currentType[0], reader.getNodeName());
    if (mapper.shouldSerializeMember(currentType[0], fieldName)) {
      String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
      final Class type;
      if (classAttribute != null) {
        type = mapper.realClass(classAttribute);
      } else {
        type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, currentType[0]));
      }
      Object value = context.convertAnother(result, type);
      reflectionProvider.writeField(result, fieldName, value, currentType[0]);
    }
    reader.moveUp();
  }
  reader.moveUp();
}

相关文章