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:org.kalypso.simulation.core.util.AbstractSimulationDataProvider.java

@Override
public Object getInputForID(final String id) throws SimulationException {
    final String path = m_idhash.get(id);
    if (path == null)
        throw new NoSuchElementException(
                Messages.getString("org.kalypso.simulation.core.util.AbstractSimulationDataProvider.0") + id); //$NON-NLS-1$

    final DataType inputType = m_modelspec == null ? null : m_modelspec.getInput(id);

    // default to xs:anyURI if no type is given
    final QName type = inputType == null ? QNAME_ANY_URI : inputType.getType();

    // URI types are treated as URLs,
    if (type.equals(QNAME_ANY_URI)) {
        try {/*from  w w w  .ja v a 2  s  . c  om*/
            final URI baseURL = getBaseURL().toURI();
            final URI relativeURI = baseURL.resolve(URIUtil.encodePath(path));

            // try to silently convert the URI to a URL
            try {
                final URL url = relativeURI.toURL();
                return url;
            } catch (final MalformedURLException e) {
                // gobble
            }
            return relativeURI;
        } catch (final IOException e) {
            throw new SimulationException(
                    Messages.getString("org.kalypso.simulation.core.util.AbstractSimulationDataProvider.1"), e); //$NON-NLS-1$
        } catch (final URISyntaxException e) {
            throw new SimulationException(
                    Messages.getString("org.kalypso.simulation.core.util.AbstractSimulationDataProvider.2"), e); //$NON-NLS-1$
        }
    } else {
        final ITypeRegistry<IMarshallingTypeHandler> typeRegistry = MarshallingTypeRegistrySingleton
                .getTypeRegistry();
        final IMarshallingTypeHandler handler = typeRegistry.getTypeHandlerForTypeName(type);
        if (handler != null) {
            try {
                return handler.parseType(path);
            } catch (final ParseException e) {
                throw new SimulationException(Messages.getString(
                        "org.kalypso.simulation.core.util.AbstractSimulationDataProvider.3", path, type), e); //$NON-NLS-1$
            }
        }
    }

    throw new SimulationException(
            Messages.getString("org.kalypso.simulation.core.util.AbstractSimulationDataProvider.4") + type, //$NON-NLS-1$
            null);
}

From source file:org.kalypso.ui.rrm.internal.newproject.ImportRrmInitialDataOperation.java

private static IValuePropertyType findColumn(final Map<IValuePropertyType, IValuePropertyType> mapping,
        final QName qname) {
    for (final IValuePropertyType targetKey : mapping.keySet()) {
        if (qname.equals(targetKey.getQName()))
            return mapping.get(targetKey);
    }//w w w  .  j  av a2 s . c o m

    return null;
}

From source file:org.kalypso.ui.rrm.internal.newproject.ImportRrmInitialDataOperation.java

private static void removeColumn(final Map<IValuePropertyType, IValuePropertyType> mapping, final QName qname) {
    for (final IValuePropertyType targetKey : mapping.keySet()) {
        if (qname.equals(targetKey.getQName())) {
            mapping.remove(targetKey);// ww w . j av  a 2  s  .co m
            return;
        }
    }
}

From source file:org.kuali.rice.kew.rule.xmlrouting.WorkflowFunctionResolver.java

public XPathFunction resolveFunction(QName fname, int arity) {
    if (fname == null) {
        throw new NullPointerException("The function name cannot be null.");
    }//from ww  w .jav a 2  s .co m
    if (fname.equals(new QName("http://nothingfornowwf.com", "ruledata", "wf"))) {
        if (ruleExtensions == null) {
            throw new IllegalArgumentException("There are no rule extensions.");
        }
        return new XPathFunction() {
            public Object evaluate(List args) {
                if (args.size() == 1) {
                    String name = (String) args.get(0);
                    for (RuleExtension ruleExtension : ruleExtensions) {
                        for (Map.Entry<String, String> entry : ruleExtension.getExtensionValuesMap()
                                .entrySet()) {
                            if (entry.getKey().equals(name)) {
                                return entry.getValue();
                            }
                        }
                    }
                }
                return "";
            }
        };
    } else if (fname.equals(new QName("http://nothingfornowwf.com", "xstreamsafe", "wf"))) {
        return new XStreamSafeSearchFunction(rootNode, this.getXpath());
    } else if (fname.equals(new QName("http://nothingfornowwf.com", "upper-case", "wf"))) {
        return new UpperCaseFunction();
    } else if (fname.equals(new QName("http://nothingfornowwf.com", "field", "wf"))) {
        return new XPathFunction() {
            public Object evaluate(java.util.List args) {
                if (args.size() == 1) {
                    String name = (String) args.get(0);
                    try {
                        return field(name);
                    } catch (Exception e) {
                        throw new WorkflowRuntimeException("Failed to find field to validate.", e);
                    }
                }
                return "";
            }
        };
    } else if (fname.equals(new QName("http://nothingfornowwf.com", "empty", "wf"))) {
        return new XPathFunction() {
            public Object evaluate(java.util.List args) {
                return empty(args.get(0));
            }
        };
    } else {
        return null;
    }
}

From source file:org.n52.wfs.ds.DescribeFeatureTypeHandler.java

private boolean checkQNameOfType(QName toCheck, QName against) {
    if (toCheck != null) {
        if (against.equals(toCheck)) {
            return true;
        } else {/*from  w ww  . j av a 2s. co m*/
            return against.getLocalPart().equals(toCheck.getLocalPart());
        }
    }
    return false;
}

From source file:org.osaf.cosmo.dav.acl.resource.DavUserPrincipalTest.java

public void testLoadProperties() throws Exception {
    DavUserPrincipal p = testHelper.getPrincipal(testHelper.getUser());

    DavProperty prop = null;/*  ww w .ja v  a 2s  .c  o m*/

    // section 4

    DisplayName displayName = (DisplayName) p.getProperty(DavPropertyName.DISPLAYNAME);
    assertNotNull("No displayname property", displayName);
    assertTrue("Empty displayname ", !StringUtils.isBlank(displayName.getDisplayName()));

    ResourceType resourceType = (ResourceType) p.getProperty(DavPropertyName.RESOURCETYPE);
    assertNotNull("No resourcetype property", resourceType);
    boolean foundPrincipalQname = false;
    for (QName qname : resourceType.getQnames()) {
        if (qname.equals(RESOURCE_TYPE_PRINCIPAL)) {
            foundPrincipalQname = true;
            break;
        }
    }
    assertTrue("Principal qname not found", foundPrincipalQname);

    // 4.1
    AlternateUriSet alternateUriSet = (AlternateUriSet) p.getProperty(ALTERNATEURISET);
    assertNotNull("No alternate-uri-set property", alternateUriSet);
    assertTrue("Found hrefs for alternate-uri-set", alternateUriSet.getHrefs().isEmpty());

    // 4.2
    PrincipalUrl principalUrl = (PrincipalUrl) p.getProperty(PRINCIPALURL);
    assertNotNull("No principal-URL property", principalUrl);
    assertEquals("principal-URL value not the same as locator href", p.getResourceLocator().getHref(false),
            principalUrl.getHref());

    // 4.4
    GroupMembership groupMembership = (GroupMembership) p.getProperty(GROUPMEMBERSHIP);
    assertNotNull("No group-membership property", groupMembership);
    assertTrue("Found hrefs for group-membership", groupMembership.getHrefs().isEmpty());
}

From source file:org.osaf.cosmo.eim.eimml.EimmlStreamReader.java

private void readCollection() throws XMLStreamException, EimmlStreamException {
    // move to <collection>
    nextTag();/*ww w. j  a  v a 2 s  .  c  o  m*/
    if (!xmlReader.isStartElement() && xmlReader.getName().equals(QN_COLLECTION))
        throw new EimmlValidationException("Outermost element must be " + QN_COLLECTION);

    for (int i = 0; i < xmlReader.getAttributeCount(); i++) {
        QName attr = xmlReader.getAttributeName(i);
        //             if (log.isDebugEnabled())
        //                 log.debug("read attr: " + attr);
        String value = xmlReader.getAttributeValue(i);
        if (attr.equals(QN_UUID)) {
            if (StringUtils.isBlank(value))
                throw new EimmlValidationException("Collection element requires " + ATTR_UUID + " attribute");
            uuid = value;
        } else if (attr.equals(QN_NAME)) {
            name = !StringUtils.isBlank(value) ? value : null;
        } else if (attr.equals(QN_HUE)) {
            try {
                hue = !StringUtils.isBlank(value) ? Long.parseLong(value) : null;
            } catch (NumberFormatException e) {
                throw new EimmlValidationException("Attribute " + ATTR_HUE + " must be an integer");
            }
        } else {
            log.warn("skipped unrecognized collection attribute " + attr);
        }
    }

    // move to first <recordset> or </collection>
    nextTag();
}

From source file:org.osaf.cosmo.eim.eimml.EimmlStreamReader.java

private EimRecordSet readNextRecordSet() throws EimmlStreamException, XMLStreamException {
    // finish stream on </collection>
    if (xmlReader.isEndElement() && xmlReader.getName().equals(QN_COLLECTION))
        return null;

    // begin at <recordset>
    if (!(xmlReader.isStartElement() && xmlReader.getName().equals(QN_RECORDSET)))
        throw new EimmlValidationException(
                "Expected start element " + QN_RECORDSET + " but got " + xmlReader.getName());

    EimRecordSet recordset = new EimRecordSet();

    for (int i = 0; i < xmlReader.getAttributeCount(); i++) {
        QName attr = xmlReader.getAttributeName(i);
        //             if (log.isDebugEnabled())
        //                 log.debug("read attr: " + attr);
        String value = xmlReader.getAttributeValue(i);
        if (attr.equals(QN_UUID)) {
            if (StringUtils.isBlank(value))
                throw new EimmlValidationException("Recordset element requires " + ATTR_UUID + " attribute");
            recordset.setUuid(value);//from w ww  .j ava2  s .  co m
        } else if (attr.equals(QN_DELETED)) {
            if (BooleanUtils.toBoolean(value))
                recordset.setDeleted(true);
        } else {
            log.warn("skipped unrecognized recordset attribute " + attr);
        }
    }

    // move to next <record> or </recordset>
    nextTag();

    while (xmlReader.hasNext()) {
        // complete on </recordset>
        if (xmlReader.isEndElement() && xmlReader.getName().equals(QN_RECORDSET))
            break;

        EimRecord record = readNextRecord();
        if (record == null)
            throw new EimmlValidationException("Expected another record");

        recordset.addRecord(record);

        // move to next <record> or </recordset>
        nextTag();
    }

    // move to next <recordset> or </collection>
    nextTag();

    return recordset;
}

From source file:org.osaf.cosmo.eim.eimml.EimmlStreamReader.java

private EimRecord readNextRecord() throws EimmlStreamException, XMLStreamException {
    // begin at <record>
    if (!(xmlReader.isStartElement() && xmlReader.getLocalName().equals(EL_RECORD)))
        throw new EimmlValidationException(
                "Expected start element " + EL_RECORD + " but got " + xmlReader.getName());

    EimRecord record = new EimRecord();

    record.setPrefix(xmlReader.getPrefix());
    record.setNamespace(xmlReader.getNamespaceURI());

    for (int i = 0; i < xmlReader.getAttributeCount(); i++) {
        QName attr = xmlReader.getAttributeName(i);
        //             if (log.isDebugEnabled())
        //                 log.debug("read attr: " + attr);
        if (attr.equals(QN_DELETED))
            record.setDeleted(true);/*w ww .  j av a2  s.c om*/
        else
            log.warn("skipped unrecognized record attribute " + attr);
    }

    // move to next field element or </record>
    nextTag();

    while (xmlReader.hasNext()) {
        // complete on </record>
        if (xmlReader.isEndElement() && xmlReader.getLocalName().equals(EL_RECORD))
            break;

        if (!xmlReader.isStartElement())
            throw new EimmlValidationException("Expected field element but got " + xmlReader.getName());

        String name = xmlReader.getLocalName();

        boolean isKey = BooleanUtils.toBoolean(xmlReader.getAttributeValue(NS_CORE, ATTR_KEY));
        boolean isEmpty = BooleanUtils.toBoolean(xmlReader.getAttributeValue(null, ATTR_EMPTY));
        boolean isMissing = BooleanUtils.toBoolean(xmlReader.getAttributeValue(null, ATTR_MISSING));
        String type = xmlReader.getAttributeValue(NS_CORE, ATTR_TYPE);
        if (StringUtils.isBlank(type))
            throw new EimmlValidationException(
                    xmlReader.getName() + " element requires " + ATTR_TYPE + " attribute");

        String text = xmlReader.getElementText();
        if (isEmpty) {
            if (!(type.equals(TYPE_TEXT) || type.equals(TYPE_CLOB) || type.equals(TYPE_BLOB)))
                throw new EimmlValidationException(
                        "Invalid empty attribute on field element " + xmlReader.getName());
            if (text != null)
                //                     if (log.isDebugEnabled())
                //                         log.debug("emptying non-null text for field " + xmlReader.getName());
                text = "";
        } else if (text.equals(""))
            text = null;

        EimRecordField field = null;
        if (type.equals(TYPE_BYTES)) {
            byte[] value = EimmlTypeConverter.toBytes(text);
            field = new BytesField(name, value);
        } else if (type.equals(TYPE_TEXT)) {
            String value = EimmlTypeConverter.toText(text, documentEncoding);
            field = new TextField(name, value);
        } else if (type.equals(TYPE_BLOB)) {
            InputStream value = EimmlTypeConverter.toBlob(text);
            field = new BlobField(name, value);
        } else if (type.equals(TYPE_CLOB)) {
            Reader value = EimmlTypeConverter.toClob(text);
            field = new ClobField(name, value);
        } else if (type.equals(TYPE_INTEGER)) {
            Integer value = EimmlTypeConverter.toInteger(text);
            field = new IntegerField(name, value);
        } else if (type.equals(TYPE_DATETIME)) {
            Calendar value = EimmlTypeConverter.toDateTime(text);
            field = new DateTimeField(name, value);
        } else if (type.equals(TYPE_DECIMAL)) {
            BigDecimal value = EimmlTypeConverter.toDecimal(text);
            field = new DecimalField(name, value);
        } else {
            throw new EimmlValidationException("Unrecognized field type");
        }

        field.setMissing(isMissing);

        if (isKey)
            record.addKeyField(field);
        else
            record.addField(field);

        // move to next field element or </record>
        nextTag();
    }

    return record;
}

From source file:org.overlord.sramp.shell.ShellCommandFactory.java

/**
 * Called to create a shell command./*  ww  w.j  a  v a  2 s.c om*/
 * @param commandName
 * @throws Exception
 */
public ShellCommand createCommand(QName commandName) throws Exception {
    ShellCommand command = null;
    if (commandName.equals(HELP_CMD_NAME)) {
        command = new HelpCommand(getCommands());
    } else if (commandName.equals(QUIT_CMD_NAME)) {
        command = new ExitCommand();
    } else if (commandName.equals(EXIT_CMD_NAME)) {
        command = new ExitCommand();
    } else {
        Class<? extends ShellCommand> commandClass = registry.get(commandName);
        if (commandClass == null)
            return new CommandNotFoundCommand();
        command = commandClass.newInstance();
    }
    return command;
}