Save This Page
Home » openjdk-7 » net.sourceforge.harness.xml » jaxb » [javadoc | source]
    1   package net.sourceforge.harness.xml.jaxb;
    2   
    3   import java.io.IOException;
    4   import java.io.InputStream;
    5   
    6   import javax.xml.bind.Dispatcher;
    7   import javax.xml.bind.DuplicateAttributeException;
    8   import javax.xml.bind.Element;
    9   import javax.xml.bind.InvalidAttributeException;
   10   import javax.xml.bind.LocalValidationException;
   11   import javax.xml.bind.MarshallableObject;
   12   import javax.xml.bind.Marshaller;
   13   import javax.xml.bind.MissingAttributeException;
   14   import javax.xml.bind.StructureValidationException;
   15   import javax.xml.bind.UnmarshalException;
   16   import javax.xml.bind.Unmarshaller;
   17   import javax.xml.bind.Validator;
   18   import javax.xml.marshal.XMLScanner;
   19   import javax.xml.marshal.XMLWriter;
   20   
   21   
   22   public class Java extends MarshallableObject implements Element {
   23       private String _Vendor;
   24       private String _Version;
   25       private String _Cp;
   26       private String _Ext;
   27   
   28       public String getVendor() {
   29           return _Vendor;
   30       }
   31   
   32       public void setVendor(String _Vendor) {
   33           this._Vendor = _Vendor;
   34   
   35           if (_Vendor == null) {
   36               invalidate();
   37           }
   38       }
   39   
   40       public String getVersion() {
   41           return _Version;
   42       }
   43   
   44       public void setVersion(String _Version) {
   45           this._Version = _Version;
   46   
   47           if (_Version == null) {
   48               invalidate();
   49           }
   50       }
   51   
   52       public String getCp() {
   53           return _Cp;
   54       }
   55   
   56       public void setCp(String _Cp) {
   57           this._Cp = _Cp;
   58   
   59           if (_Cp == null) {
   60               invalidate();
   61           }
   62       }
   63   
   64       public String getExt() {
   65           return _Ext;
   66       }
   67   
   68       public void setExt(String _Ext) {
   69           this._Ext = _Ext;
   70   
   71           if (_Ext == null) {
   72               invalidate();
   73           }
   74       }
   75   
   76       public void validateThis() throws LocalValidationException {
   77           if (_Vendor == null) {
   78               throw new MissingAttributeException("vendor");
   79           }
   80   
   81           if (_Version == null) {
   82               throw new MissingAttributeException("version");
   83           }
   84   
   85           if (_Cp == null) {
   86               throw new MissingAttributeException("cp");
   87           }
   88       }
   89   
   90       public void validate(Validator v) throws StructureValidationException {
   91       }
   92   
   93       public void marshal(Marshaller m) throws IOException {
   94           XMLWriter w = m.writer();
   95           w.start("java");
   96           w.attribute("vendor", _Vendor.toString());
   97           w.attribute("version", _Version.toString());
   98           w.attribute("cp", _Cp.toString());
   99   
  100           if (_Ext != null) {
  101               w.attribute("ext", _Ext.toString());
  102           }
  103   
  104           w.end("java");
  105       }
  106   
  107       public void unmarshal(Unmarshaller u) throws UnmarshalException {
  108           XMLScanner xs = u.scanner();
  109           Validator v = u.validator();
  110           xs.takeStart("java");
  111   
  112           while (xs.atAttribute()) {
  113               String an = xs.takeAttributeName();
  114   
  115               if (an.equals("vendor")) {
  116                   if (_Vendor != null) {
  117                       throw new DuplicateAttributeException(an);
  118                   }
  119   
  120                   _Vendor = xs.takeAttributeValue();
  121   
  122                   continue;
  123               }
  124   
  125               if (an.equals("version")) {
  126                   if (_Version != null) {
  127                       throw new DuplicateAttributeException(an);
  128                   }
  129   
  130                   _Version = xs.takeAttributeValue();
  131   
  132                   continue;
  133               }
  134   
  135               if (an.equals("cp")) {
  136                   if (_Cp != null) {
  137                       throw new DuplicateAttributeException(an);
  138                   }
  139   
  140                   _Cp = xs.takeAttributeValue();
  141   
  142                   continue;
  143               }
  144   
  145               if (an.equals("ext")) {
  146                   if (_Ext != null) {
  147                       throw new DuplicateAttributeException(an);
  148                   }
  149   
  150                   _Ext = xs.takeAttributeValue();
  151   
  152                   continue;
  153               }
  154   
  155               throw new InvalidAttributeException(an);
  156           }
  157   
  158           xs.takeEnd("java");
  159       }
  160   
  161       public static Java unmarshal(InputStream in) throws UnmarshalException {
  162           return unmarshal(XMLScanner.open(in));
  163       }
  164   
  165       public static Java unmarshal(XMLScanner xs) throws UnmarshalException {
  166           return unmarshal(xs, newDispatcher());
  167       }
  168   
  169       public static Java unmarshal(XMLScanner xs, Dispatcher d)
  170           throws UnmarshalException {
  171           return ((Java) d.unmarshal(xs, (Java.class)));
  172       }
  173   
  174       public boolean equals(Object ob) {
  175           if (this == ob) {
  176               return true;
  177           }
  178   
  179           if (!(ob instanceof Java)) {
  180               return false;
  181           }
  182   
  183           Java tob = ((Java) ob);
  184   
  185           if (_Vendor != null) {
  186               if (tob._Vendor == null) {
  187                   return false;
  188               }
  189   
  190               if (!_Vendor.equals(tob._Vendor)) {
  191                   return false;
  192               }
  193           } else {
  194               if (tob._Vendor != null) {
  195                   return false;
  196               }
  197           }
  198   
  199           if (_Version != null) {
  200               if (tob._Version == null) {
  201                   return false;
  202               }
  203   
  204               if (!_Version.equals(tob._Version)) {
  205                   return false;
  206               }
  207           } else {
  208               if (tob._Version != null) {
  209                   return false;
  210               }
  211           }
  212   
  213           if (_Cp != null) {
  214               if (tob._Cp == null) {
  215                   return false;
  216               }
  217   
  218               if (!_Cp.equals(tob._Cp)) {
  219                   return false;
  220               }
  221           } else {
  222               if (tob._Cp != null) {
  223                   return false;
  224               }
  225           }
  226   
  227           if (_Ext != null) {
  228               if (tob._Ext == null) {
  229                   return false;
  230               }
  231   
  232               if (!_Ext.equals(tob._Ext)) {
  233                   return false;
  234               }
  235           } else {
  236               if (tob._Ext != null) {
  237                   return false;
  238               }
  239           }
  240   
  241           return true;
  242       }
  243   
  244       public int hashCode() {
  245           int h = 0;
  246           h = ((127 * h) + ((_Vendor != null) ? _Vendor.hashCode() : 0));
  247           h = ((127 * h) + ((_Version != null) ? _Version.hashCode() : 0));
  248           h = ((127 * h) + ((_Cp != null) ? _Cp.hashCode() : 0));
  249           h = ((127 * h) + ((_Ext != null) ? _Ext.hashCode() : 0));
  250   
  251           return h;
  252       }
  253   
  254       public String toString() {
  255           StringBuffer sb = new StringBuffer("<<java");
  256   
  257           if (_Vendor != null) {
  258               sb.append(" vendor=");
  259               sb.append(_Vendor.toString());
  260           }
  261   
  262           if (_Version != null) {
  263               sb.append(" version=");
  264               sb.append(_Version.toString());
  265           }
  266   
  267           if (_Cp != null) {
  268               sb.append(" cp=");
  269               sb.append(_Cp.toString());
  270           }
  271   
  272           if (_Ext != null) {
  273               sb.append(" ext=");
  274               sb.append(_Ext.toString());
  275           }
  276   
  277           sb.append(">>");
  278   
  279           return sb.toString();
  280       }
  281   
  282       public static Dispatcher newDispatcher() {
  283           return Author.newDispatcher();
  284       }
  285   }

Save This Page
Home » openjdk-7 » net.sourceforge.harness.xml » jaxb » [javadoc | source]