Example usage for javax.xml.namespace QName equals

List of usage examples for javax.xml.namespace QName equals

Introduction

In this page you can find the example usage for javax.xml.namespace QName equals.

Prototype

public final boolean equals(Object objectToTest) 

Source Link

Document

Test this QName for equality with another Object.

If the Object to be tested is not a QName or is null, then this method returns false.

Two QNames are considered equal if and only if both the Namespace URI and local part are equal.

Usage

From source file:Main.java

public static boolean is(Element element, QName qName) {
    final boolean equals = qName.equals(new QName(element.getNamespaceURI(), element.getTagName()));
    return equals;
}

From source file:Main.java

/**
 * Utility method that throws an exception if the provided reader is not
 * positioned before a StartElement event with the specified tag name.
 * /*from  w w w.  j  av  a  2s .  c  om*/
 * @param reader The reader to test.
 * @param qname The required name of the start-tag. If <code>null</code>,
 *            any start tag is accepted.
 * @throws XMLStreamException If an error occurs reading from the stream.
 */
public static final void requireStartElement(XMLEventReader reader, QName qname) throws XMLStreamException {

    if (reader.hasNext()) {

        XMLEvent nextEvent = reader.peek();
        if (nextEvent.isStartElement()) {

            if (qname != null) {

                StartElement start = nextEvent.asStartElement();
                QName name = start.getName();
                if (!name.equals(qname)) {

                    throw new XMLStreamException(
                            "Encountered unexpected element; expected " + qname + ", but found " + name);

                }

            }

        } else {

            throw new XMLStreamException("Encountered unexpected event; expected " + qname
                    + " start-tag, but found event " + nextEvent);

        }

    } else {

        throw new XMLStreamException("Encountered unexpected end of stream; expected element " + qname);

    }

}

From source file:com.stratumsoft.xmlgen.SampleValueProvider.java

public static String get(QName qn) {
    String val = "";
    if (qn != null) {
        if (qn.equals(Constants.XSD_ID)) { //need to return unique values
            val = "id-" + new Random().nextInt(Integer.MAX_VALUE);
        } else/* ww  w .  j  a  v a  2s. com*/
            val = qnVal.get(qn);
    }
    return val;
}

From source file:eu.planets_project.tb.impl.services.util.DiscoveryUtils.java

/**
 * Determine the high-level service class for this service type.
 * e.g. the Basic forms are wrapped up in higher level forms.
 * @return/* ww  w  .  j  av  a  2s.c  o  m*/
 */
public static Class<? extends PlanetsService> getServiceWrapperClass(QName qName) {

    // Unqualified services cannot be dealt with:
    if (qName == null)
        return null;

    // Determine class of service:
    if (qName.equals(Migrate.QNAME)) {
        return Migrate.class;

    } else if (qName.equals(Identify.QNAME)) {
        return Identify.class;

    } else if (qName.equals(Validate.QNAME)) {
        return Validate.class;

    } else if (qName.equals(Characterise.QNAME)) {
        return Characterise.class;

    } else if (qName.equals(CreateView.QNAME)) {
        return CreateView.class;

    }

    // Otherwise, this is and unrecognised service:
    return null;
}

From source file:com.evolveum.liferay.usercreatehook.password.StringPolicyUtils.java

/**
 * Prepare usable list of strings for generator
 *///w ww  .  j  a  va  2 s.co  m

public static String collectCharacterClass(CharacterClassType cc, QName ref) {
    StrBuilder l = new StrBuilder();
    if (null == cc) {
        throw new IllegalArgumentException("Character class cannot be null");
    }

    if (null != cc.getValue() && (null == ref || ref.equals(cc.getName()))) {
        l.append(cc.getValue());
    } else if (null != cc.getCharacterClass() && !cc.getCharacterClass().isEmpty()) {
        // Process all sub lists
        for (CharacterClassType subClass : cc.getCharacterClass()) {
            // If we found requested name or no name defined
            if (null == ref || ref.equals(cc.getName())) {
                l.append(collectCharacterClass(subClass, null));
            } else {
                l.append(collectCharacterClass(subClass, ref));
            }
        }
    }
    // Remove duplicity in return;
    HashSet<String> h = new HashSet<String>();
    for (String s : l.toString().split("")) {
        h.add(s);
    }
    return new StrBuilder().appendAll(h).toString();
}

From source file:com.evolveum.midpoint.model.common.stringpolicy.StringPolicyUtils.java

/**
 * Prepare usable list of strings for generator
 * //from w w  w.  j a va 2s  .  c  o  m
 */

public static String collectCharacterClass(CharacterClassType cc, QName ref) {
    StrBuilder l = new StrBuilder();
    if (null == cc) {
        throw new IllegalArgumentException("Character class cannot be null");
    }

    if (null != cc.getValue() && (null == ref || ref.equals(cc.getName()))) {
        l.append(cc.getValue());
    } else if (null != cc.getCharacterClass() && !cc.getCharacterClass().isEmpty()) {
        // Process all sub lists
        for (CharacterClassType subClass : cc.getCharacterClass()) {
            // If we found requested name or no name defined
            if (null == ref || ref.equals(cc.getName())) {
                l.append(collectCharacterClass(subClass, null));
            } else {
                l.append(collectCharacterClass(subClass, ref));
            }
        }
    }
    // Remove duplicity in return;
    HashSet<String> h = new HashSet<>();
    for (String s : l.toString().split("")) {
        h.add(s);
    }
    return new StrBuilder().appendAll(h).toString();
}

From source file:com.evolveum.midpoint.test.util.MidPointAsserts.java

public static <F extends FocusType> void assertAssigned(PrismObject<F> user, String targetOid, QName refType) {
    F userType = user.asObjectable();// w  w w.ja v  a  2s. com
    for (AssignmentType assignmentType : userType.getAssignment()) {
        ObjectReferenceType targetRef = assignmentType.getTargetRef();
        if (targetRef != null) {
            if (refType.equals(targetRef.getType())) {
                if (targetOid.equals(targetRef.getOid())) {
                    return;
                }
            }
        }
    }
    AssertJUnit.fail(user + " does not have assigned " + refType.getLocalPart() + " " + targetOid);
}

From source file:com.evolveum.midpoint.test.util.MidPointAsserts.java

public static <F extends FocusType> void assertNotAssigned(PrismObject<F> user, String targetOid,
        QName refType) {
    F userType = user.asObjectable();//from w w  w .j  a  v  a 2s. co m
    for (AssignmentType assignmentType : userType.getAssignment()) {
        ObjectReferenceType targetRef = assignmentType.getTargetRef();
        if (targetRef != null) {
            if (refType.equals(targetRef.getType())) {
                if (targetOid.equals(targetRef.getOid())) {
                    AssertJUnit.fail(user + " does have assigned " + refType.getLocalPart() + " " + targetOid
                            + " while not expecting it");
                }
            }
        }
    }
}

From source file:com.evolveum.midpoint.test.util.MidPointAsserts.java

public static void assertAssigned(PrismObject<? extends FocusType> focus, String targetOid, QName refType,
        QName relation) {//from  ww w .j  av  a2s  . c  o m
    FocusType focusType = focus.asObjectable();
    for (AssignmentType assignmentType : focusType.getAssignment()) {
        ObjectReferenceType targetRef = assignmentType.getTargetRef();
        if (targetRef != null) {
            if (refType.equals(targetRef.getType())) {
                if (targetOid.equals(targetRef.getOid())
                        && MiscSchemaUtil.compareRelation(targetRef.getRelation(), relation)) {
                    return;
                }
            }
        }
    }
    AssertJUnit.fail(focus + " does not have assigned " + refType.getLocalPart() + " " + targetOid
            + ", relation " + relation);
}

From source file:Main.java

/**
 * returns the matching Extension provider for a given QName/namespaceURI+prefix+localName
 * combination/*from ww  w.  java 2s .c o  m*/
 *
 * @param extensionMap registered extension Map for the corresponding extension provider
 * @param namespaceURI binding namespace in xpath expression
 * @param prefix       binding prefix string in xpath expression
 * @param localName    binding localname string in xpath expression
 * @param <T>          Variable/Function Context Provider Type
 * @return matching Extension provider. returns null if no extension is found for the given
 *         combination
 */
private static <T> T getMatchingExtensionProvider(Map<QName, T> extensionMap, String namespaceURI,
        String prefix, String localName) {
    QName subject;
    if (localName != null && prefix != null) {
        subject = new QName(namespaceURI, localName, prefix);
    } else if (localName != null) {
        subject = new QName(namespaceURI, localName);
    } else {
        //can't resolve xpath extensions - invalid combination
        return null;
    }

    Set<QName> qNames = extensionMap.keySet();
    for (QName qName : qNames) {
        //check for a match for the given combination for QName registered
        if (subject.equals(qName)) {
            return extensionMap.get(qName);
        }
    }
    //no match found
    return null;

}