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:org.voltdb.utils.CatalogUtil.java

/**
 * Given the deployment object generate the XML
 * @param deployment//from   w ww.  j a va 2s  .com
 * @return XML of deployment object.
 * @throws IOException
 */
public static String getDeployment(DeploymentType deployment) throws IOException {
    try {
        if (m_jc == null || m_schema == null) {
            throw new RuntimeException("Error schema validation.");
        }
        Marshaller marshaller = m_jc.createMarshaller();
        marshaller.setSchema(m_schema);
        StringWriter sw = new StringWriter();
        marshaller.marshal(new JAXBElement(new QName("", "deployment"), DeploymentType.class, deployment), sw);
        return sw.toString();
    } catch (JAXBException e) {
        // Convert some linked exceptions to more friendly errors.
        if (e.getLinkedException() instanceof java.io.FileNotFoundException) {
            hostLog.error(e.getLinkedException().getMessage());
            return null;
        } else if (e.getLinkedException() instanceof org.xml.sax.SAXParseException) {
            hostLog.error(
                    "Error schema validating deployment.xml file. " + e.getLinkedException().getMessage());
            return null;
        } else {
            throw new RuntimeException(e);
        }
    }
}

From source file:pl.psnc.synat.wrdz.common.metadata.mets.MetsMetadataBuilder.java

/**
 * Sets the object creation or modification event.
 * /*from ww w.ja v a 2s .c  o  m*/
 * @param date
 *            date of event
 * @param version
 *            version number
 * @param updatedFiles
 *            list of files updated within this version
 * @return this builder
 */
public MetsMetadataBuilder setObjectModificationEvent(Date date, Integer version, List<String> updatedFiles) {
    EventOutcomeInformationComplexType eventOutcomeInformation = new EventOutcomeInformationComplexType();
    eventOutcomeInformation.getContent()
            .add(new JAXBElement<String>(
                    new QName(PremisConsts.PREMIS_NAMESPACE_URI, "eventOutcome", PremisConsts.PREMIS_PREFIX),
                    String.class, "successfully saved"));
    if (updatedFiles != null && updatedFiles.size() > 0) {
        for (String file : updatedFiles) {
            EventOutcomeDetailComplexType eventOutcomeDetail = new EventOutcomeDetailComplexType();
            eventOutcomeDetail.setEventOutcomeDetailNote(file);
            eventOutcomeInformation.getContent()
                    .add(new JAXBElement<EventOutcomeDetailComplexType>(
                            new QName(PremisConsts.PREMIS_NAMESPACE_URI, "eventOutcomeDetail",
                                    PremisConsts.PREMIS_PREFIX),
                            EventOutcomeDetailComplexType.class, eventOutcomeDetail));
        }
    }
    EventComplexType evtSec = getNewPremisEventSection();
    if (version.equals(1)) {
        evtSec.setEventType(MetsConsts.PREMIS_CREATION_EVENT_TYPE);
    } else {
        evtSec.setEventType(MetsConsts.PREMIS_MODIFICATION_EVENT_TYPE);
    }
    evtSec.setEventDetail(MetsConsts.METS_OBJECT_VERSION_STATUS + version.toString());
    evtSec.setEventDateTime(DATE_FORMATTER.format(date));
    evtSec.getEventOutcomeInformation().add(eventOutcomeInformation);
    return this;
}

From source file:pl.psnc.synat.wrdz.common.metadata.mets.MetsMetadataBuilder.java

/**
 * Sets the object origin./*from   w w  w .  j a  v a 2 s  .  c  o  m*/
 * 
 * @param sourceId
 *            source id section with filled identifier.
 * @param migrationType
 *            type of migration
 * @param date
 *            date of migration
 * @param info
 *            info about migration
 * @return this builder
 */
private MetsMetadataBuilder setObjectOrigin(RelatedObjectIdentificationComplexType sourceId,
        String migrationType, Date date, String info) {
    Representation premisObjSec = getPremisRepresentationSection();
    RelationshipComplexType relationship = new RelationshipComplexType();
    relationship.setRelationshipType(MetsConsts.PREMIS_RELATIONSHIP_DERIVATION_TYPE);
    relationship.setRelationshipSubType(MetsConsts.PREMIS_RELATIONSHIP_HAS_SOURCE_SUBTYPE);
    relationship.getRelatedObjectIdentification().add(sourceId);
    premisObjSec.getRelationship().add(relationship);
    EventComplexType evtSec = getNewPremisEventSection();
    evtSec.setEventType(migrationType);
    if (date != null) {
        evtSec.setEventDateTime(DATE_FORMATTER.format(date));
    }
    if (info != null) {
        EventOutcomeInformationComplexType eventOutcomeInformation = new EventOutcomeInformationComplexType();
        eventOutcomeInformation.getContent().add(new JAXBElement<String>(
                new QName(PremisConsts.PREMIS_NAMESPACE_URI, "eventOutcome", PremisConsts.PREMIS_PREFIX),
                String.class, info));
        evtSec.getEventOutcomeInformation().add(eventOutcomeInformation);
    }
    RelatedEventIdentificationComplexType evtIdf = new RelatedEventIdentificationComplexType();
    evtIdf.setRelatedEventIdentifierType(evtSec.getEventIdentifier().getEventIdentifierType());
    evtIdf.setRelatedEventIdentifierValue(evtSec.getEventIdentifier().getEventIdentifierValue());
    relationship.getRelatedEventIdentification().add(evtIdf);
    return this;
}

From source file:pl.psnc.synat.wrdz.common.metadata.mets.MetsMetadataBuilder.java

/**
 * Sets the object derivative.//from  ww  w.j  a  v  a  2s.  co  m
 * 
 * @param resultId
 *            result id section with filled identifier.
 * @param migrationType
 *            type of migration
 * @param date
 *            date of migration
 * @param info
 *            info about migration
 * @return this builder
 */
private MetsMetadataBuilder setObjectDerivative(RelatedObjectIdentificationComplexType resultId,
        String migrationType, Date date, String info) {
    Representation premisObjSec = getPremisRepresentationSection();
    RelationshipComplexType relationship = new RelationshipComplexType();
    relationship.setRelationshipType(MetsConsts.PREMIS_RELATIONSHIP_DERIVATION_TYPE);
    relationship.setRelationshipSubType(MetsConsts.PREMIS_RELATIONSHIP_IS_SOURCE_OF_SUBTYPE);
    relationship.getRelatedObjectIdentification().add(resultId);
    premisObjSec.getRelationship().add(relationship);
    EventComplexType evtSec = getNewPremisEventSection();
    evtSec.setEventType(migrationType);
    if (date != null) {
        evtSec.setEventDateTime(DATE_FORMATTER.format(date));
    }
    if (info != null) {
        EventOutcomeInformationComplexType eventOutcomeInformation = new EventOutcomeInformationComplexType();
        eventOutcomeInformation.getContent().add(new JAXBElement<String>(
                new QName(PremisConsts.PREMIS_NAMESPACE_URI, "eventOutcome", PremisConsts.PREMIS_PREFIX),
                String.class, info));
        evtSec.getEventOutcomeInformation().add(eventOutcomeInformation);
    }
    RelatedEventIdentificationComplexType evtIdf = new RelatedEventIdentificationComplexType();
    evtIdf.setRelatedEventIdentifierType(evtSec.getEventIdentifier().getEventIdentifierType());
    evtIdf.setRelatedEventIdentifierValue(evtSec.getEventIdentifier().getEventIdentifierValue());
    relationship.getRelatedEventIdentification().add(evtIdf);
    return this;
}

From source file:pl.psnc.synat.wrdz.common.metadata.mets.MetsMetadataBuilder.java

/**
 * Gets the object digital provenance metadata in the PREMIS schema.
 * //from w  ww.j a  va2s .  co m
 * @return digital provenance metadata in the PREMIS schema
 */
@SuppressWarnings("unchecked")
private PremisComplexType getPremisDigiprovMetadata() {
    MdSecType premisDpSec = getPremisDigiprovSection();
    if (premisDpSec.getMdWrap() == null) {
        PremisComplexType premis = new PremisComplexType();
        premis.setVersion(PremisConsts.PREMIS_VERSION);
        JAXBElement<PremisComplexType> jaxbPremis = new JAXBElement<PremisComplexType>(
                new QName(PremisConsts.PREMIS_NAMESPACE_URI, "premis", PremisConsts.PREMIS_PREFIX),
                PremisComplexType.class, premis);
        XmlData premisData = new XmlData();
        premisData.getAny().add(jaxbPremis);
        MdWrap mdWrap = new MdWrap();
        mdWrap.setXmlData(premisData);
        mdWrap.setMDTYPE(NamespaceType.PREMIS.name());
        mdWrap.setLABEL("premis.xml");
        premisDpSec.setMdWrap(mdWrap);
    }
    return ((JAXBElement<PremisComplexType>) premisDpSec.getMdWrap().getXmlData().getAny().get(0)).getValue();
}

From source file:pt.webdetails.cpf.repository.rca.RemoteReadWriteAccess.java

protected boolean putMetadataProperty(String fullPath, String key, String value) {
    StringKeyStringValueDto metadataProperty = new StringKeyStringValueDto();
    metadataProperty.setKey(key);// ww  w  .  j a  v a 2 s  . c o m
    metadataProperty.setValue(value);

    ArrayList<StringKeyStringValueDto> metadata = new ArrayList<>();
    metadata.add(metadataProperty);

    String requestURL = createRequestURL(fullPath, "metadata");
    ClientResponse response = client.resource(requestURL).type(MediaType.APPLICATION_XML).put(
            ClientResponse.class,
            new JAXBElement<>(new QName("stringKeyStringValueDtoes"), ArrayList.class, metadata));

    // TODO: handle non-OK status codes? log? exceptions?
    if (response.getStatus() == ClientResponse.Status.OK.getStatusCode()) {
        return true;
    }
    logger.error("Failed to set " + key + "=" + value + " for: " + fullPath);
    return false;
}

From source file:pt.webdetails.cpf.repository.rca.RemoteUserContentAccess.java

private boolean updateProperties(IFileContent file) {
    final String defaultLocale = "default"; // use default locale
    ArrayList<StringKeyStringValueDto> properties = new ArrayList<>();
    properties.add(new StringKeyStringValueDto("file.title", file.getTitle()));
    properties.add(new StringKeyStringValueDto("file.description", file.getDescription()));

    String path = file.getPath();
    String fullPath = buildPath(path);
    String requestURL = createRequestURL("/api/repo/files/", fullPath, "localeProperties");

    ClientResponse response = client.resource(requestURL).queryParam("locale", defaultLocale)
            .type(MediaType.APPLICATION_XML).put(ClientResponse.class,
                    new JAXBElement<>(new QName("stringKeyStringValueDtoes"), ArrayList.class, properties));

    //TODO: handle non-OK status codes? log? exception?
    return response.getStatus() == ClientResponse.Status.OK.getStatusCode();
}

From source file:se.inera.axel.riv.internal.ShsToRivHeaderMapper.java

private SoapHeader createStringSoapHeader(QName qname, String to) {
    JAXBElement<String> toElement = new JAXBElement<>(qname, String.class, to);

    return new SoapHeader(toElement.getName(), toElement, STRING_JAXB_BINDING);
}