Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider XMLElement's attribute while generating JAXB documentation #6

Closed
FroMage opened this issue Sep 15, 2011 · 5 comments
Closed
Labels
Milestone

Comments

@FroMage
Copy link
Owner

FroMage commented Sep 15, 2011

Reported by hv.vik...@gmail.com, Jul 28, 2011
JAXB documentation doesn't consider the XMLElement's attributes like defaultValue, nillable,required

Currently in the elements section: Name, Type and description are displayed.
Add more columns for required,defaultValue and nillable attributes.

@FroMage
Copy link
Owner Author

FroMage commented Sep 15, 2011

Comment 1 by hv.vik...@gmail.com, Aug 10, 2011
I added a patch to display XMLElement's attributes (required, nillable and defaultValue) in the Elements table.

-Vikram

@FroMage
Copy link
Owner Author

FroMage commented Sep 15, 2011

comment Comment 2 by project member stephane.epardaud, Aug 15, 2011
I agree with the feature request in general, but doesn't that presentation make it a bit too wide a table?
I'll see what alternatives there are.

I know this is painful, but could you try to redo your patch without the whitespace reformatting? I can't tell what is new and what isn't from this patch since you reformatted the whole file :( Sorry about that…

@FroMage
Copy link
Owner Author

FroMage commented Sep 15, 2011

comment Comment 3 by hv.vik...@gmail.com, Aug 15, 2011
Sorry about the formatting. Attached here is the patch.

@FroMage
Copy link
Owner Author

FroMage commented Sep 15, 2011

Index: src/main/java/com/lunatech/doclets/jax/jaxb/model/Element.java
===================================================================
--- src/main/java/com/lunatech/doclets/jax/jaxb/model/Element.java  (revision 138)
+++ src/main/java/com/lunatech/doclets/jax/jaxb/model/Element.java  (working copy)
@@ -19,6 +19,7 @@
 package com.lunatech.doclets.jax.jaxb.model;

 import com.sun.javadoc.AnnotationDesc;
+import com.sun.javadoc.AnnotationDesc.ElementValuePair;
 import com.sun.javadoc.ProgramElementDoc;

 public class Element extends JAXBMember {
@@ -41,4 +42,39 @@
   public String getWrapperName() {
     return wrapperName;
   }
+  
+  private ElementValuePair getElementAttribute(String attributeName){
+     if(xmlAnnotation != null && xmlAnnotation.elementValues() != null){
+         for (ElementValuePair elementValuePair : xmlAnnotation.elementValues()) {
+             if(attributeName.equals(elementValuePair.element().name())){
+                 return elementValuePair;
+             }
+         }
+     }
+     return null;
+  }
+  
+  public boolean isRequired(){
+     ElementValuePair elementValuePair = getElementAttribute("required");
+     if(elementValuePair != null){
+         return "true".equalsIgnoreCase(elementValuePair.value().toString());
+     }
+     return false;
+  }
+  
+  public boolean isNillable(){
+     ElementValuePair elementValuePair = getElementAttribute("nillable");
+     if(elementValuePair != null){
+         return "true".equalsIgnoreCase(elementValuePair.value().toString());
+     }
+     return false;
+  }
+  
+  public String getDefaultValue(){
+     ElementValuePair elementValuePair = getElementAttribute("defaultValue");
+     if(elementValuePair != null){
+         return elementValuePair.value().toString();
+     }
+     return "";
+  }
 }
Index: src/main/java/com/lunatech/doclets/jax/jaxb/writers/JAXBClassWriter.java
===================================================================
--- src/main/java/com/lunatech/doclets/jax/jaxb/writers/JAXBClassWriter.java    (revision 138)
+++ src/main/java/com/lunatech/doclets/jax/jaxb/writers/JAXBClassWriter.java    (working copy)
@@ -63,9 +63,66 @@
   }

   private void printElements() {
-    printMembers(jaxbClass.getElements(), "Elements", MemberType.Element);
+    printElements(jaxbClass.getElements(), "Elements", MemberType.Element);
   }

+  private void printElements(Collection<Element> members, String title,
+       MemberType type) {
+       if (members.isEmpty())
+         return;
+       tag("hr");
+       open("table class='info' id='" + title + "'");
+       boolean isValue = type == MemberType.Value;
+       around("caption class='TableCaption'", title);
+       open("tbody");
+       open("tr");
+       if (!isValue) {
+         around("th class='TableHeader'", "Name");
+       }
+       around("th class='TableHeader'", "Type");
+       around("th class='TableHeader'", "Required");
+       around("th class='TableHeader'", "Nillable");
+       around("th class='TableHeader'", "Default Value");
+       around("th class='TableHeader'", "Description");
+       close("tr");
+       for (Element member : members) {
+         open("tr");
+         if (!isValue) {
+           open("td id='m_" + member.getName() + "'");
+           print(member.getName());
+           if (type == MemberType.Element && ((Element) member).isWrapped()) {
+             print(" (wrapped by " + ((Element) member).getWrapperName() + ")");
+           }
+           if (member.getNamespace() != null) {
+             around("span class='namespace'", "(" + member.getNamespace() + ")");
+           }
+           close("td");
+         }
+         open("td");
+         printXMLMemberType(member, true);
+         close("td");
+         open("td");
+         print("" + member.isRequired());
+         close("td");
+         open("td");
+         print("" + member.isNillable());
+         close("td");
+         open("td");
+         print(member.getDefaultValue());
+         close("td");
+         open("td");
+         Doc javaDoc = member.getJavaDoc();
+         if (javaDoc != null && javaDoc.firstSentenceTags() != null)
+           writer.printSummaryComment(javaDoc);
+         close("td");
+         close("tr");
+
+       }
+       close("tbody");
+       close("table");
+     
+  }
+
   private void printAttributes() {
     printMembers(jaxbClass.getAttributes(), "Attributes", MemberType.Attribute);
   }

@FroMage
Copy link
Owner Author

FroMage commented Jan 2, 2012

Fixed now, thanks!

@FroMage FroMage closed this as completed Jan 2, 2012
FroMage added a commit that referenced this issue Jan 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant