Merge "AAFcli.java -Declare "value" on a separate line"
[aaf/authz.git] / misc / rosetta / src / main / java / org / onap / aaf / misc / rosetta / JaxInfo.java
index edc5f78..b4d5782 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -39,7 +39,7 @@ public class JaxInfo {
     public static final int DATA = 0;
     public static final int ARRAY = 1;
     public static final int OBJECT = 2;
-    
+
     public final String name;
     public final Class<?> clss;
     public Map<String, JaxInfo> extensions; // Classes, which might be found at runtime, that extend this class.  Lazy Instantiation
@@ -50,7 +50,7 @@ public class JaxInfo {
     public final boolean nillable;
     public String ns;
     public boolean isObject() {return members!=null;}
-    
+
     private JaxInfo(String n, String ns, Class<?> c, JaxInfo[] members, boolean string, boolean array, boolean required, boolean nillable) {
         name = n;
         this.ns = ns;
@@ -62,25 +62,25 @@ public class JaxInfo {
         this.nillable = nillable;
         extensions = null;
     }
-    
+
 
     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 {
@@ -95,15 +95,15 @@ public class JaxInfo {
     }
 
     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;
     }
 
     /**
      * Build up JAXB Information (recursively)
-     * 
+     *
      * @param cls
      * @param rootNns
      * @return
@@ -117,7 +117,7 @@ public class JaxInfo {
     }
     /**
      * Build up JAXB Information (recursively)
-     * 
+     *
      * @param cls
      * @param rootNns
      * @return
@@ -128,7 +128,7 @@ public class JaxInfo {
      */
     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();
@@ -136,25 +136,25 @@ public class JaxInfo {
             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");
                 }
             }
         }
-        
+
         return new JaxInfo(name,defaultNS, cls,buildFields(cls,defaultNS),false,false,false,false);
     }
-    
+
     // Build up the name and members of this particular class
     // This is recursive, if a member is a JAXB Object as well.
     private static JaxInfo[] buildFields(Class<?> clazz, String defaultNS) throws SecurityException, NoSuchFieldException, ClassNotFoundException {
@@ -162,40 +162,40 @@ public class JaxInfo {
         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();
-                
+
                 boolean required = false;
                 boolean nillable = false;
                 String xmlName = field;
                 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
@@ -208,7 +208,7 @@ public class JaxInfo {
             }
             cls = cls.getSuperclass();
         };
-        if(fields!=null) {
+        if (fields!=null) {
             JaxInfo[] rv = new JaxInfo[fields.size()];
             fields.toArray(rv);
             return rv;
@@ -219,17 +219,17 @@ public class JaxInfo {
 
 
     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);
             }