本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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
}
}
}
}
示例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());
}
}
}
示例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());
}
}
}
示例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;
}
示例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;
}
示例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());
}
}
示例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;
}
示例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());
}
}
示例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);
}
示例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);
}
示例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);
}