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 Param extends MarshallableObject implements Element {
   23       private String _Name;
   24       private String _Value;
   25   
   26       public String getName() {
   27           return _Name;
   28       }
   29   
   30       public void setName(String _Name) {
   31           this._Name = _Name;
   32   
   33           if (_Name == null) {
   34               invalidate();
   35           }
   36       }
   37   
   38       public String getValue() {
   39           return _Value;
   40       }
   41   
   42       public void setValue(String _Value) {
   43           this._Value = _Value;
   44   
   45           if (_Value == null) {
   46               invalidate();
   47           }
   48       }
   49   
   50       public void validateThis() throws LocalValidationException {
   51           if (_Name == null) {
   52               throw new MissingAttributeException("name");
   53           }
   54   
   55           if (_Value == null) {
   56               throw new MissingAttributeException("value");
   57           }
   58       }
   59   
   60       public void validate(Validator v) throws StructureValidationException {
   61       }
   62   
   63       public void marshal(Marshaller m) throws IOException {
   64           XMLWriter w = m.writer();
   65           w.start("param");
   66           w.attribute("name", _Name.toString());
   67           w.attribute("value", _Value.toString());
   68           w.end("param");
   69       }
   70   
   71       public void unmarshal(Unmarshaller u) throws UnmarshalException {
   72           XMLScanner xs = u.scanner();
   73           Validator v = u.validator();
   74           xs.takeStart("param");
   75   
   76           while (xs.atAttribute()) {
   77               String an = xs.takeAttributeName();
   78   
   79               if (an.equals("name")) {
   80                   if (_Name != null) {
   81                       throw new DuplicateAttributeException(an);
   82                   }
   83   
   84                   _Name = xs.takeAttributeValue();
   85   
   86                   continue;
   87               }
   88   
   89               if (an.equals("value")) {
   90                   if (_Value != null) {
   91                       throw new DuplicateAttributeException(an);
   92                   }
   93   
   94                   _Value = xs.takeAttributeValue();
   95   
   96                   continue;
   97               }
   98   
   99               throw new InvalidAttributeException(an);
  100           }
  101   
  102           xs.takeEnd("param");
  103       }
  104   
  105       public static Param unmarshal(InputStream in) throws UnmarshalException {
  106           return unmarshal(XMLScanner.open(in));
  107       }
  108   
  109       public static Param unmarshal(XMLScanner xs) throws UnmarshalException {
  110           return unmarshal(xs, newDispatcher());
  111       }
  112   
  113       public static Param unmarshal(XMLScanner xs, Dispatcher d)
  114           throws UnmarshalException {
  115           return ((Param) d.unmarshal(xs, (Param.class)));
  116       }
  117   
  118       public boolean equals(Object ob) {
  119           if (this == ob) {
  120               return true;
  121           }
  122   
  123           if (!(ob instanceof Param)) {
  124               return false;
  125           }
  126   
  127           Param tob = ((Param) ob);
  128   
  129           if (_Name != null) {
  130               if (tob._Name == null) {
  131                   return false;
  132               }
  133   
  134               if (!_Name.equals(tob._Name)) {
  135                   return false;
  136               }
  137           } else {
  138               if (tob._Name != null) {
  139                   return false;
  140               }
  141           }
  142   
  143           if (_Value != null) {
  144               if (tob._Value == null) {
  145                   return false;
  146               }
  147   
  148               if (!_Value.equals(tob._Value)) {
  149                   return false;
  150               }
  151           } else {
  152               if (tob._Value != null) {
  153                   return false;
  154               }
  155           }
  156   
  157           return true;
  158       }
  159   
  160       public int hashCode() {
  161           int h = 0;
  162           h = ((127 * h) + ((_Name != null) ? _Name.hashCode() : 0));
  163           h = ((127 * h) + ((_Value != null) ? _Value.hashCode() : 0));
  164   
  165           return h;
  166       }
  167   
  168       public String toString() {
  169           StringBuffer sb = new StringBuffer("<<param");
  170   
  171           if (_Name != null) {
  172               sb.append(" name=");
  173               sb.append(_Name.toString());
  174           }
  175   
  176           if (_Value != null) {
  177               sb.append(" value=");
  178               sb.append(_Value.toString());
  179           }
  180   
  181           sb.append(">>");
  182   
  183           return sb.toString();
  184       }
  185   
  186       public static Dispatcher newDispatcher() {
  187           return Author.newDispatcher();
  188       }
  189   }

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