本文整理了Java中com.thoughtworks.xstream.mapper.Mapper.defaultImplementationOf()
方法的一些代码示例,展示了Mapper.defaultImplementationOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mapper.defaultImplementationOf()
方法的具体详情如下:
包路径:com.thoughtworks.xstream.mapper.Mapper
类名称:Mapper
方法名:defaultImplementationOf
暂无
代码示例来源:origin: jenkinsci/jenkins
public Class defaultImplementationOf(Class type) {
return delegate.defaultImplementationOf(type);
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
public Class defaultImplementationOf(Class type) {
return defaultImplementationOfMapper.defaultImplementationOf(type);
}
代码示例来源:origin: jenkinsci/jenkins
private Map writeValueToImplicitCollection(UnmarshallingContext context, Object value, Map implicitCollections, Object result, String itemFieldName) {
String fieldName = mapper.getFieldNameForItemTypeAndName(context.getRequiredType(), value.getClass(), itemFieldName);
if (fieldName != null) {
if (implicitCollections == null) {
implicitCollections = new HashMap(); // lazy instantiation
}
Collection collection = (Collection) implicitCollections.get(fieldName);
if (collection == null) {
Class fieldType = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, null));
if (!Collection.class.isAssignableFrom(fieldType)) {
throw new ObjectAccessException("Field " + fieldName + " of " + result.getClass().getName() +
" is configured for an implicit Collection, but field is of type " + fieldType.getName());
}
if (pureJavaReflectionProvider == null) {
pureJavaReflectionProvider = new PureJavaReflectionProvider();
}
collection = (Collection)pureJavaReflectionProvider.newInstance(fieldType);
reflectionProvider.writeField(result, fieldName, collection, null);
implicitCollections.put(fieldName, collection);
}
collection.add(value);
}
return implicitCollections;
}
代码示例来源:origin: geoserver/geoserver
protected Class impl(Class interfce) {
// special case case classes, they don't get registered as default implementations
// only concrete classes do
if (interfce == ServiceInfo.class) {
return ServiceInfoImpl.class;
}
if (interfce == StoreInfo.class) {
return StoreInfoImpl.class;
}
if (interfce == ResourceInfo.class) {
return ResourceInfoImpl.class;
}
Class clazz = getXStream().getMapper().defaultImplementationOf(interfce);
if (clazz == null) {
throw new RuntimeException("No default mapping for " + interfce);
}
return clazz;
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
protected Object createCollection(Class type) {
ErrorWritingException ex = null;
Class defaultType = mapper().defaultImplementationOf(type);
try {
return defaultType.newInstance();
} catch (InstantiationException e) {
ex = new ConversionException("Cannot instantiate default collection", e);
} catch (IllegalAccessException e) {
ex = new ObjectAccessException("Cannot instantiate default collection", e);
}
ex.add("collection-type", type.getName());
ex.add("default-type", defaultType.getName());
throw ex;
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
private void writeField(String propertyName, Class fieldType, Object newObj) {
Class actualType = newObj.getClass();
Class defaultType = mapper.defaultImplementationOf(fieldType);
String serializedMember = mapper.serializedMember(source.getClass(), propertyName);
ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedMember, actualType);
if (!actualType.equals(defaultType) && classAttributeName != null) {
writer.addAttribute(classAttributeName, mapper.serializedClass(actualType));
}
context.convertAnother(newObj);
writer.endNode();
}
代码示例来源: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
public Object convertAnother(Object parent, Class type, Converter converter) {
type = mapper.defaultImplementationOf(type);
if (converter == null) {
converter = converterLookup.lookupConverterForType(type);
} else {
if (!converter.canConvert(type)) {
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);
}
代码示例来源: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: com.thoughtworks.xstream/xstream
collection = new ArraysList(physicalFieldType);
} else {
Class fieldType = mapper.defaultImplementationOf(physicalFieldType);
if (!(Collection.class.isAssignableFrom(fieldType) || Map.class
.isAssignableFrom(fieldType))) {
代码示例来源:origin: com.thoughtworks.xstream/xstream
final Class defaultType = mapper.defaultImplementationOf(fieldType[0]);
if (!actualType.equals(defaultType)) {
final String serializedClassName = mapper.serializedClass(actualType);
代码示例来源:origin: com.thoughtworks.xstream/xstream
public void writeField(String fieldName, String aliasName, Class fieldType,
Class definedIn, Object newObj) {
Class actualType = newObj != null ? newObj.getClass() : fieldType;
ExtendedHierarchicalStreamWriterHelper.startNode(writer, aliasName != null
? aliasName
: mapper.serializedMember(sourceType, fieldName), actualType);
if (newObj != null) {
Class defaultType = mapper.defaultImplementationOf(fieldType);
if (!actualType.equals(defaultType)) {
String serializedClassName = mapper.serializedClass(actualType);
if (!serializedClassName.equals(mapper.serializedClass(defaultType))) {
String attributeName = mapper.aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, serializedClassName);
}
}
}
final Field defaultField = (Field)defaultFieldDefinition.get(fieldName);
if (defaultField.getDeclaringClass() != definedIn) {
String attributeName = mapper.aliasForSystemAttribute("defined-in");
if (attributeName != null) {
writer.addAttribute(
attributeName, mapper.serializedClass(definedIn));
}
}
Field field = reflectionProvider.getField(definedIn, fieldName);
marshallField(context, newObj, field);
}
writer.endNode();
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
type = mapper.realClass(classAttribute);
} else {
type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(
result, fieldName, classDefiningField));
代码示例来源:origin: com.thoughtworks.xstream/xstream
type = mapper.realClass(classAttribute);
} else {
type = mapper.defaultImplementationOf(field.getType());
代码示例来源:origin: com.thoughtworks.xstream/xstream
writtenClassWrapper[0] = true;
writer.startNode(mapper.serializedClass(currentType[0]));
if (currentType[0] != mapper.defaultImplementationOf(currentType[0])) {
String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
if (classAttributeName != null) {
if (currentType[0] != mapper.defaultImplementationOf(currentType[0])) {
String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
if (classAttributeName != null) {
代码示例来源:origin: com.thoughtworks.xstream/xstream
ExtendedHierarchicalStreamWriterHelper.startNode(
writer, mapper.serializedMember(source.getClass(), field.getName()), actualType);
Class defaultType = mapper.defaultImplementationOf(field.getType());
if (!actualType.equals(defaultType)) {
String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
代码示例来源: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();
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
if (classAttribute == null) {
currentType[0] = mapper.defaultImplementationOf(mapper.realClass(nodeName));
} else {
currentType[0] = mapper.realClass(classAttribute);
代码示例来源:origin: org.apache.shindig/shindig-common
private Class<?> determineType(HierarchicalStreamReader reader,
Object result, String fieldName) {
final String classAttributeName = mapper.attributeForAlias("class");
String classAttribute = reader.getAttribute(classAttributeName);
if (classAttribute != null) {
return mapper.realClass(classAttribute);
} else {
return mapper.defaultImplementationOf(beanProvider.getPropertyType(
result, fieldName));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!