Example usage for javax.xml.bind JAXBElement JAXBElement

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

Introduction

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

Prototype

public JAXBElement(QName name, Class<T> declaredType, T value) 

Source Link

Document

Construct an xml element instance.

Usage

From source file:com.evolveum.midpoint.schema.result.OperationResultFactory.java

public static OperationResultType createOperationResult(String operation, OperationResultStatusType status,
        Map<String, Element> params) {

    OperationResultType result = createOperationResult(operation, status);
    if (params == null || params.isEmpty()) {
        return result;
    }/*from www  . j av  a  2s .co m*/

    ObjectFactory factory = new ObjectFactory();
    ParamsType paramsType = factory.createParamsType();
    result.setParams(paramsType);

    EntryType entryType;
    Set<Entry<String, Element>> set = params.entrySet();
    for (Entry<String, Element> entry : set) {
        entryType = factory.createEntryType();
        entryType.setKey(entry.getKey());
        entryType.setEntryValue(new JAXBElement(EntryType.F_ENTRY_VALUE, Element.class, entry.getValue()));

        paramsType.getEntry().add(entryType);
    }

    return result;
}

From source file:org.javelin.sws.ext.bind.internal.model.ClassHierarchyTest.java

@Test
public void handleXmlAccessTypeField() throws Exception {
    // f1, f2, f3, f4, p3, p4 - fields and annotated properties
    System.out.println("\nC2");
    JAXBContext.newInstance(C2.class).createMarshaller()
            .marshal(new JAXBElement<C2>(new QName("", "r"), C2.class, new C2()), System.out);
    JAXBContext ctx = SweJaxbContextFactory.createContext(new Class[] { C2.class }, null);
    Map<Class<?>, TypedPattern<?>> patterns = (Map<Class<?>, TypedPattern<?>>) ReflectionTestUtils.getField(ctx,
            "patterns");
    ComplexTypePattern<C2> pattern = (ComplexTypePattern<C2>) patterns.get(C2.class);
    Map<QName, PropertyMetadata<C2, ?>> elements = (Map<QName, PropertyMetadata<C2, ?>>) ReflectionTestUtils
            .getField(pattern, "elements");
    assertThat(elements.size(), equalTo(6));
    assertTrue(elements.containsKey(new QName("", "f1")));
    assertTrue(elements.containsKey(new QName("", "f2")));
    assertTrue(elements.containsKey(new QName("", "f3")));
    assertTrue(elements.containsKey(new QName("", "f4")));
    assertTrue(elements.containsKey(new QName("", "p3")));
    assertTrue(elements.containsKey(new QName("", "p4")));
}

From source file:be.fedict.eid.pkira.contracts.EIDPKIRAContractsClient.java

/**
 * Marshals the JAXB contract to a DOM document.
 * //w ww.ja  va  2 s  .  c  o  m
 * @param contractDocument
 *            document to marshal.
 * @return the text in the XML.
 * @throws XmlMarshallingException
 *             when this fails.
 */
public <T extends EIDPKIRAContractType> Document marshalToDocument(T contractDocument, Class<T> clazz)
        throws XmlMarshallingException {
    QName qname = new QName(NAMESPACE, getElementNameForType(clazz));
    JAXBElement<T> jaxbElement = new JAXBElement<T>(qname, clazz, contractDocument);

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        Document document = dbf.newDocumentBuilder().newDocument();

        getMarshaller().marshal(jaxbElement, document);

        return document;
    } catch (JAXBException e) {
        throw new XmlMarshallingException("Cannot marshal XML object.", e);
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:in.gov.uidai.auth.aua.httpclient.BfdClient.java

private String generateSignedBfdXML(Bfd bfd) throws JAXBException, Exception {
    StringWriter bfdXML = new StringWriter();

    JAXBElement<Bfd> bfdElement = new JAXBElement<Bfd>(
            new QName("http://www.uidai.gov.in/authentication/uid-bfd-request/1.0", "Bfd"), Bfd.class, bfd);

    JAXBContext.newInstance(Bfd.class).createMarshaller().marshal(bfdElement, bfdXML);
    boolean includeKeyInfo = true;

    if (System.getenv().get("SKIP_DIGITAL_SIGNATURE") != null) {
        return bfdXML.toString();
    } else {/*from   ww  w . j ava  2s .c  o m*/
        return this.digitalSignator.signXML(bfdXML.toString(), includeKeyInfo);
    }
}

From source file:com.evolveum.midpoint.jaspersoft.studio.integration.MidPointRemoteQueryExecutor.java

public static <T> JAXBElement<T> toJaxbElement(QName name, Class<T> clazz, T value) {
    return new JAXBElement<T>(name, clazz, value);
}

From source file:nl.ordina.bag.etl.dao.postgres.BAGMutatiesDAOImpl.java

@Override
public void insert(final BAGMutatie mutatie) throws DAOException {
    try {/*from w  w w .  jav  a  2  s . co  m*/
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                try {
                    PreparedStatement ps = connection.prepareStatement("insert into bag_mutatie (" + "id,"
                            + "tijdstip_verwerking," + "volgnr_verwerking," + "object_type," + "mutatie_product"
                            + ") values ((select coalesce(max(id),0) + 1 from bag_mutatie),?,?,?,?)");
                    ps.setTimestamp(1, Utils.toTimestamp(mutatie.getTijdstipVerwerking()));
                    ps.setLong(2, mutatie.getVolgnrVerwerking());
                    ps.setInt(3, mutatie.getObjectType().ordinal());
                    ps.setString(4, XMLMessageBuilder.getInstance(MutatieProduct.class)
                            .handle(new JAXBElement<MutatieProduct>(new QName(
                                    "http://www.kadaster.nl/schemas/bag-verstrekkingen/extract-producten-lvc/v20090901",
                                    "Mutatie-product"), MutatieProduct.class, mutatie.getMutatieProduct())));
                    return ps;
                } catch (JAXBException e) {
                    throw new DAOException(e);
                }
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.tiger.TigerXmlWriter.java

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    OutputStream docOS = null;/*w  w  w. j  ava 2 s  .c om*/
    try {
        docOS = getOutputStream(aJCas, filenameSuffix);

        XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
        XMLEventWriter xmlEventWriter = new IndentingXMLEventWriter(
                xmlOutputFactory.createXMLEventWriter(docOS));

        JAXBContext context = JAXBContext.newInstance(TigerSentence.class);
        Marshaller marshaller = context.createMarshaller();
        // We use the marshaller only for individual sentences. That way, we do not have to 
        // build the whole TIGER object graph before seralizing, which should safe us some
        // memory.
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

        XMLEventFactory xmlef = XMLEventFactory.newInstance();
        xmlEventWriter.add(xmlef.createStartDocument());
        xmlEventWriter.add(xmlef.createStartElement("", "", "corpus"));
        xmlEventWriter.add(xmlef.createStartElement("", "", "body"));

        int sentenceNumber = 1;
        for (Sentence s : select(aJCas, Sentence.class)) {
            TigerSentence ts = convertSentence(s, sentenceNumber);
            marshaller.marshal(new JAXBElement<TigerSentence>(new QName("s"), TigerSentence.class, ts),
                    xmlEventWriter);
            sentenceNumber++;
        }

        xmlEventWriter.add(xmlef.createEndElement("", "", "body"));
        xmlEventWriter.add(xmlef.createEndElement("", "", "corpus"));
        xmlEventWriter.add(xmlef.createEndDocument());
    } catch (Exception e) {
        throw new AnalysisEngineProcessException(e);
    } finally {
        closeQuietly(docOS);
    }
}

From source file:in.gov.uidai.core.aua.client.AuthClient.java

private String generateSignedAuthXML(Auth auth) throws JAXBException, Exception {
    StringWriter authXML = new StringWriter();

    JAXBElement authElement = new JAXBElement(
            new QName("http://www.uidai.gov.in/auth/uid-auth-request/1.0", "Auth"), Auth.class, auth);

    JAXBContext.newInstance(Auth.class).createMarshaller().marshal(authElement, authXML);
    boolean includeKeyInfo = true;

    if (System.getenv().get("SKIP_DIGITAL_SIGNATURE") != null) {
        return authXML.toString();
    } else {//from   w  w  w.ja v  a  2s  .com
        return this.digitalSignator.signXML(authXML.toString(), includeKeyInfo);
    }
}

From source file:hydrograph.ui.engine.helper.OperationsConverterHelper.java

/**
 * @param id/*  w w w .  j av a2 s. c om*/
 * @return
 */
public List<JAXBElement<?>> getFilterOperations(String id) {
    logger.debug("Generating TypeTransformOperation data :{}", properties.get(Constants.PARAM_NAME));
    List<JAXBElement<?>> operationList = new ArrayList<>();
    FilterLogicDataStructure filterData = (FilterLogicDataStructure) properties.get("filterLogic");
    if (filterData != null && filterData.isOperation()) {
        if (filterData.getOperationClassData().getExternalOperationClassData().isExternal()) {
            converterHelper.addExternalJaxbOperation(operationList,
                    filterData.getOperationClassData().getExternalOperationClassData());
        } else {
            TypeTransformOperation operation = new TypeTransformOperation();
            addFilterOperationInputFields(filterData, operation);
            operation.setId(filterData.getOperationClassData().getId());
            operation.setClazz(filterData.getOperationClassData().getQualifiedOperationClassName());
            // Added the below line for passing the properties for Filter
            // operation
            if (!filterData.getOperationClassData().getClassProperties().isEmpty()) {
                operation.setProperties(converterHelper
                        .getOperationProperties(filterData.getOperationClassData().getClassProperties()));
            }

            JAXBElement<TypeTransformOperation> jaxbElement = new JAXBElement(
                    OperationsExpressionType.OPERATION.getQName(), TypeTransformOperation.class, operation);
            operationList.add(jaxbElement);

        }
    } else if (filterData != null) {
        if (filterData.getExpressionEditorData().getExternalExpressionData().isExternal()) {
            converterHelper.addExternalJaxbExpression(operationList,
                    filterData.getExpressionEditorData().getExternalExpressionData());

        } else {
            TypeTransformExpression typeTransformExpression = new TypeTransformExpression();
            addFilterExpressionInputField(filterData.getExpressionEditorData(), typeTransformExpression);
            typeTransformExpression.setId(filterData.getExpressionEditorData().getId());

            typeTransformExpression.setExpr(filterData.getExpressionEditorData().getExpression());

            JAXBElement<TypeTransformExpression> jaxbElement = new JAXBElement(
                    OperationsExpressionType.EXPRESSION.getQName(), TypeTransformExpression.class,
                    typeTransformExpression);
            operationList.add(jaxbElement);
        }
    }

    return operationList;
}

From source file:org.javelin.sws.ext.bind.jaxb.JaxbTest.java

@Test(expected = IllegalAnnotationsException.class)
public void marshalMixed() throws Exception {
    JAXBContext ctx = JAXBContext.newInstance(org.javelin.sws.ext.bind.jaxb.context4.MyClassJ4.class);
    Marshaller m = ctx.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    org.javelin.sws.ext.bind.jaxb.context4.MyClassJ4 mc4 = new org.javelin.sws.ext.bind.jaxb.context4.MyClassJ4();
    m.marshal(new JAXBElement<org.javelin.sws.ext.bind.jaxb.context4.MyClassJ4>(new QName("a", "a"),
            org.javelin.sws.ext.bind.jaxb.context4.MyClassJ4.class, mc4), System.out);
}