Save This Page
Home » openjdk-7 » net.sourceforge.harness.xml » jaxb » [javadoc | source]
    1   package net.sourceforge.harness.xml.jaxb;
    2   
    3   import net.sourceforge.harness.xml.jaxb.PathElement;
    4   
    5   import java.io.IOException;
    6   import java.io.InputStream;
    7   
    8   import java.util.ArrayList;
    9   import java.util.Iterator;
   10   import java.util.List;
   11   
   12   import javax.xml.bind.Dispatcher;
   13   import javax.xml.bind.Element;
   14   import javax.xml.bind.InvalidAttributeException;
   15   import javax.xml.bind.InvalidContentObjectException;
   16   import javax.xml.bind.LocalValidationException;
   17   import javax.xml.bind.MarshallableObject;
   18   import javax.xml.bind.Marshaller;
   19   import javax.xml.bind.PredicatedLists;
   20   import javax.xml.bind.PredicatedLists.Predicate;
   21   import javax.xml.bind.StructureValidationException;
   22   import javax.xml.bind.UnmarshalException;
   23   import javax.xml.bind.Unmarshaller;
   24   import javax.xml.bind.ValidatableObject;
   25   import javax.xml.bind.Validator;
   26   import javax.xml.marshal.XMLScanner;
   27   import javax.xml.marshal.XMLWriter;
   28   
   29   
   30   public class ClassPath extends MarshallableObject implements Element {
   31       private List _PathElementList = PredicatedLists.createInvalidating(this,
   32               new PathElementListPredicate(), new ArrayList());
   33       private PredicatedLists.Predicate pred_PathElementList = new PathElementListPredicate();
   34   
   35       public List getPathElementList() {
   36           return _PathElementList;
   37       }
   38   
   39       public void deletePathElementList() {
   40           _PathElementList = null;
   41           invalidate();
   42       }
   43   
   44       public void emptyPathElementList() {
   45           _PathElementList = PredicatedLists.createInvalidating(this,
   46                   pred_PathElementList, new ArrayList());
   47       }
   48   
   49       public void validateThis() throws LocalValidationException {
   50       }
   51   
   52       public void validate(Validator v) throws StructureValidationException {
   53           for (Iterator i = _PathElementList.iterator(); i.hasNext();) {
   54               v.validate(((ValidatableObject) i.next()));
   55           }
   56       }
   57   
   58       public void marshal(Marshaller m) throws IOException {
   59           XMLWriter w = m.writer();
   60           w.start("classPath");
   61   
   62           if (_PathElementList.size() > 0) {
   63               for (Iterator i = _PathElementList.iterator(); i.hasNext();) {
   64                   m.marshal(((MarshallableObject) i.next()));
   65               }
   66           }
   67   
   68           w.end("classPath");
   69       }
   70   
   71       public void unmarshal(Unmarshaller u) throws UnmarshalException {
   72           XMLScanner xs = u.scanner();
   73           Validator v = u.validator();
   74           xs.takeStart("classPath");
   75   
   76           while (xs.atAttribute()) {
   77               String an = xs.takeAttributeName();
   78               throw new InvalidAttributeException(an);
   79           }
   80   
   81           {
   82               List l = PredicatedLists.create(this, pred_PathElementList,
   83                       new ArrayList());
   84   
   85               while (xs.atStart("pathElement")) {
   86                   l.add(((PathElement) u.unmarshal()));
   87               }
   88   
   89               _PathElementList = PredicatedLists.createInvalidating(this,
   90                       pred_PathElementList, l);
   91           }
   92   
   93           xs.takeEnd("classPath");
   94       }
   95   
   96       public static ClassPath unmarshal(InputStream in) throws UnmarshalException {
   97           return unmarshal(XMLScanner.open(in));
   98       }
   99   
  100       public static ClassPath unmarshal(XMLScanner xs) throws UnmarshalException {
  101           return unmarshal(xs, newDispatcher());
  102       }
  103   
  104       public static ClassPath unmarshal(XMLScanner xs, Dispatcher d)
  105           throws UnmarshalException {
  106           return ((ClassPath) d.unmarshal(xs, (ClassPath.class)));
  107       }
  108   
  109       public boolean equals(Object ob) {
  110           if (this == ob) {
  111               return true;
  112           }
  113   
  114           if (!(ob instanceof ClassPath)) {
  115               return false;
  116           }
  117   
  118           ClassPath tob = ((ClassPath) ob);
  119   
  120           if (_PathElementList != null) {
  121               if (tob._PathElementList == null) {
  122                   return false;
  123               }
  124   
  125               if (!_PathElementList.equals(tob._PathElementList)) {
  126                   return false;
  127               }
  128           } else {
  129               if (tob._PathElementList != null) {
  130                   return false;
  131               }
  132           }
  133   
  134           return true;
  135       }
  136   
  137       public int hashCode() {
  138           int h = 0;
  139           h = ((127 * h) +
  140               ((_PathElementList != null) ? _PathElementList.hashCode() : 0));
  141   
  142           return h;
  143       }
  144   
  145       public String toString() {
  146           StringBuffer sb = new StringBuffer("<<classPath");
  147   
  148           if (_PathElementList != null) {
  149               sb.append(" pathElement=");
  150               sb.append(_PathElementList.toString());
  151           }
  152   
  153           sb.append(">>");
  154   
  155           return sb.toString();
  156       }
  157   
  158       public static Dispatcher newDispatcher() {
  159           return Author.newDispatcher();
  160       }
  161   
  162       private static class PathElementListPredicate
  163           implements PredicatedLists.Predicate {
  164           public void check(Object ob) {
  165               if (!(ob instanceof PathElement)) {
  166                   throw new InvalidContentObjectException(ob, (PathElement.class));
  167               }
  168           }
  169       }
  170   }

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