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.evolveum.midpoint.web.util.ExpressionUtil.java

public static ObjectReferenceType getShadowRefValue(ExpressionType expressionType) {
    if (expressionType == null) {
        return null;
    }/*from   ww w.j ava  2  s.  c  o  m*/
    JAXBElement element = ExpressionUtil.findFirstEvaluatorByName(expressionType,
            SchemaConstantsGenerated.C_VALUE);
    ObjectReferenceType shadowRef = new ObjectReferenceType();
    if (element != null && element.getValue() instanceof RawType) {
        RawType raw = (RawType) element.getValue();
        XNode node = raw.getXnode();
        if (node instanceof MapXNode && ((MapXNode) node).containsKey(SHADOW_REF_KEY)) {
            MapXNode shadowRefNode = (MapXNode) ((MapXNode) node).get(SHADOW_REF_KEY);
            if (shadowRefNode != null && shadowRefNode.containsKey(SHADOW_OID_KEY)) {
                PrimitiveXNode shadowOidNode = (PrimitiveXNode) shadowRefNode.get(SHADOW_OID_KEY);
                String oid = shadowOidNode != null && shadowOidNode.getValueParser() != null
                        ? shadowOidNode.getValueParser().getStringValue()
                        : (shadowOidNode != null && shadowOidNode.getValue() != null
                                ? (String) shadowOidNode.getValue()
                                : null);
                shadowRef.setOid(oid);
                shadowRef.setType(ShadowType.COMPLEX_TYPE);
                return shadowRef;
            }
        }
    }
    return null;
}

From source file:ddf.catalog.registry.converter.RegistryPackageConverter.java

private static void setSlotGeoAttribute(SlotType1 slot, String metacardAttributeName, MetacardImpl metacard)
        throws RegistryConversionException {
    if (slot.isSetValueList()) {
        net.opengis.cat.wrs.v_1_0_2.ValueListType valueList = (net.opengis.cat.wrs.v_1_0_2.ValueListType) slot
                .getValueList().getValue();

        List<AnyValueType> anyValues = valueList.getAnyValue();

        for (AnyValueType anyValue : anyValues) {

            if (anyValue.isSetContent()) {

                for (Object content : anyValue.getContent()) {
                    if (content instanceof JAXBElement) {

                        JAXBElement jaxbElement = (JAXBElement) content;

                        AbstractGeometryType geometry = (AbstractGeometryType) jaxbElement.getValue();

                        String convertedGeometry = getWKTFromGeometry(geometry, jaxbElement);

                        if (StringUtils.isNotBlank(convertedGeometry)) {
                            metacard.setAttribute(metacardAttributeName, convertedGeometry);
                        }// w  w w.  ja v  a 2 s.c  o m
                    }
                }
            }
        }

    }
}

From source file:com.evolveum.midpoint.testing.model.client.sample.RunScript.java

private static <T> T unmarshallResouce(String path) throws JAXBException, FileNotFoundException {
    JAXBContext jc = getJaxbContext();
    Unmarshaller unmarshaller = jc.createUnmarshaller();

    InputStream is = null;//w ww  .ja va 2s  .co m
    JAXBElement<T> element = null;
    try {
        is = RunScript.class.getClassLoader().getResourceAsStream(path);
        if (is == null) {
            throw new FileNotFoundException("System resource " + path + " was not found");
        }
        element = (JAXBElement<T>) unmarshaller.unmarshal(is);
    } finally {
        if (is != null) {
            IOUtils.closeQuietly(is);
        }
    }
    if (element == null) {
        return null;
    }
    return element.getValue();
}

From source file:be.fedict.eid.dss.spi.utils.XAdESUtils.java

@SuppressWarnings("unchecked")
public static <T> T findUnsignedSignatureProperty(QualifyingPropertiesType qualifyingProperties,
        Class<T> declaredType, String name) {

    UnsignedPropertiesType unsignedProperties = qualifyingProperties.getUnsignedProperties();
    UnsignedSignaturePropertiesType unsignedSignatureProperties = unsignedProperties
            .getUnsignedSignatureProperties();
    List<Object> unsignedSignaturePropertiesContentList = unsignedSignatureProperties
            .getCounterSignatureOrSignatureTimeStampOrCompleteCertificateRefs();
    for (Object unsignedSignatureProperty : unsignedSignaturePropertiesContentList) {
        if (!(unsignedSignatureProperty instanceof JAXBElement)) {
            continue;
        }//  w w w .jav a 2s  .c  om
        JAXBElement<?> unsignedSignaturePropertyElement = (JAXBElement<?>) unsignedSignatureProperty;
        Object unsignedSignaturePropertyValue = unsignedSignaturePropertyElement.getValue();
        if (unsignedSignaturePropertyValue.getClass().isAssignableFrom(declaredType)) {

            if (null == name) {
                return (T) unsignedSignaturePropertyValue;
            } else if (unsignedSignaturePropertyElement.getName().getLocalPart().equals(name)) {
                return (T) unsignedSignaturePropertyValue;
            }
        }
    }

    return null;
}

From source file:ddf.catalog.registry.converter.RegistryPackageConverter.java

private static void parseRegistryObjectList(RegistryObjectListType registryObjects, MetacardImpl metacard)
        throws RegistryConversionException {
    Map<String, Set<String>> associations = new HashMap<>();
    Map<String, RegistryObjectType> registryIds = new HashMap<>();
    List<OrganizationType> orgs = new ArrayList<>();
    List<PersonType> contacts = new ArrayList<>();

    String nodeId = "";
    for (JAXBElement identifiable : registryObjects.getIdentifiable()) {
        RegistryObjectType registryObject = (RegistryObjectType) identifiable.getValue();
        registryIds.put(registryObject.getId(), registryObject);
        if (registryObject instanceof ExtrinsicObjectType
                && RegistryConstants.REGISTRY_NODE_OBJECT_TYPE.equals(registryObject.getObjectType())) {
            nodeId = registryObject.getId();
            parseNodeExtrinsicObject(registryObject, metacard);
        } else if (registryObject instanceof ServiceType
                && RegistryConstants.REGISTRY_SERVICE_OBJECT_TYPE.equals(registryObject.getObjectType())) {
            parseRegistryService((ServiceType) registryObject, metacard);
        } else if (registryObject instanceof OrganizationType) {
            orgs.add((OrganizationType) registryObject);
        } else if (registryObject instanceof PersonType) {
            contacts.add((PersonType) registryObject);
        } else if (registryObject instanceof AssociationType1) {
            AssociationType1 association = (AssociationType1) registryObject;
            if (associations.containsKey(association.getSourceObject())) {
                associations.get(association.getSourceObject()).add(association.getTargetObject());
            } else {
                associations.put(association.getSourceObject(),
                        new HashSet<>(Collections.singleton(association.getTargetObject())));
            }/*from w w  w .j ava2s .c o  m*/
        }
    }
    boolean orgFound = false;
    boolean contactFound = false;
    if (associations.get(nodeId) != null) {
        Set<String> nodeAssociations = associations.get(nodeId);
        RegistryObjectType ro;
        for (String id : nodeAssociations) {
            ro = registryIds.get(id);
            if (!orgFound && ro != null && ro instanceof OrganizationType) {
                parseRegistryOrganization((OrganizationType) ro, metacard);
                orgFound = true;
            } else if (!contactFound && ro != null && ro instanceof PersonType) {
                parseRegistryPerson((PersonType) ro, metacard);
                contactFound = true;
            }
        }
    }

    if (!orgFound && !orgs.isEmpty()) {
        parseRegistryOrganization(orgs.get(0), metacard);
    }
    if (!contactFound && !contacts.isEmpty()) {
        parseRegistryPerson(contacts.get(0), metacard);
    }
}

From source file:eu.europa.ec.markt.tlmanager.core.ObjectFiller.java

/**
 * Ensure that all necessary fields are there to which a value might be bound
 * //from www  .jav a2 s.c o m
 * @param extensionsList the <code>ExtensionsListType</code> to fill
 * 
 * @return the filled object
 */
public static ExtensionsListType fillExtensionsListType(ExtensionsListType extensionsList)
        throws FillerException {
    try {
        Util.wrapExtensionsIndividually(extensionsList);
        List<ExtensionType> extensions = extensionsList.getExtension();

        boolean tob = false, ecri = false, asi = false, q = false;
        for (ExtensionType extension : extensions) {
            JAXBElement<?> element = Util.extractJAXBElement(extension);
            if (element != null) {
                QName name = element.getName();
                if (QNames._TakenOverBy_QNAME.equals(name)) {
                    tob = true;
                    JAXBElement<TakenOverByType> el = (JAXBElement<TakenOverByType>) element;
                    fillTakenOverByType(el.getValue());
                }
                if (QNames._ExpiredCertsRevocationInfo_QNAME.equals(name)) {
                    ecri = true;
                }
                if (QNames._AdditionalServiceInformation_QNAME.equals(name)) {
                    asi = true;
                    JAXBElement<AdditionalServiceInformationType> el = (JAXBElement<AdditionalServiceInformationType>) element;
                    fillAdditionalServiceInformationType(el.getValue());
                }
                if (QNames._Qualifications_QNAME.equals(name)) {
                    JAXBElement<QualificationsType> el = (JAXBElement<QualificationsType>) element;
                    for (QualificationElementType qel : el.getValue().getQualificationElement()) {
                        fillQualificationElement(qel);
                    }
                }
            }
        }
        if (!tob) {
            ExtensionType extensionType = objectFactoryTSL.createExtensionType();
            JAXBElement<TakenOverByType> element = objectFactoryTSLX
                    .createTakenOverBy(fillTakenOverByType(objectFactoryTSLX.createTakenOverByType()));
            extensionType.getContent().add(element);
            extensions.add(extensionType);
        }
        if (!ecri) {
            ExtensionType extensionType = objectFactoryTSL.createExtensionType();
            JAXBElement<XMLGregorianCalendar> element = objectFactoryTSL.createExpiredCertsRevocationInfo(null);
            extensionType.getContent().add(element);
            extensions.add(extensionType);
        }
        if (!asi) {
            // nothing to do, because AdditionalServiceInformationAdapter is doing the work if there is no asi
        }
    } catch (Exception ex) {
        throw new FillerException("fillExtensionsListType", ex);
    }

    return extensionsList;
}

From source file:be.fedict.eid.dss.spi.utils.XAdESUtils.java

@SuppressWarnings("unchecked")
public static IdentityType findIdentity(Element nsElement, XMLSignature xmlSignature, Element signatureElement)
        throws XAdESValidationException {

    try {//from  ww  w  .j a  va2 s  . c om
        String identityUri = XAdESUtils.findReferenceUri(xmlSignature, IdentitySignatureFacet.REFERENCE_TYPE);
        if (null != identityUri) {
            String identityId = identityUri.substring(1);
            Node identityNode = XPathAPI.selectSingleNode(signatureElement,
                    "ds:Object[@Id = '" + identityId + "']/identity:Identity", nsElement);
            if (null != identityNode) {
                JAXBElement<IdentityType> identityElement = (JAXBElement<IdentityType>) identityUnmarshaller
                        .unmarshal(identityNode);
                return identityElement.getValue();
            }
        }
        return null;
    } catch (TransformerException e) {
        throw new XAdESValidationException(e);
    } catch (JAXBException e) {
        throw new XAdESValidationException(e);
    }

}

From source file:com.evolveum.midpoint.web.util.ExpressionUtil.java

public static MapXNode getOrCreateAssociationTargetSearchValues(ExpressionType expression) {
    JAXBElement element = findFirstEvaluatorByName(expression,
            SchemaConstantsGenerated.C_ASSOCIATION_TARGET_SEARCH);
    if (element == null) {
        element = createAssociationTargetSearchElement();
    }/*from  w  ww . j a  v a2 s.co  m*/
    SearchObjectExpressionEvaluatorType evaluator = (SearchObjectExpressionEvaluatorType) element.getValue();
    if (evaluator == null) {
        evaluator = new SearchObjectExpressionEvaluatorType();
    }
    SearchFilterType filterType = evaluator.getFilter();
    if (filterType == null) {
        filterType = new SearchFilterType();
    }
    MapXNode filterClauseNode = filterType.getFilterClauseXNode();
    if (filterClauseNode == null) {
        filterClauseNode = new MapXNode();
    }
    if (!filterClauseNode.containsKey(new QName("equal"))) {
        filterClauseNode.put(new QName("equal"), null);
    }
    MapXNode values = (MapXNode) filterClauseNode.get(new QName("equal"));
    if (values == null) {
        values = new MapXNode();
    }

    return values;
}

From source file:com.evolveum.midpoint.model.client.ModelClientUtil.java

public static <O> O unmarshallFile(File file) throws JAXBException, FileNotFoundException {
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

    InputStream is = null;/*from  w  ww  . j a v  a 2s .  c  o m*/
    JAXBElement<O> element = null;
    try {
        is = new FileInputStream(file);
        element = (JAXBElement<O>) unmarshaller.unmarshal(is);
    } finally {
        if (is != null) {
            IOUtils.closeQuietly(is);
        }
    }
    if (element == null) {
        return null;
    }
    return element.getValue();
}

From source file:be.fedict.eid.dss.spi.utils.XAdESUtils.java

@SuppressWarnings("unchecked")
public static QualifyingPropertiesType getQualifyingProperties(Element nsElement, XMLSignature xmlSignature,
        Element signatureElement) throws XAdESValidationException {

    try {//from  ww  w. j a  v  a  2s. co  m
        String xadesSignedPropertiesUri = findReferenceUri(xmlSignature,
                "http://uri.etsi.org/01903#SignedProperties");
        if (null == xadesSignedPropertiesUri) {
            LOG.error("no XAdES SignedProperties as part of signed XML data");
            throw new XAdESValidationException("no XAdES SignedProperties");
        }

        String xadesSignedPropertiesId = xadesSignedPropertiesUri.substring(1);
        Node xadesQualifyingPropertiesNode = XPathAPI.selectSingleNode(signatureElement,
                "ds:Object/xades:QualifyingProperties[xades:SignedProperties/@Id='" + xadesSignedPropertiesId
                        + "']",
                nsElement);

        JAXBElement<QualifyingPropertiesType> qualifyingPropertiesElement = (JAXBElement<QualifyingPropertiesType>) xadesUnmarshaller
                .unmarshal(xadesQualifyingPropertiesNode);
        return qualifyingPropertiesElement.getValue();
    } catch (TransformerException e) {
        throw new XAdESValidationException(e);
    } catch (JAXBException e) {
        throw new XAdESValidationException(e);
    }
}