List of usage examples for javax.xml.namespace QName getPrefix
public String getPrefix()
Get the prefix of this QName
.
The prefix assigned to a QName
might NOT be valid in a different context.
From source file:org.modeldriven.fuml.assembly.ElementAssembler.java
public void assemleFeatures() { try {//from www .j ava2 s . c o m NamespaceDomain domain = null; // only lookup as needed StreamNode eventNode = (StreamNode) source; Location loc = eventNode.getLocation(); if (log.isDebugEnabled()) log.debug("element line/column: " + loc.getLineNumber() + ":" + loc.getColumnNumber()); // look at XML attributes Iterator<Attribute> attributes = eventNode.getAttributes(); while (attributes != null && attributes.hasNext()) { Attribute xmlAttrib = attributes.next(); QName name = xmlAttrib.getName(); String prefix = name.getPrefix(); if (prefix != null && prefix.length() > 0) continue; // not applicable to current // element/association-end. if ("href".equals(name.getLocalPart())) continue; // FIXME: find/write URI resolver Property property = this.prototype.findProperty(name.getLocalPart()); if (property == null) { if (domain == null) domain = FumlConfiguration.getInstance().findNamespaceDomain(source.getNamespaceURI()); ValidationExemption exemption = FumlConfiguration.getInstance() .findValidationExemptionByProperty(ValidationExemptionType.UNDEFINED_PROPERTY, this.prototype, name.getLocalPart(), source.getNamespaceURI(), domain); if (exemption == null) { throw new ValidationException(new ValidationError(eventNode, name.getLocalPart(), ErrorCode.UNDEFINED_PROPERTY, ErrorSeverity.FATAL)); } else { if (log.isDebugEnabled()) log.debug("undefined property exemption found within domain '" + exemption.getDomain().toString() + "' for property '" + this.prototype.getName() + "." + name.getLocalPart() + "' - ignoring error"); continue; // ignore attrib } } Classifier type = property.getType(); if (this.modelSupport.isReferenceAttribute(property)) { XmiReferenceAttribute reference = new XmiReferenceAttribute(source, xmlAttrib, this.getPrototype()); this.addReference(reference); continue; } String value = xmlAttrib.getValue(); if (value == null || value.length() == 0) { String defaultValue = property.findPropertyDefault(); if (defaultValue != null) { value = defaultValue; if (log.isDebugEnabled()) log.debug("using default '" + String.valueOf(value) + "' for enumeration feature <" + type.getName() + "> " + this.getPrototype().getName() + "." + property.getName()); } } this.assembleNonReferenceFeature(property, value, type); } // look at model properties not found in above attribute set List<Property> properties = this.prototype.getNamedProperties(); for (Property property : properties) { QName name = new QName(property.getName()); String value = eventNode.getAttributeValue(name); if (value != null && value.trim().length() > 0) continue; // handled above String defaultValue = property.findPropertyDefault(); if (defaultValue != null) { Classifier type = property.getType(); if (log.isDebugEnabled()) log.debug("using default: '" + String.valueOf(defaultValue) + "' for enumeration feature <" + type.getName() + "> " + this.getPrototype().getName() + "." + property.getName()); this.assembleNonReferenceFeature(property, defaultValue, type); continue; } if (!property.isRequired()) continue; // don't bother digging further for a value if (eventNode.findChildByName(property.getName()) != null) continue; // it has such a child, let if (this.modelSupport.isReferenceAttribute(property) && FumlConfiguration.getInstance().hasReferenceMapping(this.prototype, property)) { ReferenceMappingType mappingType = FumlConfiguration.getInstance() .getReferenceMappingType(this.prototype, property); if (mappingType == ReferenceMappingType.PARENT) { if (parent != null && parent.getXmiId() != null && parent.getXmiId().length() > 0) { XmiMappedReference reference = new XmiMappedReference(source, property.getName(), new String[] { parent.getXmiId() }, this.prototype); this.addReference(reference); continue; } else log.warn("no parent XMI id found, ignoring mapping for, " + this.prototype.getName() + "." + property.getName()); } else log.warn("unrecognized mapping type, " + mappingType.value() + " ignoring mapping for, " + this.prototype.getName() + "." + property.getName()); } if (!property.isDerived()) { if (domain == null) domain = FumlConfiguration.getInstance().findNamespaceDomain(source.getNamespaceURI()); ValidationExemption exemption = FumlConfiguration.getInstance() .findValidationExemptionByProperty(ValidationExemptionType.REQUIRED_PROPERTY, this.prototype, name.getLocalPart(), source.getNamespaceURI(), domain); if (exemption == null) { if (log.isDebugEnabled()) log.debug("throwing " + ErrorCode.PROPERTY_REQUIRED.toString() + " error for " + this.prototype.getName() + "." + property.getName()); throw new ValidationException(new ValidationError(eventNode, property.getName(), ErrorCode.PROPERTY_REQUIRED, ErrorSeverity.FATAL)); } else { if (log.isDebugEnabled()) log.debug("required property exemption found within domain '" + exemption.getDomain().toString() + "' for property '" + this.prototype.getName() + "." + name.getLocalPart() + "' - ignoring error"); continue; // ignore property } } } } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchMethodException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InvocationTargetException e) { log.error(e.getCause().getMessage(), e.getCause()); throw new AssemblyException(e.getCause()); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InstantiationException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchFieldException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } }
From source file:org.modeldriven.fuml.xmi.stream.StreamContext.java
private void loadNamespaces(XMLEvent root) { List<Namespace> list = new ArrayList<Namespace>(); Iterator<Namespace> namespaceIter = root.asStartElement().getNamespaces(); while (namespaceIter.hasNext()) { Namespace namespace = namespaceIter.next(); list.add(namespace);/*from w ww . ja v a 2 s . c o m*/ QName name = namespace.getName(); if (log.isDebugEnabled()) log.debug("root namespace: " + name.toString()); String uri = namespace.getValue(); if (!XmiConstants.NAMESPACE_PREFIX.equals(name.getPrefix())) continue; //not a namespace namespaceLocalNameMap.put(name.getLocalPart(), namespace); namespaceURIMap.put(namespace.getNamespaceURI(), namespace); NamespaceDomain domain = FumlConfiguration.getInstance().findNamespaceDomain(uri); if (domain == null) { log.debug("could not find domain for namespace '" + uri + "' - mapping only by local name"); continue; } Namespace existing = this.namespaceDomainMap.get(domain); if (existing != null) throw new XmiException("multiple " + domain.value() + " namespaces (" + existing.getNamespaceURI() + ", " + namespace.getNamespaceURI() + ")"); this.namespaceDomainMap.put(domain, namespace); } // while() if (getXmiNamespace() == null) { throw new XmiException(createNamespaceMessge(NamespaceDomain.XMI)); } if (getUmlNamespace() == null) { throw new XmiException(createNamespaceMessge(NamespaceDomain.UML)); } namespaces = new Namespace[list.size()]; list.toArray(namespaces); }
From source file:org.modeldriven.fuml.xmi.stream.StreamNode.java
public String getPrefix() { QName name = startElementEvent.asStartElement().getName(); String uri = name.getNamespaceURI(); if (uri == null || uri.trim().length() == 0) return this.context.getDefaultNamespace().getPrefix(); else//from w ww . ja v a 2s . c om return name.getPrefix(); }
From source file:org.modeldriven.fuml.xmi.validation.ValidationErrorCollector.java
private void validateAttributes(StreamNode target, XmiNode source, Class_ classifier, Iterator<Attribute> attributes) { NamespaceDomain domain = null; // only lookup as needed // look at XML attributes while (attributes.hasNext()) { Attribute xmlAttrib = attributes.next(); QName name = xmlAttrib.getName(); String prefix = name.getPrefix(); if (prefix != null && prefix.length() > 0) continue; // not applicable to current element/association-end. if ("href".equals(name.getLocalPart())) continue; // FIXME: why is this "special" ? Property property = classifier.findProperty(name.getLocalPart()); if (property == null) { if (domain == null) domain = FumlConfiguration.getInstance().findNamespaceDomain(target.getNamespaceURI()); ValidationExemption exemption = FumlConfiguration.getInstance().findValidationExemptionByProperty( ValidationExemptionType.UNDEFINED_PROPERTY, classifier, name.getLocalPart(), target.getNamespaceURI(), domain); if (exemption == null) { addError(ErrorCode.UNDEFINED_PROPERTY, ErrorSeverity.FATAL, target, name.getLocalPart()); } else { if (log.isDebugEnabled()) log.debug("undefined property exemption found within domain '" + exemption.getDomain().toString() + "' for property '" + classifier.getName() + "." + name.getLocalPart() + "' - ignoring error"); }/*from www. j a v a2 s . co m*/ continue; } if (isReferenceAttribute(property)) { XmiReferenceAttribute reference = new XmiReferenceAttribute(target, xmlAttrib, classifier); this.references.add(reference); } // TODO: when this error is commented out, an erroneous 'invalid internal reference' validation // error was seen to be thrown during assembly. This seems to be a bug if (property.isDerived()) if (checkDerivedPropertyInstantiationError(target, source, classifier, property)) { addError(ErrorCode.DERIVED_PROPERTY_INSTANTIATION, ErrorSeverity.FATAL, target, property.getName()); } } }
From source file:org.mule.module.extension.internal.capability.xml.schema.SchemaBuilder.java
private GroupRef generateNestedProcessorGroup(Parameter parameter, String maxOccurs) { QName ref = MULE_MESSAGE_PROCESSOR_OR_OUTBOUND_ENDPOINT_TYPE; TypeRestrictionCapability restrictionCapability = getSingleCapability(parameter, TypeRestrictionCapability.class); if (restrictionCapability != null) { ref = getSubstitutionGroup(restrictionCapability.getType()); ref = new QName(ref.getNamespaceURI(), getGroupName(ref.getLocalPart()), ref.getPrefix()); }/*from w ww .j a va 2 s .co m*/ GroupRef group = new GroupRef(); group.setRef(ref); group.setMinOccurs(parameter.isRequired() ? BigInteger.ONE : BigInteger.ZERO); group.setMaxOccurs(maxOccurs); return group; }
From source file:org.plasma.provisioning.xsd.SDOXSchemaConverter.java
private Property buildProperty(ComplexType complexType, LocalElement element, int sequenceNum) { Property property = new Property(); property.setId(UUID.randomUUID().toString()); Alias alias = new Alias(); property.setAlias(alias);//from w w w . j a v a 2s . c o m alias.setLocalName(element.getName()); // because XML schema "projection" names could differ QName nameQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_NAME, SDOXConstants.SDOX_NAMESPACE_PREFIX); String name = getOpenAttributeValue(nameQName, element); property.setName(name); // actual SDO type name stored as sdox name XmlProperty xmlProp = new XmlProperty(); xmlProp.setNodeType(XmlNodeType.ELEMENT); property.setXmlProperty(xmlProp); Documentation documentation = createDocumentation(DocumentationType.DEFINITION, getDocumentationContent(element)); property.getDocumentations().add(documentation); property.setVisibility(VisibilityType.PUBLIC); if ("1".equals(String.valueOf(element.getMinOccurs()))) property.setNullable(false); QName aliasQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_ALIAS_NAME, SDOXConstants.SDOX_NAMESPACE_PREFIX); String physicalNameAlias = findOpenAttributeValue(aliasQName, element); if (physicalNameAlias != null) alias.setPhysicalName(physicalNameAlias); else if (!"unbounded".equals(element.getMaxOccurs())) log.warn("expected SDOX '" + SDOXConstants.LOCAL_NAME_ALIAS_NAME + "' attribute for local Element '" + element.getName() + "' for ComplexType '" + complexType.getName() + "'"); QName manyQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_MANY, SDOXConstants.SDOX_NAMESPACE_PREFIX); Boolean many = new Boolean(getOpenAttributeValue(manyQName, element)); if (many.booleanValue()) property.setMany(true); else property.setMany(false); // is key // FIXME: is there not a key-type SDOX attribute?? QName keyQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_KEY, SDOXConstants.SDOX_NAMESPACE_PREFIX); Boolean isKey = new Boolean(findOpenAttributeValue(keyQName, element)); if (isKey.booleanValue()) { property.setVisibility(VisibilityType.PRIVATE); Key key = new Key(); key.setType(KeyType.PRIMARY); property.setKey(key); } QName typeQName = element.getType(); // if a reference to another entity if (typeQName.getPrefix() == null || (appNamespaceQName != null && typeQName.getPrefix().equals(this.appNamespaceQName.getPrefix()))) { QName oppositeQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_OPPOSITE_PROPERTY, SDOXConstants.SDOX_NAMESPACE_PREFIX); String oppositeName = findOpenAttributeValue(oppositeQName, element); if (oppositeName != null) property.setOpposite(oppositeName); QName datatypeQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_DATATYPE, SDOXConstants.SDOX_NAMESPACE_PREFIX); Class targetDef = this.classQualifiedNameMap.get(getOpenAttributeValue(datatypeQName, element)); if (targetDef != null) { ClassRef targetClassRef = new ClassRef(); targetClassRef.setName(targetDef.getName()); targetClassRef.setUri(targetDef.getUri()); property.setType(targetClassRef); property.setContainment(true); } else { throw new IllegalStateException("could not find target class from, " + datatypeQName); } } else { // datatype . QName datatypeQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_DATATYPE, SDOXConstants.SDOX_NAMESPACE_PREFIX); DataTypeRef dataTypeRef = new DataTypeRef(); dataTypeRef.setName(getOpenAttributeValue(datatypeQName, element)); dataTypeRef.setUri(PlasmaConfig.getInstance().getSDODataTypesNamespace().getUri()); property.setType(dataTypeRef); } QName readonlyQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_READ_ONLY, SDOXConstants.SDOX_NAMESPACE_PREFIX); Boolean isReadonly = new Boolean(getOpenAttributeValue(readonlyQName, element)); property.setReadOnly(isReadonly); // FIXME; add isSequence and isUnique and maxlength added to plasma specific XML annotation ?? //Integer maxLength = (Integer)property.get(PlasmaProperty.INSTANCE_PROPERTY_INT_MAXLENGTH); //if (maxLength != null && maxLength.intValue() > 0) // pdef.setMaxLength(maxLength.intValue()); if (sequenceNum > -1) { Sort seq = new Sort(); seq.setKey(String.valueOf(sequenceNum)); property.setSort(seq); } return property; }
From source file:org.plasma.provisioning.xsd.SDOXSchemaConverter.java
/** * Creates non-reference property definitions. * @param complexType the Schema Complex Type * @param attribute the Schema Attribute * @return the property definition//from w w w . j a va2s.c o m */ private Property buildDatatypeProperty(ComplexType complexType, Attribute attribute) { Property property = new Property(); property.setId(UUID.randomUUID().toString()); // set property names and aliases Alias alias = new Alias(); property.setAlias(alias); alias.setLocalName(attribute.getName()); // because XML schema "projection" names could differ QName nameQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_NAME, SDOXConstants.SDOX_NAMESPACE_PREFIX); String name = getOpenAttributeValue(nameQName, attribute); property.setName(name); // actual SDO type name stored as sdox name QName aliasQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_ALIAS_NAME, SDOXConstants.SDOX_NAMESPACE_PREFIX); String physicalNameAlias = getOpenAttributeValue(aliasQName, attribute); alias.setPhysicalName(physicalNameAlias); XmlProperty xmlProp = new XmlProperty(); xmlProp.setNodeType(XmlNodeType.ATTRIBUTE); property.setXmlProperty(xmlProp); Documentation documentation = new Documentation(); documentation.setType(DocumentationType.DEFINITION); Body body = new Body(); body.setValue(getDocumentationContent(attribute)); documentation.setBody(body); property.getDocumentations().add(documentation); property.setVisibility(VisibilityType.PUBLIC); // FIXME // nullable if ("required".equals(attribute.getUse())) property.setNullable(false); else property.setNullable(true); // multiplicity QName manyQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_MANY, SDOXConstants.SDOX_NAMESPACE_PREFIX); Boolean many = new Boolean(getOpenAttributeValue(manyQName, attribute)); if (many.booleanValue()) property.setMany(true); else property.setMany(false); // datatype QName datatypeQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_DATATYPE, SDOXConstants.SDOX_NAMESPACE_PREFIX); DataTypeRef dataTypeRef = new DataTypeRef(); dataTypeRef.setName(getOpenAttributeValue(datatypeQName, attribute)); dataTypeRef.setUri(PlasmaConfig.getInstance().getSDODataTypesNamespace().getUri()); property.setType(dataTypeRef); // is key QName keyQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_KEY, SDOXConstants.SDOX_NAMESPACE_PREFIX); Boolean isKey = new Boolean(findOpenAttributeValue(keyQName, attribute)); if (isKey.booleanValue()) { QName keyTypeQName = new QName(SDOXConstants.SDOX_NAMESPACE_URI, SDOXConstants.LOCAL_NAME_KEY_TYPE, SDOXConstants.SDOX_NAMESPACE_PREFIX); String keyType = findOpenAttributeValue(keyTypeQName, attribute); property.setVisibility(VisibilityType.PRIVATE); // FIXME: really Key key = new Key(); key.setType(KeyType.valueOf(keyType.toUpperCase())); property.setKey(key); } QName typeQName = attribute.getType(); if (typeQName != null) { // if local restriction will not have a simple type if (typeQName.getPrefix() == null || (appNamespaceQName != null && typeQName.getPrefix().equals(this.appNamespaceQName.getPrefix()))) { SimpleType simpleType = this.simpleTypeMap.get(typeQName.getLocalPart()); EnumerationConstraint constraint = new EnumerationConstraint(); EnumerationRef enumRef = new EnumerationRef(); enumRef.setName(simpleType.getName()); enumRef.setUri(this.destNamespaceURI); constraint.setValue(enumRef); property.setEnumerationConstraint(constraint); } } else { LocalSimpleType lst = attribute.getSimpleType(); Restriction rest = lst.getRestriction(); ValueConstraint constraint = this.constraintAssembler.buildValueConstraint(rest); property.setValueConstraint(constraint); } return property; }
From source file:org.slc.sli.modeling.wadl.writer.WadlWriter.java
private static final void writeElement(final DmElement element, final XMLStreamWriter xsw) throws XMLStreamException { final QName name = element.getName(); xsw.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); try {// w w w. j a v a 2s . c om writeContents(element.getChildAxis(), xsw); } finally { xsw.writeEndElement(); } }
From source file:org.unc.hive.services.rs.ConceptsResource.java
/** * Utility method to transform a map of String keys and QName values * into XML.//from w w w . j ava2s.c om * * @param treeMap the map of String keys and QName values * @return xmlString the XML string */ public static String conceptTreeMapToXML(TreeMap<String, QName> treeMap) { String xmlString = ""; StringBuffer xmlStringBuffer = new StringBuffer(XML_DECLARATION); xmlStringBuffer.append("<concepts>\n"); for (String s : treeMap.keySet()) { QName qName = treeMap.get(s); if (qName != null) { xmlStringBuffer.append("<concept>\n"); xmlStringBuffer.append(" <prefLabel>" + s + "</prefLabel>\n"); xmlStringBuffer.append(" <QName>\n"); xmlStringBuffer.append(" <namespaceURI>" + qName.getNamespaceURI() + "</namespaceURI>\n"); xmlStringBuffer.append(" <prefix>" + qName.getPrefix() + "</prefix>\n"); xmlStringBuffer.append(" <localPart>" + qName.getLocalPart() + "</localPart>\n"); xmlStringBuffer.append(" <string>" + qName.toString() + "</string>\n"); xmlStringBuffer.append(" </QName>\n"); xmlStringBuffer.append("</concept>\n"); } } xmlStringBuffer.append("</concepts>"); xmlString = xmlStringBuffer.toString(); return xmlString; }
From source file:org.unc.hive.services.rs.ConceptsResource.java
/** * Utility method to transform a QName to XML. * //from w w w . ja v a 2 s . com * @param qName the QName object to be transformed * @return xmlString the XML string */ public static String qNameToXML(QName qName) { String xmlString = ""; StringBuffer xmlStringBuffer = new StringBuffer(XML_DECLARATION); if (qName != null) { xmlStringBuffer.append(" <QName>\n"); xmlStringBuffer.append(" <namespaceURI>" + qName.getNamespaceURI() + "</namespaceURI>\n"); xmlStringBuffer.append(" <prefix>" + qName.getPrefix() + "</prefix>\n"); xmlStringBuffer.append(" <localPart>" + qName.getLocalPart() + "</localPart>\n"); xmlStringBuffer.append(" <string>" + qName.toString() + "</string>\n"); xmlStringBuffer.append(" </QName>"); xmlString = xmlStringBuffer.toString(); } return xmlString; }