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

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