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

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

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

Mapper.aliasForSystemAttribute介绍

[英]Get the alias for a system attribute's name.
[中]获取系统属性名称的别名。

代码示例

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

  1. public String aliasForSystemAttribute(String attribute) {
  2. return delegate.aliasForSystemAttribute(attribute);
  3. }

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

  1. public String aliasForSystemAttribute(String attribute) {
  2. return aliasForSystemAttributeMapper.aliasForSystemAttribute(attribute);
  3. }

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

  1. public static String readClassAttribute(HierarchicalStreamReader reader, Mapper mapper) {
  2. String attributeName = mapper.aliasForSystemAttribute("resolves-to");
  3. String classAttribute = attributeName == null ? null : reader.getAttribute(attributeName);
  4. if (classAttribute == null) {
  5. attributeName = mapper.aliasForSystemAttribute("class");
  6. if (attributeName != null) {
  7. classAttribute = reader.getAttribute(attributeName);
  8. }
  9. }
  10. return classAttribute;
  11. }

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

  1. protected void fireValidReference(Object referenceKey) {
  2. String attributeName = getMapper().aliasForSystemAttribute("id");
  3. if (attributeName != null) {
  4. writer.addAttribute(attributeName, referenceKey.toString());
  5. }
  6. }
  7. }

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

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

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

  1. protected Object getCurrentReferenceKey() {
  2. String attributeName = getMapper().aliasForSystemAttribute("id");
  3. return attributeName == null ? null : reader.getAttribute(attributeName);
  4. }
  5. }

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

  1. @SuppressWarnings("unchecked")
  2. public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
  3. String attributeName = mapper.aliasForSystemAttribute("enum-type");
  4. if (attributeName == null) {
  5. throw new ConversionException("No EnumType specified for EnumSet");
  6. }
  7. Class enumTypeForSet = mapper.realClass(reader.getAttribute(attributeName));
  8. EnumSet set = EnumSet.noneOf(enumTypeForSet);
  9. String[] enumValues = reader.getValue().split(",");
  10. for (int i = 0; i < enumValues.length; i++) {
  11. String enumValue = enumValues[i];
  12. if(enumValue.length() > 0) {
  13. set.add(Enum.valueOf(enumTypeForSet, enumValue));
  14. }
  15. }
  16. return set;
  17. }

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

  1. private void writeField(String fieldName, String aliasName, Class fieldType, Class definedIn, Object newObj) {
  2. try {
  3. if (!mapper.shouldSerializeMember(definedIn, aliasName)) {
  4. return;
  5. }
  6. ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(definedIn, aliasName), fieldType);
  7. Class actualType = newObj.getClass();
  8. Class defaultType = mapper.defaultImplementationOf(fieldType);
  9. if (!actualType.equals(defaultType)) {
  10. String serializedClassName = mapper.serializedClass(actualType);
  11. if (!serializedClassName.equals(mapper.serializedClass(defaultType))) {
  12. writer.addAttribute(mapper.aliasForSystemAttribute("class"), serializedClassName);
  13. }
  14. }
  15. if (seenFields.contains(aliasName)) {
  16. writer.addAttribute(mapper.aliasForAttribute("defined-in"), mapper.serializedClass(definedIn));
  17. }
  18. Field field = reflectionProvider.getField(definedIn,fieldName);
  19. marshallField(context, newObj, field);
  20. writer.endNode();
  21. } catch (RuntimeException e) {
  22. // intercept an exception so that the stack trace shows how we end up marshalling the object in question
  23. throw new RuntimeException("Failed to serialize "+definedIn.getName()+"#"+fieldName+" for "+source.getClass(),e);
  24. }
  25. }

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

  1. public void marshal(Object original, final HierarchicalStreamWriter writer,
  2. final MarshallingContext context) {
  3. final Object source = serializationMembers.callWriteReplace(original);
  4. if (source != original && context instanceof ReferencingMarshallingContext) {
  5. ((ReferencingMarshallingContext)context).replace(original, source);
  6. }
  7. if (source.getClass() != original.getClass()) {
  8. String attributeName = mapper.aliasForSystemAttribute("resolves-to");
  9. if (attributeName != null) {
  10. writer.addAttribute(attributeName, mapper.serializedClass(source.getClass()));
  11. }
  12. context.convertAnother(source);
  13. } else {
  14. doMarshal(source, writer, context);
  15. }
  16. }

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

  1. @Override
  2. public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
  3. final boolean oldFormat = "custom".equals(reader.getAttribute(mapper.aliasForSystemAttribute("serialization")));
  4. if (oldFormat) {
  5. reader.moveDown();
  6. reader.moveDown();
  7. }
  8. final Map<String, Long> elements = new HashMap<>();
  9. while (reader.hasMoreChildren()) {
  10. reader.moveDown();
  11. final String name = reader.getNodeName();
  12. elements.put(oldFormat ? name : mapper.realMember(ValueRange.class, name), Long.valueOf(reader.getValue()));
  13. reader.moveUp();
  14. }
  15. if (oldFormat) {
  16. reader.moveUp();
  17. reader.moveUp();
  18. }
  19. return ValueRange.of(elements.get("minSmallest").longValue(), elements.get("minLargest").longValue(), elements
  20. .get("maxSmallest")
  21. .longValue(), elements.get("maxLargest").longValue());
  22. }

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

  1. public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  2. InvocationHandler invocationHandler = Proxy.getInvocationHandler(source);
  3. addInterfacesToXml(source, writer);
  4. writer.startNode("handler");
  5. String attributeName = mapper.aliasForSystemAttribute("class");
  6. if (attributeName != null) {
  7. writer.addAttribute(attributeName, mapper.serializedClass(invocationHandler.getClass()));
  8. }
  9. context.convertAnother(invocationHandler);
  10. writer.endNode();
  11. }

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

  1. protected static void marshalComparator(
  2. Mapper mapper,
  3. Comparator comparator,
  4. HierarchicalStreamWriter writer,
  5. MarshallingContext context) {
  6. if (comparator != null) {
  7. writer.startNode("comparator");
  8. writer.addAttribute(
  9. mapper.aliasForSystemAttribute("class"),
  10. mapper.serializedClass(comparator.getClass()));
  11. context.convertAnother(comparator);
  12. writer.endNode();
  13. }
  14. }

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

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

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

  1. @SuppressWarnings("unchecked")
  2. public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
  3. String attributeName = mapper().aliasForSystemAttribute("enum-type");
  4. if (attributeName == null) {
  5. throw new ConversionException("No EnumType specified for EnumMap");
  6. }
  7. Class type = mapper().realClass(reader.getAttribute(attributeName));
  8. EnumMap map = new EnumMap(type);
  9. populateMap(reader, context, map);
  10. return map;
  11. }
  12. }

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

  1. protected void writeItem(String name, Class type, Object item, MarshallingContext context,
  2. HierarchicalStreamWriter writer) {
  3. Class itemType = item == null ? Mapper.Null.class : item.getClass();
  4. ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
  5. if (!itemType.equals(type)) {
  6. String attributeName = mapper().aliasForSystemAttribute("class");
  7. if (attributeName != null) {
  8. writer.addAttribute(attributeName, mapper().serializedClass(itemType));
  9. }
  10. }
  11. if (item != null) {
  12. context.convertAnother(item);
  13. }
  14. writer.endNode();
  15. }

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

  1. /**
  2. * @deprecated As of 1.4.11 use {@link #writeCompleteItem(Object, MarshallingContext, HierarchicalStreamWriter)}
  3. * instead.
  4. */
  5. protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) {
  6. final Class itemType = item == null ? Mapper.Null.class : item.getClass();
  7. ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
  8. if (!itemType.equals(type)) {
  9. String attributeName = mapper().aliasForSystemAttribute("class");
  10. if (attributeName != null) {
  11. writer.addAttribute(attributeName, mapper().serializedClass(itemType));
  12. }
  13. }
  14. if (item != null) {
  15. context.convertAnother(item);
  16. }
  17. writer.endNode();
  18. }

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

  1. public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  2. EnumSet set = (EnumSet) source;
  3. Class enumTypeForSet = (Class) Fields.read(typeField, set);
  4. String attributeName = mapper.aliasForSystemAttribute("enum-type");
  5. if (attributeName != null) {
  6. writer.addAttribute(attributeName, mapper.serializedClass(enumTypeForSet));
  7. }
  8. writer.setValue(joinEnumValues(set));
  9. }

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

  1. protected void marshalComparator(Comparator comparator, HierarchicalStreamWriter writer,
  2. MarshallingContext context) {
  3. if (comparator != null) {
  4. writer.startNode("comparator");
  5. writer.addAttribute(mapper().aliasForSystemAttribute("class"),
  6. mapper().serializedClass(comparator.getClass()));
  7. context.convertAnother(comparator);
  8. writer.endNode();
  9. }
  10. }

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

  1. public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  2. Class type = (Class) Fields.read(typeField, source);
  3. String attributeName = mapper().aliasForSystemAttribute("enum-type");
  4. if (attributeName != null) {
  5. writer.addAttribute(attributeName, mapper().serializedClass(type));
  6. }
  7. super.marshal(source, writer, context);
  8. }

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

  1. protected Object instantiateNewInstance(HierarchicalStreamReader reader,
  2. UnmarshallingContext context) {
  3. String attributeName = mapper.aliasForSystemAttribute("resolves-to");
  4. String readResolveValue = attributeName == null ? null : reader
  5. .getAttribute(attributeName);
  6. Object currentObject = context.currentObject();
  7. if (currentObject != null) {
  8. return currentObject;
  9. } else if (readResolveValue != null) {
  10. return reflectionProvider.newInstance(mapper.realClass(readResolveValue));
  11. } else {
  12. return reflectionProvider.newInstance(context.getRequiredType());
  13. }
  14. }

相关文章