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

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

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

Mapper.defaultImplementationOf介绍

暂无

代码示例

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

  1. public Class defaultImplementationOf(Class type) {
  2. return delegate.defaultImplementationOf(type);
  3. }

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

  1. public Class defaultImplementationOf(Class type) {
  2. return defaultImplementationOfMapper.defaultImplementationOf(type);
  3. }

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

  1. private Map writeValueToImplicitCollection(UnmarshallingContext context, Object value, Map implicitCollections, Object result, String itemFieldName) {
  2. String fieldName = mapper.getFieldNameForItemTypeAndName(context.getRequiredType(), value.getClass(), itemFieldName);
  3. if (fieldName != null) {
  4. if (implicitCollections == null) {
  5. implicitCollections = new HashMap(); // lazy instantiation
  6. }
  7. Collection collection = (Collection) implicitCollections.get(fieldName);
  8. if (collection == null) {
  9. Class fieldType = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, null));
  10. if (!Collection.class.isAssignableFrom(fieldType)) {
  11. throw new ObjectAccessException("Field " + fieldName + " of " + result.getClass().getName() +
  12. " is configured for an implicit Collection, but field is of type " + fieldType.getName());
  13. }
  14. if (pureJavaReflectionProvider == null) {
  15. pureJavaReflectionProvider = new PureJavaReflectionProvider();
  16. }
  17. collection = (Collection)pureJavaReflectionProvider.newInstance(fieldType);
  18. reflectionProvider.writeField(result, fieldName, collection, null);
  19. implicitCollections.put(fieldName, collection);
  20. }
  21. collection.add(value);
  22. }
  23. return implicitCollections;
  24. }

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

  1. protected Class impl(Class interfce) {
  2. // special case case classes, they don't get registered as default implementations
  3. // only concrete classes do
  4. if (interfce == ServiceInfo.class) {
  5. return ServiceInfoImpl.class;
  6. }
  7. if (interfce == StoreInfo.class) {
  8. return StoreInfoImpl.class;
  9. }
  10. if (interfce == ResourceInfo.class) {
  11. return ResourceInfoImpl.class;
  12. }
  13. Class clazz = getXStream().getMapper().defaultImplementationOf(interfce);
  14. if (clazz == null) {
  15. throw new RuntimeException("No default mapping for " + interfce);
  16. }
  17. return clazz;
  18. }

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

  1. protected Object createCollection(Class type) {
  2. ErrorWritingException ex = null;
  3. Class defaultType = mapper().defaultImplementationOf(type);
  4. try {
  5. return defaultType.newInstance();
  6. } catch (InstantiationException e) {
  7. ex = new ConversionException("Cannot instantiate default collection", e);
  8. } catch (IllegalAccessException e) {
  9. ex = new ObjectAccessException("Cannot instantiate default collection", e);
  10. }
  11. ex.add("collection-type", type.getName());
  12. ex.add("default-type", defaultType.getName());
  13. throw ex;
  14. }
  15. }

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

  1. private void writeField(String propertyName, Class fieldType, Object newObj) {
  2. Class actualType = newObj.getClass();
  3. Class defaultType = mapper.defaultImplementationOf(fieldType);
  4. String serializedMember = mapper.serializedMember(source.getClass(), propertyName);
  5. ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedMember, actualType);
  6. if (!actualType.equals(defaultType) && classAttributeName != null) {
  7. writer.addAttribute(classAttributeName, mapper.serializedClass(actualType));
  8. }
  9. context.convertAnother(newObj);
  10. writer.endNode();
  11. }

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

  1. private Class determineType(HierarchicalStreamReader reader, boolean validField, Object result, String fieldName, Class definedInCls) {
  2. String classAttribute = reader.getAttribute(mapper.aliasForAttribute("class"));
  3. Class fieldType = reflectionProvider.getFieldType(result, fieldName, definedInCls);
  4. if (classAttribute != null) {
  5. Class specifiedType = mapper.realClass(classAttribute);
  6. if(fieldType.isAssignableFrom(specifiedType))
  7. // make sure that the specified type in XML is compatible with the field type.
  8. // this allows the code to evolve in more flexible way.
  9. return specifiedType;
  10. }
  11. if (!validField) {
  12. Class itemType = mapper.getItemTypeForItemFieldName(result.getClass(), fieldName);
  13. if (itemType != null) {
  14. return itemType;
  15. } else {
  16. return mapper.realClass(reader.getNodeName());
  17. }
  18. } else {
  19. return mapper.defaultImplementationOf(fieldType);
  20. }
  21. }

代码示例来源: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 Object convertAnother(Object parent, Class type, Converter converter) {
  2. type = mapper.defaultImplementationOf(type);
  3. if (converter == null) {
  4. converter = converterLookup.lookupConverterForType(type);
  5. } else {
  6. if (!converter.canConvert(type)) {
  7. ConversionException e = new ConversionException(
  8. "Explicit selected converter cannot handle type");
  9. e.add("item-type", type.getName());
  10. e.add("converter-type", converter.getClass().getName());
  11. throw e;
  12. }
  13. }
  14. return convert(parent, type, converter);
  15. }

代码示例来源: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. collection = new ArraysList(physicalFieldType);
  2. } else {
  3. Class fieldType = mapper.defaultImplementationOf(physicalFieldType);
  4. if (!(Collection.class.isAssignableFrom(fieldType) || Map.class
  5. .isAssignableFrom(fieldType))) {

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

  1. final Class defaultType = mapper.defaultImplementationOf(fieldType[0]);
  2. if (!actualType.equals(defaultType)) {
  3. final String serializedClassName = mapper.serializedClass(actualType);

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

  1. public void writeField(String fieldName, String aliasName, Class fieldType,
  2. Class definedIn, Object newObj) {
  3. Class actualType = newObj != null ? newObj.getClass() : fieldType;
  4. ExtendedHierarchicalStreamWriterHelper.startNode(writer, aliasName != null
  5. ? aliasName
  6. : mapper.serializedMember(sourceType, fieldName), actualType);
  7. if (newObj != null) {
  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. String attributeName = mapper.aliasForSystemAttribute("class");
  13. if (attributeName != null) {
  14. writer.addAttribute(attributeName, serializedClassName);
  15. }
  16. }
  17. }
  18. final Field defaultField = (Field)defaultFieldDefinition.get(fieldName);
  19. if (defaultField.getDeclaringClass() != definedIn) {
  20. String attributeName = mapper.aliasForSystemAttribute("defined-in");
  21. if (attributeName != null) {
  22. writer.addAttribute(
  23. attributeName, mapper.serializedClass(definedIn));
  24. }
  25. }
  26. Field field = reflectionProvider.getField(definedIn, fieldName);
  27. marshallField(context, newObj, field);
  28. }
  29. writer.endNode();
  30. }

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

  1. type = mapper.realClass(classAttribute);
  2. } else {
  3. type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(
  4. result, fieldName, classDefiningField));

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

  1. type = mapper.realClass(classAttribute);
  2. } else {
  3. type = mapper.defaultImplementationOf(field.getType());

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

  1. writtenClassWrapper[0] = true;
  2. writer.startNode(mapper.serializedClass(currentType[0]));
  3. if (currentType[0] != mapper.defaultImplementationOf(currentType[0])) {
  4. String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
  5. if (classAttributeName != null) {
  6. if (currentType[0] != mapper.defaultImplementationOf(currentType[0])) {
  7. String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
  8. if (classAttributeName != null) {

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

  1. ExtendedHierarchicalStreamWriterHelper.startNode(
  2. writer, mapper.serializedMember(source.getClass(), field.getName()), actualType);
  3. Class defaultType = mapper.defaultImplementationOf(field.getType());
  4. if (!actualType.equals(defaultType)) {
  5. String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);

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

  1. public void defaultReadObject() {
  2. if (serializationMembers.getSerializablePersistentFields(currentType[0]) != null) {
  3. readFieldsFromStream();
  4. return;
  5. }
  6. if (!reader.hasMoreChildren()) {
  7. return;
  8. }
  9. reader.moveDown();
  10. if (!reader.getNodeName().equals(ELEMENT_DEFAULT)) {
  11. throw new ConversionException("Expected <" + ELEMENT_DEFAULT + "/> element in readObject() stream");
  12. }
  13. while (reader.hasMoreChildren()) {
  14. reader.moveDown();
  15. String fieldName = mapper.realMember(currentType[0], reader.getNodeName());
  16. if (mapper.shouldSerializeMember(currentType[0], fieldName)) {
  17. String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
  18. final Class type;
  19. if (classAttribute != null) {
  20. type = mapper.realClass(classAttribute);
  21. } else {
  22. type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, currentType[0]));
  23. }
  24. Object value = context.convertAnother(result, type);
  25. reflectionProvider.writeField(result, fieldName, value, currentType[0]);
  26. }
  27. reader.moveUp();
  28. }
  29. reader.moveUp();
  30. }

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

  1. String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
  2. if (classAttribute == null) {
  3. currentType[0] = mapper.defaultImplementationOf(mapper.realClass(nodeName));
  4. } else {
  5. currentType[0] = mapper.realClass(classAttribute);

代码示例来源:origin: org.apache.shindig/shindig-common

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

相关文章