< prev index next >

src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/reader/xmlschema/bindinfo/BindInfo.java

Print this page




  62 import org.xml.sax.Locator;
  63 
  64 /**
  65  * Container for customization declarations.
  66  *
  67  * We use JAXB ourselves and parse this object from "xs:annotation".
  68  *
  69  * @author
  70  *     Kohsuke Kawaguchi (kohsuke,kawaguchi@sun.com)
  71  */
  72 @XmlRootElement(namespace= WellKnownNamespace.XML_SCHEMA,name="annotation")
  73 @XmlType(namespace=WellKnownNamespace.XML_SCHEMA,name="foobar")
  74 public final class BindInfo implements Iterable<BIDeclaration> {
  75 
  76     private BGMBuilder builder;
  77 
  78     @XmlLocation
  79     private Locator location;
  80 
  81     /**
  82      * Documentation taken from &lt;xs:documentation>s.
  83      */
  84     @XmlElement(namespace=WellKnownNamespace.XML_SCHEMA)
  85     private Documentation documentation;
  86 
  87     /**
  88      * Returns true if this {@link BindInfo} doesn't contain any useful
  89      * information.
  90      *
  91      * This flag is used to discard unused {@link BindInfo}s early to save memory footprint.
  92      */
  93     public boolean isPointless() {
  94         if(size()>0)     return false;
  95         if(documentation!=null && !documentation.contents.isEmpty())
  96             return false;
  97 
  98         return true;
  99     }
 100 
 101     private static final class Documentation {
 102         @XmlAnyElement


 195      * Gets the first declaration with a given name, or null
 196      * if none is found.
 197      */
 198     public <T extends BIDeclaration>
 199     T get( Class<T> kind ) {
 200         for( BIDeclaration decl : decls ) {
 201             if( kind.isInstance(decl) )
 202                 return kind.cast(decl);
 203         }
 204         return null; // not found
 205     }
 206 
 207     /**
 208      * Gets all the declarations
 209      */
 210     public BIDeclaration[] getDecls() {
 211         return decls.toArray(new BIDeclaration[decls.size()]);
 212     }
 213 
 214     /**
 215      * Gets the documentation parsed from &lt;xs:documentation>s.
 216      * The returned collection is to be added to {@link JDocComment#append(Object)}.
 217      * @return  maybe null.
 218      */
 219     public String getDocumentation() {
 220         // TODO: FIXME: correctly turn individual items to String including DOM
 221         if(documentation==null || documentation.contents==null) return null;
 222 
 223         StringBuilder buf = new StringBuilder();
 224         for (Object c : documentation.contents) {
 225             if(c instanceof String) {
 226                 buf.append(c.toString());
 227             }
 228             if(c instanceof Element) {
 229                 Transformer t = builder.getIdentityTransformer();
 230                 StringWriter w = new StringWriter();
 231                 try {
 232                     Writer fw = new FilterWriter(w) {
 233                         char[] buf = new char[1];
 234 
 235                         public void write(int c) throws IOException {


 336                     }
 337                 }
 338             }
 339             return customizationContext;
 340         } catch (JAXBException e) {
 341             throw new AssertionError(e);
 342         }
 343     }
 344 
 345     public static Unmarshaller getCustomizationUnmarshaller() {
 346         try {
 347             return getCustomizationContext().createUnmarshaller();
 348         } catch (JAXBException e) {
 349             throw new AssertionError(e);
 350         }
 351     }
 352 
 353     /**
 354      * Lazily parsed schema for the binding file.
 355      */
 356     public static SchemaCache bindingFileSchema = new SchemaCache("binding.xsd", BindInfo.class, true);
 357 }


  62 import org.xml.sax.Locator;
  63 
  64 /**
  65  * Container for customization declarations.
  66  *
  67  * We use JAXB ourselves and parse this object from "xs:annotation".
  68  *
  69  * @author
  70  *     Kohsuke Kawaguchi (kohsuke,kawaguchi@sun.com)
  71  */
  72 @XmlRootElement(namespace= WellKnownNamespace.XML_SCHEMA,name="annotation")
  73 @XmlType(namespace=WellKnownNamespace.XML_SCHEMA,name="foobar")
  74 public final class BindInfo implements Iterable<BIDeclaration> {
  75 
  76     private BGMBuilder builder;
  77 
  78     @XmlLocation
  79     private Locator location;
  80 
  81     /**
  82      * Documentation taken from {@code <xs:documentation>s}.
  83      */
  84     @XmlElement(namespace=WellKnownNamespace.XML_SCHEMA)
  85     private Documentation documentation;
  86 
  87     /**
  88      * Returns true if this {@link BindInfo} doesn't contain any useful
  89      * information.
  90      *
  91      * This flag is used to discard unused {@link BindInfo}s early to save memory footprint.
  92      */
  93     public boolean isPointless() {
  94         if(size()>0)     return false;
  95         if(documentation!=null && !documentation.contents.isEmpty())
  96             return false;
  97 
  98         return true;
  99     }
 100 
 101     private static final class Documentation {
 102         @XmlAnyElement


 195      * Gets the first declaration with a given name, or null
 196      * if none is found.
 197      */
 198     public <T extends BIDeclaration>
 199     T get( Class<T> kind ) {
 200         for( BIDeclaration decl : decls ) {
 201             if( kind.isInstance(decl) )
 202                 return kind.cast(decl);
 203         }
 204         return null; // not found
 205     }
 206 
 207     /**
 208      * Gets all the declarations
 209      */
 210     public BIDeclaration[] getDecls() {
 211         return decls.toArray(new BIDeclaration[decls.size()]);
 212     }
 213 
 214     /**
 215      * Gets the documentation parsed from {@code <xs:documentation>}s.
 216      * The returned collection is to be added to {@link JDocComment#append(Object)}.
 217      * @return  maybe null.
 218      */
 219     public String getDocumentation() {
 220         // TODO: FIXME: correctly turn individual items to String including DOM
 221         if(documentation==null || documentation.contents==null) return null;
 222 
 223         StringBuilder buf = new StringBuilder();
 224         for (Object c : documentation.contents) {
 225             if(c instanceof String) {
 226                 buf.append(c.toString());
 227             }
 228             if(c instanceof Element) {
 229                 Transformer t = builder.getIdentityTransformer();
 230                 StringWriter w = new StringWriter();
 231                 try {
 232                     Writer fw = new FilterWriter(w) {
 233                         char[] buf = new char[1];
 234 
 235                         public void write(int c) throws IOException {


 336                     }
 337                 }
 338             }
 339             return customizationContext;
 340         } catch (JAXBException e) {
 341             throw new AssertionError(e);
 342         }
 343     }
 344 
 345     public static Unmarshaller getCustomizationUnmarshaller() {
 346         try {
 347             return getCustomizationContext().createUnmarshaller();
 348         } catch (JAXBException e) {
 349             throw new AssertionError(e);
 350         }
 351     }
 352 
 353     /**
 354      * Lazily parsed schema for the binding file.
 355      */
 356     public static final SchemaCache bindingFileSchema = new SchemaCache("binding.xsd", BindInfo.class, true);
 357 }
< prev index next >