Example usage for javax.xml.bind JAXBElement getName

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

Introduction

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

Prototype

public QName getName() 

Source Link

Document

Returns the xml element tag name.

Usage

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

public static String getOrig(PolyStringType polyStringType) {
    if (polyStringType == null) {
        return null;
    }/*from  w  w  w  .  ja v a2 s  .  co m*/
    StringBuilder sb = new StringBuilder();
    for (Object o : polyStringType.getContent()) {
        if (o instanceof String) {
            sb.append(o);
        } else if (o instanceof Element) {
            Element e = (Element) o;
            if ("orig".equals(e.getLocalName())) {
                return e.getTextContent();
            }
        } else if (o instanceof JAXBElement) {
            JAXBElement je = (JAXBElement) o;
            if ("orig".equals(je.getName().getLocalPart())) {
                return (String) je.getValue();
            }
        }
    }
    return sb.toString();
}

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

public static void removeEvaluatorByName(ExpressionType expression, QName elementName) {
    if (isEmpty(expression) || elementName == null) {
        return;/*  w  w w.j av  a 2  s. co m*/
    }
    Iterator<JAXBElement<?>> it = expression.getExpressionEvaluator().iterator();
    while (it.hasNext()) {
        JAXBElement<?> element = it.next();
        if (element != null && element.getName().equals(elementName)) {
            it.remove();
        }
    }
}

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

public static JAXBElement findFirstEvaluatorByName(ExpressionType expression, QName elementName) {
    if (isEmpty(expression) || elementName == null) {
        return null;
    }//from w w w  .j av  a2s  .com
    for (JAXBElement<?> element : expression.getExpressionEvaluator()) {
        if (element != null && element.getName().equals(elementName)) {
            return element;
        }
    }
    return null;
}

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

public static List<JAXBElement> findAllEvaluatorsByName(ExpressionType expression, QName elementName) {
    List<JAXBElement> elements = new ArrayList<>();
    if (isEmpty(expression) || elementName == null) {
        return elements;
    }//from   ww  w. j  av a2 s . c om
    for (JAXBElement<?> element : expression.getExpressionEvaluator()) {
        if (element != null && element.getName().equals(elementName)) {
            elements.add(element);
        }
    }
    return elements;
}

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

private static String serialize(JAXBElement<?> element, PrismContext prismContext) throws SchemaException {
    String xml;/*w  w  w  .  ja va 2 s .  c  o m*/
    if (element.getValue() instanceof RawType) {
        RawType raw = (RawType) element.getValue();
        RootXNode rootNode = new RootXNode(element.getName(), raw.serializeToXNode());
        xml = prismContext.xmlSerializer().serialize(rootNode);
    } else {
        xml = prismContext.xmlSerializer().serialize(element);
    }
    return WebXmlUtil.stripNamespaceDeclarations(xml);
}

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  w w w.  j ava2  s .  co m
 * Note: There are different approaches for parsing data here. E.g. a 'PolicySet' could be stored in a
 * 'CriteriaListType' as well as in the 'otherCriteriaList' as 'AnyType'. However, the following annotation (taken
 * from ts_102231v030102_sie_xsd.xsd) is taken into account here:
 * --------
 * <complexType name="CriteriaListType">
 * <annotation>
 *      <documentation>Please first try to use the CriteriaList before doing the OtherCriteria extension
 *          point.</documentation>
 * </annotation>
 * --------
 *  
 * Note: values could be carried over, otherwise they are lost and
 * have to be reentered in TLManager Example: if there are PolicySets defined in otherCriteria, they could be parsed
 * and set directly below the criteriaList! Furthermore, especially this object seems to be a source for a multitude
 * of different interpretations throughout other MS TSL; data which is not stored in the correct objects (see
 * specification) cannot be parsed and have to be re-entered in TLManager.
 * 
 * @param element the <code>QualificationElementType</code> to fill
 * 
 * @return the filled object
 */
@SuppressWarnings("restriction")
public static QualificationElementType fillQualificationElement(QualificationElementType element)
        throws FillerException {
    try {
        CriteriaListType criteriaList = element.getCriteriaList();
        if (criteriaList == null) {
            criteriaList = objectFactoryECC.createCriteriaListType();
            element.setCriteriaList(criteriaList);
        }
        if (criteriaList.getAssert() == null || criteriaList.getAssert().isEmpty()) {
            criteriaList.setAssert(Util.DEFAULT_NO_SELECTION_ENTRY);
        }

        if (criteriaList.getKeyUsage().isEmpty()) {
            KeyUsageType keyUsageType = objectFactoryECC.createKeyUsageType();
            criteriaList.getKeyUsage().add(keyUsageType);
        }
        for (KeyUsageType keyUsage : criteriaList.getKeyUsage()) {
            fillKeyUsageType(keyUsage);
        }

        if (criteriaList.getPolicySet().isEmpty()) {
            PoliciesListType policiesListType = objectFactoryECC.createPoliciesListType();
            criteriaList.getPolicySet().add(policiesListType);
        }

        if (criteriaList.getOtherCriteriaList() == null) {
            criteriaList.setOtherCriteriaList(objectFactoryXADES.createAnyType());
        }

        boolean createEKUT = true, createCSDAT = true;
        List<Object> otherCriteriaContent = criteriaList.getOtherCriteriaList().getContent();
        if (otherCriteriaContent.isEmpty()) {

            ExtendedKeyUsageType extendedKeyUsageType = objectFactoryTSLX.createExtendedKeyUsageType();
            JAXBElement<ExtendedKeyUsageType> extendedKeyUsage = objectFactoryTSLX
                    .createExtendedKeyUsage(extendedKeyUsageType);

            CertSubjectDNAttributeType certSubjectDNAttributeType = objectFactoryTSLX
                    .createCertSubjectDNAttributeType();
            JAXBElement<CertSubjectDNAttributeType> certSubjectDNAttribute = objectFactoryTSLX
                    .createCertSubjectDNAttribute(certSubjectDNAttributeType);
            otherCriteriaContent.add(extendedKeyUsage);
            otherCriteriaContent.add(certSubjectDNAttribute);
        } else {
            for (Object othCrit : otherCriteriaContent) {
                if (othCrit instanceof JAXBElement<?>) {
                    JAXBElement<?> elem = (JAXBElement<?>) othCrit;

                    if (elem.getName().equals(QNames._ExtendedKeyUsage_QNAME)) {
                        createEKUT = false;
                    } else if (elem.getName().equals(QNames._CertSubjectDNAttribute_QNAME)) {
                        createCSDAT = false;
                    }
                }
            }
        }

        if (createEKUT) {
            ExtendedKeyUsageType extendedKeyUsageType = objectFactoryTSLX.createExtendedKeyUsageType();
            JAXBElement<ExtendedKeyUsageType> extendedKeyUsage = objectFactoryTSLX
                    .createExtendedKeyUsage(extendedKeyUsageType);
            otherCriteriaContent.add(extendedKeyUsage);
        }
        if (createCSDAT) {
            CertSubjectDNAttributeType certSubjectDNAttributeType = objectFactoryTSLX
                    .createCertSubjectDNAttributeType();
            JAXBElement<CertSubjectDNAttributeType> certSubjectDNAttribute = objectFactoryTSLX
                    .createCertSubjectDNAttribute(certSubjectDNAttributeType);
            otherCriteriaContent.add(certSubjectDNAttribute);
        }

        QualifiersType qualifiers = element.getQualifiers();
        if (qualifiers == null) {
            qualifiers = objectFactoryECC.createQualifiersType();
            element.setQualifiers(qualifiers);
        }
        final short NUMBER_OF_QUALIFIERS = 1;
        for (int i = 0; i < NUMBER_OF_QUALIFIERS; i++) {
            if (qualifiers.getQualifier().size() == i) {
                QualifierType qualifier = objectFactoryECC.createQualifierType();
                qualifier.setUri(Util.DEFAULT_NO_SELECTION_ENTRY);
                qualifiers.getQualifier().add(qualifier);
            }
        }
        // remove any qualifier besides of the first NUMBER_OF_QUALIFIERS (a loaded list may contain these)
        List<QualifierType> qualifierList = qualifiers.getQualifier();
        while (qualifierList.size() > NUMBER_OF_QUALIFIERS) {
            qualifierList = qualifierList.subList(0, NUMBER_OF_QUALIFIERS);
        }
    } catch (Exception ex) {
        throw new FillerException("fillQualificationElement", ex);
    }

    return element;
}

From source file:com.evolveum.midpoint.schema.util.PolicyRuleTypeUtil.java

@SuppressWarnings("unchecked")
private static void resolveLocalReferences(PolicyConstraintsType pc, ConstraintResolver resolver)
        throws ObjectNotFoundException, SchemaException {
    for (PolicyConstraintReferenceType ref : pc.getRef()) {
        String refName = ref != null ? ref.getName() : null;
        if (StringUtils.isEmpty(refName)) {
            throw new SchemaException("Illegal empty reference: " + ref);
        }/*from w  ww. ja v  a 2  s  . c o  m*/
        List<String> pathToRoot = getPathToRoot(pc);
        if (pathToRoot.contains(refName)) {
            throw new SchemaException("Trying to resolve cyclic reference to constraint '" + refName
                    + "'. Contained in: " + pathToRoot);
        }
        JAXBElement<? extends AbstractPolicyConstraintType> resolved = resolver.resolve(refName);
        QName constraintName = resolved.getName();
        AbstractPolicyConstraintType constraintValue = resolved.getValue();
        PrismContainer<? extends AbstractPolicyConstraintType> container = pc.asPrismContainerValue()
                .findOrCreateContainer(constraintName);
        container.add(constraintValue.asPrismContainerValue().clone());
    }
    pc.getRef().clear();
}

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
 * /* www  .ja va 2 s  .  co 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:com.evolveum.midpoint.schema.util.PolicyRuleTypeUtil.java

public static String toShortString(PolicyConstraintsType constraints, char join) {
    if (constraints == null) {
        return "null";
    }//from ww w .j a v  a2 s.co  m
    StringBuilder sb = new StringBuilder();
    // we ignore refs to be able to dump even unresolved policy rules
    for (JAXBElement<AbstractPolicyConstraintType> constraint : toConstraintsList(constraints, false, true)) {
        QName name = constraint.getName();
        String abbreviation = CONSTRAINT_NAMES.get(name.getLocalPart());
        if (sb.length() > 0) {
            sb.append(join);
        }
        if (QNameUtil.match(name, PolicyConstraintsType.F_AND)) {
            sb.append('(');
            sb.append(toShortString((PolicyConstraintsType) constraint.getValue(), JOIN_AND));
            sb.append(')');
        } else if (QNameUtil.match(name, PolicyConstraintsType.F_OR)) {
            sb.append('(');
            sb.append(toShortString((PolicyConstraintsType) constraint.getValue(), JOIN_OR));
            sb.append(')');
        } else if (QNameUtil.match(name, PolicyConstraintsType.F_NOT)) {
            sb.append('(');
            sb.append(toShortString((PolicyConstraintsType) constraint.getValue(), JOIN_AND));
            sb.append(')');
        } else if (QNameUtil.match(name, PolicyConstraintsType.F_TRANSITION)) {
            TransitionPolicyConstraintType trans = (TransitionPolicyConstraintType) constraint.getValue();
            sb.append(SYMBOL_TRANSITION);
            sb.append(toTransSymbol(trans.isStateBefore()));
            sb.append(toTransSymbol(trans.isStateAfter()));
            sb.append('(');
            sb.append(toShortString(trans.getConstraints(), JOIN_AND));
            sb.append(')');
        } else {
            sb.append(abbreviation != null ? abbreviation : name.getLocalPart());
        }
    }
    for (PolicyConstraintReferenceType ref : constraints.getRef()) {
        if (sb.length() > 0) {
            sb.append(join);
        }
        sb.append("ref:").append(ref.getName());
    }
    return sb.toString();
}

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
 * //ww  w  .  java  2s.  c  om
 * @param pointer the <code>OtherTSLPointerType</code> to fill
 * 
 * @return the filled object
 */
public static OtherTSLPointerType fillOtherTSPPointerType(OtherTSLPointerType pointer) throws FillerException {
    try {
        if (pointer.getServiceDigitalIdentities() == null) {
            pointer.setServiceDigitalIdentities(objectFactoryTSL.createServiceDigitalIdentityListType());
        }
        if (pointer.getServiceDigitalIdentities().getServiceDigitalIdentity().isEmpty()) {
            pointer.getServiceDigitalIdentities().getServiceDigitalIdentity()
                    .add(objectFactoryTSL.createDigitalIdentityListType());
        }

        AdditionalInformationType additionalInformationType = null;
        if (pointer.getAdditionalInformation() == null) {
            additionalInformationType = objectFactoryTSL.createAdditionalInformationType();
            pointer.setAdditionalInformation(additionalInformationType);
        } else {
            additionalInformationType = pointer.getAdditionalInformation();
        }

        if (pointer.getTSLLocation() == null) {
            pointer.setTSLLocation("Pointer to TSL");
        }

        List<Serializable> othObjects = additionalInformationType.getTextualInformationOrOtherInformation();
        boolean son = false, stcr = false, st = false, mt = false, tt = false;

        for (Object obj : othObjects) {
            if (obj instanceof AnyType) {
                JAXBElement<?> element = Util.extractJAXBElement((AnyType) obj);
                if (element != null) {
                    QName name = element.getName();
                    if (QNames._SchemeOperatorName_QNAME.equals(name)) {
                        son = true;
                    }
                    if (QNames._SchemeTypeCommunityRules_QNAME.equals(name)) {
                        stcr = true;
                    }
                    if (QNames._SchemeTerritory_QNAME.equals(name)) {
                        st = true;
                    }
                    if (QNames._MimeType_QNAME.equals(name)) {
                        mt = true;
                    }
                    if (QNames._TSLType_QNAME.equals(name)) {
                        tt = true;
                    }
                }
            }
        }

        if (!son) { // tsl:SchemeOperatorName
            InternationalNamesType internationalNamesType = objectFactoryTSL.createInternationalNamesType();
            JAXBElement<InternationalNamesType> schemeOperatorName = objectFactoryTSL
                    .createSchemeOperatorName(internationalNamesType);
            othObjects.add(addToAnyType(schemeOperatorName));
        }

        if (!stcr) { // tsl:SchemeTypeCommunityRules
            NonEmptyMultiLangURIListType nonEmptyMultiLangURIType = objectFactoryTSL
                    .createNonEmptyMultiLangURIListType();
            JAXBElement<NonEmptyMultiLangURIListType> schemeTypeCommunityRules = objectFactoryTSL
                    .createSchemeTypeCommunityRules(nonEmptyMultiLangURIType);
            othObjects.add(addToAnyType(schemeTypeCommunityRules));
        }

        if (!st) { // tsl:SchemeTerritory
            JAXBElement<String> schemeTerritory = objectFactoryTSL
                    .createSchemeTerritory(Util.DEFAULT_NO_SELECTION_ENTRY);
            othObjects.add(addToAnyType(schemeTerritory));
        }

        if (!mt) { // tslx:MimeType
            JAXBElement<String> mimeType = objectFactoryTSLX.createMimeType(Util.DEFAULT_NO_SELECTION_ENTRY);
            othObjects.add(addToAnyType(mimeType));
        }

        if (!tt) { // tsl:TSLType
            final String tslTypeInverse = Configuration.getInstance().getTSL().getTslTypeInverse();
            JAXBElement<String> TSLType = objectFactoryTSL.createTSLType(tslTypeInverse);
            othObjects.add(addToAnyType(TSLType));
        }

        pointer.setAdditionalInformation(additionalInformationType);
    } catch (Exception ex) {
        throw new FillerException("fillOtherTSPPointerType", ex);
    }

    return pointer;
}