Examples of IXMLWriter


Examples of org.jibx.runtime.IXMLWriter

        boolean requestCompleted = false;
        try {
            logger.debug("Starting send message");
            soapWriter.startMessage(m_encodingStyle);
            IXMLWriter xmlWriter = soapWriter.getWriter();
            if (context.hasHandlers(SoapPhase.HEADER)) {
                soapWriter.startHeader();
                context.invokeHandlers(SoapPhase.HEADER, xmlWriter);
                soapWriter.endHeader();
            }
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

        boolean requestCompleted = false;

        try {
            soapWriter.startMessage(m_encodingStyle);
            IXMLWriter xmlWriter = soapWriter.getWriter();

            logger.debug("Starting send fault");
            soapWriter.startBody();

            SoapFault fault = (SoapFault) error;
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

     */
    private void preGet(IMarshallingContext ictx) throws IOException {
        if (m_namespaceDeclares != null) {
           
            // set up information for namespace indexes and prefixes
            IXMLWriter writer = ictx.getXmlWriter();
            String[] uris = new String[m_namespaceDeclares.size()/2];
            int[] indexes = new int[uris.length];
            String[] prefs = new String[uris.length];
            int base = writer.getNamespaceCount();
            for (int i = 0; i < uris.length; i++) {
                indexes[i] = base + i;
                prefs[i] = (String)m_namespaceDeclares.get(i*2);
                uris[i] = (String)m_namespaceDeclares.get(i*2+1);
            }
           
            // add the namespace declarations to current element
            writer.pushExtensionNamespaces(uris);
            writer.openNamespaces(indexes, prefs);
            for (int i = 0; i < uris.length; i++) {
                String prefix = prefs[i];
                String name = prefix.length() == 0 ?
                    "xmlns" : "xmlns:" + prefix;
                writer.addAttribute(0, name, uris[i]);
            }
           
        }
    }
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

    protected void writeNamespaces(IMarshallingContext ictx) throws JiBXException {
        if (m_namespaces != null) {
            try {
               
                // build sets of namespace uris and prefixes
                IXMLWriter writer = ictx.getXmlWriter();
                int curcnt = writer.getNamespaceCount();
                StringIntSizedMap uriindexes = new StringIntSizedMap(curcnt);
                int defcnt = m_namespaces.size() / 2;
                StringSizedSet prefixes = new StringSizedSet(curcnt + defcnt);
                for (int i = 0; i < curcnt; i++) {
                    uriindexes.add(writer.getNamespaceUri(i), i);
                    String prefix = writer.getNamespacePrefix(i);
                    if (prefix != null && prefix.length() > 0) {
                        prefixes.add(prefix);
                    }
                }
               
                // check namespace declarations on this element against writer state
                List uris = new ArrayList();
                GrowableIntArray indexes = new GrowableIntArray();
                GrowableStringArray prefs = new GrowableStringArray();
                int base = writer.getNamespaceCount();
                for (int i = 0; i < defcnt; i++) {
                    String pref = (String)m_namespaces.get(i * 2);
                    String uri = (String)m_namespaces.get(i * 2 + 1);
                    int index = uriindexes.get(uri);
                    if (index >= 0) {
                        if (writer.getNamespacePrefix(index) == null) {
                            indexes.add(index);
                            prefs.add(makeUniquePrefix(pref, prefixes));
                        }
                    } else {
                        indexes.add(base + uris.size());
                        prefs.add(makeUniquePrefix(pref, prefixes));
                        uris.add(uri);
                    }
                }
               
                // add the namespace declarations to current element
                writer.pushExtensionNamespaces((String[])uris.toArray(new String[uris.size()]));
                writer.openNamespaces(indexes.toArray(), prefs.toArray());
                for (int i = 0; i < prefs.size(); i++) {
                    String prefix = prefs.get(i);
                    String name = prefix.length() > 0 ? "xmlns:" + prefix : "xmlns";
                    writer.addAttribute(0, name, writer.getNamespaceUri(indexes.get(i)));
                }
               
            } catch (IOException e) {
                throw new JiBXException("Error writing output document", e);
            }
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

        // call base class implementation to handle namespaces
        super.preget(ictx);
       
        // write all extra attributes to element start tag
        if (m_attributes != null) {
            IXMLWriter writer = ictx.getXmlWriter();
            for (int i = 0; i < m_attributes.size();) {
                String name = (String)m_attributes.get(i++);
                String uri = (String)m_attributes.get(i++);
                String value = (String)m_attributes.get(i++);
                int index = writer.getNamespaceCount();
                while (--index >= 0 && !uri.equals(writer.getNamespaceUri(index)));
                if (index >= 0) {
                    try {
                        writer.addAttribute(index, name, value);
                    } catch (IOException e) {
                        throw new JiBXException("Error writing attribute", e);
                    }
                } else {
                    throw new JiBXException("Namespace uri \"" + uri + "\" is not defined");
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

        }
    }
   
    protected void setNamespaces(IMarshallingContext ictx) throws IOException {
        if (m_namespaces != null) {
            IXMLWriter writer = ((MarshallingContext)ictx).getXmlWriter();
            String[] uris = new String[m_namespaces.size()/2];
            int[] indexes = new int[uris.length];
            String[] prefs = new String[uris.length];
            int base = writer.getNamespaceCount();
            for (int i = 0; i < uris.length; i++) {
                indexes[i] = base + i;
                String pref = (String)m_namespaces.get(i*2);
                if (pref == null) {
                    pref = "";
                }
                prefs[i] = pref;
                uris[i] = (String)m_namespaces.get(i*2+1);
            }
            writer.pushExtensionNamespaces(uris);
            writer.openNamespaces(indexes, prefs);
            for (int i = 0; i < uris.length; i++) {
                String prefix = prefs[i];
                String name = prefix.length() > 0 ? "xmlns:" + prefix : "xmlns";
                writer.addAttribute(0, name, uris[i]);
            }
        }
    }
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

     */
    public static String serialize(QName qname, IMarshallingContext ictx)
        throws JiBXException {
       
        // check if prefix is alread defined in document with correct URI
        IXMLWriter ixw = ((MarshallingContext)ictx).getXmlWriter();
        int index = -1;
        int tryidx = ixw.getPrefixIndex(qname.m_prefix);
        if (tryidx >= 0 &&
            qname.m_uri.equals(ixw.getNamespaceUri(tryidx))) {
            index = tryidx;
        }
        if (index < 0) {
           
            // prefix not defined, find the namespace index in binding
            String[] nss = ixw.getNamespaces();
            for (int i = 0; i < nss.length; i++) {
                if (nss[i].equals(qname.m_uri)) {
                    index = i;
                    break;
                }
            }
            if (index < 0) {
               
                // namespace not in binding, check extensions
                String[][] nsss = ixw.getExtensionNamespaces();
                if (nsss != null) {
                    int base = nss.length;
                    outer: for (int i = 0; i < nsss.length; i++) {
                        nss = nsss[i];
                        for (int j = 0; j < nss.length; j++) {
                            if (nss[j].equals(qname.m_uri)) {
                                index = base + j;
                                break outer;
                            }
                        }
                        base += nss.length;
                    }
                }
               
            }
        }
        if (index >= 0) {
           
            // get prefix defined for namespace
            String prefix = ixw.getNamespacePrefix(index);
            if (prefix == null) {
                throw new JiBXException("Namespace URI " + qname.m_uri +
                    " cannot be used since it is not active");
            } else if (prefix.length() > 0) {
                return prefix + ':' + qname.m_name;
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

        // call base class implementation to handle namespaces
        super.preget(ictx);
       
        // write all extra attributes to element start tag
        if (m_attributes != null) {
            IXMLWriter writer = ictx.getXmlWriter();
            for (int i = 0; i < m_attributes.size();) {
                String name = (String) m_attributes.get(i++);
                String uri = (String) m_attributes.get(i++);
                String value = (String) m_attributes.get(i++);
                int index = writer.getNamespaceCount();
                while (--index >= 0 &&
                    !uri.equals(writer.getNamespaceUri(index)));
                if (index >= 0) {
                    try {
                        writer.addAttribute(index, name, value);
                    } catch (IOException e) {
                        throw new JiBXException("Error writing attribute", e);
                    }
                } else {
                    throw new JiBXException("Namespace uri \"" + uri +
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

        if (qname == null) {
            return null;
        } else {
           
            // check for specified prefix
            IXMLWriter ixw = ((MarshallingContext)ictx).getXmlWriter();
            int index = -1;
            String uri = qname.getUri();
            if (uri == null) {
                uri = "";
            }
            String prefix = qname.getPrefix();
            if (prefix != null) {
               
                // see if prefix already defined in document with correct URI
                int tryidx = ixw.getPrefixIndex(prefix);
                if (tryidx >= 0 &&
                    uri.equals(ixw.getNamespaceUri(tryidx))) {
                    index = tryidx;
                } else if ("".equals(prefix)) {
                   
                    // check for no-namespace schema imported into namespace
                    int depth = ictx.getStackDepth();
                    for (int i = 0; i < depth; i++) {
                        Object obj = ictx.getStackObject(i);
                        if (obj instanceof SchemaElement) {
                            SchemaElement schema = (SchemaElement)obj;
                            String ens = schema.getEffectiveNamespace();
                            if (ens != schema.getTargetNamespace()) {
                                return qname.getName();
                            } else {
                                break;
                            }
                        }
                    }
                   
                }
            }
           
            // check if need to lookup prefix for namespace
            if (index < 0) {
               
                // prefix not defined, find the namespace index in binding
                if (uri == null) {
                    uri = "";
                }
                String[] nss = ixw.getNamespaces();
                for (int i = 0; i < nss.length; i++) {
                    if (nss[i].equals(uri)) {
                        index = i;
                        break;
                    }
                }
                if (index < 0) {
                   
                    // namespace not in binding, check extensions
                    String[][] nsss = ixw.getExtensionNamespaces();
                    if (nsss != null) {
                        int base = nss.length;
                        outer: for (int i = nsss.length-1; i >= 0; i--) {
                            nss = nsss[i];
                            for (int j = 0; j < nss.length; j++) {
                                if (nss[j].equals(uri)) {
                                   
                                    // adjust for other extension namespaces
                                    index = base + j;
                                    for (int k = 0; k < i; k++) {
                                        index += nsss[k].length;
                                    }
                                    break outer;
                                }
                            }
                        }
                    }
                }
            }
           
            // check if prefix is alread defined in document with correct URI
            if (index >= 0) {
               
                // get prefix defined for namespace
                prefix = ixw.getNamespacePrefix(index);
                if (prefix == null) {
                    throw new JiBXException("Namespace URI " + qname.getUri() +
                        " cannot be used since it is not active");
                } else if (prefix.length() > 0) {
                    return prefix + ':' + qname.getName();
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

            throw new JiBXException("Invalid object type for marshaller");
        } else {
           
            // start by setting up added namespaces
            MarshallingContext ctx = (MarshallingContext)ictx;
            IXMLWriter xwrite = ctx.getXmlWriter();
            int ixsi = xwrite.getNamespaces().length;
            String[][] extens = xwrite.getExtensionNamespaces();
            if (extens != null) {
                for (int i = 0; i < extens.length; i++) {
                    ixsi += extens[i].length;
                }
            }
            xwrite.pushExtensionNamespaces(SCHEMA_NAMESPACE_URIS);
           
            // generate start tag for containing element
            Map map = (Map)obj;
            ctx.startTagNamespaces(m_index, m_name, new int[] { ixsi, ixsi+1 },
                SCHEMA_NAMESPACE_PREFIXES).
                attribute(m_index, SIZE_ATTRIBUTE_NAME, map.size()).
                closeStartContent();
           
            // loop through all entries in hashmap
            Iterator iter = map.entrySet().iterator();
            while (iter.hasNext()) {
               
                // first make sure we have a value
                Map.Entry entry = (Map.Entry)iter.next();
                Object value = entry.getValue();
                if (value != null) {
                   
                    // write element with key attribute
                    ctx.startTagAttributes(m_index, ENTRY_ELEMENT_NAME);
                    ctx.attribute(m_index, KEY_ATTRIBUTE_NAME,
                        entry.getKey().toString());
                   
                    // translate value object class to schema type
                    String tname = value.getClass().getName();
                    int type = s_javaTypesEnum.getValue(tname);
                    if (type < 0) {
                        throw new JiBXException("Value of type " + tname +
                            " with key " + entry.getKey() +
                            " is not a supported type");
                    }
                   
                    // generate xsi:type attribute for value
                    ctx.attribute(ixsi, TYPE_ATTRIBUTE_NAME,
                        XSD_PREFIX_LEAD + s_schemaTypesEnum.getName(type));
                    ctx.closeStartContent();
                   
                    // handle the actual value conversion based on type
                    switch (type) {
                       
                        case BOOLEAN_TYPE:
                            ctx.content(Utility.serializeBoolean
                                (((Boolean)value).booleanValue()));
                            break;
                           
                        case BYTE_TYPE:
                            ctx.content(Utility.
                                serializeByte(((Byte)value).byteValue()));
                            break;
                           
                        case DOUBLE_TYPE:
                            ctx.content(Utility.
                                serializeDouble(((Double)value).doubleValue()));
                            break;
                           
                        case FLOAT_TYPE:
                            ctx.content(Utility.
                                serializeFloat(((Float)value).floatValue()));
                            break;
                           
                        case INT_TYPE:
                            ctx.content(((Integer)value).intValue());
                            break;
                           
                        case LONG_TYPE:
                            ctx.content(Utility.
                                serializeLong(((Long)value).longValue()));
                            break;
                           
                        case SHORT_TYPE:
                            ctx.content(Utility.
                                serializeShort(((Short)value).shortValue()));
                            break;
                           
                        case DATETIME_TYPE:
                            ctx.content(Utility.serializeDateTime((Date)value));
                            break;
                           
//#!j2me{
                        case DATE_TYPE:
                            ctx.content(Utility.
                                serializeSqlDate((java.sql.Date)value));
                            break;
                           
                        case TIME_TYPE:
                            ctx.content(Utility.
                                serializeSqlTime((java.sql.Time)value));
                            break;
//#j2me}
                           
                        case BYTERRAY_TYPE:
                            ctx.content(Utility.serializeBase64((byte[])value));
                            break;
                           
                        case DECIMAL_TYPE:
                        case INTEGER_TYPE:
                        case STRING_TYPE:
                            ctx.content(value.toString());
                            break;
                    }
                   
                    // finish with close tag for entry element
                    ctx.endTag(m_index, ENTRY_ELEMENT_NAME);
                }
            }
           
            // finish with end tag for container element
            ctx.endTag(m_index, m_name);
            xwrite.popExtensionNamespaces();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.