List of usage examples for javax.xml.namespace QName getLocalPart
public String getLocalPart()
Get the local part of this QName
.
From source file:com.evolveum.midpoint.model.impl.lens.projector.PolicyRuleProcessor.java
private <F extends FocusType> void checkAssigneeConstraints(LensContext<F> context, EvaluatedAssignment<F> assignment, PlusMinusZero plusMinus, OperationResult result) throws PolicyViolationException, SchemaException { PrismObject<?> target = assignment.getTarget(); if (target == null || !(target.asObjectable() instanceof AbstractRoleType)) { return;//from w ww . ja va 2 s . co m } AbstractRoleType targetRole = (AbstractRoleType) target.asObjectable(); QName relation = ObjectTypeUtil.normalizeRelation(assignment.getRelation()); Collection<EvaluatedPolicyRule> policyRules = assignment.getThisTargetPolicyRules(); for (EvaluatedPolicyRule policyRule : policyRules) { PolicyConstraintsType policyConstraints = policyRule.getPolicyConstraints(); if (policyConstraints == null) { continue; } List<MultiplicityPolicyConstraintType> relevantMinAssignees = getForRelation( policyConstraints.getMinAssignees(), relation); List<MultiplicityPolicyConstraintType> relevantMaxAssignees = getForRelation( policyConstraints.getMaxAssignees(), relation); if (relevantMinAssignees.isEmpty() && relevantMaxAssignees.isEmpty()) { continue; } String focusOid = null; if (context.getFocusContext() != null) { focusOid = context.getFocusContext().getOid(); } int currentAssigneesExceptMyself = getNumberOfAssigneesExceptMyself(targetRole, focusOid, relation, result); for (MultiplicityPolicyConstraintType constraint : relevantMinAssignees) { Integer requiredMultiplicity = XsdTypeMapper.multiplicityToInteger(constraint.getMultiplicity()); if (requiredMultiplicity <= 0) { continue; // unbounded or 0 } // Complain only if the situation is getting worse if (currentAssigneesExceptMyself < requiredMultiplicity && plusMinus == PlusMinusZero.MINUS) { EvaluatedPolicyRuleTrigger<MultiplicityPolicyConstraintType> trigger = new EvaluatedPolicyRuleTrigger<>( PolicyConstraintKindType.MIN_ASSIGNEES, constraint, target + " requires at least " + requiredMultiplicity + " assignees with the relation of '" + relation.getLocalPart() + "'. The operation would result in " + currentAssigneesExceptMyself + " assignees."); assignment.triggerConstraint(policyRule, trigger); } } for (MultiplicityPolicyConstraintType constraint : relevantMaxAssignees) { Integer requiredMultiplicity = XsdTypeMapper.multiplicityToInteger(constraint.getMultiplicity()); if (requiredMultiplicity < 0) { continue; // unbounded } // Complain only if the situation is getting worse if (currentAssigneesExceptMyself >= requiredMultiplicity && plusMinus == PlusMinusZero.PLUS) { EvaluatedPolicyRuleTrigger<MultiplicityPolicyConstraintType> trigger = new EvaluatedPolicyRuleTrigger<>( PolicyConstraintKindType.MAX_ASSIGNEES, constraint, target + " requires at most " + requiredMultiplicity + " assignees with the relation of '" + relation.getLocalPart() + "'. The operation would result in " + (currentAssigneesExceptMyself + 1) + " assignees."); assignment.triggerConstraint(policyRule, trigger); } } } }
From source file:com.evolveum.midpoint.model.impl.lens.TestAssignmentProcessor2.java
private String getStringRepresentation(EvaluationOrder order) { List<String> names = new ArrayList<>(); for (@NotNull QName relation : order.getRelations()) { int count = order.getMatchingRelationOrder(relation); if (count == 0) { continue; } else if (count < 0) { fail("Negative count for " + relation + " in " + order); }/*from w w w. jav a2 s .c om*/ while (count-- > 0) { names.add(relation.getLocalPart()); } } names.sort(String::compareTo); return StringUtils.join(names, " "); }
From source file:com.nortal.jroad.typegen.xmlbeans.XteeSchemaCodePrinter.java
void printPropertyGetters(QName qName, boolean isAttr, String propertyName, int javaType, String type, String xtype, boolean nillable, boolean optional, boolean several, boolean singleton, String xteeTitle, Long xteeSequence) throws IOException { String propdesc = "\"" + qName.getLocalPart() + "\"" + (isAttr ? " attribute" : " element"); boolean xmltype = (javaType == SchemaProperty.XML_OBJECT); if (singleton) { printJavaDoc((several ? "Gets first " : "Gets the ") + propdesc); // change begin - add annotation printXteeElement(xteeTitle, xteeSequence); // change end - add annotation emit(type + " get" + propertyName + "();"); if (!xmltype) { printJavaDoc((several ? "Gets (as xml) first " : "Gets (as xml) the ") + propdesc); emit(xtype + " xget" + propertyName + "();"); }/*from w w w .j av a 2 s.c o m*/ if (nillable) { printJavaDoc((several ? "Tests for nil first " : "Tests for nil ") + propdesc); emit("boolean isNil" + propertyName + "();"); } } if (optional) { printJavaDoc((several ? "True if has at least one " : "True if has ") + propdesc); emit("boolean isSet" + propertyName + "();"); } if (several) { String arrayName = propertyName + "Array"; if (_useJava15) { String wrappedType = type; if (isJavaPrimitive(javaType)) wrappedType = javaWrappedType(javaType); printJavaDoc("Gets a List of " + propdesc + "s"); // change begin - add annotation printXteeElement(xteeTitle, xteeSequence); // change end - add annotation emit("java.util.List<" + wrappedType + "> get" + propertyName + "List();"); } if (_useJava15) { emit(""); emit("/**"); emit(" * Gets array of all " + propdesc + "s"); emit(" * @deprecated"); emit(" */"); } else printJavaDoc("Gets array of all " + propdesc + "s"); // change begin - add annotation printXteeElement(xteeTitle, xteeSequence); // change end - add annotation emit(type + "[] get" + arrayName + "();"); printJavaDoc("Gets ith " + propdesc); emit(type + " get" + arrayName + "(int i);"); if (!xmltype) { if (_useJava15) { printJavaDoc("Gets (as xml) a List of " + propdesc + "s"); emit("java.util.List<" + xtype + "> xget" + propertyName + "List();"); } if (_useJava15) { emit(""); emit("/**"); emit(" * Gets (as xml) array of all " + propdesc + "s"); emit(" * @deprecated"); emit(" */"); } else printJavaDoc("Gets (as xml) array of all " + propdesc + "s"); emit(xtype + "[] xget" + arrayName + "();"); printJavaDoc("Gets (as xml) ith " + propdesc); emit(xtype + " xget" + arrayName + "(int i);"); } if (nillable) { printJavaDoc("Tests for nil ith " + propdesc); emit("boolean isNil" + arrayName + "(int i);"); } printJavaDoc("Returns number of " + propdesc); emit("int sizeOf" + arrayName + "();"); } }
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);//from w w w .j av a 2 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.nortal.jroad.typegen.xmlbeans.XteeSchemaCodePrinter.java
void printTopComment(SchemaType sType) throws IOException { emit("/*");/*from w ww.j av a2 s . c om*/ 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.nortal.jroad.typegen.xmlbeans.XteeSchemaCodePrinter.java
void printGetterImpls(String parentJavaName, SchemaProperty prop, QName qName, boolean isAttr, String propertyName, int javaType, String type, String xtype, boolean nillable, boolean optional, boolean several, boolean singleton, boolean isunion, String identifier, String setIdentifier) throws IOException { String propdesc = "\"" + qName.getLocalPart() + "\"" + (isAttr ? " attribute" : " element"); boolean xmltype = (javaType == SchemaProperty.XML_OBJECT); String jtargetType = (isunion || !xmltype) ? "org.apache.xmlbeans.SimpleValue" : xtype; if (singleton) { // Value getProp() printJavaDoc((several ? "Gets first " : "Gets the ") + propdesc); emit("public " + type + " get" + propertyName + "()"); startBlock();//w w w.jav a2s . c o m emitImplementationPreamble(); emitGetTarget(setIdentifier, identifier, isAttr, "0", NOTHING, jtargetType); if (isAttr && (prop.hasDefault() == SchemaProperty.CONSISTENTLY || prop.hasFixed() == SchemaProperty.CONSISTENTLY)) { emit("if (target == null)"); startBlock(); makeAttributeDefaultValue(jtargetType, prop, identifier); endBlock(); } emit("if (target == null)"); startBlock(); makeMissingValue(javaType); endBlock(); printJGetValue(javaType, type); emitImplementationPostamble(); endBlock(); if (!xmltype) { // Value xgetProp() printJavaDoc((several ? "Gets (as xml) first " : "Gets (as xml) the ") + propdesc); emit("public " + xtype + " xget" + propertyName + "()"); startBlock(); emitImplementationPreamble(); emitGetTarget(setIdentifier, identifier, isAttr, "0", NOTHING, xtype); if (isAttr && (prop.hasDefault() == SchemaProperty.CONSISTENTLY || prop.hasFixed() == SchemaProperty.CONSISTENTLY)) { emit("if (target == null)"); startBlock(); makeAttributeDefaultValue(xtype, prop, identifier); endBlock(); } emit("return target;"); emitImplementationPostamble(); endBlock(); } if (nillable) { // boolean isNilProp() printJavaDoc((several ? "Tests for nil first " : "Tests for nil ") + propdesc); emit("public boolean isNil" + propertyName + "()"); startBlock(); emitImplementationPreamble(); emitGetTarget(setIdentifier, identifier, isAttr, "0", NOTHING, xtype); emit("if (target == null) return false;"); emit("return target.isNil();"); emitImplementationPostamble(); endBlock(); } } if (optional) { // boolean isSetProp() printJavaDoc((several ? "True if has at least one " : "True if has ") + propdesc); emit("public boolean isSet" + propertyName + "()"); startBlock(); emitImplementationPreamble(); if (isAttr) emit("return get_store().find_attribute_user(" + identifier + ") != null;"); else emit("return get_store().count_elements(" + setIdentifier + ") != 0;"); emitImplementationPostamble(); endBlock(); } if (several) { String arrayName = propertyName + "Array"; if (_useJava15) { // use boxed type if the java type is a primitive and jdk1.5 // jdk1.5 will box/unbox for us String wrappedType = type; if (isJavaPrimitive(javaType)) wrappedType = javaWrappedType(javaType); printListGetter15Impl(parentJavaName, propdesc, propertyName, wrappedType, xtype, xmltype, false); } // Value[] getProp() if (_useJava15) { emit(""); emit("/**"); emit(" * Gets array of all " + propdesc + "s"); emit(" * @deprecated"); emit(" */"); } else printJavaDoc("Gets array of all " + propdesc + "s"); emit("public " + type + "[] get" + arrayName + "()"); startBlock(); emitImplementationPreamble(); if (_useJava15) emit("java.util.List<" + xtype + "> targetList = new java.util.ArrayList<" + xtype + ">();"); else emit("java.util.List targetList = new java.util.ArrayList();"); emit("get_store().find_all_element_users(" + setIdentifier + ", targetList);"); printJGetArrayValue(javaType, type); emitImplementationPostamble(); endBlock(); // Value getProp(int i) printJavaDoc("Gets ith " + propdesc); emit("public " + type + " get" + arrayName + "(int i)"); startBlock(); emitImplementationPreamble(); emitGetTarget(setIdentifier, identifier, isAttr, "i", THROW_EXCEPTION, jtargetType); printJGetValue(javaType, type); emitImplementationPostamble(); endBlock(); if (!xmltype) { if (_useJava15) { printListGetter15Impl(parentJavaName, propdesc, propertyName, xtype, xtype, xmltype, true); } // Value[] xgetProp() if (_useJava15) { emit(""); emit("/**"); emit(" * Gets array of all " + propdesc + "s"); emit(" * @deprecated"); emit(" */"); } else printJavaDoc("Gets (as xml) array of all " + propdesc + "s"); emit("public " + xtype + "[] xget" + arrayName + "()"); startBlock(); emitImplementationPreamble(); if (_useJava15) emit("java.util.List<" + xtype + "> targetList = new java.util.ArrayList<" + xtype + ">();"); else emit("java.util.List targetList = new java.util.ArrayList();"); emit("get_store().find_all_element_users(" + setIdentifier + ", targetList);"); emit(xtype + "[] result = new " + xtype + "[targetList.size()];"); emit("targetList.toArray(result);"); emit("return result;"); emitImplementationPostamble(); endBlock(); // Value xgetProp(int i) printJavaDoc("Gets (as xml) ith " + propdesc); emit("public " + xtype + " xget" + arrayName + "(int i)"); startBlock(); emitImplementationPreamble(); emitGetTarget(setIdentifier, identifier, isAttr, "i", THROW_EXCEPTION, xtype); emit("return (" + xtype + ")target;"); emitImplementationPostamble(); endBlock(); } if (nillable) { // boolean isNil(int i); printJavaDoc("Tests for nil ith " + propdesc); emit("public boolean isNil" + arrayName + "(int i)"); startBlock(); emitImplementationPreamble(); emitGetTarget(setIdentifier, identifier, isAttr, "i", THROW_EXCEPTION, xtype); emit("return target.isNil();"); emitImplementationPostamble(); endBlock(); } // int countProp(); printJavaDoc("Returns number of " + propdesc); emit("public int sizeOf" + arrayName + "()"); startBlock(); emitImplementationPreamble(); emit("return get_store().count_elements(" + setIdentifier + ");"); emitImplementationPostamble(); endBlock(); } }
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("");// www .ja va 2s .co 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.nortal.jroad.typegen.xmlbeans.XteeSchemaCodePrinter.java
void printPropertySetters(QName qName, boolean isAttr, String propertyName, int javaType, String type, String xtype, boolean nillable, boolean optional, boolean several, boolean singleton) throws IOException { String safeVarName = NameUtil.nonJavaKeyword(NameUtil.lowerCamelCase(propertyName)); if (safeVarName.equals("i")) safeVarName = "iValue"; boolean xmltype = (javaType == SchemaProperty.XML_OBJECT); String propdesc = "\"" + qName.getLocalPart() + "\"" + (isAttr ? " attribute" : " element"); if (singleton) { printJavaDoc((several ? "Sets first " : "Sets the ") + propdesc); emit("void set" + propertyName + "(" + type + " " + safeVarName + ");"); if (!xmltype) { printJavaDoc((several ? "Sets (as xml) first " : "Sets (as xml) the ") + propdesc); emit("void xset" + propertyName + "(" + xtype + " " + safeVarName + ");"); }/*from ww w . j a v a 2 s . c om*/ if (xmltype && !several) { printJavaDoc("Appends and returns a new empty " + propdesc); emit(xtype + " addNew" + propertyName + "();"); } if (nillable) { printJavaDoc((several ? "Nils the first " : "Nils the ") + propdesc); emit("void setNil" + propertyName + "();"); } } if (optional) { printJavaDoc((several ? "Removes first " : "Unsets the ") + propdesc); emit("void unset" + propertyName + "();"); } if (several) { String arrayName = propertyName + "Array"; printJavaDoc("Sets array of all " + propdesc); emit("void set" + arrayName + "(" + type + "[] " + safeVarName + "Array);"); printJavaDoc("Sets ith " + propdesc); emit("void set" + arrayName + "(int i, " + type + " " + safeVarName + ");"); if (!xmltype) { printJavaDoc("Sets (as xml) array of all " + propdesc); emit("void xset" + arrayName + "(" + xtype + "[] " + safeVarName + "Array);"); printJavaDoc("Sets (as xml) ith " + propdesc); emit("void xset" + arrayName + "(int i, " + xtype + " " + safeVarName + ");"); } if (nillable) { printJavaDoc("Nils the ith " + propdesc); emit("void setNil" + arrayName + "(int i);"); } if (!xmltype) { printJavaDoc("Inserts the value as the ith " + propdesc); emit("void insert" + propertyName + "(int i, " + type + " " + safeVarName + ");"); printJavaDoc("Appends the value as the last " + propdesc); emit("void add" + propertyName + "(" + type + " " + safeVarName + ");"); } printJavaDoc("Inserts and returns a new empty value (as xml) as the ith " + propdesc); emit(xtype + " insertNew" + propertyName + "(int i);"); printJavaDoc("Appends and returns a new empty value (as xml) as the last " + propdesc); emit(xtype + " addNew" + propertyName + "();"); printJavaDoc("Removes the ith " + propdesc); emit("void remove" + propertyName + "(int i);"); } }
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); }//w ww .ja v a 2 s . com 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.provisioning.ucf.impl.ConnectorInstanceIcfImpl.java
private void transformConnectorTimeoutsConfiguration(APIConfiguration apiConfig, PrismContainer<?> connectorTimeoutsContainer) throws SchemaException { if (connectorTimeoutsContainer == null || connectorTimeoutsContainer.getValue() == null) { return;/*from w w w .ja v a 2 s . c om*/ } for (PrismProperty prismProperty : connectorTimeoutsContainer.getValue().getProperties()) { QName propertQName = prismProperty.getElementName(); if (ConnectorFactoryIcfImpl.NS_ICF_CONFIGURATION.equals(propertQName.getNamespaceURI())) { String opName = propertQName.getLocalPart(); Class<? extends APIOperation> apiOpClass = ConnectorFactoryIcfImpl.resolveApiOpClass(opName); if (apiOpClass != null) { apiConfig.setTimeout(apiOpClass, parseInt(prismProperty)); } else { throw new SchemaException("Unknown operation name " + opName + " in " + ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_TIMEOUTS_XML_ELEMENT_NAME); } } } }