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:com.evolveum.midpoint.prism.PrismContainerDefinition.java

public <ID extends ItemDefinition> ID findNamedItemDefinition(QName firstName, ItemPath rest, Class<ID> clazz) {

    // we need to be compatible with older versions..soo if the path does
    // not contains qnames with namespaces defined (but the prefix was
    // specified) match definition according to the local name
    if (StringUtils.isEmpty(firstName.getNamespaceURI())) {
        for (ItemDefinition def : getDefinitions()) {
            if (QNameUtil.match(firstName, def.getName())) {
                return (ID) def.findItemDefinition(rest, clazz);
            }//w ww  . j  av  a2 s.co  m
        }
    }

    for (ItemDefinition def : getDefinitions()) {
        if (firstName.equals(def.getName())) {
            return (ID) def.findItemDefinition(rest, clazz);
        }
    }

    if (isRuntimeSchema()) {
        return findRuntimeItemDefinition(firstName, rest, clazz);
    }

    return null;
}

From source file:com.evolveum.midpoint.web.component.assignment.ConstructionAssociationPanel.java

private List<ObjectReferenceType> getAssociationsShadowRefs(boolean compareName, QName name) {
    List<ObjectReferenceType> shadowsList = new ArrayList<>();
    ContainerWrapper associationWrapper = getModelObject()
            .findContainerWrapper(getModelObject().getPath().append(ConstructionType.F_ASSOCIATION));
    associationWrapper.getValues().forEach(associationValueWrapper -> {
        if (ValueStatus.DELETED.equals(((ContainerValueWrapper) associationValueWrapper).getStatus())) {
            return;
        }//from   w  w  w  .ja  va2s  .com
        PrismContainerValue associationValue = ((ContainerValueWrapper) associationValueWrapper)
                .getContainerValue();
        ResourceObjectAssociationType assoc = (ResourceObjectAssociationType) associationValue
                .asContainerable();
        if (assoc == null || assoc.getOutbound() == null || assoc.getOutbound().getExpression() == null
                || ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()) == null) {
            return;
        }
        if (compareName) {
            QName assocRef = ItemPathUtil.getOnlySegmentQName(assoc.getRef());
            if (name != null && name.equals(assocRef)) {
                shadowsList.add(ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()));
            }
        } else {
            shadowsList.add(ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()));
        }
    });
    return shadowsList;

}

From source file:com.evolveum.midpoint.model.impl.expr.MidpointFunctionsImpl.java

@Override
public Collection<OrgType> getParentOrgs(ObjectType object, QName relation, String orgType)
        throws SchemaException, SecurityViolationException {
    List<ObjectReferenceType> parentOrgRefs = object.getParentOrgRef();
    List<OrgType> parentOrgs = new ArrayList<OrgType>(parentOrgRefs.size());
    for (ObjectReferenceType parentOrgRef : parentOrgRefs) {
        if (relation == null) {
            if (parentOrgRef.getRelation() != null) {
                continue;
            }// w  w w .  j  ava2  s . co m
        } else if (!relation.equals(PrismConstants.Q_ANY)) {
            if (!QNameUtil.match(parentOrgRef.getRelation(), relation)) {
                continue;
            }
        }
        OrgType parentOrg;
        try {
            parentOrg = getObject(OrgType.class, parentOrgRef.getOid());
        } catch (ObjectNotFoundException e) {
            LOGGER.warn("Org " + parentOrgRef.getOid() + " specified in parentOrgRef in " + object
                    + " was not found: " + e.getMessage(), e);
            // but do not rethrow, just skip this
            continue;
        } catch (CommunicationException | ConfigurationException e) {
            // This should not happen.
            throw new SystemException(e.getMessage(), e);
        }
        if (orgType == null || parentOrg.getOrgType().contains(orgType)) {
            parentOrgs.add(parentOrg);
        }
    }
    return parentOrgs;
}

From source file:com.evolveum.midpoint.prism.parser.XNodeProcessor.java

private <T> T parseAtomicValueFromPrimitive(PrimitiveXNode<T> xprim, PrismPropertyDefinition def,
        QName typeName) throws SchemaException {
    T realValue = null;//from  ww  w  .jav  a2 s  .c om
    if (ItemPathType.COMPLEX_TYPE.equals(typeName)) {
        return (T) parseItemPathType(xprim);
    } else if (ProtectedStringType.COMPLEX_TYPE.equals(typeName)) {
        return (T) parseProtectedTypeFromPrimitive(xprim);
    } else if (getBeanConverter().canProcess(typeName) && !typeName.equals(PolyStringType.COMPLEX_TYPE)
            && !typeName.equals(ItemPathType.COMPLEX_TYPE)) {
        // Primitive elements may also have complex Java representations (e.g. enums)
        return getBeanConverter().unmarshallPrimitive(xprim, typeName);
    } else if (def != null && def.isRuntimeSchema() && def.getAllowedValues() != null
            && def.getAllowedValues().size() > 0) {
        //TODO: ugly hack to support enum in extension schemas --- need to be fixed

        realValue = xprim.getParsedValue(DOMUtil.XSD_STRING);
        if (!isAllowed(realValue, def.getAllowedValues())) {
            if (isStrict()) {
                throw new SchemaException("Illegal value found in property " + xprim + ". Allowed values are: "
                        + def.getAllowedValues());
            } else {
                // just skip the value
                LOGGER.error("Skipping unknown value of type {}. Value: {}", typeName, xprim.getStringValue());
                return null;
            }
        }

    } else {
        try {
            realValue = xprim.getParsedValue(typeName);
        } catch (SchemaException e) {
            if (isStrict()) {
                throw e;
            } else {
                // just skip the value
                LoggingUtils.logException(LOGGER,
                        "Couldn't parse primitive value of type {}. Value: {}.\nDefinition: {}", e, typeName,
                        xprim.getStringValue(), def != null ? def.debugDump() : "(null)");
                return null;
            }
        }
    }

    if (realValue == null) {
        return realValue;
    }

    if (realValue instanceof PolyStringType) {
        PolyStringType polyStringType = (PolyStringType) realValue;
        realValue = (T) new PolyString(polyStringType.getOrig(), polyStringType.getNorm());
    }

    if (!(realValue instanceof PolyString) && typeName.equals(PolyStringType.COMPLEX_TYPE)) {
        String val = (String) realValue;
        realValue = (T) new PolyString(val);
    }

    PrismUtil.recomputeRealValue(realValue, prismContext);
    return realValue;
}

From source file:com.evolveum.midpoint.web.component.assignment.ConstructionAssociationPanel.java

private IModel<List<ObjectReferenceType>> getShadowReferencesModel(RefinedAssociationDefinition def) {
    return new LoadableModel<List<ObjectReferenceType>>() {
        private static final long serialVersionUID = 1L;

        @Override//from   ww  w .java2  s  . c  om
        public List<ObjectReferenceType> load() {
            QName defName = def.getName();
            List<ObjectReferenceType> shadowsList = new ArrayList<>();
            ContainerWrapper associationWrapper = getModelObject()
                    .findContainerWrapper(getModelObject().getPath().append(ConstructionType.F_ASSOCIATION));
            associationWrapper.getValues().forEach(associationValueWrapper -> {
                if (ValueStatus.DELETED.equals(((ContainerValueWrapper) associationValueWrapper).getStatus())) {
                    return;
                }
                PrismContainerValue associationValue = ((ContainerValueWrapper) associationValueWrapper)
                        .getContainerValue();
                ResourceObjectAssociationType assoc = (ResourceObjectAssociationType) associationValue
                        .asContainerable();
                if (assoc == null || assoc.getOutbound() == null || assoc.getOutbound().getExpression() == null
                        || (ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()) == null
                                && !ValueStatus.ADDED.equals(
                                        ((ContainerValueWrapper) associationValueWrapper).getStatus()))) {
                    return;
                }
                QName assocRef = ItemPathUtil.getOnlySegmentQName(assoc.getRef());
                if ((defName != null && defName.equals(assocRef)) || (assocRef == null && ValueStatus.ADDED
                        .equals(((ContainerValueWrapper) associationValueWrapper).getStatus()))) {
                    shadowsList.add(ExpressionUtil.getShadowRefValue(assoc.getOutbound().getExpression()));
                }
            });
            return shadowsList;
        }
    };
}

From source file:com.evolveum.midpoint.prism.PrismContainerValue.java

@Override
public void accept(Visitor visitor, ItemPath path, boolean recursive) {
    if (path == null || path.isEmpty()) {
        // We are at the end of path, continue with regular visits all the way to the bottom
        if (recursive) {
            accept(visitor);/*www  . j av  a  2s.  c o  m*/
        } else {
            visitor.visit(this);
        }
    } else {
        ItemPathSegment first = path.first();
        if (!(first instanceof NameItemPathSegment)) {
            throw new IllegalArgumentException(
                    "Attempt to lookup item using a non-name path " + path + " in " + this);
        }
        QName subName = ((NameItemPathSegment) first).getName();
        ItemPath rest = path.rest();
        if (items != null) {
            for (Item<?, ?> item : items) { // todo unqualified names!
                if (first.isWildcard() || subName.equals(item.getElementName())) {
                    item.accept(visitor, rest, recursive);
                }
            }
        }
    }
}

From source file:com.evolveum.midpoint.prism.PrismContainerValue.java

<IV extends PrismValue, ID extends ItemDefinition, I extends Item<IV, ID>> void removeItem(ItemPath propPath,
        Class<I> itemType) {
    if (items == null) {
        return;//from  w  w  w.  jav a2s. c om
    }
    ItemPathSegment first = propPath.first();
    if (!(first instanceof NameItemPathSegment)) {
        throw new IllegalArgumentException(
                "Attempt to remove item using a non-name path " + propPath + " in " + this);
    }
    QName subName = ((NameItemPathSegment) first).getName();
    ItemPath rest = propPath.rest();
    Iterator<Item<?, ?>> itemsIterator = items.iterator();
    while (itemsIterator.hasNext()) {
        Item<?, ?> item = itemsIterator.next();
        if (subName.equals(item.getElementName())) {
            if (!rest.isEmpty() && item instanceof PrismContainer) {
                ((PrismContainer<?>) item).removeItem(propPath, itemType);
                return;
            } else {
                if (itemType.isAssignableFrom(item.getClass())) {
                    itemsIterator.remove();
                } else {
                    throw new IllegalArgumentException(
                            "Attempt to remove item " + subName + " from " + this + " of type " + itemType
                                    + " while the existing item is of incompatible type " + item.getClass());
                }
            }
        }
    }
}

From source file:it.cnr.icar.eric.server.profile.ws.wsdl.cataloger.WSDLCatalogerEngine.java

private Element resolvePortType(WSDLDocument wsdlCatalogedDocument, String bindingTypeStr)
        throws CatalogingException {
    Element resolvedPortType = null;
    List<Element> portTypes = wsdlDocument.getElements(WSDLConstants.QNAME_PORT_TYPE);
    Iterator<Element> portTypeItr = portTypes.iterator();
    QName portBindingQName = createQName(null, bindingTypeStr);
    while (portTypeItr.hasNext()) {
        Element portType = portTypeItr.next();
        String portTypeStr = wsdlDocument.getRequiredAttribute(portType, WSDLConstants.ATTR_NAME);
        String portTypeTargetNS = wsdlDocument.getTargetNamespaceURI(portType, WSDLConstants.QNAME_PORT_TYPE);
        // Try to resolve based on namespace:localValue
        QName bindingTypeQName = createQName(portTypeTargetNS, portTypeStr);
        if (portBindingQName.equals(bindingTypeQName) || portTypeStr.equals(bindingTypeStr)) {
            resolvedPortType = portType;
            break;
        }//from   w ww .j  av a 2 s .  c o  m
    }
    return resolvedPortType;
}

From source file:com.example.soaplegacy.WsdlValidator.java

private void validateDocLiteral(BindingOperation bindingOperation, Part[] parts, XmlObject msgXml,
        List<XmlError> errors, boolean isResponse, boolean strict) throws Exception {

    Part part = null;//from  ww w. j a  v  a 2s.  c  o  m
    // start by finding body part
    for (int c = 0; c < parts.length; c++) {
        // content part?
        if ((isResponse && !WsdlUtils.isAttachmentOutputPart(parts[c], bindingOperation))
                || (!isResponse && !WsdlUtils.isAttachmentInputPart(parts[c], bindingOperation))) {
            // already found?
            if (part != null) {
                if (strict) {
                    errors.add(XmlError.forMessage("DocLiteral message must contain 1 body part definition"));
                }
                return;
            }
            part = parts[c];
        }
    }

    QName elementName = part.getElementName();
    if (elementName != null) {
        // just check for correct message element, other elements are avoided
        // (should create an error)
        XmlObject[] paths = msgXml
                .selectPath("declare namespace env='" + wsdlContext.getSoapVersion().getEnvelopeNamespace()
                        + "';" + "declare namespace ns='" + elementName.getNamespaceURI() + "';"
                        + "$this/env:Envelope/env:Body/ns:" + elementName.getLocalPart());

        if (paths.length == 1) {
            SchemaGlobalElement elm = wsdlContext.getSchemaTypeLoader().findElement(elementName);
            if (elm != null) {
                validateMessageBody(errors, elm.getType(), paths[0]);

                // ensure no other elements in body
                NodeList children = XmlUtils.getChildElements((Element) paths[0].getDomNode().getParentNode());
                for (int d = 0; d < children.getLength(); d++) {
                    QName childName = XmlUtils.getQName(children.item(d));
                    if (!elementName.equals(childName)) {
                        XmlCursor cur = paths[0].newCursor();
                        cur.toParent();
                        cur.toChild(childName);
                        errors.add(XmlError.forCursor("Invalid element [" + childName + "] in SOAP Body", cur));
                        cur.dispose();
                    }
                }
            } else {
                errors.add(XmlError.forMessage("Missing part type [" + elementName + "] in associated schema"));
            }
        } else {
            errors.add(XmlError.forMessage("Missing message part with name [" + elementName + "]"));
        }
    } else if (part.getTypeName() != null) {
        QName typeName = part.getTypeName();

        XmlObject[] paths = msgXml.selectPath("declare namespace env='"
                + wsdlContext.getSoapVersion().getEnvelopeNamespace() + "';" + "declare namespace ns='"
                + typeName.getNamespaceURI() + "';" + "$this/env:Envelope/env:Body/ns:" + part.getName());

        if (paths.length == 1) {
            SchemaType type = wsdlContext.getSchemaTypeLoader().findType(typeName);
            if (type != null) {
                validateMessageBody(errors, type, paths[0]);
                // XmlObject obj = paths[0].copy().changeType( type );
                // obj.validate( new XmlOptions().setErrorListener( errors ));
            } else
                errors.add(XmlError.forMessage("Missing part type in associated schema"));
        } else
            errors.add(XmlError.forMessage(
                    "Missing message part with name:type [" + part.getName() + ":" + typeName + "]"));
    }
}

From source file:it.cnr.icar.eric.server.profile.ws.wsdl.cataloger.WSDLCatalogerEngine.java

private Element resolveBinding(WSDLDocument wsdlDocument, String portBindingStr) throws CatalogingException {
    Element resolvedBinding = null;
    List<Element> bindings = wsdlDocument.getElements(WSDLConstants.QNAME_BINDING);
    Iterator<Element> bindingItr = bindings.iterator();
    QName portBindingQName = createQName(null, portBindingStr);
    while (bindingItr.hasNext()) {
        Element binding = bindingItr.next();
        String bindingTypeStr = wsdlDocument.getRequiredAttribute(binding, WSDLConstants.ATTR_NAME);
        // Get target namespace
        String bindingTargetNS = wsdlDocument.getTargetNamespaceURI(binding, WSDLConstants.QNAME_BINDING);
        // Try to resolve based on namespace:localValue
        QName bindingTypeQName = createQName(bindingTargetNS, bindingTypeStr);
        if (portBindingQName.equals(bindingTypeQName) || bindingTypeStr.equals(portBindingStr)) {
            resolvedBinding = binding;/*from  w ww  .  j a  v a 2  s  . co m*/
            break;
        }
    }
    return resolvedBinding;
}