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

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

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

Mapper.aliasForAttribute介绍

[英]Returns an alias for a single field defined in an specific type.
[中]返回特定类型中定义的单个字段的别名。

代码示例

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

public String aliasForAttribute(String attribute) {
  return delegate.aliasForAttribute(attribute);
}

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

/**
 * @deprecated since 1.3, use combination of {@link #serializedMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)}
 */
@Deprecated
public String aliasForAttribute(Class definedIn, String fieldName) {
  return delegate.aliasForAttribute(definedIn, fieldName);
}

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

/**
 * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and
 *             {@link #getConverterFromItemType(String, Class, Class)}
 */
public String aliasForAttribute(Class definedIn, String fieldName) {
  return aliasForAttributeMapper.aliasForAttribute(definedIn, fieldName);
}

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

public String aliasForAttribute(String attribute) {
  return aliasForAttributeMapper.aliasForAttribute(attribute);
}

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

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

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

public void marshal(Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) {
  final Object source = serializationMethodInvoker.callWriteReplace(original);
  if (source.getClass() != original.getClass()) {
    writer.addAttribute(mapper.aliasForAttribute("resolves-to"), mapper.serializedClass(source.getClass()));
  }
  OwnerContext oc = OwnerContext.find(context);
  oc.startVisiting(writer, classOwnership.ownerOf(original.getClass()));
  try {
    doMarshal(source, writer, context);
  } finally {
    oc.stopVisiting();
  }
}

代码示例来源: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: jenkinsci/jenkins

public void visit(String fieldName, Class type, Class definedIn, Object value) {
    SingleValueConverter converter = mapper.getConverterFromItemType(fieldName, type, definedIn);
    if (converter == null) converter = mapper.getConverterFromItemType(fieldName, type);
    if (converter == null) converter = mapper.getConverterFromItemType(type);
    if (converter != null) {
      if (value != null) {
        final String str = converter.toString(value);
        if (str != null) {
          writer.addAttribute(mapper.aliasForAttribute(fieldName), str);
        }
      }
      seenAsAttributes.add(fieldName);
    }
  }
});

代码示例来源: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: jenkinsci/jenkins

private void writeField(String fieldName, String aliasName, Class fieldType, Class definedIn, Object newObj) {
  try {
    if (!mapper.shouldSerializeMember(definedIn, aliasName)) {
      return;
    }
    ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(definedIn, aliasName), fieldType);
    Class actualType = newObj.getClass();
    Class defaultType = mapper.defaultImplementationOf(fieldType);
    if (!actualType.equals(defaultType)) {
      String serializedClassName = mapper.serializedClass(actualType);
      if (!serializedClassName.equals(mapper.serializedClass(defaultType))) {
        writer.addAttribute(mapper.aliasForSystemAttribute("class"), serializedClassName);
      }
    }
    if (seenFields.contains(aliasName)) {
      writer.addAttribute(mapper.aliasForAttribute("defined-in"), mapper.serializedClass(definedIn));
    }
    Field field = reflectionProvider.getField(definedIn,fieldName);
    marshallField(context, newObj, field);
    writer.endNode();
  } catch (RuntimeException e) {
    // intercept an exception so that the stack trace shows how we end up marshalling the object in question
    throw new RuntimeException("Failed to serialize "+definedIn.getName()+"#"+fieldName+" for "+source.getClass(),e);
  }
}

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

fieldName, type, definedIn);
if (converter != null) {
  final String attribute = mapper.aliasForAttribute(mapper.serializedMember(
    definedIn, fieldName));
  if (value != null) {

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.xstream-java8

/**
 * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and
 *             {@link #getConverterFromItemType(String, Class, Class)}
 */
public String aliasForAttribute(Class definedIn, String fieldName) {
  return aliasForAttributeMapper.aliasForAttribute(definedIn, fieldName);
}

代码示例来源:origin: org.sonatype.nexus.xstream/xstream

/**
 * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)} 
 */
public String aliasForAttribute(Class definedIn, String fieldName) {
  return wrapped.aliasForAttribute(definedIn, fieldName);
}

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

/**
 * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)} 
 */
public String aliasForAttribute(Class definedIn, String fieldName) {
  return wrapped.aliasForAttribute(definedIn, fieldName);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * @deprecated since 1.3, use combination of {@link #serializedMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)}
 */
@Deprecated
public String aliasForAttribute(Class definedIn, String fieldName) {
  return delegate.aliasForAttribute(definedIn, fieldName);
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

public void marshal(Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) {
  final Object source = serializationMethodInvoker.callWriteReplace(original);
  if (source.getClass() != original.getClass()) {
    writer.addAttribute(mapper.aliasForAttribute("resolves-to"), mapper.serializedClass(source.getClass()));
  }
  doMarshal(source, writer, context);
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

public void marshal(Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) {
  final Object source = serializationMethodInvoker.callWriteReplace(original);
  if (source.getClass() != original.getClass()) {
    writer.addAttribute(mapper.aliasForAttribute("resolves-to"), mapper.serializedClass(source.getClass()));
  }
  doMarshal(source, writer, context);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

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: org.jvnet.hudson.main/hudson-core

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: org.eclipse.hudson.main/hudson-core

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);
}

相关文章