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:edu.harvard.i2b2.crc.dao.setfinder.querybuilder.temporal.TemporalQuery.java

public void parseQueryDefinitionXml(String queryXml) throws JAXBUtilException, I2B2Exception {
    if (queryXml == null)
        return;//from  w ww .  ja v a 2s . com

    //start by converting string object to query definition object
    QueryDefinitionUnWrapUtil queryDefUnWrapHelper = new QueryDefinitionUnWrapUtil();
    queryDef = queryDefUnWrapHelper.getQueryDefinitionType(queryXml);

    //get query timing out - this will be used as the default timing for all groups 
    //and panels. Panel timing values will override this value
    queryTiming = queryDef.getQueryTiming();

    //extract out project and security information. this will be reused when validating
    //panel items with ontology cell
    JAXBElement responseJaxb = CRCJAXBUtil.getJAXBUtil().unMashallFromString(queryXml);
    RequestMessageType request = (RequestMessageType) responseJaxb.getValue();
    projectId = request.getMessageHeader().getProjectId();
    userSecurityType = request.getMessageHeader().getSecurity();
    securityType = PMServiceAccountUtil.getServiceSecurityType(userSecurityType.getDomain());

    parseQuery();
}

From source file:ddf.security.pdp.xacml.processor.BalanaPdp.java

/**
 * Unmarshalls the XACML response./* w  w w . j  a v  a 2  s  .c  om*/
 * 
 * @param xacmlResponse
 *            The XACML response with all namespaces and namespace prefixes added.
 * @return The XACML response.
 * @throws PdpException
 */
private ResponseType unmarshal(DOMResult xacmlResponse) throws PdpException {
    JAXBElement<ResponseType> xacmlResponseTypeElement = null;

    try {
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

        xacmlResponseTypeElement = unmarshaller.unmarshal(xacmlResponse.getNode(), ResponseType.class);
    } catch (JAXBException e) {
        String message = "Unable to unmarshal XACML response.";
        LOGGER.error(message);
        throw new PdpException(message, e);
    }

    return xacmlResponseTypeElement.getValue();
}

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

private void addPagination(HashMap<String, String> fields, Pagination pagination) {
    String startPage = "";
    String endPage = "";
    for (JAXBElement<String> element : pagination.getContent()) {
        if ("MedlinePgn".equals(element.getName().getLocalPart())) {
            putIfValueNotNull(fields, "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, "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("pages", fixPageRange(startPage + "-" + endPage));
        }/*from  www.j  a v a  2  s  . c o  m*/
    }
}

From source file:be.agiv.security.client.IPSTSClient.java

private SecurityToken getSecurityToken(String username, String password, X509Certificate certificate,
        PrivateKey privateKey) {// www.j  a v a2s.  c o  m
    RequestSecurityTokenType requestSecurityToken = this.objectFactory.createRequestSecurityTokenType();
    List<Object> requestSecurityTokenContent = requestSecurityToken.getAny();
    requestSecurityTokenContent.add(this.objectFactory.createRequestType(WSConstants.ISSUE_REQUEST_TYPE));

    EntropyType entropy = this.objectFactory.createEntropyType();
    requestSecurityTokenContent.add(this.objectFactory.createEntropy(entropy));
    BinarySecretType binarySecret = this.objectFactory.createBinarySecretType();
    entropy.getAny().add(this.objectFactory.createBinarySecret(binarySecret));
    binarySecret.setType(WSConstants.SECRET_TYPE_NONCE);

    requestSecurityTokenContent.add(this.objectFactory.createKeyType(WSConstants.KEY_TYPE_SYMMETRIC));

    requestSecurityTokenContent.add(this.objectFactory.createKeySize(256L));

    if (null == this.wsTrustHandler.getSecondaryParameters()) {
        requestSecurityTokenContent
                .add(this.objectFactory.createKeyWrapAlgorithm(WSConstants.KEY_WRAP_ALGO_RSA_OAEP_MGF1P));

        requestSecurityTokenContent.add(this.objectFactory.createEncryptWith(WSConstants.ENC_ALGO_AES256_CBC));

        requestSecurityTokenContent.add(this.objectFactory.createSignWith(WSConstants.SIGN_ALGO_HMAC_SHA1));

        requestSecurityTokenContent
                .add(this.objectFactory.createCanonicalizationAlgorithm(WSConstants.C14N_ALGO_EXC));

        requestSecurityTokenContent
                .add(this.objectFactory.createEncryptionAlgorithm(WSConstants.ENC_ALGO_AES256_CBC));
    }

    AppliesTo appliesTo = this.policyObjectFactory.createAppliesTo();
    EndpointReferenceType endpointReference = this.addrObjectFactory.createEndpointReferenceType();
    AttributedURIType address = this.addrObjectFactory.createAttributedURIType();
    address.setValue(this.realm);
    endpointReference.setAddress(address);
    appliesTo.getAny().add(this.addrObjectFactory.createEndpointReference(endpointReference));
    requestSecurityTokenContent.add(appliesTo);

    requestSecurityTokenContent
            .add(this.objectFactory.createComputedKeyAlgorithm(WSConstants.COMP_KEY_ALGO_PSHA1));

    byte[] entropyData = new byte[256 / 8];
    // entropy = keysize / 8
    this.secureRandom.setSeed(System.currentTimeMillis());
    this.secureRandom.nextBytes(entropyData);
    binarySecret.setValue(entropyData);

    BindingProvider bindingProvider = (BindingProvider) this.port;
    if (null != username) {
        this.wsSecurityHandler.setCredentials(username, password);
    } else if (null != certificate) {
        this.wsSecurityHandler.setCredentials(privateKey, certificate);
    }
    this.wsAddressingHandler.setAddressing(WSConstants.WS_TRUST_ISSUE_ACTION, this.location);

    RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.port
            .requestSecurityToken(requestSecurityToken);

    SecurityToken securityToken = new SecurityToken();

    List<RequestSecurityTokenResponseType> requestSecurityTokenResponseList = requestSecurityTokenResponseCollection
            .getRequestSecurityTokenResponse();
    RequestSecurityTokenResponseType requestSecurityTokenResponse = requestSecurityTokenResponseList.get(0);
    List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny();
    for (Object contentObject : requestSecurityTokenResponseContent) {
        LOG.debug("content object: " + contentObject.getClass().getName());
        if (contentObject instanceof Element) {
            Element contentElement = (Element) contentObject;
            LOG.debug("element name: " + contentElement.getLocalName());
        }
        if (contentObject instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) contentObject;
            QName qname = jaxbElement.getName();
            LOG.debug("qname: " + qname);
            if (WSConstants.ENTROPY_QNAME.equals(qname)) {
                LOG.debug("trust:Entropy");
                EntropyType serverEntropy = (EntropyType) jaxbElement.getValue();
                List<Object> entropyContent = serverEntropy.getAny();
                for (Object entropyObject : entropyContent) {
                    if (entropyObject instanceof JAXBElement) {
                        JAXBElement entropyElement = (JAXBElement) entropyObject;
                        if (WSConstants.BINARY_SECRET_QNAME.equals(entropyElement.getName())) {
                            BinarySecretType serverBinarySecret = (BinarySecretType) entropyElement.getValue();
                            byte[] serverSecret = serverBinarySecret.getValue();
                            P_SHA1 p_SHA1 = new P_SHA1();
                            byte[] key;
                            try {
                                key = p_SHA1.createKey(entropyData, serverSecret, 0, 256 / 8);
                            } catch (ConversationException e) {
                                LOG.error(e);
                                return null;
                            }
                            LOG.debug("client secret size: " + entropyData.length);
                            LOG.debug("server secret size: " + serverSecret.length);
                            LOG.debug("key size: " + key.length);
                            securityToken.setKey(key);
                        }
                    }
                }
            } else if (WSConstants.LIFETIME_QNAME.equals(qname)) {
                LOG.debug("trust:Lifetime");
                LifetimeType lifetime = (LifetimeType) jaxbElement.getValue();
                String createdValue = lifetime.getCreated().getValue();
                DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser();
                DateTime created = dateTimeFormatter.parseDateTime(createdValue);
                securityToken.setCreated(created.toDate());
                String expiresString = lifetime.getExpires().getValue();
                DateTime expires = dateTimeFormatter.parseDateTime(expiresString);
                securityToken.setExpires(expires.toDate());
            } else if (WSConstants.REQUESTED_ATTACHED_REFERENCE_QNAME.equals(qname)) {
                RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue();
                SecurityTokenReferenceType securityTokenReference = requestedReference
                        .getSecurityTokenReference();
                List<Object> securityTokenReferenceContent = securityTokenReference.getAny();
                for (Object securityTokenReferenceObject : securityTokenReferenceContent) {
                    LOG.debug("SecurityTokenReference object: "
                            + securityTokenReferenceObject.getClass().getName());
                    if (securityTokenReferenceObject instanceof JAXBElement) {
                        JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject;
                        LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName());
                        if (securityTokenReferenceElement.getName().equals(WSConstants.KEY_IDENTIFIER_QNAME)) {
                            KeyIdentifierType keyIdentifier = (KeyIdentifierType) securityTokenReferenceElement
                                    .getValue();
                            String attachedReference = keyIdentifier.getValue();
                            securityToken.setAttachedReference(attachedReference);
                        }

                    }
                }
            } else if (WSConstants.REQUESTED_UNATTACHED_REFERENCE_QNAME.equals(qname)) {
                RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue();
                SecurityTokenReferenceType securityTokenReference = requestedReference
                        .getSecurityTokenReference();
                List<Object> securityTokenReferenceContent = securityTokenReference.getAny();
                for (Object securityTokenReferenceObject : securityTokenReferenceContent) {
                    LOG.debug("SecurityTokenReference object: "
                            + securityTokenReferenceObject.getClass().getName());
                    if (securityTokenReferenceObject instanceof JAXBElement) {
                        JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject;
                        LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName());
                        if (securityTokenReferenceElement.getName().equals(WSConstants.KEY_IDENTIFIER_QNAME)) {
                            KeyIdentifierType keyIdentifier = (KeyIdentifierType) securityTokenReferenceElement
                                    .getValue();
                            String unattachedReference = keyIdentifier.getValue();
                            securityToken.setUnattachedReference(unattachedReference);
                        }

                    }
                }
            }
        }
    }

    Element requestedSecurityToken = this.wsTrustHandler.getRequestedSecurityToken();
    securityToken.setToken(requestedSecurityToken);
    securityToken.setRealm(this.realm);
    securityToken.setStsLocation(this.location);

    return securityToken;
}

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

/**
 * Used to convert property values from DOM 
 *///from   w  w w . jav  a2 s.c om
public Object toJavaValue(Element element, QName xsdType) throws JAXBException {
    Class<?> declaredType = getCompileTimeClass(xsdType);
    if (declaredType == null) {
        // This may happen if the schema is runtime and there is no associated compile-time class
        throw new SystemException("Cannot determine Java type for " + xsdType);
    }
    JAXBElement<?> jaxbElement = createUnmarshaller().unmarshal(element, declaredType);
    Object object = jaxbElement.getValue();
    return object;
}

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

private CTRelationships getRelationships(String relsEntryName) throws IOException, JAXBException {
    URL ooxmlUrl = this.signatureService.getOfficeOpenXMLDocumentURL();
    ZipInputStream zipInputStream = new ZipInputStream(ooxmlUrl.openStream());
    ZipEntry zipEntry;// ww  w.  j av a2 s  .com
    InputStream relationshipsInputStream = null;
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (false == relsEntryName.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:gov.va.ds4p.ds4pmobileportal.pep.XACMLPolicyEnforcement.java

private void processMetaData(RegistryObjectListType objList) {
    List<ExchangeResults> docInfoList = new ArrayList();
    //add all from nhinresults
    List<JAXBElement<? extends IdentifiableType>> extrinsicObjects = objList.getIdentifiable();

    if (extrinsicObjects != null && extrinsicObjects.size() > 0) {
        for (JAXBElement<? extends IdentifiableType> jaxb : extrinsicObjects) {
            ExchangeResults docInfo = new ExchangeResults();

            if (jaxb.getValue() instanceof ExtrinsicObjectType) {
                ExtrinsicObjectType extrinsicObject = (ExtrinsicObjectType) jaxb.getValue();

                if (extrinsicObject != null) {
                    docType = extractDocumentType(extrinsicObject);
                    //String creationTime = extractCreationTime(extrinsicObject);
                    docId = extractDocumentID(extrinsicObject);
                    docRep = extractRespositoryUniqueID(extrinsicObject);
                }/*from  ww w. j  av  a2s  . com*/
            }
        }
    }
    System.out.println("DOCUMENT TYPE: " + docType);
    System.out.println("DOCUMENT ID: " + docId);
    System.out.println("DOCUMENT RESP: " + docRep);
}

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

public XCube getCube(String cubeName) {
    WebTarget target = getMetastoreWebTarget();
    JAXBElement<XCube> cube = target.path("cubes").path(cubeName)
            .queryParam("sessionid", this.connection.getSessionHandle()).request(MediaType.APPLICATION_XML)
            .get(new GenericType<JAXBElement<XCube>>() {
            });/*from   ww w.j  a  v  a2s.com*/
    return cube.getValue();
}

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

public <T> T fromElement(Object element, Class<T> type) throws SchemaException {

    if (element == null) {
        return null;
    }// ww w  .ja va  2s  .  co m

    if (type.isAssignableFrom(element.getClass())) {
        return (T) element;
    }

    if (element instanceof JAXBElement) {
        if (((JAXBElement) element).getValue() == null) {
            return null;
        }
        if (type.isAssignableFrom(((JAXBElement) element).getValue().getClass())) {
            return (T) ((JAXBElement) element).getValue();
        }
    }

    if (element instanceof Element) {
        try {
            JAXBElement<T> unmarshalledElement = unmarshalElement((Element) element, type);
            return unmarshalledElement.getValue();
        } catch (JAXBException e) {
            throw new IllegalArgumentException("Unmarshall failed: " + e.getMessage(), e);
        }
    }

    throw new IllegalArgumentException("Unknown element type " + element.getClass().getName());
}

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

private CTTypes getContentTypes(URL url)
        throws IOException, ParserConfigurationException, SAXException, JAXBException {
    ZipInputStream zipInputStream = new ZipInputStream(url.openStream());
    ZipEntry zipEntry;//www  . ja  v a  2 s  . c o  m
    InputStream contentTypesInputStream = null;
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (!"[Content_Types].xml".equals(zipEntry.getName())) {
            continue;
        }
        contentTypesInputStream = zipInputStream;
        break;
    }
    if (null == contentTypesInputStream) {
        return null;
    }
    JAXBContext jaxbContext = JAXBContext
            .newInstance(be.fedict.eid.applet.service.signer.jaxb.opc.contenttypes.ObjectFactory.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    JAXBElement<CTTypes> contentTypesElement = (JAXBElement<CTTypes>) unmarshaller
            .unmarshal(contentTypesInputStream);
    return contentTypesElement.getValue();
}