public String extractString(String defaultValue) { if (xnode instanceof PrimitiveXNode) { return ((PrimitiveXNode<?>) xnode).getStringValue(); } else { return defaultValue; } }
/** * TEMPORARY. EXPERIMENTAL. DO NOT USE. */ public String extractString() { if (xnode instanceof PrimitiveXNode) { return ((PrimitiveXNode<?>) xnode).getStringValue(); } else { return toString(); } }
@Override @SuppressWarnings("unchecked") public <T> T tryParsingPrimitiveAsBean(PrimitiveXNode<T> primitive, Class<T> beanClass, ParsingContext pc) { if (LocalizableMessageType.class.equals(beanClass)) { return (T) new SingleLocalizableMessageType().fallbackMessage(primitive.getStringValue()); } else if (InformationType.class.equals(beanClass)) { // This is to allow specifying plain text where InformationType is expected. It is not very clean; and // quite experimental for now. return (T) stringToInformationType(primitive.getStringValue()); } else { return null; } }
private void checkAssignmentConstruction(UserType jack, String attributeName, String value) throws SchemaException { assertEquals("jack's assignments", 1, jack.getAssignment().size()); AssignmentType assignmentType = jack.getAssignment().get(0); ConstructionType constructionType = assignmentType.getConstruction(); assertNotNull("construction is null", constructionType); boolean found = false; for (ResourceAttributeDefinitionType attributeDefinitionType : constructionType.getAttribute()) { if (attributeDefinitionType.getRef().equivalent(new ItemPathType(ItemPath.create(new QName(attributeName))))) { ExpressionType expressionType = attributeDefinitionType.getOutbound().getExpression(); assertNotNull("no expression", expressionType); assertEquals("wrong # of expression evaluators", 1, expressionType.getExpressionEvaluator().size()); JAXBElement<?> element = expressionType.getExpressionEvaluator().get(0); PrimitiveXNode valueXNode = (PrimitiveXNode) (((RawType) element.getValue()).serializeToXNode()); assertEquals("wrong outbound value", value, valueXNode.getStringValue()); found = true; } } assertTrue("attribute " + attributeName + " mapping not found", found); }
/** * Extracts a "real value" from RawType object without expecting any specific type beforehand. * If no explicit type is present, assumes xsd:string (and fails if the content is structured). */ public Object getValue() throws SchemaException { if (parsed != null) { return parsed.getRealValue(); } if (xnode == null) { return null; } if (xnode.getTypeQName() != null) { TypeDefinition typeDefinition = prismContext.getSchemaRegistry().findTypeDefinitionByType(xnode.getTypeQName()); if (typeDefinition != null && typeDefinition.getCompileTimeClass() != null) { return getParsedRealValue(typeDefinition.getCompileTimeClass()); } Class<?> javaClass = XsdTypeMapper.getXsdToJavaMapping(xnode.getTypeQName()); if (javaClass != null) { return getParsedRealValue(javaClass); } } // unknown or null type -- try parsing as string if (!(xnode instanceof PrimitiveXNode<?>)) { throw new SchemaException("Trying to parse non-primitive XNode as type '" + xnode.getTypeQName() + "'"); } else { return ((PrimitiveXNode) xnode).getStringValue(); } }