當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。