public int getType() {
- if(isArray)return ARRAY;
- else if(members!=null)return OBJECT;
+ if (isArray)return ARRAY;
+ else if (members!=null)return OBJECT;
return DATA;
}
public JaxInfo getDerived(String derivedName) {
JaxInfo derived;
// Lazy Instantiation
- if(extensions == null) {
+ if (extensions == null) {
extensions = new HashMap<>();
derived = null;
} else {
derived = extensions.get(derivedName);
}
- if(derived == null) {
+ if (derived == null) {
//TODO for the moment, Classes are in same package
Package pkg = clss.getPackage();
try {
}
public static JaxInfo get(JaxInfo[] fields, String name) {
- for(JaxInfo f : fields) {
- if(name.equals(f.name)) return f;
+ for (JaxInfo f : fields) {
+ if (name.equals(f.name)) return f;
}
return null;
}
*/
public static JaxInfo build(Class<?> cls, String ... rootNns) throws SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException {
String defaultNS;
- if(rootNns.length>0 && rootNns[0]!=null) {
+ if (rootNns.length>0 && rootNns[0]!=null) {
defaultNS = rootNns[0];
} else {
Package pkg = cls.getPackage();
defaultNS = xs==null?"":xs.namespace();
}
String name;
- if(rootNns.length>1) {
+ if (rootNns.length>1) {
name = rootNns[1];
} else {
XmlRootElement xre = cls.getAnnotation(XmlRootElement.class);
- if(xre!=null) {
+ if (xre!=null) {
name = xre.name();
} else {
XmlType xt = cls.getAnnotation(XmlType.class);
- if(xt!=null) {
+ if (xt!=null) {
name=xt.name();
} else {
throw new ParseException("Need a JAXB Object with XmlRootElement, or stipulate in parms");
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<>();
- for(String field : xt.propOrder()) {
- if("".equals(field)) break; // odd bug. "" returned when no fields exist, rather than empty array
+ while ((xt = cls.getAnnotation(XmlType.class))!=null) {
+ if (fields==null)fields = new ArrayList<>();
+ 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();
String namespace = defaultNS;
XmlElement xe = rf.getAnnotation(XmlElement.class);
- if(xe!=null) {
+ if (xe!=null) {
xmlName=xe.name();
required = xe.required();
nillable = false;
- if(DEFAULT.equals(xmlName)) {
+ if (DEFAULT.equals(xmlName)) {
xmlName = field;
}
namespace = xe.namespace();
- if(DEFAULT.equals(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)) {
+ 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())) {
+ if (xe!=null && !DEFAULT.equals(xe.namespace())) {
namespace = xe.namespace();
}
// add recursed recursed member, marked as array
}
cls = cls.getSuperclass();
};
- if(fields!=null) {
+ if (fields!=null) {
JaxInfo[] rv = new JaxInfo[fields.size()];
fields.toArray(rv);
return rv;
public StringBuilder dump(StringBuilder sb, int idx) {
- for(int i=0;i<idx;++i)sb.append(' ');
+ for (int i=0;i<idx;++i)sb.append(' ');
sb.append("Field ");
sb.append(name);
sb.append(" [");
sb.append(clss.getName());
sb.append("] ");
- if(isArray)sb.append(" (array)");
- if(required)sb.append(" (required)");
- if(nillable)sb.append(" (nillable)");
- if(members!=null) {
- for(JaxInfo f : members) {
+ if (isArray)sb.append(" (array)");
+ if (required)sb.append(" (required)");
+ if (nillable)sb.append(" (nillable)");
+ if (members!=null) {
+ for (JaxInfo f : members) {
sb.append('\n');
f.dump(sb,idx+2);
}