FileDocCategorySizeDatePackage
Movie.javaAPI DocExample8940Sun Jul 07 09:31:54 BST 2002javajaxb.generated.movies

Movie.java

package javajaxb.generated.movies;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javajaxb.generated.movies.Cast;
import javax.xml.bind.ConversionException;
import javax.xml.bind.Dispatcher;
import javax.xml.bind.Element;
import javax.xml.bind.InvalidAttributeException;
import javax.xml.bind.InvalidContentObjectException;
import javax.xml.bind.LocalValidationException;
import javax.xml.bind.MarshallableObject;
import javax.xml.bind.Marshaller;
import javax.xml.bind.MissingContentException;
import javax.xml.bind.PredicatedLists;
import javax.xml.bind.PredicatedLists.Predicate;
import javax.xml.bind.StructureValidationException;
import javax.xml.bind.UnmarshalException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.Validator;
import javax.xml.marshal.XMLScanner;
import javax.xml.marshal.XMLWriter;


public class Movie
    extends MarshallableObject
    implements Element
{

    private String _Title;
    private Cast _Cast;
    private String _Director;
    private List _Producer = PredicatedLists.createInvalidating(this, new ProducerPredicate(), new ArrayList());
    private PredicatedLists.Predicate pred_Producer = new ProducerPredicate();

    public String getTitle() {
        return _Title;
    }

    public void setTitle(String _Title) {
        this._Title = _Title;
        if (_Title == null) {
            invalidate();
        }
    }

    public Cast getCast() {
        return _Cast;
    }

    public void setCast(Cast _Cast) {
        this._Cast = _Cast;
        if (_Cast == null) {
            invalidate();
        }
    }

    public String getDirector() {
        return _Director;
    }

    public void setDirector(String _Director) {
        this._Director = _Director;
        if (_Director == null) {
            invalidate();
        }
    }

    public List getProducer() {
        return _Producer;
    }

    public void deleteProducer() {
        _Producer = null;
        invalidate();
    }

    public void emptyProducer() {
        _Producer = PredicatedLists.createInvalidating(this, pred_Producer, new ArrayList());
    }

    public void validateThis()
        throws LocalValidationException
    {
        if (_Title == null) {
            throw new MissingContentException("title");
        }
        if (_Cast == null) {
            throw new MissingContentException("cast");
        }
    }

    public void validate(Validator v)
        throws StructureValidationException
    {
        v.validate(_Cast);
    }

    public void marshal(Marshaller m)
        throws IOException
    {
        XMLWriter w = m.writer();
        w.start("movie");
        w.leaf("title", _Title.toString());
        m.marshal(_Cast);
        if (_Director!= null) {
            w.leaf("director", _Director.toString());
        }
        for (Iterator i = _Producer.iterator(); i.hasNext(); ) {
            w.leaf("producer", ((String) i.next()).toString());
        }
        w.end("movie");
    }

    public void unmarshal(Unmarshaller u)
        throws UnmarshalException
    {
        XMLScanner xs = u.scanner();
        Validator v = u.validator();
        xs.takeStart("movie");
        while (xs.atAttribute()) {
            String an = xs.takeAttributeName();
            throw new InvalidAttributeException(an);
        }
        if (xs.atStart("title")) {
            xs.takeStart("title");
            String s;
            if (xs.atChars(XMLScanner.WS_COLLAPSE)) {
                s = xs.takeChars(XMLScanner.WS_COLLAPSE);
            } else {
                s = "";
            }
            try {
                _Title = String.valueOf(s);
            } catch (Exception x) {
                throw new ConversionException("title", x);
            }
            xs.takeEnd("title");
        }
        _Cast = ((Cast) u.unmarshal());
        if (xs.atStart("director")) {
            xs.takeStart("director");
            String s;
            if (xs.atChars(XMLScanner.WS_COLLAPSE)) {
                s = xs.takeChars(XMLScanner.WS_COLLAPSE);
            } else {
                s = "";
            }
            try {
                _Director = String.valueOf(s);
            } catch (Exception x) {
                throw new ConversionException("director", x);
            }
            xs.takeEnd("director");
        }
        {
            List l = new ArrayList();
            while (xs.atStart()) {
                if (xs.atStart("producer")) {
                    xs.takeStart("producer");
                    String s;
                    if (xs.atChars(XMLScanner.WS_COLLAPSE)) {
                        s = xs.takeChars(XMLScanner.WS_COLLAPSE);
                    } else {
                        s = "";
                    }
                    String uf;
                    try {
                        uf = String.valueOf(s);
                    } catch (Exception x) {
                        throw new ConversionException("producer", x);
                    }
                    l.add(uf);
                    xs.takeEnd("producer");
                } else {
                    break;
                }
            }
            _Producer = PredicatedLists.createInvalidating(this, pred_Producer, l);
        }
        xs.takeEnd("movie");
    }

    public static Movie unmarshal(InputStream in)
        throws UnmarshalException
    {
        return unmarshal(XMLScanner.open(in));
    }

    public static Movie unmarshal(XMLScanner xs)
        throws UnmarshalException
    {
        return unmarshal(xs, newDispatcher());
    }

    public static Movie unmarshal(XMLScanner xs, Dispatcher d)
        throws UnmarshalException
    {
        return ((Movie) d.unmarshal(xs, (Movie.class)));
    }

    public boolean equals(Object ob) {
        if (this == ob) {
            return true;
        }
        if (!(ob instanceof Movie)) {
            return false;
        }
        Movie tob = ((Movie) ob);
        if (_Title!= null) {
            if (tob._Title == null) {
                return false;
            }
            if (!_Title.equals(tob._Title)) {
                return false;
            }
        } else {
            if (tob._Title!= null) {
                return false;
            }
        }
        if (_Cast!= null) {
            if (tob._Cast == null) {
                return false;
            }
            if (!_Cast.equals(tob._Cast)) {
                return false;
            }
        } else {
            if (tob._Cast!= null) {
                return false;
            }
        }
        if (_Director!= null) {
            if (tob._Director == null) {
                return false;
            }
            if (!_Director.equals(tob._Director)) {
                return false;
            }
        } else {
            if (tob._Director!= null) {
                return false;
            }
        }
        if (_Producer!= null) {
            if (tob._Producer == null) {
                return false;
            }
            if (!_Producer.equals(tob._Producer)) {
                return false;
            }
        } else {
            if (tob._Producer!= null) {
                return false;
            }
        }
        return true;
    }

    public int hashCode() {
        int h = 0;
        h = ((127 *h)+((_Title!= null)?_Title.hashCode(): 0));
        h = ((127 *h)+((_Cast!= null)?_Cast.hashCode(): 0));
        h = ((127 *h)+((_Director!= null)?_Director.hashCode(): 0));
        h = ((127 *h)+((_Producer!= null)?_Producer.hashCode(): 0));
        return h;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer("<<movie");
        if (_Title!= null) {
            sb.append(" title=");
            sb.append(_Title.toString());
        }
        if (_Cast!= null) {
            sb.append(" cast=");
            sb.append(_Cast.toString());
        }
        if (_Director!= null) {
            sb.append(" director=");
            sb.append(_Director.toString());
        }
        if (_Producer!= null) {
            sb.append(" producer=");
            sb.append(_Producer.toString());
        }
        sb.append(">>");
        return sb.toString();
    }

    public static Dispatcher newDispatcher() {
        return Actor.newDispatcher();
    }


    private static class ProducerPredicate
        implements PredicatedLists.Predicate
    {


        public void check(Object ob) {
            if (!(ob instanceof String)) {
                throw new InvalidContentObjectException(ob, (String.class));
            }
        }

    }

}