当前位置: 首页>>代码示例>>Java>>正文


Java XStreamAlias类代码示例

本文整理汇总了Java中com.thoughtworks.xstream.annotations.XStreamAlias的典型用法代码示例。如果您正苦于以下问题:Java XStreamAlias类的具体用法?Java XStreamAlias怎么用?Java XStreamAlias使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XStreamAlias类属于com.thoughtworks.xstream.annotations包,在下文中一共展示了XStreamAlias类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: xmlBean2Map

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
private Map<String, String> xmlBean2Map(Object bean) {
  Map<String, String> result = Maps.newHashMap();
  for (Entry<String, Reflect> entry : Reflect.on(bean).fields().entrySet()) {
    Reflect reflect = entry.getValue();
    if (reflect.get() == null) {
      continue;
    }

    try {
      Field field = bean.getClass().getDeclaredField(entry.getKey());
      if (field.isAnnotationPresent(XStreamAlias.class)) {
        result.put(field.getAnnotation(XStreamAlias.class).value(),
            reflect.get().toString());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

  }

  return result;
}
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:23,代码来源:WxMpPayServiceImpl.java

示例2: existsCDATA

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
/**
 * 功能描述:检查字段是否存在XStreamCDATA标签
 * 
 * @param clazz
 *            属性类型
 * @param fieldAlias
 *            XStream 属性名称
 * @return boolean 是否
 */
private static boolean existsCDATA(Class<?> clazz, String fieldAlias) {
	// scan fields
	Field[] fields = clazz.getDeclaredFields();
	for (Field field : fields) {
		// 1. exists XStreamCDATA
		if (null != field.getAnnotation(XStream2Field.class)) {
			XStreamAlias xStreamAlias = field
					.getAnnotation(XStreamAlias.class);
			// 2. exists XStreamAlias
			if (null != xStreamAlias) {
				if (fieldAlias.equals(xStreamAlias.value()))// matched
					return true;
			} else {// not exists XStreamAlias
				if (fieldAlias.equals(field.getName()))
					return true;
			}
		}
	}
	return false;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:30,代码来源:XStreamFacade.java

示例3: loadXML

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
public static SPStoryWorldData loadXML(File xmlFile) throws FileNotFoundException {
	
	
	FileReader reader = new FileReader(xmlFile);
	XStream xstream = new XStream(new DomDriver());
	xstream.autodetectAnnotations(true);
	xstream.alias(SPStoryWorldData.class.getAnnotation(XStreamAlias.class).value(), SPStoryWorldData.class);
	Object obj = xstream.fromXML(reader);
	try {
		reader.close();
	} catch (IOException e) {
	}
	if (!(obj instanceof SPStoryWorldData)) throw new RuntimeException("file " + xmlFile.getAbsolutePath() + " doesn't contain a xml with SPStoryWorldData");
	SPStoryWorldData data = (SPStoryWorldData) obj;
	data.file = xmlFile.getAbsolutePath();
	return data;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:18,代码来源:SPStoryWorldData.java

示例4: processAliasAnnotation

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
private void processAliasAnnotation(final Class<?> type, final Set<Class<?>> types) {
    final XStreamAlias aliasAnnotation = type.getAnnotation(XStreamAlias.class);
    if (aliasAnnotation != null) {
        if (classAliasingMapper == null) {
            throw new InitializationException("No " + ClassAliasingMapper.class.getName() + " available");
        }
        classAliasingMapper.addClassAlias(aliasAnnotation.value(), type);
        if (aliasAnnotation.impl() != Void.class) {
            // Alias for Interface/Class with an impl
            defaultImplementationsMapper.addDefaultImplementation(aliasAnnotation.impl(), type);
            if (type.isInterface()) {
                types.add(aliasAnnotation.impl()); // alias Interface's impl
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:AnnotationMapper.java

示例5: test

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
public void test() throws NoSuchFieldException, SecurityException {

    WxSendRedpackRequest request = new WxSendRedpackRequest();
    request.setMchBillno("123");
    request.setActName("ab");
    for (Entry<String, Reflect> entry : Reflect.on(request).fields().entrySet()) {
      Reflect reflect = entry.getValue();
      if (reflect.get() == null) {
        continue;
      }

      Field field = WxSendRedpackRequest.class.getDeclaredField(entry.getKey());
      if (field.isAnnotationPresent(XStreamAlias.class)) {
        System.err.println(reflect.get() + "  =  " + field.getAnnotation(XStreamAlias.class).value());
      }
    }

  }
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:19,代码来源:WxSendRedpackRequestTest.java

示例6: processAliasAnnotation

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
private void processAliasAnnotation(Class<?> paramClass, Set<Class<?>> paramSet)
{
  XStreamAlias localXStreamAlias = (XStreamAlias)paramClass.getAnnotation(XStreamAlias.class);
  if (localXStreamAlias != null)
  {
    if (this.classAliasingMapper == null)
      throw new InitializationException("No " + ClassAliasingMapper.class.getName() + " available");
    this.classAliasingMapper.addClassAlias(localXStreamAlias.value(), paramClass);
    if (localXStreamAlias.impl() != Void.class)
    {
      this.defaultImplementationsMapper.addDefaultImplementation(localXStreamAlias.impl(), paramClass);
      if (paramClass.isInterface())
        paramSet.add(localXStreamAlias.impl());
    }
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:17,代码来源:AnnotationMapper.java

示例7: getFieldMap

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
private Map<String, Field> getFieldMap(List<Field> fields) {
  Map<String, Field> fieldMap = Maps.uniqueIndex(fields, new Function<Field, String>() {
    @Override
    public String apply(Field field) {
      if (field.isAnnotationPresent(XStreamAlias.class)) {
        return field.getAnnotation(XStreamAlias.class).value();
      }
      return field.getName();
    }
  });
  return fieldMap;
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:13,代码来源:WxPayOrderNotifyResultConverter.java

示例8: xmlBean2Map

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
/**
 * 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象
 *
 * @param bean 包含@XStreamAlias的xml bean对象
 * @return map对象
 */
public static Map<String, String> xmlBean2Map(Object bean) {
  Map<String, String> result = Maps.newHashMap();
  List<Field> fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields()));
  fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields()));
  for (Field field : fields) {
    try {
      boolean isAccessible = field.isAccessible();
      field.setAccessible(true);
      if (field.get(bean) == null) {
        field.setAccessible(isAccessible);
        continue;
      }

      if (field.isAnnotationPresent(XStreamAlias.class)) {
        result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString());
      }

      field.setAccessible(isAccessible);
    } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
      e.printStackTrace();
    }

  }

  return result;
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:33,代码来源:BeanUtils.java

示例9: processFieldAliasAnnotation

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
private void processFieldAliasAnnotation(final Field field) {
    final XStreamAlias aliasAnnotation = field.getAnnotation(XStreamAlias.class);
    if (aliasAnnotation != null) {
        if (fieldAliasingMapper == null) {
            throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available");
        }
        fieldAliasingMapper.addFieldAlias(aliasAnnotation.value(), field.getDeclaringClass(), field.getName());
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:AnnotationMapper.java

示例10: xmlBean2Map

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
/**
 * 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象
 *
 * @param bean 包含@XStreamAlias的xml bean对象
 * @return map对象
 */
public static Map<String, String> xmlBean2Map(Object bean) {
  Map<String, String> result = Maps.newHashMap();
  List<Field> fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields()));
  fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields()));
  for (Field field : fields) {
    try {
      boolean isAccessible = field.isAccessible();
      field.setAccessible(true);
      if (field.get(bean) == null) {
        field.setAccessible(isAccessible);
        continue;
      }

      if (field.isAnnotationPresent(XStreamAlias.class)) {
        result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString());
      } else if (!Modifier.isStatic(field.getModifiers())) {
        //忽略掉静态成员变量
        result.put(field.getName(), field.get(bean).toString());
      }

      field.setAccessible(isAccessible);
    } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
      log.error(e.getMessage(), e);
    }

  }

  return result;
}
 
开发者ID:binarywang,项目名称:weixin-java-tools,代码行数:36,代码来源:BeanUtils.java

示例11: processFieldAliasAnnotation

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
private void processFieldAliasAnnotation(Field paramField)
{
  XStreamAlias localXStreamAlias = (XStreamAlias)paramField.getAnnotation(XStreamAlias.class);
  if (localXStreamAlias != null)
  {
    if (this.fieldAliasingMapper == null)
      throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available");
    this.fieldAliasingMapper.addFieldAlias(localXStreamAlias.value(), paramField.getDeclaringClass(), paramField.getName());
  }
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:11,代码来源:AnnotationMapper.java

示例12: isReadable

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    return type.getAnnotation(XStreamAlias.class) != null || isXtreamable(genericType);
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:5,代码来源:XStreamAliasProvider.java

示例13: isWriteable

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    return type.getAnnotation(XStreamAlias.class) != null || isXtreamable(genericType);
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:5,代码来源:XStreamAliasProvider.java

示例14: isXtreamable

import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
private boolean isXtreamable(Type genericType) {
    return (genericType instanceof Class && ((Class) genericType).getAnnotation(XStreamAlias.class) != null);
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:5,代码来源:XStreamAliasProvider.java


注:本文中的com.thoughtworks.xstream.annotations.XStreamAlias类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。