Example usage for javax.xml.namespace QName getNamespaceURI

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

Introduction

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

Prototype

public String getNamespaceURI() 

Source Link

Document

Get the Namespace URI of this QName.

Usage

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

private <C extends Containerable> PrismContainerValue<C> parsePrismContainerValueFromMap(MapXNode xmap,
        PrismContainerDefinition<C> containerDef, Collection<QName> ignoredItems) throws SchemaException {
    Long id = getContainerId(xmap);

    // override container definition, if explicit type is specified
    PrismContainerDefinition valueDefinition = containerDef;
    if (xmap.getTypeQName() != null) {
        PrismContainerDefinition specificDef = prismContext.getSchemaRegistry()
                .findContainerDefinitionByType(xmap.getTypeQName());
        if (specificDef != null) {
            valueDefinition = specificDef;
        } else {//w  ww  .ja v  a2  s . co  m
            // TODO raise exception here?
            // by silently proceeding we risk losing some subclass-specific items
        }
    }
    PrismContainerValue<C> cval = new PrismContainerValue<C>(null, null, null, id, xmap.getTypeQName(),
            prismContext);
    for (Entry<QName, XNode> xentry : xmap.entrySet()) {
        QName itemQName = xentry.getKey();
        if (QNameUtil.match(itemQName, XNode.KEY_CONTAINER_ID)) {
            continue;
        }
        if (QNameUtil.matchAny(itemQName, ignoredItems)) {
            continue;
        }
        ItemDefinition itemDef = locateItemDefinition(valueDefinition, itemQName, xentry.getValue());
        if (itemDef == null) {
            if (valueDefinition.isRuntimeSchema()) {
                PrismSchema itemSchema = getSchemaRegistry().findSchemaByNamespace(itemQName.getNamespaceURI());
                if (itemSchema != null) {
                    // If we already have schema for this namespace then a missing element is
                    // an error. We positively know that it is not in the schema.
                    if (isStrict()) {
                        throw new SchemaException(
                                "Item " + itemQName + " has no definition (schema present, in container "
                                        + containerDef + ")" + "while parsing " + xmap.debugDump(),
                                itemQName);
                    } else {
                        // Just skip item
                        continue;
                    }
                } else {
                    // No definition for item, but the schema is runtime. the definition may come later.
                    // Null is OK here. The item will be parsed as "raw"
                }
            } else {
                if (isStrict()) {
                    throw new SchemaException("Item " + itemQName + " has no definition (in container value "
                            + valueDefinition + ")" + "while parsing " + xmap.debugDump(), itemQName);
                } else {
                    // Just skip item
                    continue;
                }
            }
        }
        Item<?, ?> item = parseItem(xentry.getValue(), itemQName, itemDef);
        // Merge must be here, not just add. Some items (e.g. references) have alternative
        // names and representations and these cannot be processed as one map or list
        if (item != null) {
            cval.merge(item);
        }
    }
    return cval;
}

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

@NotNull
@Override//from w  w w.j a v a  2  s  .c o m
public <ID extends ItemDefinition> List<ID> findItemDefinitionsByElementName(@NotNull QName elementName,
        @NotNull Class<ID> definitionClass) {
    if (QNameUtil.noNamespace(elementName)) {
        return resolveGlobalItemDefinitionsWithoutNamespace(elementName.getLocalPart(), definitionClass);
    } else {
        PrismSchema schema = findSchemaByNamespace(elementName.getNamespaceURI());
        if (schema == null) {
            return new ArrayList<>();
        }
        return schema.findItemDefinitionsByElementName(elementName, definitionClass);
    }
}

From source file:com.emental.mindraider.ui.graph.spiders.SpidersGraph.java

/**
 * As subject is used selected node. TODO FUUUUJ - forget about QNames and
 * change to URNs!// ww  w .  ja v a  2  s  .co m
 *
 * @param predicate
 *            the predicate
 * @param object
 *            the object
 * @param literal
 *            the literal flag
 * @return the Statement
 */
public Statement createStatement(QName predicate, QName object, boolean literal) {
    Resource subject = null;
    ConceptResource conceptResource = OutlineJPanel.getInstance().conceptJPanel.getConceptResource();
    if (conceptResource == null) {
        JOptionPane.showMessageDialog(MindRaider.mainJFrame, "No not selected - RDF triplet cannot be created!",
                "Triplet Creation Error", JOptionPane.ERROR_MESSAGE);
    } else {
        subject = rdfModel.getResource(conceptResource.getUri());
        if (subject == null) {
            JOptionPane.showMessageDialog(MindRaider.mainJFrame,
                    "Unable to find RDF node with ID '" + conceptResource.getUri() + "'",
                    "Triplet Creation Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    Statement statement = rdfModel.createStatement(subject,
            (predicate.getNamespaceURI() == null ? MindRaiderConstants.MR_RDF_NS : predicate.getNamespaceURI())
                    + predicate.getLocalPart(),
            (object.getNamespaceURI() == null ? object.getLocalPart()
                    : object.getNamespaceURI() + object.getLocalPart()),
            literal);

    save();
    renderModel();

    return statement;
}

From source file:com.evolveum.midpoint.schema.xjc.schema.SchemaProcessor.java

private void addComplextType(Outline outline, Map<String, JFieldVar> namespaceFields) {
    Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
    for (Map.Entry<NClass, CClassInfo> entry : set) {
        ClassOutline classOutline = outline.getClazz(entry.getValue());
        QName qname = entry.getValue().getTypeName();
        if (qname == null) {
            continue;
        }/*  w w w .ja  v a  2s . c o m*/

        JFieldVar var = namespaceFields.get(qname.getNamespaceURI());
        if (var != null) {
            createQNameDefinition(outline, classOutline.implClass, COMPLEX_TYPE_FIELD_NAME, var, qname);
        } else {
            createPSFField(outline, classOutline.implClass, COMPLEX_TYPE_FIELD_NAME, qname);
        }
    }
}

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

@Override
public <T> Class<T> determineCompileTimeClass(QName typeName) {
    if (QNameUtil.noNamespace(typeName)) {
        TypeDefinition td = resolveGlobalTypeDefinitionWithoutNamespace(typeName.getLocalPart(),
                TypeDefinition.class);
        if (td == null) {
            return null;
        }/*from   w  ww  .j  a va2  s .c  om*/
        return (Class<T>) td.getCompileTimeClass();
    }
    SchemaDescription desc = findSchemaDescriptionByNamespace(typeName.getNamespaceURI());
    if (desc == null) {
        return null;
    }
    Package pkg = desc.getCompileTimeClassesPackage();
    if (pkg == null) {
        return null;
    }
    return JAXBUtil.findClassForType(typeName, pkg);
}

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

@Nullable
@Override//from   w ww  .  ja va2 s  .  c  o  m
public <ID extends ItemDefinition> ID findItemDefinitionByType(@NotNull QName typeName,
        @NotNull Class<ID> definitionClass) {
    if (QNameUtil.noNamespace(typeName)) {
        TypeDefinition td = resolveGlobalTypeDefinitionWithoutNamespace(typeName.getLocalPart(),
                TypeDefinition.class);
        if (td == null) {
            return null;
        }
        typeName = td.getTypeName();
    }
    PrismSchema schema = findSchemaByNamespace(typeName.getNamespaceURI());
    if (schema == null) {
        return null;
    }
    return schema.findItemDefinitionByType(typeName, definitionClass);
}

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

private <IV extends PrismValue, ID extends ItemDefinition, I extends Item<IV, ID>> I createSubItem(QName name,
        Class<I> type, ID itemDefinition) throws SchemaException {
    // the item with specified name does not exist, create it now
    I newItem = null;//from  w ww  .  j a  v  a 2 s . co  m

    if (itemDefinition == null && getActualDefinition() != null) {
        itemDefinition = determineItemDefinition(name, getActualDefinition());
        if (itemDefinition == null) {
            throw new SchemaException("No definition for item " + name + " in " + getParent());
        }
    }

    if (itemDefinition != null) {
        if (StringUtils.isNotBlank(name.getNamespaceURI())) {
            newItem = (I) itemDefinition.instantiate(name);
        } else {
            QName computed = new QName(itemDefinition.getNamespace(), name.getLocalPart());
            newItem = (I) itemDefinition.instantiate(computed);
        }
        if (newItem instanceof PrismObject) {
            throw new IllegalStateException(
                    "PrismObject instantiated as a subItem in " + this + " from definition " + itemDefinition);
        }
    } else {
        newItem = Item.createNewDefinitionlessItem(name, type, prismContext);
        if (newItem instanceof PrismObject) {
            throw new IllegalStateException("PrismObject instantiated as a subItem in " + this
                    + " as definitionless instance of class " + type);
        }
    }

    if (type.isAssignableFrom(newItem.getClass())) {
        add(newItem);
        return newItem;
    } else {
        throw new IllegalStateException(
                "The " + type.getSimpleName() + " cannot be created because the item should be of type "
                        + newItem.getClass().getSimpleName() + " (" + newItem.getElementName() + ")");
    }
}

From source file:com.evolveum.midpoint.schema.xjc.schema.SchemaProcessor.java

/**
 * Marks ObjectFactory.createXYZ methods for elements with a:rawType annotation as @Raw.
 *///from  ww  w  .  j a  v  a 2s.c  om
private void updateObjectFactoryElements(Outline outline) {
    XSSchemaSet schemaSet = outline.getModel().schemaComponent;
    for (CElementInfo elementInfo : outline.getModel().getAllElements()) {
        QName name = elementInfo.getElementName();
        XSComponent elementDecl;
        if (elementInfo.getSchemaComponent() != null) { // it's strange but elements seem not to have this filled-in...
            elementDecl = elementInfo.getSchemaComponent();
        } else {
            elementDecl = schemaSet.getElementDecl(name.getNamespaceURI(), name.getLocalPart());
        }
        boolean isRaw = hasAnnotation(elementDecl, A_RAW_TYPE);
        if (isRaw) {
            System.out.println("*** Raw element found: " + elementInfo.getElementName());
            JDefinedClass objectFactory = outline.getPackageContext(elementInfo._package()).objectFactory();
            boolean methodFound = false; // finding method corresponding to the given element
            for (JMethod method : objectFactory.methods()) {
                for (JAnnotationUse annotationUse : method.annotations()) {
                    if (XmlElementDecl.class.getName().equals(annotationUse.getAnnotationClass().fullName())) {
                        // ugly method of finding the string value of the annotation members (couldn't find any better)
                        JAnnotationValue namespaceValue = annotationUse.getAnnotationMembers().get("namespace");
                        StringWriter namespaceWriter = new StringWriter();
                        JFormatter namespaceFormatter = new JFormatter(namespaceWriter);
                        namespaceValue.generate(namespaceFormatter);

                        JAnnotationValue nameValue = annotationUse.getAnnotationMembers().get("name");
                        StringWriter nameWriter = new StringWriter();
                        JFormatter nameFormatter = new JFormatter(nameWriter);
                        nameValue.generate(nameFormatter);

                        if (("\"" + name.getNamespaceURI() + "\"").equals(namespaceWriter.toString())
                                && ("\"" + name.getLocalPart() + "\"").equals(nameWriter.toString())) {
                            System.out.println("*** Annotating method as @Raw: " + method.name());
                            method.annotate(Raw.class);
                            methodFound = true;
                            break;
                        }
                    }
                }
            }
            if (!methodFound) {
                throw new IllegalStateException("No factory method found for element " + name);
            }
        }
    }
}

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

@Override
public ItemDefinition resolveGlobalItemDefinition(QName itemName,
        @Nullable ComplexTypeDefinition complexTypeDefinition) throws SchemaException {
    if (QNameUtil.noNamespace(itemName)) {
        if (complexTypeDefinition != null && complexTypeDefinition.getDefaultNamespace() != null) {
            itemName = new QName(complexTypeDefinition.getDefaultNamespace(), itemName.getLocalPart());
        } else {/* w  w  w . j  av  a2 s  .  c  o m*/
            List<String> ignoredNamespaces = complexTypeDefinition != null
                    ? complexTypeDefinition.getIgnoredNamespaces()
                    : null;
            return resolveGlobalItemDefinitionWithoutNamespace(itemName.getLocalPart(), ItemDefinition.class,
                    true, ignoredNamespaces);
        }
    }
    PrismSchema schema = findSchemaByNamespace(itemName.getNamespaceURI());
    if (schema == null) {
        return null;
    }
    return schema.findItemDefinitionByElementName(itemName, ItemDefinition.class);
}

From source file:com.evolveum.midpoint.testing.model.client.sample.AbstractTestForExchangeConnector.java

protected ShadowType getShadowByName(String resourceOid, QName objectClass, String name)
        throws JAXBException, SAXException, IOException, FaultMessage {
    // WARNING: in a real case make sure that the username is properly escaped before putting it in XML
    SearchFilterType filter = ModelClientUtil.parseSearchFilterType(
            "                        <q:and xmlns:q='http://prism.evolveum.com/xml/ns/public/query-3' xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'>\n"
                    + "                            <q:ref>\n"
                    + "                                <q:path>resourceRef</q:path>\n"
                    + "                                <q:value>\n"
                    + "                                    <oid>" + resourceOid + "</oid>\n"
                    + "                                    <type>ResourceType</type>\n"
                    + "                                </q:value>\n" + "                            </q:ref>\n"
                    + "                            <q:equal>\n"
                    + "                                <q:path>objectClass</q:path>\n"
                    + "                                <q:value xmlns:a=\"" + objectClass.getNamespaceURI()
                    + "\">a:" + objectClass.getLocalPart() + "</q:value>\n"
                    + "                            </q:equal>\n" + "                            <q:equal>\n"
                    + "                                <q:path>attributes/name</q:path>\n"
                    + "                                <q:value>" + name + "</q:value>\n"
                    + "                            </q:equal>\n" + "                        </q:and>\n");
    QueryType query = new QueryType();
    query.setFilter(filter);//from   w ww. j a va2  s .c  o m
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    Holder<ObjectListType> objectListHolder = new Holder<>();
    Holder<OperationResultType> resultHolder = new Holder<>();

    modelPort.searchObjects(ModelClientUtil.getTypeQName(ShadowType.class), query, options, objectListHolder,
            resultHolder);

    ObjectListType objectList = objectListHolder.value;
    List<ObjectType> objects = objectList.getObject();
    if (objects.isEmpty()) {
        return null;
    }
    if (objects.size() == 1) {
        return (ShadowType) objects.get(0);
    }
    throw new IllegalStateException("Expected to find a single shadow with name '" + name + "' but found "
            + objects.size() + " ones instead");
}