Example usage for javax.xml.bind MarshalException MarshalException

List of usage examples for javax.xml.bind MarshalException MarshalException

Introduction

In this page you can find the example usage for javax.xml.bind MarshalException MarshalException.

Prototype

public MarshalException(Throwable exception) 

Source Link

Document

Construct a MarshalException with a linkedException.

Usage

From source file:org.javelin.sws.ext.bind.SweJaxbMarshaller.java

/**
 * The main marshal method which converts an object into a series of {@link XMLEventWriter XML events} being added to {@link XMLEventWriter}.
 * /*from  w w w.  j  ava2s  .  c  om*/
 * @param jaxbElement
 * @param writer
 */
private void marshal0(Object jaxbElement, XMLEventWriter writer) throws JAXBException {
    ElementPattern<?> pattern = this.determineXmlPattern(jaxbElement);
    try {
        if (this.formatting)
            writer = new IndentingXMLEventWriter(writer);

        if (!this.fragment)
            writer.add(XmlEventsPattern.XML_EVENTS_FACTORY.createStartDocument(this.encoding, "1.0", true));

        MarshallingContext context = new MarshallingContext();
        // TODO: correctly handle internal xmlOutputFactory's IS_REPAIRING_NAMESPACES property!
        context.setRepairingXmlEventWriter(
                (Boolean) this.xmlOutputFactory.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES));
        context.setMultiRefEncoding(this.multiRefEncoding);
        context.setSendTypes(this.sendTypes);

        // go!
        pattern.replay(jaxbElement, writer, context);

        if (context.isMultiRefEncoding())
            context.getMultiRefSupport().outputMultiRefs(writer, context);

        if (!this.fragment)
            writer.add(XmlEventsPattern.XML_EVENTS_FACTORY.createEndDocument());
    } catch (XMLStreamException e) {
        throw new MarshalException(e);
    }
}

From source file:org.javelin.sws.ext.bind.SweJaxbMarshaller.java

/**
 * Using the class of the object to be marshalled determines a series of XML Events to be generated in order to marshal given object.
 * Used only at the highest level of marshalling and must result in a pattern which {@link XmlEventsPattern#isElement() is an element}.
 * /*from w ww .  ja v a  2  s .co m*/
 * @param jaxbElement
 * @return
 * @throws MarshalException 
 */
private ElementPattern<?> determineXmlPattern(Object jaxbElement) throws MarshalException {
    Class<?> clz = jaxbElement.getClass();
    if (jaxbElement instanceof JAXBElement)
        clz = ((JAXBElement<?>) jaxbElement).getDeclaredType();

    // pattern (both for root and non-root classes) must be present in context's mapping metadata
    TypedPattern<?> pattern = this.jaxbContext.patterns.get(clz);

    if (pattern == null)
        throw new MarshalException("Unable to determine XML Events pattern to marshal object of class "
                + jaxbElement.getClass().getName());

    // if we marshal XmlRootElement, then return proper pattern
    if (this.jaxbContext.rootPatterns.containsKey(clz))
        return this.jaxbContext.rootPatterns.get(clz);

    // if we marshal JAXBElement, we create ElementPattern on demand (without caching it!)
    if (jaxbElement instanceof JAXBElement) {
        // TODO: use ((JAXBElement<?>) jaxbElement).getDeclaredType() or ((JAXBElement<?>) jaxbElement).getValue().getClass()?
        return ElementPattern.newElementPattern(((JAXBElement<?>) jaxbElement).getName(), pattern);
    }

    throw new MarshalException("Unable to marshal object of class " + clz.getName()
            + ". Only JAXBElements and @XmlRootElement annotated classes may be marshalled.");
}

From source file:org.kuali.rice.core.util.jaxb.NameAndNamespacePairValidatingAdapter.java

/**
 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
 */// w  w  w. j  a va2  s . co m
@Override
public NameAndNamespacePair marshal(NameAndNamespacePair v) throws Exception {
    if (v != null) {
        if (StringUtils.isBlank(v.getName())) {
            throw new MarshalException("Cannot export a name-and-namespace pair with a blank name");
        } else if (StringUtils.isBlank(v.getNamespaceCode())) {
            throw new MarshalException("Cannot export a name-and-namespace pair with a blank namespace code");
        } else if (CoreServiceApiServiceLocator.getNamespaceService()
                .getNamespace(v.getNamespaceCode()) == null) {
            throw new MarshalException(
                    "Cannot export a name-and-namespace pair with invalid or unknown namespace \""
                            + v.getNamespaceCode() + "\"");
        }

        v.setName(new NormalizedStringAdapter().marshal(v.getName()));
        v.setNamespaceCode(v.getNamespaceCode());
    }
    return v;
}

From source file:org.kuali.rice.kim.api.jaxb.NameAndNamespacePairToKimTypeIdAdapter.java

/**
 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
 *//*  w  w  w . j av a2  s .  c om*/
@Override
public NameAndNamespacePair marshal(String v) throws Exception {
    if (v != null) {
        KimTypeContract kimType = KimApiServiceLocator.getKimTypeInfoService().getKimType(StringUtils.trim(v));
        if (kimType == null) {
            throw new MarshalException("Cannot find KIM Type with ID \"" + v + "\"");
        }
        return new NameAndNamespacePair(kimType.getNamespaceCode(), kimType.getName());
    }
    return null;
}