本文整理汇总了Java中javax.xml.bind.annotation.XmlType.propOrder方法的典型用法代码示例。如果您正苦于以下问题:Java XmlType.propOrder方法的具体用法?Java XmlType.propOrder怎么用?Java XmlType.propOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.bind.annotation.XmlType
的用法示例。
在下文中一共展示了XmlType.propOrder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPropertyOrder
import javax.xml.bind.annotation.XmlType; //导入方法依赖的package包/类
private static int getPropertyOrder(final Map<String, Integer> propMap, final Class<?> beanClass, final int offset) {
int index = offset;
if (beanClass.getSuperclass() != null) {
index = getPropertyOrder(propMap, beanClass.getSuperclass(), offset);
}
final XmlType xmlTypeAnnotation = beanClass.getAnnotation(XmlType.class);
if (xmlTypeAnnotation != null && xmlTypeAnnotation.propOrder() != null && !xmlTypeAnnotation.propOrder()[0].isEmpty()) {
for (final String propName : xmlTypeAnnotation.propOrder()) {
propMap.put(propName, index++);
}
} else {
try {
final BeanInfo beanInfo = Introspector.getBeanInfo(beanClass, beanClass.getSuperclass());
for (final PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) {
propMap.put(propertyDescriptor.getName(), index++);
}
} catch (final IntrospectionException e) {
throw new JXPathException(e);
}
}
return index;
}
示例2: getPropOrderUncached
import javax.xml.bind.annotation.XmlType; //导入方法依赖的package包/类
private List<String> getPropOrderUncached(Class<? extends Object> beanClass) {
List<String> propOrder;
// Superclass first!
Class superclass = beanClass.getSuperclass();
if (superclass == null || superclass.equals(Object.class) || superclass.getAnnotation(XmlType.class) == null) {
propOrder = new ArrayList<>();
} else {
propOrder = new ArrayList<>(getPropOrder(superclass));
}
XmlType xmlType = beanClass.getAnnotation(XmlType.class);
if (xmlType == null) {
throw new IllegalArgumentException("Cannot marshall "+beanClass+" it does not have @XmlType annotation");
}
String[] myPropOrder = xmlType.propOrder();
for (String myProp: myPropOrder) {
if (StringUtils.isNotBlank(myProp)) {
// some properties starts with underscore..we don't want to serialize them with underscore, so remove it..
if (myProp.startsWith("_")){
myProp = myProp.replace("_", "");
}
propOrder.add(myProp);
}
}
Field[] fields = beanClass.getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(XmlAttribute.class)) {
propOrder.add(field.getName());
}
}
Method[] methods = beanClass.getDeclaredMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(XmlAttribute.class)) {
propOrder.add(getPropertyNameFromGetter(method.getName()));
}
}
return propOrder;
}
示例3: buildFields
import javax.xml.bind.annotation.XmlType; //导入方法依赖的package包/类
private static JaxInfo[] buildFields(Class<?> clazz, String defaultNS) throws SecurityException, NoSuchFieldException, ClassNotFoundException {
ArrayList<JaxInfo> fields = null; // allow for lazy instantiation, because many structures won't have XmlType
Class<?> cls = clazz;
// Build up Method names from JAXB Annotations
XmlType xt;
while((xt = cls.getAnnotation(XmlType.class))!=null) {
if(fields==null)fields = new ArrayList<JaxInfo>();
for(String field : xt.propOrder()) {
if("".equals(field)) break; // odd bug. "" returned when no fields exist, rather than empty array
Field rf = cls.getDeclaredField(field);
Class<?> ft = rf.getType();
boolean required = false;
boolean nillable = false;
String xmlName = field;
String namespace = defaultNS;
XmlElement xe = rf.getAnnotation(XmlElement.class);
if(xe!=null) {
xmlName=xe.name();
required = xe.required();
nillable = false;
if(DEFAULT.equals(xmlName)) {
xmlName = field;
}
namespace = xe.namespace();
if(DEFAULT.equals(namespace)) {
namespace = defaultNS;
}
}
// If object is a List, then it is possible multiple, per XML/JAXB evaluation
if(ft.isAssignableFrom(List.class)) {
Type t = rf.getGenericType();
String classname = t.toString();
int start = classname.indexOf('<');
int end = classname.indexOf('>');
Class<?> genClass = Class.forName(classname.substring(start+1, end));
xe = genClass.getAnnotation(XmlElement.class);
if(xe!=null && !DEFAULT.equals(xe.namespace())) {
namespace = xe.namespace();
}
// add recursed recursed member, marked as array
fields.add(new JaxInfo(xmlName,namespace,genClass,buildFields(genClass,namespace), genClass.equals(String.class),true,required,nillable));
} else {
boolean isString = ft.equals(String.class) || ft.equals(XMLGregorianCalendar.class);
// add recursed member
fields.add(new JaxInfo(xmlName,namespace,ft,buildFields(ft,namespace),isString,false,required,nillable));
}
}
cls = cls.getSuperclass();
};
if(fields!=null) {
JaxInfo[] rv = new JaxInfo[fields.size()];
fields.toArray(rv);
return rv;
} else {
return null;
}
}
示例4: getPropOrderUncached
import javax.xml.bind.annotation.XmlType; //导入方法依赖的package包/类
private List<String> getPropOrderUncached(Class<?> beanClass) {
List<String> propOrder;
// Superclass first!
Class superclass = beanClass.getSuperclass();
if (superclass == null || superclass.equals(Object.class) || superclass.getAnnotation(XmlType.class) == null) {
propOrder = new ArrayList<>();
} else {
propOrder = new ArrayList<>(getPropOrder(superclass));
}
XmlType xmlType = beanClass.getAnnotation(XmlType.class);
if (xmlType == null) {
throw new IllegalArgumentException("Cannot marshall "+beanClass+" it does not have @XmlType annotation");
}
String[] myPropOrder = xmlType.propOrder();
for (String myProp: myPropOrder) {
if (StringUtils.isNotBlank(myProp)) {
// some properties starts with underscore..we don't want to serialize them with underscore, so remove it..
if (myProp.startsWith("_")){
myProp = myProp.replace("_", "");
}
propOrder.add(myProp);
}
}
Field[] fields = beanClass.getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(XmlAttribute.class)) {
propOrder.add(field.getName());
}
}
Method[] methods = beanClass.getDeclaredMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(XmlAttribute.class)) {
propOrder.add(getPropertyNameFromGetter(method.getName()));
}
}
return propOrder;
}