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.schema.PrismSchema.java

private <T extends PrismReferenceDefinition> T findReferenceDefinitionByElementName(QName elementName,
        Class<T> type) {/*ww w.j  ava 2 s. c o  m*/
    if (elementName == null) {
        throw new IllegalArgumentException("elementName must be supplied");
    }
    // TODO: check for multiple definition with the same type
    for (Definition definition : definitions) {
        if (type.isAssignableFrom(definition.getClass())
                && elementName.equals(((PrismReferenceDefinition) definition).getName())) {
            return (T) definition;
        }
    }
    return null;
}

From source file:com.evolveum.midpoint.web.component.wizard.resource.component.schemahandling.ResourceAttributeEditor.java

@Override
protected void initLayout() {
    Label label = new Label(ID_LABEL, new AbstractReadOnlyModel<String>() {

        @Override/*from ww w .  j  ava2  s.c  om*/
        public String getObject() {
            ResourceAttributeDefinitionType attribute = getModelObject();

            if (attribute.getRef() == null || attribute.getRef().equals(new ItemPathType())) {
                return getString("ResourceAttributeEditor.label.new");
            } else {
                return getString("ResourceAttributeEditor.label.edit",
                        ItemPathUtil.getOnlySegmentQName(attribute.getRef()).getLocalPart());
            }
        }
    });
    add(label);

    QNameEditorPanel nonSchemaRefPanel = new QNameEditorPanel(ID_NON_SCHEMA_REF_PANEL,
            new PropertyModel<ItemPathType>(getModel(), "ref"),
            "SchemaHandlingStep.attribute.label.attributeName",
            "SchemaHandlingStep.attribute.tooltip.attributeLocalPart",
            "SchemaHandlingStep.attribute.label.attributeNamespace",
            "SchemaHandlingStep.attribute.tooltip.attributeNamespace");

    nonSchemaRefPanel.setOutputMarkupId(true);
    nonSchemaRefPanel.setOutputMarkupPlaceholderTag(true);
    nonSchemaRefPanel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return nonSchemaRefValueAllowed;
        }
    });
    add(nonSchemaRefPanel);

    WebMarkupContainer schemaRefPanel = new WebMarkupContainer(ID_SCHEMA_REF_PANEL);
    schemaRefPanel.setOutputMarkupId(true);
    schemaRefPanel.setOutputMarkupPlaceholderTag(true);
    schemaRefPanel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !nonSchemaRefValueAllowed;
        }

    });
    add(schemaRefPanel);

    Label refTooltip = new Label(ID_T_REF);
    refTooltip.add(new InfoTooltipBehavior());
    refTooltip.setOutputMarkupId(true);
    refTooltip.setOutputMarkupId(true);
    schemaRefPanel.add(refTooltip);

    DropDownChoice refSelect = new DropDownChoice<ItemPathType>(ID_REFERENCE_SELECT,
            new PropertyModel<ItemPathType>(getModel(), "ref"),
            new AbstractReadOnlyModel<List<ItemPathType>>() {

                @Override
                public List<ItemPathType> getObject() {
                    return loadObjectReferences();
                }
            }, new IChoiceRenderer<ItemPathType>() {

                @Override
                public Object getDisplayValue(ItemPathType object) {
                    return prepareReferenceDisplayValue(object);
                }

                @Override
                public String getIdValue(ItemPathType object, int index) {
                    return Integer.toString(index);
                }
            }) {

        @Override
        protected boolean isSelected(ItemPathType object, int index, String selected) {
            if (getModelObject() == null || getModelObject().equals(new ItemPathType())) {
                return false;
            }

            QName referenceQName = ItemPathUtil.getOnlySegmentQName(getModelObject());
            QName optionQName = ItemPathUtil.getOnlySegmentQName(object);

            return referenceQName.equals(optionQName);
        }
    };
    refSelect.setNullValid(false);

    refSelect.setOutputMarkupId(true);
    refSelect.setOutputMarkupPlaceholderTag(true);
    schemaRefPanel.add(refSelect);

    CheckBox allowNonSchema = new CheckBox(ID_REFERENCE_ALLOW,
            new PropertyModel<Boolean>(this, "nonSchemaRefValueAllowed"));
    allowNonSchema.add(new AjaxFormComponentUpdatingBehavior("onchange") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(get(ID_NON_SCHEMA_REF_PANEL), get(ID_SCHEMA_REF_PANEL));
        }
    });
    add(allowNonSchema);

    TextField displayName = new TextField<>(ID_DISPLAY_NAME,
            new PropertyModel<String>(getModel(), "displayName"));
    add(displayName);

    TextArea description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(getModel(), "description"));
    add(description);

    AjaxLink limitations = new AjaxLink(ID_BUTTON_LIMITATIONS) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            limitationsEditPerformed(target);
        }
    };
    add(limitations);

    CheckBox exclusiveStrong = new CheckBox(ID_EXCLUSIVE_STRONG,
            new PropertyModel<Boolean>(getModel(), "exclusiveStrong"));
    add(exclusiveStrong);

    CheckBox tolerant = new CheckBox(ID_TOLERANT, new PropertyModel<Boolean>(getModel(), "tolerant"));
    add(tolerant);

    MultiValueTextPanel tolerantVP = new MultiValueTextPanel<>(ID_TOLERANT_VP,
            new PropertyModel<List<String>>(getModel(), "tolerantValuePattern"));
    add(tolerantVP);

    MultiValueTextPanel intolerantVP = new MultiValueTextPanel<>(ID_INTOLERANT_VP,
            new PropertyModel<List<String>>(getModel(), "intolerantValuePattern"));
    add(intolerantVP);

    DropDownChoice fetchStrategy = new DropDownChoice<>(ID_FETCH_STRATEGY,
            new PropertyModel<AttributeFetchStrategyType>(getModel(), "fetchStrategy"),
            WebMiscUtil.createReadonlyModelFromEnum(AttributeFetchStrategyType.class),
            new EnumChoiceRenderer<AttributeFetchStrategyType>(this));
    fetchStrategy.setNullValid(true);
    add(fetchStrategy);

    DropDownChoice matchingRule = new DropDownChoice<>(ID_MATCHING_RULE,
            new PropertyModel<QName>(getModel(), "matchingRule"), new AbstractReadOnlyModel<List<QName>>() {

                @Override
                public List<QName> getObject() {
                    return WebMiscUtil.getMatchingRuleList();
                }
            }, new IChoiceRenderer<QName>() {

                @Override
                public Object getDisplayValue(QName object) {
                    return object.getLocalPart();
                }

                @Override
                public String getIdValue(QName object, int index) {
                    return Integer.toString(index);
                }
            });
    matchingRule.setNullValid(true);
    add(matchingRule);

    TextField outboundLabel = new TextField<>(ID_OUTBOUND_LABEL, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            ResourceAttributeDefinitionType attributeDefinition = getModel().getObject();

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

            return MappingTypeDto.createMappingLabel(attributeDefinition.getOutbound(), LOGGER,
                    getPageBase().getPrismContext(), getString("MappingType.label.placeholder"),
                    getString("MultiValueField.nameNotSpecified"));
        }
    });
    outboundLabel.setEnabled(false);
    outboundLabel.setOutputMarkupId(true);
    add(outboundLabel);

    AjaxSubmitLink outbound = new AjaxSubmitLink(ID_BUTTON_OUTBOUND) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            outboundEditPerformed(target);
        }
    };
    outbound.setOutputMarkupId(true);
    add(outbound);

    AjaxSubmitLink deleteOutbound = new AjaxSubmitLink(ID_DELETE_OUTBOUND) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            deleteOutboundPerformed(target);
        }
    };
    deleteOutbound.setOutputMarkupId(true);
    add(deleteOutbound);

    MultiValueTextEditPanel inbound = new MultiValueTextEditPanel<MappingType>(ID_INBOUND,
            new PropertyModel<List<MappingType>>(getModel(), "inbound"), false) {

        @Override
        protected IModel<String> createTextModel(final IModel<MappingType> model) {
            return new Model<String>() {

                @Override
                public String getObject() {
                    return MappingTypeDto.createMappingLabel(model.getObject(), LOGGER,
                            getPageBase().getPrismContext(), getString("MappingType.label.placeholder"),
                            getString("MultiValueField.nameNotSpecified"));
                }
            };
        }

        @Override
        protected MappingType createNewEmptyItem() {
            return WizardUtil.createEmptyMapping();
        }

        @Override
        protected void editPerformed(AjaxRequestTarget target, MappingType object) {
            inboundEditPerformed(target, object);
        }
    };
    inbound.setOutputMarkupId(true);
    add(inbound);

    Label allowTooltip = new Label(ID_T_ALLOW);
    allowTooltip.add(new InfoTooltipBehavior());
    add(allowTooltip);

    Label limitationsTooltip = new Label(ID_T_LIMITATIONS);
    limitationsTooltip.add(new InfoTooltipBehavior());
    add(limitationsTooltip);

    Label exclusiveStrongTooltip = new Label(ID_T_EXCLUSIVE_STRONG);
    exclusiveStrongTooltip.add(new InfoTooltipBehavior());
    add(exclusiveStrongTooltip);

    Label tolerantTooltip = new Label(ID_T_TOLERANT);
    tolerantTooltip.add(new InfoTooltipBehavior());
    add(tolerantTooltip);

    Label tolerantVPTooltip = new Label(ID_T_TOLERANT_VP);
    tolerantVPTooltip.add(new InfoTooltipBehavior());
    add(tolerantVPTooltip);

    Label intolerantVPTooltip = new Label(ID_T_INTOLERANT_VP);
    intolerantVPTooltip.add(new InfoTooltipBehavior());
    add(intolerantVPTooltip);

    Label fetchTooltip = new Label(ID_T_FETCH);
    fetchTooltip.add(new InfoTooltipBehavior());
    add(fetchTooltip);

    Label matchingRuleTooltip = new Label(ID_T_MATCHING_RULE);
    matchingRuleTooltip.add(new InfoTooltipBehavior());
    add(matchingRuleTooltip);

    Label outboundTooltip = new Label(ID_T_OUTBOUND);
    outboundTooltip.add(new InfoTooltipBehavior());
    add(outboundTooltip);

    Label inboundTooltip = new Label(ID_T_INBOUND);
    inboundTooltip.add(new InfoTooltipBehavior());
    add(inboundTooltip);

    initModals();
}

From source file:com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor.java

private void parseSubElementsGroupAsMapEntry(MapXNode xmap, QName elementQName, List<Element> elements)
        throws SchemaException {
    if (elements == null || elements.isEmpty()) {
        return;/* w ww .java  2  s  . co  m*/
    }
    XNode xsub;
    // We really want to have equals here, not match
    // we want to be very explicit about namespace here
    if (elementQName.equals(SCHEMA_ELEMENT_QNAME)) {
        if (elements.size() == 1) {
            xsub = parseSchemaElement(elements.iterator().next());
        } else {
            throw new SchemaException("Too many schema elements");
        }
    } else if (elements.size() == 1) {
        xsub = parseElementContent(elements.get(0), false);
    } else {
        xsub = parseElementList(elements, false);
    }
    xmap.merge(elementQName, xsub);
}

From source file:com.evolveum.midpoint.model.impl.lens.Construction.java

public boolean hasValueForAttribute(QName attributeName) {
    for (MappingImpl<? extends PrismPropertyValue<?>, ? extends PrismPropertyDefinition<?>> attributeConstruction : attributeMappings) {
        if (attributeName.equals(attributeConstruction.getItemName())) {
            PrismValueDeltaSetTriple<? extends PrismPropertyValue<?>> outputTriple = attributeConstruction
                    .getOutputTriple();//from   w  w w .  j  a  v a 2 s .c o  m
            if (outputTriple != null && !outputTriple.isEmpty()) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.evolveum.midpoint.prism.schema.PrismSchema.java

/**
* Finds item definition by type.//from  ww w.  ja v a 2 s.  com
* 
*/
@SuppressWarnings("unchecked")
public <T extends ItemDefinition> T findItemDefinitionByType(QName typeName, Class<T> definitionType) {
    if (typeName == null) {
        throw new IllegalArgumentException("typeName must be supplied");
    }
    // TODO: check for multiple definition with the same type
    for (Definition definition : definitions) {
        if (definitionType.isAssignableFrom(definition.getClass())) {
            ItemDefinition idef = (ItemDefinition) definition;
            if (typeName.equals(idef.getTypeName())) {
                return (T) idef;
            }
        }
    }
    return null;
}

From source file:com.evolveum.midpoint.prism.schema.PrismSchema.java

/**
 * Finds item definition by name.//from   w w  w .j a  v a  2 s  .  c o  m
 * 
 */
@SuppressWarnings("unchecked")
public <T extends ItemDefinition> T findItemDefinition(QName definitionName, Class<T> definitionType) {
    if (definitionName == null) {
        throw new IllegalArgumentException("definitionName must be supplied");
    }
    // TODO: check for multiple definition with the same type
    for (Definition definition : definitions) {
        if (definitionType.isAssignableFrom(definition.getClass())) {
            ItemDefinition idef = (ItemDefinition) definition;
            if (definitionName.equals(idef.getName())) {
                return (T) idef;
            }
        }
    }
    return null;
}

From source file:com.evolveum.midpoint.prism.schema.SchemaToDomProcessor.java

/**
 * Adds XSD element definition./*from  w  w  w .j a v  a  2s.  c  o m*/
 * @param name element QName
 * @param typeName element type QName
 * @param parent element under which the definition will be added
 */
private Element addElementDefinition(QName name, QName typeName, int minOccurs, int maxOccurs, Element parent) {
    Element elementDef = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "element"));
    parent.appendChild(elementDef);

    if (isMyNamespace(name)) {
        setAttribute(elementDef, "name", name.getLocalPart());

        if (typeName.equals(DOMUtil.XSD_ANY)) {
            addSequenceXsdAnyDefinition(elementDef);
        } else {
            setQNameAttribute(elementDef, "type", typeName);
        }
    } else {
        // Need to create "ref" instead of "name"
        setAttribute(elementDef, "ref", name);
        if (typeName != null) {
            // Type cannot be stored directly, XSD does not allow it with "ref"s.
            addAnnotationToDefinition(elementDef, A_TYPE, typeName);
        }
    }

    setMultiplicityAttribute(elementDef, "minOccurs", minOccurs);
    setMultiplicityAttribute(elementDef, "maxOccurs", maxOccurs);

    return elementDef;
}

From source file:org.bedework.util.dav.DavUtil.java

/**
 * @param cl the client/*from  ww w.  j a  va 2 s.com*/
 * @param path to resource
 * @param props   null for a default set
 * @param depthHeader to set depth of operation
 * @return List<Element> from multi-status response
 * @throws Throwable
 */
public List<Element> propfind(final BasicHttpClient cl, final String path, final Collection<QName> props,
        final Header depthHeader) throws Throwable {
    final StringWriter sw = new StringWriter();
    final XmlEmit xml = getXml();

    addNs(xml, WebdavTags.namespace);

    xml.startEmit(sw);

    xml.openTag(WebdavTags.propfind);
    xml.openTag(WebdavTags.prop);
    xml.emptyTag(WebdavTags.displayname);
    xml.emptyTag(WebdavTags.resourcetype);

    if (props != null) {
        for (final QName pr : props) {
            if (pr.equals(WebdavTags.displayname)) {
                continue;
            }

            if (pr.equals(WebdavTags.resourcetype)) {
                continue;
            }

            addNs(xml, pr.getNamespaceURI());
            xml.emptyTag(pr);
        }
    }

    xml.closeTag(WebdavTags.prop);
    xml.closeTag(WebdavTags.propfind);

    final byte[] content = sw.toString().getBytes();

    final int res = sendRequest(cl, "PROPFIND", path, depthHeader, "text/xml", // contentType,
            content.length, // contentLen,
            content);

    if (res == HttpServletResponse.SC_NOT_FOUND) {
        return null;
    }

    final int SC_MULTI_STATUS = 207; // not defined for some reason
    if (res != SC_MULTI_STATUS) {
        if (debug()) {
            debug("Got response " + res + " for path " + path);
        }

        //throw new Exception("Got response " + res + " for path " + path);
        return null;
    }

    final Document doc = parseContent(cl.getResponseBodyAsStream());

    final Element root = doc.getDocumentElement();

    /*    <!ELEMENT multistatus (response+, responsedescription?) > */

    expect(root, WebdavTags.multistatus);

    return getChildren(root);
}

From source file:org.bedework.util.dav.DavUtil.java

/** Do a synch report on the targeted collection.
 *
 *
 * @param cl http client//from   w  w  w .  ja  v a 2  s .c om
 * @param path of collection
 * @param syncToken from last report or null
 * @param props   null for a default set
 * @return Collection of DavChild or null for not found
 * @throws Throwable
 */
public Collection<DavChild> syncReport(final BasicHttpClient cl, final String path, final String syncToken,
        final Collection<QName> props) throws Throwable {
    final StringWriter sw = new StringWriter();
    final XmlEmit xml = getXml();

    addNs(xml, WebdavTags.namespace);

    xml.startEmit(sw);

    /*
      <?xml version="1.0" encoding="utf-8" ?>
      <D:sync-collection xmlns:D="DAV:"
                 xmlns:C="urn:ietf:params:xml:ns:caldav">
        <D:sync-token/>
        <D:prop>
          <D:getetag/>
        </D:prop>
      </D:sync-collection>
     */
    xml.openTag(WebdavTags.syncCollection);
    if (syncToken == null) {
        xml.emptyTag(WebdavTags.syncToken);
    } else {
        xml.property(WebdavTags.syncToken, syncToken);
    }
    xml.property(WebdavTags.synclevel, "1");
    xml.openTag(WebdavTags.prop);
    xml.emptyTag(WebdavTags.getetag);

    if (props != null) {
        for (final QName pr : props) {
            if (pr.equals(WebdavTags.getetag)) {
                continue;
            }

            addNs(xml, pr.getNamespaceURI());
            xml.emptyTag(pr);
        }
    }

    xml.closeTag(WebdavTags.prop);
    xml.closeTag(WebdavTags.syncCollection);

    final byte[] content = sw.toString().getBytes();

    final int res = sendRequest(cl, "REPORT", path, depth0, "text/xml", // contentType,
            content.length, // contentLen,
            content);

    if (res == HttpServletResponse.SC_NOT_FOUND) {
        return null;
    }

    final int SC_MULTI_STATUS = 207; // not defined for some reason
    if (res != SC_MULTI_STATUS) {
        if (debug()) {
            debug("Got response " + res + " for path " + path);
        }

        //throw new Exception("Got response " + res + " for path " + path);
        return null;
    }

    final Document doc = parseContent(cl.getResponseBodyAsStream());

    final Element root = doc.getDocumentElement();

    /*    <!ELEMENT multistatus (response+, responsedescription?) > */

    expect(root, WebdavTags.multistatus);

    return processResponses(getChildren(root), null);
}

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

@Override
public <ID extends ItemDefinition> ID findNamedItemDefinition(@NotNull QName firstName, @NotNull ItemPath rest,
        @NotNull 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 a  va 2  s.  c o 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;
}