Package org.jibx.runtime.impl

Examples of org.jibx.runtime.impl.MarshallingContext


        } 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;
            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 instanceof IMarshallable) {
                    ((IMarshallable)item).marshal(ctx);
                } else if (item == null) {
                    throw new JiBXException("Null value at offset " + i +
                        " not supported");
                } else {
                    throw new JiBXException("Array value of type " +
                        item.getClass().getName() + " at offset " + i +
                        " is not marshallable");
                }
            }
       
            // finish with end tag for container element
            if (m_name != null) {
                ctx.endTag(m_index, m_name);
            }
               
        }
    }
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 object type for marshaller");
    } else {
      OverlapBehaviorInfo overlapBehaviorInfo = (OverlapBehaviorInfo) obj;
      // start by generating start tag for container
      MarshallingContext ctx = (MarshallingContext) ictx;
      ctx.startTag(index, name).content(overlapBehaviorInfo.getOverlapBehavior().xmlValue())
          .closeStartContent();
      ctx.endTag(index, name);
    }
  }
View Full Code Here

      if (!(obj instanceof Properties))
         throw new JiBXException("Invalid object type for marshaller");
      if (!(ictx instanceof MarshallingContext))
         throw new JiBXException("Invalid object type for marshaller");

      MarshallingContext ctx = (MarshallingContext)ictx;
      Properties map = (Properties)obj;
      MarshallingContext mContext = ctx.startTagAttributes(marshallIndex, marshallName);
      mContext.attribute(marshallIndex, SIZE_ATTRIBUTE_NAME, map.size()).closeStartContent();

      Iterator<Map.Entry<String, String>> iter = map.entrySet().iterator();
      while (iter.hasNext())
      {
         Map.Entry<String, String> entry = iter.next();
View Full Code Here

        if (!(obj instanceof Properties))
            throw new JiBXException("Invalid object type for marshaller");
        if (!(ictx instanceof MarshallingContext))
            throw new JiBXException("Invalid object type for marshaller");

        MarshallingContext ctx = (MarshallingContext) ictx;
        Properties map = (Properties) obj;
        MarshallingContext mContext = ctx.startTagAttributes(marshallIndex, marshallName);
        mContext.attribute(marshallIndex, SIZE_ATTRIBUTE_NAME, map.size()).closeStartContent();

        Iterator<Map.Entry<String, String>> iter = map.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<String, String> entry = iter.next();
            String key = entry.getKey().toString();
View Full Code Here

public class NullBindingFactory implements IBindingFactory {
   
    private static final String[] EMPTY_STRINGS = new String[0];
   
    public IMarshallingContext createMarshallingContext() throws JiBXException {
        return new MarshallingContext(EMPTY_STRINGS, EMPTY_STRINGS, EMPTY_STRINGS, this);
    }
View Full Code Here

        throws JiBXException {

        IBindingFactory factory = BindingDirectory.getFactory(
            "metadata", JIBX_FACTORY_CLASS);

        MarshallingContext ctx = (MarshallingContext) iMarshallingContext;
        preprocessMarshallingContext(ctx);

        MarshallingContext delegateContext =
            (MarshallingContext) factory.createMarshallingContext();
        try {
            delegateContext.setFromContext(ctx);
        } catch(java.io.IOException e) {
            throw new JiBXException("Could not set from another context", e);
        }
        int pos = findIndex(factory.getMappedClasses(), o.getClass().getName());
        if (pos < 0) {
            throw new JiBXException(EXCEPTION_LOCALIZER.format(
                "marshaller-not-found", o.getClass().getName()));
        }

        IMarshaller marshaller =
            delegateContext.getMarshaller(pos, o.getClass().getName());

        marshaller.marshal(o, delegateContext);
        postprocessMarshallingContext(ctx);
    }
View Full Code Here

        throws JiBXException {

        IBindingFactory factory = BindingDirectory.getFactory(
            getTargetBindingName(), getTargetClass());

        MarshallingContext ctx = (MarshallingContext) iMarshallingContext;

        MarshallingContext delegateContext =
            (MarshallingContext) factory.createMarshallingContext();
        try {
            delegateContext.setFromContext(ctx);
        } catch(java.io.IOException e) {
            throw new JiBXException("Could not set from another context", e);
        }

        delegateContext.setXmlWriter(ctx.getXmlWriter());
        int pos = findIndex(factory.getMappedClasses(), getTargetClass().getName());
        if (pos < 0) {
            throw new JiBXException(EXCEPTION_LOCALIZER.format(
                "marshaller-not-found", o.getClass().getName()));
        }

        IMarshaller marshaller =
            delegateContext.getMarshaller(pos, getTargetClass().getName());

        marshaller.marshal(o, delegateContext);
    }
View Full Code Here

   
    // javadoc inherited
    public void marshal(Object arg0, IMarshallingContext context)
            throws JiBXException {
        MarshallingContext ctx = (MarshallingContext) context;
        DatasourceConfiguration dataSource = (DatasourceConfiguration) arg0;
        DataSourceType type = dataSource.getType();
        if (type == DataSourceType.JDBC_DATASOURCE) {
            JDBCDatasource jdbcDatasource = (JDBCDatasource) dataSource;
            ctx.startTag(index, JDBC_DATASOURCE_TAG_NAME);

            writeTagsTextContent(ctx, DRIVER_CLASS_TAG_NAME,
                    jdbcDatasource.getDriverClass());
            writeTagsTextContent(ctx, CONNECTION_STRING_TAG_NAME,
                    jdbcDatasource.getConnectionString());

            marshalName(index, ctx, jdbcDatasource.getName());
           
            ctx.endTag(index, JDBC_DATASOURCE_TAG_NAME);             
        } else if (type == DataSourceType.INTERNAL_POOL_DATASOURCE) {
            InternalPoolDatasource internalPoolDatasource =
                (InternalPoolDatasource) dataSource;  
            ctx.startTag(index, INTERNAL_POOL_DATASOURCE_TAG_NAME);
           
            writeTagsTextContent(ctx, DRIVER_CLASS_TAG_NAME,
                    internalPoolDatasource.getDriverClass());
            writeTagsTextContent(ctx, URL_TAG_NAME,
                    internalPoolDatasource.getUrl());
            writeTagsTextContent(ctx, USERNAME_TAG_NAME,
                    internalPoolDatasource.getUsername());
            writeTagsTextContent(ctx, PASSWORD_TAG_NAME,
                    internalPoolDatasource.getPassword());
            writeTagsTextContent(ctx, MAX_ACTIVE_TAG_NAME,
                    internalPoolDatasource.getMaxActive());
            writeTagsTextContent(ctx, MAX_IDLE_TAG_NAME,
                    internalPoolDatasource.getMaxIdle());
            writeTagsTextContent(ctx, MAX_WAIT_TAG_NAME,
                    internalPoolDatasource.getMaxWait());

            marshalName(index, ctx, internalPoolDatasource.getName());
           
            ctx.endTag(index, INTERNAL_POOL_DATASOURCE_TAG_NAME);           
        } else if (type == DataSourceType.JNDI_DATASOURCE) {
            JNDIDatasource jndiDatasource = (JNDIDatasource) dataSource;
            ctx.startTag(index, JNDI_DATASOURCE_TAG_NAME);
           
            writeTagsTextContent(ctx, JNDI_NAME_TAG_NAME,
                    jndiDatasource.getJndiName());

            marshalName(index, ctx, jndiDatasource.getName());
           
            ctx.endTag(index, JNDI_DATASOURCE_TAG_NAME);           
        } else {
            throw new JiBXException(EXCEPTION_LOCALIZER
                    .format("invalid-datasource-type"));
        }
    }
View Full Code Here

  }

  @Override
  protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException {
    try {
      MarshallingContext marshallingContext = (MarshallingContext) createMarshallingContext();
      IXMLWriter xmlWriter = new StAXWriter(marshallingContext.getNamespaces(), streamWriter);
      marshallingContext.setXmlWriter(xmlWriter);
      marshallingContext.marshalDocument(graph);
    }
    catch (JiBXException ex) {
      throw convertJibxException(ex, false);
    }
  }
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.