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

📄 wantpropertyelement.java

📁 jena2.5.4推理机系统的一种最基本实现 HP实验室出品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * (c) Copyright 2005, 2006, 2007 Hewlett-Packard Development Company, LP
 * [See end of file]
 */

package com.hp.hpl.jena.rdf.arp.states;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXParseException;

import com.hp.hpl.jena.rdf.arp.impl.ANode;
import com.hp.hpl.jena.rdf.arp.impl.ARPResource;
import com.hp.hpl.jena.rdf.arp.impl.AResourceInternal;
import com.hp.hpl.jena.rdf.arp.impl.AbsXMLContext;
import com.hp.hpl.jena.rdf.arp.impl.AttributeLexer;
import com.hp.hpl.jena.rdf.arp.impl.ElementLexer;
import com.hp.hpl.jena.rdf.arp.impl.TaintImpl;
import com.hp.hpl.jena.rdf.arp.impl.URIReference;

public class WantPropertyElement extends Frame implements WantsObjectFrameI,
        HasSubjectFrameI {
    int liCounter = 1;

    ANode predicate;

    ANode object;

    ANode reify;

    boolean objectIsBlank = false;

    public WantPropertyElement(HasSubjectFrameI s, AbsXMLContext x) {
        super(s, x);
    }

    // These three are used as bitfields
    static final private int TYPEDLITERAL = 1;

    static final private int EMPTYWITHOBJ = 2;

    static final private int PARSETYPE = 4;

    public FrameI startElement(String uri, String localName, String rawName,
            Attributes atts) throws SAXParseException {
        clearObject();
        if (nonWhiteMsgGiven)
            taint.isTainted();
        nonWhiteMsgGiven = false;
        if (uri==null || uri.equals("")) {
            warning(WARN_UNQUALIFIED_ELEMENT,"Unqualified property elements are not allowed. Treated as a relative URI.");
        }
        ElementLexer el = new ElementLexer(taint, this, uri, localName,
                rawName, E_LI, CoreAndOldTerms | E_DESCRIPTION, false);
        // if (el.badMatch)
        // warning(ERR_SYNTAX_ERROR,"bad use of " + rawName);
        predicate = el.goodMatch ? (AResourceInternal) rdf_n(liCounter++)
                : URIReference.fromQName(this, uri, localName);
        if (taint.isTainted())
            predicate.taint();
        taint = new TaintImpl();

        AttributeLexer ap = new AttributeLexer(this,
        // xml:
                A_XMLLANG | A_XMLBASE | A_XML_OTHER
                // legal rdf:
                        | A_DATATYPE | A_ID | A_NODEID | A_PARSETYPE
                        | A_RESOURCE | A_TYPE,
                // bad rdf:
                A_BADATTRS);
        int cnt = ap.processSpecials(taint, atts);

        // These three states are intended as mutually
        // incompatible, but all three can occur
        // together. Any two of the three, or all
        // three is a syntax errror.
        // Having none of these is legal.
        final int nextStateCode = (ap.datatype == null ? 0 : TYPEDLITERAL)
                | (ap.parseType == null ? 0 : PARSETYPE)
                | (mustBeEmpty(ap, atts, cnt) ? EMPTYWITHOBJ : 0);

        if (this.badStateCode(nextStateCode)) {
            warning(errorNumber(nextStateCode), descriptionOfCases(ap,
                    nextStateCode, propertyAttributeDescription(atts, ap, cnt)));
        }

        AbsXMLContext x = ap.xml(xml);

        reify = ap.id == null ? null : URIReference.fromID(this, x, ap.id);
        if (taint.isTainted())
            predicate.taint();

        if (mustBeEmpty(ap, atts, cnt)) {
            if (ap.nodeID != null) {

                object = new ARPResource(arp, ap.nodeID);
                checkXMLName(object, ap.nodeID);
                objectIsBlank = true;
            }
            if (ap.resource != null) {
                if (object != null) {
                    if (!badStateCode(nextStateCode))
                        // otherwise warning already given
                        warning(ERR_SYNTAX_ERROR, 
                                "On a property element, only one of the attributes rdf:nodeID or rdf:resource is permitted.");
                } else
                    object = URIReference.resolve(this, x, ap.resource);
            }
            if (object == null) {
                object = new ARPResource(arp);
                objectIsBlank = true;
            }
            if (taint.isTainted())
                object.taint();
            processPropertyAttributes(ap, atts, x);
        }

        FrameI nextFrame = nextFrame(atts, ap, cnt, nextStateCode, x);
        if (object != null) {
            if (taint.isTainted())
                object.taint();
            theObject(object);
        }
        if (taint.isTainted())
            predicate.taint();
        return nextFrame;

    }

    private boolean mustBeEmpty(AttributeLexer ap, Attributes atts, int cnt) {
        return cnt < atts.getLength() || ap.type != null || ap.nodeID != null
                || ap.resource != null;
    }

    private FrameI nextFrame(Attributes atts, AttributeLexer ap, int cnt,
            int nextStateCode, AbsXMLContext x) throws SAXParseException {
        switch (nextStateCode) {
        case 0:
            return new WantLiteralValueOrDescription(this, x);
        case PARSETYPE | TYPEDLITERAL:
        case PARSETYPE | TYPEDLITERAL | EMPTYWITHOBJ:
        case PARSETYPE | EMPTYWITHOBJ:
        case PARSETYPE:
            return withParsetype(ap.parseType, x);
        case TYPEDLITERAL | EMPTYWITHOBJ:
        case TYPEDLITERAL:
            return new WantTypedLiteral(this, ap.datatype, x);
        case EMPTYWITHOBJ:
            return new WantEmpty(this, x);
        }
        throw new IllegalStateException("impossible");
    }

    private FrameI withParsetype(String pt, AbsXMLContext x)
            throws SAXParseException {
        if (pt.equals("Collection")) {
            return new RDFCollection(this, x);
        }
        if (pt.equals("daml:collection") && !arp.isError(WARN_IN_STRICT_MODE)) {
            warning(IGN_DAML_COLLECTION,
                    "'daml:collection' is not really a legal value for rdf:parseType");
            return new DAMLCollection(this, x);
        }
        if (pt.equals("Resource")) {
            if (object == null) {
                // in some error cases the object has already been set.
                object = new ARPResource(arp);
                objectIsBlank = true;
            }
            return new WantPropertyElement(this, x);
        }
        if (!pt.equals("Literal")) {
            warning(WARN_UNKNOWN_PARSETYPE, "Unknown rdf:parseType: '" + pt
                    + "' (treated as 'Literal'.");
        }
        return new OuterXMLLiteral(this, x, pt);
    }

    String suggestParsetypeLiteral() {
        return (getParent() instanceof WantTopLevelDescription) ? "" : super
                .suggestParsetypeLiteral();
    }

    public void aPredAndObj(ANode p, ANode o) {
        triple(object, p, o);
    }

    public void makeSubjectReificationWith(ANode r) {
        triple(r, RDF_SUBJECT, object);
    }

    public void theObject(ANode o) {
        HasSubjectFrameI p = (HasSubjectFrameI) getParent();
        p.aPredAndObj(predicate, o);
        if (reify != null) {
            triple(reify, RDF_TYPE, RDF_STATEMENT);
            triple(reify, RDF_OBJECT, o);
            triple(reify, RDF_PREDICATE, predicate);
            p.makeSubjectReificationWith(reify);
        }
    }

    public void endElement() {
        clearObject();
    }

    public void abort() {
        clearObject();
    }

    private void clearObject() {
        if (objectIsBlank)
            arp.endLocalScope(object);
        objectIsBlank = false;
        object = null;
    }

    static private URIReference _rdf_n[] = new URIReference[0];

    static private URIReference rdf_n(int i) {
        if (i >= _rdf_n.length) {
            int newLength = (i + 10) * 3 / 2;
            URIReference new_rdf_n[] = new URIReference[newLength];
            System.arraycopy(_rdf_n, 0, new_rdf_n, 0, _rdf_n.length);
            for (int j = _rdf_n.length; j < newLength; j++) {
                new_rdf_n[j] = URIReference.createNoChecks(rdfns + "_" + j);
            }
            _rdf_n = new_rdf_n;

⌨️ 快捷键说明

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