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

📄 marshallingcontext.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        } catch (IOException ex) {
            throw new JiBXException("Error writing marshalled document", ex);
        }
    }
    
    /**
     * Add integer content to current element.
     *
     * @param value integer element content
     * @return this context (to allow chained calls)
     * @throws JiBXException on any error (possibly wrapping other exception)
     */

    public MarshallingContext content(int value) throws JiBXException {
        content(Integer.toString(value));
        return this;
    }
    
    /**
     * Add enumeration content to current element. The actual text to be
     * written is obtained by indexing into the supplied array of values.
     *
     * @param value integer enumeration value (zero-based)
     * @param table text values in enumeration
     * @return this context (to allow chained calls)
     * @throws JiBXException on any error (possibly wrapping other exception)
     */

    public MarshallingContext content(int value, String[] table)
        throws JiBXException {
        try {
            content(table[value]);
            return this;
        } catch (ArrayIndexOutOfBoundsException ex) {
            throw new JiBXException("Enumeration value of " + value +
                " is outside to allowed range of 0 to " + table.length);
        }
    }
    
    /**
     * Generate end tag for element.
     *
     * @param index namespace URI index number
     * @param name element name
     * @return this context (to allow chained calls)
     * @throws JiBXException on any error (possibly wrapping other exception)
     */

    public MarshallingContext endTag(int index, String name)
        throws JiBXException {
        try {
            m_writer.endTag(index, name);
            return this;
        } catch (IOException ex) {
            throw new JiBXException("Error writing marshalled document", ex);
        }
    }

    /**
     * Generate complete element with text content.
     *
     * @param index namespace URI index number
     * @param name element name
     * @param value text element content
     * @return this context (to allow chained calls)
     * @throws JiBXException on any error (possibly wrapping other exception)
     */

    public MarshallingContext element(int index, String name, String value) 
        throws JiBXException {
        try {
            if (value.length() == 0) {
                m_writer.startTagOpen(index, name);
                m_writer.closeEmptyTag();
            } else {
                m_writer.startTagClosed(index, name);
                m_writer.writeTextContent(value);
                m_writer.endTag(index, name);
            }
            return this;
        } catch (IOException ex) {
            throw new JiBXException("Error writing marshalled document", ex);
        } catch (Exception ex) {
            String text = buildNameString(index, name);
            if (value == null) {
                throw new JiBXException("null value for element " +
                    text + " from object of type " +
                    getStackTop().getClass().getName());
            } else {
                throw new JiBXException
                    ("Exception while marshalling element " + text, ex);
            }
        }
    }
    
    /**
     * Generate complete element with integer content.
     *
     * @param index namespace URI index number
     * @param name element name
     * @param value integer element content
     * @return this context (to allow chained calls)
     * @throws JiBXException on any error (possibly wrapping other exception)
     */

    public MarshallingContext element(int index, String name, int value) 
        throws JiBXException {
        return element(index, name, Integer.toString(value));
    }
    
    /**
     * Generate complete element with enumeration content. The actual text to be
     * written is obtained by indexing into the supplied array of values.
     *
     * @param index namespace URI index number
     * @param name element name
     * @param value integer enumeration value (zero-based)
     * @param table text values in enumeration
     * @return this context (to allow chained calls)
     * @throws JiBXException on any error (possibly wrapping other exception)
     */

    public MarshallingContext element(int index, String name, int value,
        String[] table) throws JiBXException {
        try {
            return element(index, name, table[value]);
        } catch (ArrayIndexOutOfBoundsException ex) {
            throw new JiBXException("Enumeration value of " + value +
                " is outside to allowed range of 0 to " + table.length);
        }
    }
    
    /**
     * Write CDATA text to document.
     *
     * @param text content value text
     * @return this context (to allow chained calls)
     * @throws IOException on error writing to document
     */

    public MarshallingContext writeCData(String text) throws IOException {
        try {
            m_writer.writeCData(text);
            return this;
        } catch (NullPointerException e) {
            if (text == null) {
                throw new IOException
                    ("Null value writing CDATA from object of type " +
                    getStackTop().getClass().getName());
            } else {
                throw e;
            }
        }
    }
    
    /**
     * Write content value with character entity substitutions.
     *
     * @param text content value text
     * @return this context (to allow chained calls)
     * @throws IOException on error writing to document
     */

    public MarshallingContext writeContent(String text) throws IOException {
        try {
            m_writer.writeTextContent(text);
            return this;
        } catch (NullPointerException e) {
            if (text == null) {
                throw new IOException
                    ("Null value writing text content from object " +
                    getStackTop().getClass().getName());
            } else {
                throw e;
            }
        }
    }
    
    /**
     * Marshal all items in a collection. This variation is for generic
     * collections.
     *
     * @param col collection of items to be marshalled
     * @return this context (to allow chained calls)
     * @throws JiBXException on any error (possibly wrapping other exception)
     */

    public MarshallingContext marshalCollection(Collection col) 
        throws JiBXException {
        Iterator iter = col.iterator();
        while (iter.hasNext()) {
            Object obj = iter.next();
            if (obj instanceof IMarshallable) {
                ((IMarshallable)obj).marshal(this);
            } else {
                throw new JiBXException
                    ("Unmarshallable object of class " + obj.getClass() +
                    " found in marshalling");
            }
        }
        return this;
    }
    
    /**
     * Marshal all items in a collection. This variation is for ArrayList
     * collections.
     *
     * @param col collection of items to be marshalled
     * @return this context (to allow chained calls)
     * @throws JiBXException on any error (possibly wrapping other exception)
     */

    public MarshallingContext marshalCollection(ArrayList col) 
        throws JiBXException {
        for (int i = 0; i < col.size(); i++) {
            Object obj = col.get(i);
            if (obj instanceof IMarshallable) {
                ((IMarshallable)obj).marshal(this);
            } else {
                throw new JiBXException
                    ("Unmarshallable object of class " +
                     obj.getClass().getName() + " found in marshalling");
            }
        }
        return this;
    }
    
    /**
     * Marshal all items in a collection. This variation is for Vector
     * collections.
     *
     * @param col collection of items to be marshalled
     * @return this context (to allow chained calls)
     * @throws JiBXException on any error (possibly wrapping other exception)
     */

    public MarshallingContext marshalCollection(Vector col) 
        throws JiBXException {
        for (int i = 0; i < col.size(); i++) {
            Object obj = col.elementAt(i);
            if (obj instanceof IMarshallable) {
                ((IMarshallable)obj).marshal(this);
            } else {
                throw new JiBXException
                    ("Unmarshallable object of class " +
                     obj.getClass().getName() + " found in marshalling");
            }
        }
        return this;
    }
    
    /**
     * Define marshalling for class. Adds the marshalling definition using fixed
     * indexes for each class, allowing direct lookup of the marshaller when
     * multiple versions are defined.
     *
     * @param index class index for marshalling definition
     * @param name marshaller class name handling 
     */
    
    public void addMarshalling(int index, String name) {
        m_marshallerClasses[index] = name;
    }
    
    /**
     * Undefine marshalling for element. Removes the marshalling
     * definition for a particular class index.
     *
     * @param index class index for marshalling definition
     */
    
    public void removeMarshalling(int index) {
        m_marshallers[index] = null;
    }
    
    /**
     * Generate start tag for element with namespaces. This creates the actual
     * start tag, along with any necessary namespace declarations. Previously
     * active namespace declarations are not duplicated. The tag is
     * left incomplete, allowing other attributes to be added.
     *
     * TODO: Handle nested default namespaces declarations, prefixes for outers
     *
     * @param index namespace URI index number
     * @param name element name
     * @param nums array of namespace indexes defined by this element (must
     * be constant, reference is kept until end of element)
     * @param prefs array of namespace prefixes mapped by this element (no
     * <code>null</code> values, use "" for default namespace declaration)
     * @return this context (to allow chained calls)
     * @throws JiBXException on any error (possibly wrapping other exception)
     */

    public MarshallingContext startTagNamespaces(int index, String name,
        int[] nums, String[] prefs) throws JiBXException {
        try {
            m_writer.startTagNamespaces(index, name, nums, prefs);
            return this;
        } catch (IOException ex) {
            throw new JiBXException("Error writing marshalled document", ex);
        }
    }
    
    /**
     * Find the marshaller for a particular class index
     * in the current context.
     * TODO: Eliminate the string passing, since it's not a common enough
     * problem to be worth checking (and with abstract mappings can be really
     * difficult to set properly)
     *
     * @param index class index for marshalling definition
     * @param name fully qualified name of class to be marshalled (used only
     * for validation)
     * @return marshalling handler for class
     * @throws JiBXException on any error (possibly wrapping other exception)

⌨️ 快捷键说明

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