Package org.jibx.runtime.impl

Examples of org.jibx.runtime.impl.MarshallingContext


            }
        }
    }

    private MarshallingContext createMarshaller(IBindingFactory factory) throws WsBindingException {
        MarshallingContext marshaller;
        try {
            marshaller = (MarshallingContext) factory.createMarshallingContext();
        } catch (JiBXException e) {
            throw new WsBindingException("Unable to create MarshallingContext.", e);
        }
View Full Code Here


            if (match.equals(m_versionTexts[i])) {
               
                // version found, create marshaller for the associated binding
                IBindingFactory fact = BindingDirectory.
                    getFactory(m_versionBindings[i], obj.getClass());
                MarshallingContext context =
                    (MarshallingContext)fact.createMarshallingContext();
               
                // configure marshaller for writing document
                context.setIndent(m_outputIndent);
                if (m_outputWriter == null) {
                    if (m_outputStream == null) {
                        throw new JiBXException("Output not configured");
                    } else {
                        context.setOutput(m_outputStream, m_outputEncoding);
                    }
                } else {
                    context.setOutput(m_outputWriter);
                }
               
                // output object as document
                context.startDocument(m_outputEncoding, null);
                ((IMarshallable)obj).marshal(context);
                context.endDocument();
                return;
               
            }
        }
       
View Full Code Here

        } else if (!(ictx instanceof MarshallingContext)) {
            throw new JiBXException("Invalid context type for marshaller");
        } else {
           
            // generate the element start tag
            MarshallingContext ctx = (MarshallingContext)ictx;
            ctx.startTagAttributes(m_index, m_name);
           
            // add attribute reference to object ID
            ctx.attribute(0, getAttributeName(), getIdValue(obj));
           
            // close start tag for empty element
            ctx.closeStartEmpty();
        }
    }
View Full Code Here

        } else if (!(ictx instanceof MarshallingContext)) {
            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

            if (!clas.isArray()) {
                throw new JiBXException("Invalid object type for marshaller");
            } else {
           
                // start by generating start tag for container
                MarshallingContext ctx = (MarshallingContext)ictx;
                Object[] array = (Object[])obj;
                if (m_name != null) {
                    ctx.startTag(m_index, m_name);
                }
       
                // loop through all entries in array
                for (int i = 0; i < array.length; i++) {
                    Object item = array[i];
                    if (item == null) {
                        throw new JiBXException("Null value at offset " + i +
                            " not supported");
                    } else if (item instanceof IMarshallable) {
                        ((IMarshallable)item).marshal(ctx);
                    } else {
                        throw new JiBXException("Array item of type " +
                            item.getClass().getName() + " does not implement " +
                            "org.jibx.runtime.IMarshallable");
                    }
                }
       
                // finish with end tag for container element
                if (m_name != null) {
                    ctx.endTag(m_index, m_name);
                }
               
            }
        }
    }
View Full Code Here

        } else if (!(ictx instanceof MarshallingContext)) {
            throw new JiBXException("Invalid object type for marshaller");
        } else {
           
            // start by generating start tag for container
            MarshallingContext ctx = (MarshallingContext)ictx;
            HashMap map = (HashMap)obj;
            ctx.startTagAttributes(m_index, m_name).
                attribute(m_index, SIZE_ATTRIBUTE_NAME, map.size()).
                closeStartContent();
           
            // loop through all entries in hashmap
            Iterator iter = map.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry)iter.next();
                ctx.startTagAttributes(m_index, ENTRY_ELEMENT_NAME);
                if (entry.getKey() != null) {
                    ctx.attribute(m_index, KEY_ATTRIBUTE_NAME,
                        entry.getKey().toString());
                }
                ctx.closeStartContent();
                if (entry.getValue() instanceof IMarshallable) {
                    ((IMarshallable)entry.getValue()).marshal(ctx);
                    ctx.endTag(m_index, ENTRY_ELEMENT_NAME);
                } else {
                    throw new JiBXException("Mapped value is not marshallable");
                }
            }
           
            // finish with end tag for container element
            ctx.endTag(m_index, m_name);
        }
    }
View Full Code Here

        } else if (!(ictx instanceof MarshallingContext)) {
            throw new JiBXException("Invalid context type for marshaller");
        } else {
           
            // check if ID already defined
            MarshallingContext ctx = (MarshallingContext)ictx;
            HashMap map = ctx.getIdMap();
            String id = getIdValue(obj);
            Object value = map.get(id);
            if (value == null) {
                if (obj instanceof IMarshallable) {
                   
                    // new id, write full representation and add to map
                    map.put(id, obj);
                    ((IMarshallable)obj).marshal(ctx);
                   
                } else {
                    throw new JiBXException("Object of type " +
                        obj.getClass().getName() + " is not marshallable");
                }
            } else if (value.equals(obj)) {
               
                // generate reference to previously-defined item
                ctx.startTagAttributes(m_index, m_name);
                ctx.attribute(0, getAttributeName(), id);
                ctx.closeStartEmpty();
               
            } else {
                throw new JiBXException("Duplicate definition for ID " + id);
            }
        }
View Full Code Here

        } else if (!(ictx instanceof MarshallingContext)) {
            throw new JiBXException("Invalid object type for marshaller");
        } else {
           
            // start by generating start tag for container
            MarshallingContext ctx = (MarshallingContext)ictx;
            Map map = (Map)obj;
            ctx.startTagAttributes(m_index, m_name).
                attribute(m_index, getSizeAttributeName(), map.size()).
                closeStartContent();
           
            // loop through all entries in map
            Iterator iter = map.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry)iter.next();
                ctx.startTagAttributes(m_index, getEntryElementName());
                ctx.attribute(m_index, getKeyAttributeName(),
                    entry.getKey().toString());
                ctx.closeStartContent();
                if (entry.getValue() instanceof IMarshallable) {
                    ((IMarshallable)entry.getValue()).marshal(ctx);
                    ctx.endTag(m_index, getEntryElementName());
                } else {
                    throw new JiBXException("Mapped value is not marshallable");
                }
            }
           
            // finish with end tag for container element
            ctx.endTag(m_index, m_name);
        }
    }
View Full Code Here

    /* (non-Javadoc)
     * @see org.jibx.runtime.IMarshaller#marshal(java.lang.Object, org.jibx.runtime.IMarshallingContext)
     */
    public void marshal(Object obj, IMarshallingContext ictx)
        throws JiBXException {
        MarshallingContext ctx = (MarshallingContext)ictx;
        Name name = (Name)obj;
        ctx.startTag(0, "name");
        ctx.element(0, "first-name", name.firstName);
        ctx.element(0, "last-name", name.lastName);
        ctx.endTag(0, "name");
    }
View Full Code Here

    /* (non-Javadoc)
     * @see org.jibx.runtime.IMarshaller#marshal(java.lang.Object, org.jibx.runtime.IMarshallingContext)
     */
    public void marshal(Object obj, IMarshallingContext ictx)
        throws JiBXException {
        MarshallingContext ctx = (MarshallingContext)ictx;
        Name name = (Name)obj;
        ctx.startTag(m_index, m_name);
        ctx.element(m_index, "first-name", name.firstName);
        ctx.element(m_index, "last-name", name.lastName);
        ctx.endTag(m_index, m_name);
    }
View Full Code Here

TOP

Related Classes of org.jibx.runtime.impl.MarshallingContext

Copyright © 2018 www.massapicom. 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.