⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msvvalidator.java

📁 这是一个基于计算网格的web service。它用java编写。一旦安装完成
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.4-b18-fcs // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2005.07.17 at 02:32:59 EDT //package jwsgrid.xsd.jobhostsearchresult.impl.runtime;import javax.xml.bind.ValidationEvent;import org.relaxng.datatype.Datatype;import org.xml.sax.SAXException;import org.xml.sax.helpers.AttributesImpl;import com.sun.msv.grammar.IDContextProvider2;import com.sun.msv.util.LightStack;import com.sun.msv.util.StartTagInfo;import com.sun.msv.util.StringRef;import com.sun.msv.verifier.Acceptor;import com.sun.msv.verifier.regexp.StringToken;import com.sun.xml.bind.JAXBAssertionError;import com.sun.xml.bind.JAXBObject;import com.sun.xml.bind.RIElement;import com.sun.xml.bind.marshaller.IdentifiableObject;import com.sun.xml.bind.serializer.AbortSerializationException;import com.sun.xml.bind.serializer.Util;import com.sun.xml.bind.validator.Messages;/** * XMLSerializer that calls the native interface of MSV and performs validation. * Used in a pair with a ValidationContext. *  * @author  Kohsuke Kawaguchi */public class MSVValidator implements XMLSerializer, IDContextProvider2{    /** Current acceptor in use. */    private Acceptor acceptor;        /** Context object that coordinates the entire validation effort. */    private final ValidationContext context;        /** The object which we are validating. */    private final ValidatableObject target;        final DefaultJAXBContextImpl jaxbContext;        /**     * Acceptor stack. Whenever an element is found, the current acceptor is     * pushed to the stack and new one is created.     *      * LightStack is a light-weight stack implementation     */    private final LightStack stack = new LightStack();    public NamespaceContext2 getNamespaceContext() {        return context.getNamespaceContext();    }        /**     * To use this class, call the static validate method.     */    private MSVValidator( DefaultJAXBContextImpl _jaxbCtx, ValidationContext _ctxt, ValidatableObject vo ) {        jaxbContext = _jaxbCtx;        acceptor = vo.createRawValidator().createAcceptor();        context = _ctxt;        target = vo;    }        /**     * Validates the specified object and reports any error to the context.     */    public static void validate( DefaultJAXBContextImpl jaxbCtx, ValidationContext context, ValidatableObject vo )            throws SAXException {        try {            new MSVValidator(jaxbCtx,context,vo)._validate();        } catch( RuntimeException e ) {            // sometimes when a conversion between Java object and            // lexical value fails, it may throw an exception like            // NullPointerException or NumberFormatException.            //            // catch them and report them as an error.            context.reportEvent(vo,e);        }    }        /** performs the validation to the object specified in the constructor. */    private void _validate() throws SAXException {        context.getNamespaceContext().startElement();                // validate attributes        target.serializeURIs(this);                endNamespaceDecls();                target.serializeAttributes(this);                endAttributes();                // validate content model        target.serializeBody(this);        writePendingText();                context.getNamespaceContext().endElement();                if(!acceptor.isAcceptState(null)) {            // some elements are missing            // report error            StringRef ref = new StringRef();            acceptor.isAcceptState(ref);            context.reportEvent(target,ref.str);        }    }        public void endNamespaceDecls() throws SAXException {        context.getNamespaceContext().endNamespaceDecls();    }        public void endAttributes() throws SAXException {        if(!acceptor.onEndAttributes( null, null )) {            // some required attributes are missing.            // report a validation error            // Note that we don't know which property of this object            // causes this error.            StringRef ref = new StringRef();            StartTagInfo sti = new StartTagInfo(                currentElementUri,currentElementLocalName,currentElementLocalName,                emptyAttributes,this);            acceptor.onEndAttributes( sti, ref );            context.reportEvent(target,ref.str);        }    }        /** stores text reported by the text method. */    private StringBuffer buf = new StringBuffer();            public final void text( String text, String fieldName ) throws SAXException {        if(text==null) {            reportMissingObjectError(fieldName);            return;        }                if(buf.length()!=0)            buf.append(' ');        buf.append(text);    }        public void reportMissingObjectError(String fieldName) throws SAXException {        reportError(Util.createMissingObjectError(target,fieldName));    }        // used to keep attribute names until the endAttribute method is called.    private String attNamespaceUri;    private String attLocalName;    private boolean insideAttribute;    public void startAttribute( String uri, String local ) {        // we will do the processing at the end element        this.attNamespaceUri = uri;        this.attLocalName = local;        insideAttribute = true;    }        public void endAttribute() throws SAXException {        insideAttribute = false;        if(!acceptor.onAttribute2( attNamespaceUri, attLocalName,            attLocalName /* we don't have QName, so just use the local name */,            buf.toString(),            this, null, null )) {                        // either the name was incorrect (which is quite unlikely),            // or the value was wrong.            // report an error            StringRef ref = new StringRef();            acceptor.onAttribute2( attNamespaceUri, attLocalName, attLocalName,            buf.toString(), this, ref, null );                        context.reportEvent(target,ref.str);        }                buf = new StringBuffer();    }        private void writePendingText() throws SAXException {        // assert(textBuf!=null);        if(!acceptor.onText2( buf.toString(), this, null, null )) {            // this text is invalid.            // report an error            StringRef ref = new StringRef();            acceptor.onText2( buf.toString(), this, ref, null );            context.reportEvent(target,ref.str);        }                if(buf.length()>1024)            buf = new StringBuffer();        else            buf.setLength(0);    }        private String currentElementUri;    private String currentElementLocalName;        public void startElement( String uri, String local ) throws SAXException {        writePendingText();                context.getNamespaceContext().startElement();                stack.push(acceptor);                StartTagInfo sti = new StartTagInfo(uri,local,local,emptyAttributes,this);                // we pass in an empty attributes, as there is just no way for us to        // properly re-construct attributes. Fortunately, I know MSV is not using        // attribute values, so this would work, but nevertheless this code is        // ugly. This is one of the problems of the "middle" approach.        Acceptor child = acceptor.createChildAcceptor( sti, null );        if( child==null ) {            // this element is invalid. probably, so this object is invalid            // report an error            StringRef ref = new StringRef();            child = acceptor.createChildAcceptor( sti, ref );            context.reportEvent(target,ref.str);        }                this.currentElementUri = uri;        this.currentElementLocalName = local;                acceptor = child;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -