List of usage examples for javax.xml.namespace QName getNamespaceURI
public String getNamespaceURI()
Get the Namespace URI of this QName
.
From source file:org.apache.juddi.v3.client.mapping.wadl.WADL2UDDI.java
/** * Creates a UDDI Business Service.//from w w w . ja v a 2 s . com * * @param serviceQName This must be specified to identify the namespace of * the service, which is used to set the service uddi key * @param wadlDefinition * @return BusinessService * @throws MalformedURLException */ public BusinessService createBusinessService(QName serviceQName, Application wadlDefinition) throws MalformedURLException { log.debug("Constructing Service UDDI Information for " + serviceQName); BusinessService service = new BusinessService(); // BusinessKey service.setBusinessKey(businessKey); // ServiceKey service.setServiceKey(UDDIKeyConvention.getServiceKey(properties, serviceQName.getLocalPart())); // Description String serviceDescription = properties.getProperty(Property.SERVICE_DESCRIPTION, Property.DEFAULT_SERVICE_DESCRIPTION); // Override with the service description from the WADL if present boolean lengthwarn = false; if (!wadlDefinition.getDoc().isEmpty()) { for (int i = 0; i < wadlDefinition.getDoc().size(); i++) { String locallang = lang; if (wadlDefinition.getDoc().get(i).getLang() != null) { locallang = (wadlDefinition.getDoc().get(i).getLang()); } if (locallang.length() > UDDIConstants.MAX_xml_lang_length) { lengthwarn = true; locallang = (locallang.substring(0, UDDIConstants.MAX_xml_lang_length - 1)); } StringBuilder sb = new StringBuilder(); sb.append(wadlDefinition.getDoc().get(i).getTitle()).append(" "); sb.append(ContentToString(wadlDefinition.getDoc().get(i).getContent())); service.getDescription().addAll(Common2UDDI.mapDescription(sb.toString(), locallang)); } } else { service.getDescription().addAll(Common2UDDI.mapDescription(serviceDescription, lang)); } // Service name Name sName = new Name(); sName.setLang(lang); if (!wadlDefinition.getDoc().isEmpty()) { sName.setValue(wadlDefinition.getDoc().get(0).getTitle()); } if (sName.getValue() == null) { sName.setValue(serviceQName.getLocalPart()); } service.getName().add(sName); CategoryBag categoryBag = new CategoryBag(); String namespace = serviceQName.getNamespaceURI(); if (namespace != null && namespace.length() != 0) { KeyedReference namespaceReference = newKeyedReference("uddi:uddi.org:xml:namespace", "uddi-org:xml:namespace", namespace); categoryBag.getKeyedReference().add(namespaceReference); } KeyedReference serviceReference = newKeyedReference("uddi:uddi.org:wadl:types", "uddi-org:wadl:types", "service"); categoryBag.getKeyedReference().add(serviceReference); KeyedReference localNameReference = newKeyedReference("uddi:uddi.org:xml:localname", "uddi-org:xml:localName", serviceQName.getLocalPart()); categoryBag.getKeyedReference().add(localNameReference); service.setCategoryBag(categoryBag); for (int i = 0; i < wadlDefinition.getResources().size(); i++) { BindingTemplate bindingTemplate = createWADLBinding(serviceQName, getDocTitle(wadlDefinition.getResources().get(i).getDoc()), new URL(wadlDefinition.getResources().get(i).getBase()), wadlDefinition.getResources().get(i)); service.setBindingTemplates(new BindingTemplates()); service.getBindingTemplates().getBindingTemplate().add(bindingTemplate); } if (lengthwarn) { log.warn( "Some object descriptions are longer than the maximum allowed by UDDI and have been truncated."); } return service; }
From source file:com.evolveum.midpoint.prism.parser.DomSerializer.java
private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Element parentElement, QName elementOrAttributeName, boolean asAttribute) throws SchemaException { QName typeQName = xprim.getTypeQName(); // if typeQName is not explicitly specified, we try to determine it from parsed value // TODO we should probably set typeQName when parsing the value... if (typeQName == null && xprim.isParsed()) { Object v = xprim.getValue(); if (v != null) { typeQName = XsdTypeMapper.toXsdType(v.getClass()); }//from w w w. j ava 2s . c o m } if (typeQName == null) { // this means that either xprim is unparsed or it is empty if (com.evolveum.midpoint.prism.PrismContext.isAllowSchemalessSerialization()) { // We cannot correctly serialize without a type. But this is needed // sometimes. So just default to string String stringValue = xprim.getStringValue(); if (stringValue != null) { if (asAttribute) { DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), stringValue); DOMUtil.setNamespaceDeclarations(parentElement, xprim.getRelevantNamespaceDeclarations()); } else { Element element; try { element = createElement(elementOrAttributeName, parentElement); appendCommentIfPresent(element, xprim); } catch (DOMException e) { throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement)); } parentElement.appendChild(element); DOMUtil.setElementTextContent(element, stringValue); DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations()); } } return; } else { throw new IllegalStateException("No type for primitive element " + elementOrAttributeName + ", cannot serialize (schemaless serialization is disabled)"); } } // typeName != null after this point if (StringUtils.isBlank(typeQName.getNamespaceURI())) { typeQName = XsdTypeMapper.determineQNameWithNs(typeQName); } Element element = null; if (typeQName.equals(ItemPath.XSD_TYPE)) { ItemPath itemPath = (ItemPath) xprim.getValue(); if (itemPath != null) { if (asAttribute) { throw new UnsupportedOperationException( "Serializing ItemPath as an attribute is not supported yet"); } XPathHolder holder = new XPathHolder(itemPath); element = holder.toElement(elementOrAttributeName, parentElement.getOwnerDocument()); parentElement.appendChild(element); } } else { // not an ItemPathType if (!asAttribute) { try { element = createElement(elementOrAttributeName, parentElement); } catch (DOMException e) { throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement)); } appendCommentIfPresent(element, xprim); parentElement.appendChild(element); } if (typeQName.equals(DOMUtil.XSD_QNAME)) { QName value = (QName) xprim.getParsedValueWithoutRecording(DOMUtil.XSD_QNAME); value = setQNamePrefixExplicitIfNeeded(value); if (asAttribute) { try { DOMUtil.setQNameAttribute(parentElement, elementOrAttributeName.getLocalPart(), value); } catch (DOMException e) { throw new DOMException(e.code, e.getMessage() + "; setting attribute " + elementOrAttributeName.getLocalPart() + " in element " + DOMUtil.getQName(parentElement) + " to QName value " + value); } } else { DOMUtil.setQNameValue(element, value); } } else { // not ItemType nor QName String value = xprim.getGuessedFormattedValue(); if (asAttribute) { DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), value); } else { DOMUtil.setElementTextContent(element, value); } } } if (!asAttribute && xprim.isExplicitTypeDeclaration()) { DOMUtil.setXsiType(element, setQNamePrefixExplicitIfNeeded(typeQName)); } }
From source file:com.evolveum.midpoint.schema.xjc.schema.SchemaProcessor.java
private void addContainerName(Outline outline, Map<String, JFieldVar> namespaceFields) { Map<QName, List<QName>> complexTypeToElementName = null; Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet(); for (Map.Entry<NClass, CClassInfo> entry : set) { CClassInfo classInfo = entry.getValue(); ClassOutline classOutline = outline.getClazz(classInfo); if (complexTypeToElementName == null) { complexTypeToElementName = getComplexTypeToElementName(classOutline); }/*from ww w.jav a2 s . co m*/ QName qname = getCClassInfoQName(classInfo); if (qname == null || !hasParentAnnotation(classOutline, A_PRISM_OBJECT)) { continue; } //element name List<QName> qnames = complexTypeToElementName.get(qname); if (qnames == null || qnames.size() != 1) { System.out.println( "Found zero or more than one element names for type '" + qname + "', " + qnames + "."); continue; } qname = qnames.get(0); JDefinedClass definedClass = classOutline.implClass; JMethod getContainerName = definedClass.method(JMod.NONE, QName.class, METHOD_GET_CONTAINER_NAME); // getContainerName.annotate(CLASS_MAP.get(XmlTransient.class)); JBlock body = getContainerName.body(); JFieldVar var = namespaceFields.get(qname.getNamespaceURI()); JInvocation invocation = JExpr._new(CLASS_MAP.get(QName.class)); if (var != null) { JClass schemaClass = outline.getModel().codeModel._getClass(StepSchemaConstants.CLASS_NAME); invocation.arg(schemaClass.staticRef(var)); invocation.arg(qname.getLocalPart()); } else { invocation.arg(qname.getNamespaceURI()); invocation.arg(qname.getLocalPart()); } body._return(invocation); //get container type JMethod getContainerType = definedClass.method(JMod.NONE, QName.class, METHOD_GET_CONTAINER_TYPE); // getContainerType.annotate(CLASS_MAP.get(XmlTransient.class)); body = getContainerType.body(); body._return(definedClass.staticRef(COMPLEX_TYPE_FIELD_NAME)); } }
From source file:com.evolveum.midpoint.prism.lex.dom.DomLexicalWriter.java
private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Element parentElement, QName elementOrAttributeName, boolean asAttribute) throws SchemaException { QName typeQName = xprim.getTypeQName(); // if typeQName is not explicitly specified, we try to determine it from parsed value // TODO we should probably set typeQName when parsing the value... if (typeQName == null && xprim.isParsed()) { Object v = xprim.getValue(); if (v != null) { typeQName = XsdTypeMapper.toXsdType(v.getClass()); }/* w w w.j a va2 s . c o m*/ } if (typeQName == null) { // this means that either xprim is unparsed or it is empty if (com.evolveum.midpoint.prism.PrismContextImpl.isAllowSchemalessSerialization()) { // We cannot correctly serialize without a type. But this is needed // sometimes. So just default to string String stringValue = xprim.getStringValue(); if (stringValue != null) { if (asAttribute) { DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), stringValue); DOMUtil.setNamespaceDeclarations(parentElement, xprim.getRelevantNamespaceDeclarations()); } else { Element element; try { element = createElement(elementOrAttributeName, parentElement); appendCommentIfPresent(element, xprim); } catch (DOMException e) { throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement)); } parentElement.appendChild(element); DOMUtil.setElementTextContent(element, stringValue); DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations()); } } return; } else { throw new IllegalStateException("No type for primitive element " + elementOrAttributeName + ", cannot serialize (schemaless serialization is disabled)"); } } // typeName != null after this point if (StringUtils.isBlank(typeQName.getNamespaceURI())) { typeQName = XsdTypeMapper.determineQNameWithNs(typeQName); } Element element = null; if (ItemPathType.COMPLEX_TYPE.equals(typeQName)) { //ItemPathType itemPathType = //ItemPathType.asItemPathType(xprim.getValue()); // TODO fix this hack ItemPathType itemPathType = (ItemPathType) xprim.getValue(); if (itemPathType != null) { if (asAttribute) { throw new UnsupportedOperationException( "Serializing ItemPath as an attribute is not supported yet"); } ItemPathHolder holder = new ItemPathHolder(itemPathType.getItemPath()); element = holder.toElement(elementOrAttributeName, parentElement.getOwnerDocument()); parentElement.appendChild(element); } } else { // not an ItemPathType if (!asAttribute) { try { element = createElement(elementOrAttributeName, parentElement); } catch (DOMException e) { throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement)); } appendCommentIfPresent(element, xprim); parentElement.appendChild(element); } if (DOMUtil.XSD_QNAME.equals(typeQName)) { QName value = (QName) xprim.getParsedValueWithoutRecording(DOMUtil.XSD_QNAME); value = setQNamePrefixExplicitIfNeeded(value); if (asAttribute) { try { DOMUtil.setQNameAttribute(parentElement, elementOrAttributeName.getLocalPart(), value); } catch (DOMException e) { throw new DOMException(e.code, e.getMessage() + "; setting attribute " + elementOrAttributeName.getLocalPart() + " in element " + DOMUtil.getQName(parentElement) + " to QName value " + value); } } else { DOMUtil.setQNameValue(element, value); } } else { // not ItemType nor QName String value = xprim.getGuessedFormattedValue(); if (asAttribute) { DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), value); } else { DOMUtil.setElementTextContent(element, value); } } } if (!asAttribute && xprim.isExplicitTypeDeclaration()) { DOMUtil.setXsiType(element, setQNamePrefixExplicitIfNeeded(typeQName)); } }
From source file:com.nortal.jroad.typegen.xmlbeans.XteeSchemaCodePrinter.java
Map<QName, String[]> printStaticFields(SchemaProperty[] properties) throws IOException { final Map<QName, String[]> results = new HashMap<QName, String[]>(); emit("");/*from w ww. j a v a 2 s . c o m*/ for (int i = 0; i < properties.length; i++) { final String[] identifiers = new String[2]; final SchemaProperty prop = properties[i]; final QName name = prop.getName(); results.put(name, identifiers); final String javaName = prop.getJavaPropertyName(); identifiers[0] = (javaName + "$" + (i * 2)).toUpperCase(); final String uriString = "\"" + name.getNamespaceURI() + "\""; emit("private static final javax.xml.namespace.QName " + identifiers[0] + " = "); indent(); emit("new javax.xml.namespace.QName(" + uriString + ", \"" + name.getLocalPart() + "\");"); outdent(); if (properties[i].acceptedNames() != null) { final QName[] qnames = properties[i].acceptedNames(); if (qnames.length > 1) { identifiers[1] = (javaName + "$" + (i * 2 + 1)).toUpperCase(); emit("private static final org.apache.xmlbeans.QNameSet " + identifiers[1] + " = org.apache.xmlbeans.QNameSet.forArray( new javax.xml.namespace.QName[] { "); indent(); for (int j = 0; j < qnames.length; j++) { emit("new javax.xml.namespace.QName(\"" + qnames[j].getNamespaceURI() + "\", \"" + qnames[j].getLocalPart() + "\"),"); } outdent(); emit("});"); } } } emit(""); return results; }
From source file:com.evolveum.midpoint.testing.model.client.sample.TestExchangeConnector.java
private 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);/*w w w.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"); }
From source file:com.evolveum.midpoint.schema.xjc.schema.SchemaProcessor.java
private void addFieldQNames(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 = getCClassInfoQName(entry.getValue()); if (qname == null) { continue; }/*w w w . j a va 2 s . c o m*/ JDefinedClass implClass = classOutline.implClass; Map<String, JFieldVar> fields = implClass.fields(); if (fields == null) { continue; } boolean isObject = hasAnnotation(classOutline, A_PRISM_OBJECT); List<FieldBox<QName>> boxes = new ArrayList<FieldBox<QName>>(); for (Entry<String, JFieldVar> fieldEntry : fields.entrySet()) { String field = normalizeFieldName(fieldEntry.getKey()); if ((isObject && ("oid".equals(field) || "version".equals(field)) || "serialVersionUID".equals(field) || "id".equals(field) || COMPLEX_TYPE_FIELD_NAME.equals(field))) { continue; } if (hasAnnotationClass(fieldEntry.getValue(), XmlAnyElement.class)) { continue; } String fieldName = fieldFPrefixUnderscoredUpperCase(field); boxes.add(new FieldBox<QName>(fieldName, new QName(qname.getNamespaceURI(), field))); } for (FieldBox<QName> box : boxes) { JFieldVar var = namespaceFields.get(qname.getNamespaceURI()); if (var != null) { createQNameDefinition(outline, implClass, box.getFieldName(), var, box.getValue()); } else { createPSFField(outline, implClass, box.getFieldName(), box.getValue()); } } } }
From source file:com.nortal.jroad.typegen.xmlbeans.XteeSchemaCodePrinter.java
void printTopComment(SchemaType sType) throws IOException { emit("/*");/*from w ww . j ava2 s .co m*/ if (sType.getName() != null) { emit(" * XML Type: " + sType.getName().getLocalPart()); emit(" * Namespace: " + sType.getName().getNamespaceURI()); } else { QName thename = null; if (sType.isDocumentType()) { thename = sType.getDocumentElementName(); emit(" * An XML document type."); } else if (sType.isAttributeType()) { thename = sType.getAttributeTypeAttributeName(); emit(" * An XML attribute type."); } else assert false; assert (thename != null); emit(" * Localname: " + thename.getLocalPart()); emit(" * Namespace: " + thename.getNamespaceURI()); } emit(" * Java type: " + sType.getFullJavaName()); emit(" *"); emit(" * Automatically generated - do not modify."); emit(" */"); }
From source file:com.evolveum.midpoint.provisioning.ucf.impl.connid.ConnectorInstanceConnIdImpl.java
private void convertFromPassword(Set<Attribute> attributes, PropertyDelta<ProtectedStringType> passwordDelta) throws SchemaException { if (passwordDelta == null) { throw new IllegalArgumentException("No password was provided"); }//from ww w. j a v a2 s . c o m QName elementName = passwordDelta.getElementName(); if (StringUtils.isBlank(elementName.getNamespaceURI())) { if (!QNameUtil.match(elementName, PasswordType.F_VALUE)) { return; } } else if (!passwordDelta.getElementName().equals(PasswordType.F_VALUE)) { return; } PrismProperty<ProtectedStringType> newPassword = passwordDelta.getPropertyNewMatchingPath(); if (newPassword == null || newPassword.isEmpty()) { // This is the case of setting no password. E.g. removing existing password LOGGER.debug("Setting null password."); attributes.add(AttributeBuilder.build(OperationalAttributes.PASSWORD_NAME, Collections.EMPTY_LIST)); } else if (newPassword.getRealValue().canGetCleartext()) { // We have password and we can get a cleartext value of the passowrd. This is normal case GuardedString guardedPassword = ConnIdUtil.toGuardedString(newPassword.getRealValue(), "new password", protector); attributes.add(AttributeBuilder.build(OperationalAttributes.PASSWORD_NAME, guardedPassword)); } else { // We have password, but we cannot get a cleartext value. Just to nothing. LOGGER.debug( "We would like to set password, but we do not have cleartext value. Skipping the opearation."); } }
From source file:com.evolveum.midpoint.provisioning.ucf.impl.ConnectorInstanceIcfImpl.java
private void transformConnectorPoolConfiguration(ObjectPoolConfiguration connectorPoolConfiguration, PrismContainer<?> connectorPoolContainer) throws SchemaException { if (connectorPoolContainer == null || connectorPoolContainer.getValue() == null) { return;//from ww w . j a v a 2s . co m } for (PrismProperty prismProperty : connectorPoolContainer.getValue().getProperties()) { QName propertyQName = prismProperty.getElementName(); if (propertyQName.getNamespaceURI().equals(ConnectorFactoryIcfImpl.NS_ICF_CONFIGURATION)) { String subelementName = propertyQName.getLocalPart(); if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_MIN_EVICTABLE_IDLE_TIME_MILLIS .equals(subelementName)) { connectorPoolConfiguration.setMinEvictableIdleTimeMillis(parseLong(prismProperty)); } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_MIN_IDLE .equals(subelementName)) { connectorPoolConfiguration.setMinIdle(parseInt(prismProperty)); } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_MAX_IDLE .equals(subelementName)) { connectorPoolConfiguration.setMaxIdle(parseInt(prismProperty)); } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_MAX_OBJECTS .equals(subelementName)) { connectorPoolConfiguration.setMaxObjects(parseInt(prismProperty)); } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_MAX_WAIT .equals(subelementName)) { connectorPoolConfiguration.setMaxWait(parseLong(prismProperty)); } else { throw new SchemaException("Unexpected element " + propertyQName + " in " + ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_XML_ELEMENT_NAME); } } else { throw new SchemaException("Unexpected element " + propertyQName + " in " + ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_XML_ELEMENT_NAME); } } }