Example usage for javax.xml.bind JAXBElement getValue

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

Introduction

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

Prototype

public T getValue() 

Source Link

Document

Return the content model and attribute values for this element.

See #isNil() for a description of a property constraint when this value is null

Usage

From source file:com.inmobi.grill.client.GrillMetadataClient.java

public XStorage getStorage(String storageName) {
    WebTarget target = getMetastoreWebTarget();
    JAXBElement<XStorage> result = target.path("storages").path(storageName)
            .queryParam("sessionid", this.connection.getSessionHandle()).request(MediaType.APPLICATION_XML)
            .get(new GenericType<JAXBElement<XStorage>>() {
            });/*from ww  w .ja v  a2 s  . c  om*/
    return result.getValue();
}

From source file:com.inmobi.grill.client.GrillMetadataClient.java

public FactTable getFactTable(String factTableName) {
    WebTarget target = getMetastoreWebTarget();
    JAXBElement<FactTable> table = target.path("facts").path(factTableName)
            .queryParam("sessionid", this.connection.getSessionHandle()).request(MediaType.APPLICATION_XML)
            .get(new GenericType<JAXBElement<FactTable>>() {
            });//from ww  w .j  a v a  2  s. c o m
    return table.getValue();
}

From source file:net.sf.jabref.logic.importer.fileformat.MedlineImporter.java

private void addPagination(Map<String, String> fields, Pagination pagination) {
    String startPage = "";
    String endPage = "";
    for (JAXBElement<String> element : pagination.getContent()) {
        if ("MedlinePgn".equals(element.getName().getLocalPart())) {
            putIfValueNotNull(fields, FieldName.PAGES, fixPageRange(element.getValue()));
        } else if ("StartPage".equals(element.getName().getLocalPart())) {
            //it could happen, that the article has only a start page
            startPage = element.getValue() + endPage;
            putIfValueNotNull(fields, FieldName.PAGES, startPage);
        } else if ("EndPage".equals(element.getName().getLocalPart())) {
            endPage = element.getValue();
            //but it should not happen, that a endpage appears without startpage
            fields.put(FieldName.PAGES, fixPageRange(startPage + "-" + endPage));
        }//from w w w . j ava  2s. c o  m
    }
}

From source file:com.inmobi.grill.client.GrillMetadataClient.java

public DimensionTable getDimensionTable(String table) {
    WebTarget target = getMetastoreWebTarget();
    JAXBElement<DimensionTable> result = target.path("dimensions").path(table)
            .queryParam("sessionid", this.connection.getSessionHandle()).request(MediaType.APPLICATION_XML)
            .get(new GenericType<JAXBElement<DimensionTable>>() {
            });/*from w ww  . j  ava 2 s  .c om*/
    return result.getValue();
}

From source file:com.evolveum.midpoint.prism.util.JaxbTestUtil.java

public <T> T unmarshalObject(File file, Class<T> type)
        throws JAXBException, SchemaException, FileNotFoundException {
    JAXBElement<T> element = unmarshalElement(file, type);
    if (element == null) {
        return null;
    }//from   w  w  w . ja v a 2 s.  co m
    T value = element.getValue();
    // adopt not needed, already adopted in unmarshalElement call above
    if (!type.isAssignableFrom(value.getClass())) {
        throw new IllegalArgumentException(
                "Unmarshalled " + value.getClass() + " from file " + file + " while " + type + " was expected");
    }
    return value;
}

From source file:com.evolveum.midpoint.prism.util.JaxbTestUtil.java

public <T> T unmarshalObject(String stringXml, Class<T> type) throws JAXBException, SchemaException {
    JAXBElement<T> element = unmarshalElement(stringXml, type);
    if (element == null) {
        return null;
    }/*from   w ww.jav  a 2  s . c  om*/
    T value = element.getValue();
    adopt(value, type);
    return value;
}

From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureVerifier.java

private CTRelationships getRelationships(URL url, String relationshipsEntryName)
        throws IOException, JAXBException {
    ZipInputStream zipInputStream = new ZipInputStream(url.openStream());
    ZipEntry zipEntry;//  w w w.  j av  a  2  s  .  c  o  m
    InputStream relationshipsInputStream = null;
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (false == relationshipsEntryName.equals(zipEntry.getName())) {
            continue;
        }
        relationshipsInputStream = zipInputStream;
        break;
    }
    if (null == relationshipsInputStream) {
        return null;
    }
    JAXBContext jaxbContext = JAXBContext
            .newInstance(be.fedict.eid.applet.service.signer.jaxb.opc.relationships.ObjectFactory.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    JAXBElement<CTRelationships> relationshipsElement = (JAXBElement<CTRelationships>) unmarshaller
            .unmarshal(relationshipsInputStream);
    return relationshipsElement.getValue();
}

From source file:be.fedict.eid.tsl.Tsl2PdfExporter.java

private QualificationsType unmarshallQualifications(Element element) throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(be.fedict.eid.tsl.jaxb.ecc.ObjectFactory.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    JAXBElement<QualificationsType> jaxbElement = (JAXBElement<QualificationsType>) unmarshaller
            .unmarshal(element);/*from ww w . j a  v  a 2  s .c o  m*/
    QualificationsType qualifications = jaxbElement.getValue();
    return qualifications;
}

From source file:de.ingrid.interfaces.csw.domain.filter.impl.LuceneFilterParser.java

@Override
public SpatialQuery parse(CSWQuery cswQuery) throws Exception {

    Document filterDoc = cswQuery.getConstraint();

    if (this.filterUnmarshaller == null) {
        MarshallerPool marshallerPool = new MarshallerPool(
                "org.geotoolkit.ogc.xml.v110:org.geotoolkit.gml.xml.v311:org.geotoolkit.gml.xml.v321");
        this.filterUnmarshaller = marshallerPool.acquireUnmarshaller();
    }/*from  w ww.  j  a v a  2  s. c  o m*/

    if (filterDoc == null) {
        return new SpatialQuery(defaultField);
    }

    JAXBElement<FilterType> filterEl = this.filterUnmarshaller.unmarshal(filterDoc, FilterType.class);
    FilterType filter = filterEl.getValue();

    SpatialQuery query = null;
    if (filter != null) {
        Filter nullFilter = null;
        // process logical operators like AND, OR, ...
        if (filter.getLogicOps() != null) {
            query = this.processLogicalOperator(filter.getLogicOps());
        }
        // process comparison operators: PropertyIsLike, IsNull, IsBetween,
        // ...
        else if (filter.getComparisonOps() != null) {
            query = new SpatialQuery(this.processComparisonOperator(filter.getComparisonOps()), nullFilter,
                    SerialChainFilter.AND);
        }
        // process spatial constraint : BBOX, Beyond, Overlaps, ...
        else if (filter.getSpatialOps() != null) {
            query = new SpatialQuery("", this.processSpatialOperator(filter.getSpatialOps()),
                    SerialChainFilter.AND);
        }
        // process id
        else if (filter.getId() != null) {
            query = new SpatialQuery(this.processIDOperator(filter.getId()), nullFilter, SerialChainFilter.AND);
        }
    }

    Document sortBy = cswQuery.getSort();
    if (sortBy != null) {
        NodeList sortProperties = this.xpath.getNodeList(sortBy, "//csw:SortProperty");
        if (sortProperties != null && sortProperties.getLength() > 0) {
            List<SortField> sortFields = new ArrayList<SortField>();
            for (int i = 0; i < sortProperties.getLength(); i++) {
                Node sortProperty = sortProperties.item(i);
                String propertyName = this.xpath.getString(sortProperty, "//csw:PropertyName");
                String sortOrder = this.xpath.getString(sortProperty, "//csw:SortOrder");
                if (sortOrder == null) {
                    sortOrder = "ASC";
                }
                // TODO determine type of sort field by queryable type
                sortFields.add(new SortField(propertyName + "_sort", SortField.STRING,
                        sortOrder.equalsIgnoreCase("DESC") ? true : false));
            }
            SortField[] a = sortFields.toArray(new SortField[0]);
            query.setSort(new Sort(a));
        }
    }

    return query;
}

From source file:be.e_contract.dssp.client.DigitalSignatureServiceClient.java

/**
 * Verifies the signatures on the given document.
 * //from   ww w . ja  v  a2s .  c om
 * @param mimetype
 *            the mime-type of the document.
 * @param data
 *            the document data.
 * @param useAttachments
 *            <code>true</code> when you want to use SOAP attachments.
 * @return the verification result.
 * @throws UnsupportedDocumentTypeException
 *             for unsupported mime-types
 * @throws DocumentSignatureException
 *             when the document or signature is incorrect.
 */
public VerificationResult verify(String mimetype, byte[] data, boolean useAttachments)
        throws UnsupportedDocumentTypeException, DocumentSignatureException {
    List<SignatureInfo> signatureInfos = new LinkedList<SignatureInfo>();

    VerifyRequest verifyRequest = this.objectFactory.createVerifyRequest();
    verifyRequest.setProfile(DigitalSignatureServiceConstants.PROFILE);
    InputDocuments inputDocuments = this.objectFactory.createInputDocuments();
    verifyRequest.setInputDocuments(inputDocuments);
    addDocument(mimetype, data, useAttachments, inputDocuments);

    AnyType optionalInputs = this.objectFactory.createAnyType();
    verifyRequest.setOptionalInputs(optionalInputs);
    ReturnVerificationReport returnVerificationReport = this.vrObjectFactory.createReturnVerificationReport();
    optionalInputs.getAny().add(returnVerificationReport);
    returnVerificationReport.setIncludeVerifier(false);
    returnVerificationReport.setIncludeCertificateValues(true);

    this.wsSecuritySOAPHandler.setSession(null);
    ResponseBaseType response = this.dssPort.verify(verifyRequest);

    Result result = response.getResult();
    String resultMajor = result.getResultMajor();
    String resultMinor = result.getResultMinor();
    if (false == DigitalSignatureServiceConstants.SUCCESS_RESULT_MAJOR.equals(resultMajor)) {
        if (DigitalSignatureServiceConstants.REQUESTER_ERROR_RESULT_MAJOR.equals(resultMajor)) {
            if (DigitalSignatureServiceConstants.UNSUPPORTED_MIME_TYPE_RESULT_MINOR.equals(resultMinor)) {
                throw new UnsupportedDocumentTypeException();
            }
            if (DigitalSignatureServiceConstants.INCORRECT_SIGNATURE_RESULT_MINOR.equals(resultMinor)) {
                throw new DocumentSignatureException();
            }
        }
        throw new RuntimeException("not successfull: " + resultMajor + " " + resultMinor);
    }

    DateTime timeStampRenewalBefore = null;
    AnyType optionalOutputs = response.getOptionalOutputs();
    List<Object> optionalOutputsList = optionalOutputs.getAny();
    for (Object optionalOutput : optionalOutputsList) {
        if (false == optionalOutput instanceof JAXBElement) {
            continue;
        }
        JAXBElement jaxbElement = (JAXBElement) optionalOutput;
        LOG.debug("optional output: " + optionalOutput.getClass().getName());
        if (jaxbElement.getValue() instanceof DeadlineType) {
            DeadlineType deadlineType = (DeadlineType) jaxbElement.getValue();
            timeStampRenewalBefore = new DateTime(deadlineType.getBefore().toGregorianCalendar());
        } else if (jaxbElement.getValue() instanceof VerificationReportType) {
            LOG.debug("found VerificationReport");
            VerificationReportType verificationReport = (VerificationReportType) jaxbElement.getValue();
            List<IndividualReportType> individualReports = verificationReport.getIndividualReport();
            for (IndividualReportType individualReport : individualReports) {

                if (!DigitalSignatureServiceConstants.SUCCESS_RESULT_MAJOR
                        .equals(individualReport.getResult().getResultMajor())) {
                    LOG.warn("some invalid VR result reported: "
                            + individualReport.getResult().getResultMajor());
                    continue;
                }
                SignedObjectIdentifierType signedObjectIdentifier = individualReport
                        .getSignedObjectIdentifier();
                Date signingTime = signedObjectIdentifier.getSignedProperties().getSignedSignatureProperties()
                        .getSigningTime().toGregorianCalendar().getTime();
                String location = signedObjectIdentifier.getSignedProperties().getSignedSignatureProperties()
                        .getLocation();
                SignerRoleType signerRole = signedObjectIdentifier.getSignedProperties()
                        .getSignedSignatureProperties().getSignerRole();
                String role = null;
                if (null != signerRole) {
                    ClaimedRolesListType claimedRolesList = signerRole.getClaimedRoles();
                    if (null != claimedRolesList) {
                        List<be.e_contract.dssp.ws.jaxb.xades.AnyType> claimedRoles = claimedRolesList
                                .getClaimedRole();
                        be.e_contract.dssp.ws.jaxb.xades.AnyType claimedRole = claimedRoles.get(0);
                        role = claimedRole.getContent().get(0).toString();
                    }
                }

                List<Object> details = individualReport.getDetails().getAny();
                X509Certificate certificate = null;
                String name = null;
                for (Object detail : details) {
                    if (detail instanceof JAXBElement<?>) {
                        JAXBElement<?> detailElement = (JAXBElement<?>) detail;
                        if (detailElement.getValue() instanceof DetailedSignatureReportType) {
                            DetailedSignatureReportType detailedSignatureReport = (DetailedSignatureReportType) detailElement
                                    .getValue();

                            List<CertificateValidityType> certificateValidities = detailedSignatureReport
                                    .getCertificatePathValidity().getPathValidityDetail()
                                    .getCertificateValidity();
                            CertificateValidityType certificateValidity = certificateValidities.get(0);
                            name = certificateValidity.getSubject();
                            byte[] encodedCertificate = certificateValidity.getCertificateValue();
                            try {
                                certificate = (X509Certificate) this.certificateFactory
                                        .generateCertificate(new ByteArrayInputStream(encodedCertificate));
                            } catch (CertificateException e) {
                                throw new RuntimeException("cert decoding error: " + e.getMessage(), e);
                            }
                        }
                    }
                }
                signatureInfos.add(new SignatureInfo(name, certificate, signingTime, role, location));
            }
        }
    }

    if (signatureInfos.isEmpty()) {
        return null;
    }
    return new VerificationResult(signatureInfos, timeStampRenewalBefore);
}