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 PathElement extends MarshallableObject implements Element {
   23       private String _Path;
   24   
   25       public String getPath() {
   26           return _Path;
   27       }
   28   
   29       public void setPath(String _Path) {
   30           this._Path = _Path;
   31   
   32           if (_Path == null) {
   33               invalidate();
   34           }
   35       }
   36   
   37       public void validateThis() throws LocalValidationException {
   38           if (_Path == null) {
   39               throw new MissingAttributeException("path");
   40           }
   41       }
   42   
   43       public void validate(Validator v) throws StructureValidationException {
   44       }
   45   
   46       public void marshal(Marshaller m) throws IOException {
   47           XMLWriter w = m.writer();
   48           w.start("pathElement");
   49           w.attribute("path", _Path.toString());
   50           w.end("pathElement");
   51       }
   52   
   53       public void unmarshal(Unmarshaller u) throws UnmarshalException {
   54           XMLScanner xs = u.scanner();
   55           Validator v = u.validator();
   56           xs.takeStart("pathElement");
   57   
   58           while (xs.atAttribute()) {
   59               String an = xs.takeAttributeName();
   60   
   61               if (an.equals("path")) {
   62                   if (_Path != null) {
   63                       throw new DuplicateAttributeException(an);
   64                   }
   65   
   66                   _Path = xs.takeAttributeValue();
   67   
   68                   continue;
   69               }
   70   
   71               throw new InvalidAttributeException(an);
   72           }
   73   
   74           xs.takeEnd("pathElement");
   75       }
   76   
   77       public static PathElement unmarshal(InputStream in)
   78           throws UnmarshalException {
   79           return unmarshal(XMLScanner.open(in));
   80       }
   81   
   82       public static PathElement unmarshal(XMLScanner xs)
   83           throws UnmarshalException {
   84           return unmarshal(xs, newDispatcher());
   85       }
   86   
   87       public static PathElement unmarshal(XMLScanner xs, Dispatcher d)
   88           throws UnmarshalException {
   89           return ((PathElement) d.unmarshal(xs, (PathElement.class)));
   90       }
   91   
   92       public boolean equals(Object ob) {
   93           if (this == ob) {
   94               return true;
   95           }
   96   
   97           if (!(ob instanceof PathElement)) {
   98               return false;
   99           }
  100   
  101           PathElement tob = ((PathElement) ob);
  102   
  103           if (_Path != null) {
  104               if (tob._Path == null) {
  105                   return false;
  106               }
  107   
  108               if (!_Path.equals(tob._Path)) {
  109                   return false;
  110               }
  111           } else {
  112               if (tob._Path != null) {
  113                   return false;
  114               }
  115           }
  116   
  117           return true;
  118       }
  119   
  120       public int hashCode() {
  121           int h = 0;
  122           h = ((127 * h) + ((_Path != null) ? _Path.hashCode() : 0));
  123   
  124           return h;
  125       }
  126   
  127       public String toString() {
  128           StringBuffer sb = new StringBuffer("<<pathElement");
  129   
  130           if (_Path != null) {
  131               sb.append(" path=");
  132               sb.append(_Path.toString());
  133           }
  134   
  135           sb.append(">>");
  136   
  137           return sb.toString();
  138       }
  139   
  140       public static Dispatcher newDispatcher() {
  141           return Author.newDispatcher();
  142       }
  143   }

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