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

📄 unmarshallingcontext.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    public int parseContentInt(String ns, String tag) throws JiBXException {
        String text = parseContentText(ns, tag);
        try {
            return Utility.parseInt(text);
        } catch (JiBXException ex) {
            throw new JiBXException(ex.getMessage() + ' ' +
                buildPositionString(), ex.getRootCause());
        }
    }

    /**
     * Parse entire element, returning text content.
     * Expects to find the element start tag, text content, and end tag,
     * in that order, and returns with the parser positioned following
     * the end tag.
     *
     * @param ns namespace URI for expected element (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param tag element name expected
     * @return content text from element
     * @throws JiBXException on any error (possible wrapping other exception)
     */
    public String parseElementText(String ns, String tag) throws JiBXException {
        parsePastStartTag(ns, tag);
        return parseContentText(ns, tag);
    }

    /**
     * Parse entire element, returning optional text content.
     * Expects to find the element start tag, text content, and end tag,
     * in that order, and returns with the parser positioned following
     * the end tag. Returns the default text if the element is not found.
     *
     * @param ns namespace URI for expected element (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param tag element name expected
     * @param dflt default text value
     * @return content text from element
     * @throws JiBXException on any error (possible wrapping other exception)
     */
    public String parseElementText(String ns, String tag, String dflt)
        throws JiBXException {
        if (parseIfStartTag(ns, tag)) {
            return parseContentText(ns, tag);
        } else {
            return dflt;
        }
    }

    /**
     * Get text value of attribute from current start tag.
     * Throws an exception if the attribute value is not found in the start
     * tag.
     *
     * @param ns namespace URI for expected attribute (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param name attribute name expected
     * @return attribute value text
     * @throws JiBXException if attribute not present
     */
    public String attributeText(String ns, String name) throws JiBXException {
        String value = getAttributeValue(ns, name);
        if (value == null) {
            throw new JiBXException("Missing required attribute " +
                buildNameString(ns, name) + " " + buildPositionString());
        } else {
            return value;
        }
    }

    /**
     * Get text value of optional attribute from current start
     * tag. If the attribute is not present the supplied default value is
     * returned instead.
     *
     * @param ns namespace URI for expected attribute (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param name attribute name expected
     * @param dflt value to be returned if attribute is not present
     * @return attribute value text
     */
    public String attributeText(String ns, String name, String dflt) {
        String value = getAttributeValue(ns, name);
        if (value == null) {
            return dflt;
        } else {
            return value;
        }
    }

    /**
     * Find the object corresponding to an ID. This method just handles the
     * lookup and checks the object type.
     *
     * @param id ID text
     * @param index expected reference type index
     * @return object corresponding to IDREF, or <code>null</code> if not
     * yet defined
     * @throws JiBXException on any error
     */
    public Object findID(String id, int index) throws JiBXException {
        HashMap map = m_idMaps[index];
        if (map != null) {
            Object obj = map.get(id);
            if (obj == null || obj instanceof BackFillHolder) {
                return null;
            } else if (m_idClasses == null ||
                m_idClasses[index].equals(obj.getClass().getName())) {
                return obj;
            } else {
                throwStartTagException
                    ("IDREF element content mapped to wrong type");
            }
        }
        return null;
    }

    /**
     * Find previously defined object corresponding to an ID. This does the
     * lookup and checks that the referenced object has been defined.
     *
     * @param id ID text
     * @param index expected reference type index
     * @return object corresponding to IDREF
     * @throws JiBXException on any error
     */
    public Object findDefinedID(String id, int index) throws JiBXException {
        Object obj = findID(id, index);
        if (obj == null) {
            throwStartTagException("ID " + id + " not defined");
        }
        return obj;
    }

    /**
     * Parse entire element, returning object (if defined yet) corresponding
     * to content interpreted as IDREF. Expects to find the element start tag,
     * text content, and end tag, in that order, and returns with the parser
     * positioned following the end tag. 
     *
     * @param ns namespace URI for expected element (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param tag attribute name expected
     * @param index expected reference type index
     * @return object corresponding to IDREF, or <code>null</code> if not
     * yet defined
     * @throws JiBXException on any error (possibly wrapping other exception)
     */
    public Object parseElementForwardIDREF(String ns, String tag, int index)
        throws JiBXException {
        parsePastStartTag(ns, tag);
        m_idref = parseContentText(ns, tag);
        return findID(m_idref, index);
    }

    /**
     * Get object (if defined yet) corresponding to IDREF attribute from
     * current start tag.
     *
     * @param ns namespace URI for expected attribute (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param name attribute name expected
     * @param index expected reference type index
     * @return object corresponding to IDREF, or <code>null</code> if not
     * yet defined
     * @throws JiBXException if attribute not present, or ID mapped to a
     * different type of object than expected
     */
    public Object attributeForwardIDREF(String ns, String name, int index)
        throws JiBXException {
        m_idref = attributeText(ns, name);
        return findID(m_idref, index);
    }

    /**
     * Parse entire element, returning previously defined object corresponding
     * to content interpreted as IDREF. Expects to find the element start tag,
     * text content, and end tag, in that order, and returns with the parser
     * positioned following the end tag. 
     *
     * @param ns namespace URI for expected element (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param tag attribute name expected
     * @param index expected reference type index
     * @return object corresponding to IDREF
     * @throws JiBXException if attribute not present, ID not defined, or
     * mapped to a different type of object than expected
     */
    public Object parseElementExistingIDREF(String ns, String tag, int index)
        throws JiBXException {
        parsePastStartTag(ns, tag);
        m_idref = parseContentText(ns, tag);
        return findDefinedID(m_idref, index);
    }

    /**
     * Get previously defined object corresponding to IDREF attribute from
     * current start tag.
     *
     * @param ns namespace URI for expected attribute (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param name attribute name expected
     * @param index expected reference type index
     * @return object corresponding to IDREF
     * @throws JiBXException if attribute not present, ID not defined, or
     * mapped to a different type of object than expected
     */
    public Object attributeExistingIDREF(String ns, String name, int index)
        throws JiBXException {
        m_idref = attributeText(ns, name);
        return findDefinedID(m_idref, index);
    }

    /**
     * Get integer value of attribute from current start tag.
     * Throws an exception if the attribute is not found in the start
     * tag, or if it is not a valid integer value.
     *
     * @param ns namespace URI for expected attribute (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param name attribute name expected
     * @return attribute integer value
     * @throws JiBXException if attribute not present or not a valid integer
     * value
     */
    public int attributeInt(String ns, String name) throws JiBXException {
        String text = attributeText(ns, name);
        try {
            return Utility.parseInt(text);
        } catch (JiBXException ex) {
            throw new JiBXException(ex.getMessage() + ' ' +
                buildPositionString(), ex.getRootCause());
        }
    }

    /**
     * Get integer value of optional attribute from current
     * start tag. If the attribute is not present the supplied default value
     * is returned instead.
     *
     * @param ns namespace URI for expected attribute (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param name attribute name expected
     * @param dflt value to be returned if attribute is not present
     * @return attribute integer value
     * @throws JiBXException if attribute value is not a valid integer
     */
    public int attributeInt(String ns, String name, int dflt)
        throws JiBXException {
        String value = getAttributeValue(ns, name);
        if (value == null) {
            return dflt;
        } else {
            try {
                return Utility.parseInt(value);
            } catch (JiBXException ex) {
                throw new JiBXException(ex.getMessage() + ' ' +
                    buildPositionString(), ex.getRootCause());
            }
        }
    }

    /**
     * Parse entire element, returning integer value of content.
     * Expects to find the element start tag, text content, and end tag,
     * in that order, and returns with the parser positioned following
     * the end tag.
     *
     * @param ns namespace URI for expected element (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param tag element name expected
     * @return content text from element
     * @throws JiBXException on any error (possibly wrapping other exception)
     */
    public int parseElementInt(String ns, String tag) throws JiBXException {
        parsePastStartTag(ns, tag);
        return parseContentInt(ns, tag);
    }

    /**
     * Parse entire optional element, returning integer value of content.
     * Expects to find the element start tag, text content, and end tag,
     * in that order, and returns with the parser positioned following
     * the end tag. Returns the default value if the element is missing or
     * has no content.
     *
     * @param ns namespace URI for expected element (may be <code>null</code>
     * or the empty string for the empty namespace)
     * @param tag element name expected
     * @param dflt default value
     * @return content text from element
     * @throws JiBXException on any error (possibly wrapping other exception)
     */
    public int parseElementInt(String ns, String tag, int dflt)
        throws JiBXException {
        if (parseIfStartTag(ns, tag)) {
            return parseContentInt(ns, tag);
        } else {
            return dflt;
        }
    }

    /**
     * Find required text value in enumeration. Looks up and returns the
     * enumeration value corresponding to the target text.
     *
     * @param target text to be found in enumeration
     * @param enums ordered array of texts included in enumeration
     * @param vals array of values to be returned for corresponding text match
     * positions (position returned directly if this is <code>null</code>)
     * @return enumeration value for target text
     * @throws JiBXException if target text not found in enumeration
     */
    public int convertEnum(String target, String[] enums, int[] vals)
        throws JiBXException {
        if (target == null) {
            throwStartTagException("Missing required enumeration value");
        }
        try {
            return Utility.enumValue(target, enums, vals);
        } catch (JiBXException ex) {
            throw new JiBXException(ex.getMessage() + ' ' +
                buildPositionString());
        }

⌨️ 快捷键说明

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