List of usage examples for javax.xml.bind JAXBElement getValue
public T getValue()
Return the content model and attribute values for this element.
See #isNil() for a description of a property constraint when this value is null
From source file:be.fedict.eid.dss.ws.DSSUtil.java
public static byte[] getOriginalDocument(Element element) throws JAXBException { JAXBElement<OriginalDocumentType> originalDocumentElement = (JAXBElement<OriginalDocumentType>) originalDocumentUnmarshaller .unmarshal(element);//www. j a va 2s . com OriginalDocumentType originalDocument = originalDocumentElement.getValue(); InputDocuments inputDocuments = originalDocument.getInputDocuments(); List<Object> documentObjects = inputDocuments.getDocumentOrTransformedDataOrDocumentHash(); for (Object documentObject : documentObjects) { if (!(documentObject instanceof DocumentType)) { continue; } DocumentType document = (DocumentType) documentObject; Base64Data base64Data = document.getBase64Data(); byte[] data; if (null != base64Data) { data = base64Data.getValue(); } else { data = document.getBase64XML(); } if (null != data) { return data; } } return null; }
From source file:com.evolveum.midpoint.schema.util.ValueDisplayUtil.java
public static String toStringValue(PrismPropertyValue propertyValue) { Object value = propertyValue.getValue(); if (value == null) { return null; } else if (value instanceof String) { return (String) value; } else if (value instanceof PolyString) { return ((PolyString) value).getOrig(); } else if (value instanceof ProtectedStringType) { return "(protected string)"; // todo i18n } else if (value instanceof Boolean || value instanceof Integer || value instanceof Long) { return value.toString(); } else if (value instanceof XMLGregorianCalendar) { return ((XMLGregorianCalendar) value).toGregorianCalendar().getTime().toLocaleString(); // todo fix } else if (value instanceof Date) { return ((Date) value).toLocaleString(); // todo fix } else if (value instanceof LoginEventType) { LoginEventType loginEventType = (LoginEventType) value; if (loginEventType.getTimestamp() != null) { return loginEventType.getTimestamp().toGregorianCalendar().getTime().toLocaleString(); // todo fix } else {//from www. j a va 2 s. c o m return ""; } } else if (value instanceof ApprovalSchemaType) { ApprovalSchemaType approvalSchemaType = (ApprovalSchemaType) value; return approvalSchemaType.getName() + (approvalSchemaType.getDescription() != null ? (": " + approvalSchemaType.getDescription()) : "") + " (...)"; } else if (value instanceof ConstructionType) { ConstructionType ct = (ConstructionType) value; Object resource = (ct.getResource() != null ? ct.getResource().getName() : (ct.getResourceRef() != null ? ct.getResourceRef().getOid() : null)); return "resource object" + (resource != null ? " on " + resource : "") + (ct.getDescription() != null ? ": " + ct.getDescription() : ""); } else if (value instanceof Enum) { return value.toString(); } else if (value instanceof ResourceAttributeDefinitionType) { ResourceAttributeDefinitionType radt = (ResourceAttributeDefinitionType) value; ItemPathType ref = radt.getRef(); String path; if (ref != null) { path = ref.getItemPath().toString(); } else { path = "(null)"; } StringBuilder sb = new StringBuilder(); MappingType mappingType = radt.getOutbound(); if (mappingType != null) { if (mappingType.getExpression() == null) { sb.append("Empty mapping for ").append(path); } else { sb.append(path).append(" = "); boolean first = true; for (JAXBElement<?> evaluator : mappingType.getExpression().getExpressionEvaluator()) { if (first) { first = false; } else { sb.append(", "); } if (QNameUtil.match(SchemaConstants.C_VALUE, evaluator.getName()) && evaluator.getValue() instanceof RawType) { RawType raw = (RawType) evaluator.getValue(); try { XNode xnode = raw.serializeToXNode(); if (xnode instanceof PrimitiveXNode) { sb.append(((PrimitiveXNode) xnode).getStringValue()); } else { sb.append("(a complex value)"); } } catch (SchemaException e) { sb.append("(an invalid value)"); } } else { sb.append("(a complex expression)"); } } } if (mappingType.getStrength() != null) { sb.append(" (").append(mappingType.getStrength().value()).append(")"); } } else { sb.append("Empty mapping for ").append(path); } return sb.toString(); } else if (value instanceof QName) { QName qname = (QName) value; if (StringUtils.isNotEmpty(qname.getNamespaceURI())) { return qname.getLocalPart() + " (in " + qname.getNamespaceURI() + ")"; } else { return qname.getLocalPart(); } } else { return "(a value of type " + value.getClass().getName() + ")"; // todo i18n } }
From source file:com.evolveum.midpoint.web.util.ExpressionUtil.java
public static List<String> getLiteralExpressionValues(ExpressionType expression) throws SchemaException { List<String> values = new ArrayList<>(); List<JAXBElement> elements = ExpressionUtil.findAllEvaluatorsByName(expression, SchemaConstantsGenerated.C_VALUE); if (elements != null) { for (JAXBElement element : elements) { if (element.getValue() instanceof RawType) { RawType raw = (RawType) element.getValue(); if (raw != null) { if (raw.getXnode() != null && raw.getXnode() instanceof PrimitiveXNode) { PrimitiveXNode valueNode = (PrimitiveXNode) raw.getXnode(); if (valueNode != null && valueNode.getValue() != null) { values.add(valueNode.getValue().toString()); } else if (valueNode.getValueParser() != null) { values.add(valueNode.getValueParser().getStringValue()); }//from w w w. j a v a 2s. c o m } else if (raw.getParsedRealValue(String.class) != null) { values.add(raw.getParsedRealValue(String.class)); } } } } } return values; }
From source file:fileMapper.ws.FileMapperServiceDriver.java
public static int processSecurityResult(String response) { int timeout = -1; try {//from w w w. j a v a 2s . c om JAXBElement jaxbElement = FileMapperJAXBUtil.getJAXBUtil().unMashallFromString(response); ResponseMessageType respMessageType = (ResponseMessageType) jaxbElement.getValue(); // Get response message status MessageHeaderType messageHeader = respMessageType.getMessageHeader(); if (messageHeader.getSecurity() != null && messageHeader.getSecurity().getPassword() != null && messageHeader.getSecurity().getPassword().getTokenMsTimeout() != null) { timeout = messageHeader.getSecurity().getPassword().getTokenMsTimeout().intValue(); } /*if (procStatus.equals("ERROR")) { log.error("Error reported by Ont web Service " + procMessage); } else if (procStatus.equals("WARNING")) { log.error("Warning reported by Ont web Service" + procMessage); }*/ } catch (JAXBUtilException e) { log.error(e.getMessage()); } return timeout; }
From source file:com.evolveum.midpoint.testing.model.client.sample.RunScript.java
private static <T> T unmarshalFile(File file) throws JAXBException, FileNotFoundException { JAXBContext jc = getJaxbContext(); Unmarshaller unmarshaller = jc.createUnmarshaller(); InputStream is = null;//from w ww .j a va2 s . c om JAXBElement<T> element = null; try { is = new FileInputStream(file); element = (JAXBElement<T>) unmarshaller.unmarshal(is); } finally { if (is != null) { IOUtils.closeQuietly(is); } } if (element == null) { return null; } return element.getValue(); }
From source file:com.evolveum.midpoint.web.util.ExpressionUtil.java
private static String serialize(JAXBElement<?> element, PrismContext prismContext) throws SchemaException { String xml;//from w w w.java2 s. c o m if (element.getValue() instanceof RawType) { RawType raw = (RawType) element.getValue(); RootXNode rootNode = new RootXNode(element.getName(), raw.serializeToXNode()); xml = prismContext.xmlSerializer().serialize(rootNode); } else { xml = prismContext.xmlSerializer().serialize(element); } return WebXmlUtil.stripNamespaceDeclarations(xml); }
From source file:com.evolveum.midpoint.model.client.ModelClientUtil.java
public static String getOrig(PolyStringType polyStringType) { if (polyStringType == null) { return null; }// w ww . j a v a 2 s.c o m StringBuilder sb = new StringBuilder(); for (Object o : polyStringType.getContent()) { if (o instanceof String) { sb.append(o); } else if (o instanceof Element) { Element e = (Element) o; if ("orig".equals(e.getLocalName())) { return e.getTextContent(); } } else if (o instanceof JAXBElement) { JAXBElement je = (JAXBElement) o; if ("orig".equals(je.getName().getLocalPart())) { return (String) je.getValue(); } } } return sb.toString(); }
From source file:com.evolveum.midpoint.web.util.ExpressionUtil.java
public static MapXNode getAssociationTargetSearchFilterValuesMap(ExpressionType expression) { if (expression == null) { return null; }/*from w ww . jav a2 s. c o m*/ JAXBElement element = ExpressionUtil.findFirstEvaluatorByName(expression, SchemaConstantsGenerated.C_ASSOCIATION_TARGET_SEARCH); if (element != null && element.getValue() != null && element.getValue() instanceof SearchObjectExpressionEvaluatorType) { SearchFilterType filter = ((SearchObjectExpressionEvaluatorType) element.getValue()).getFilter(); if (filter == null) { return null; } MapXNode filterValue = filter.getFilterClauseXNode(); return filterValue != null && filterValue.containsKey(new QName("equal")) ? (MapXNode) filterValue.get(new QName("equal")) : null; } return null; }
From source file:com.evolveum.midpoint.web.util.ExpressionUtil.java
public static void parseExpressionEvaluators(String xml, ExpressionType expressionObject, PrismContext context) throws SchemaException { expressionObject.getExpressionEvaluator().clear(); if (StringUtils.isNotBlank(xml)) { xml = WebXmlUtil.wrapInElement("expression", xml, true); LOGGER.info("Expression to serialize: {}", xml); JAXBElement<?> newElement = context.parserFor(xml).xml().parseRealValueToJaxbElement(); expressionObject.getExpressionEvaluator() .addAll(((ExpressionType) (newElement.getValue())).getExpressionEvaluator()); }//from w w w. jav a2 s . co m }
From source file:edu.harvard.i2b2.eclipse.plugins.workplace.ws.WorkplaceServiceDriver.java
public static int processSecurityResult(String response) { int timeout = -1; try {//from w w w .j a v a 2s .c o m JAXBElement jaxbElement = WorkplaceJAXBUtil.getJAXBUtil().unMashallFromString(response); ResponseMessageType respMessageType = (ResponseMessageType) jaxbElement.getValue(); // Get response message status MessageHeaderType messageHeader = respMessageType.getMessageHeader(); if (messageHeader.getSecurity() != null && messageHeader.getSecurity().getPassword() != null && messageHeader.getSecurity().getPassword().getTokenMsTimeout() != null) { timeout = messageHeader.getSecurity().getPassword().getTokenMsTimeout().intValue(); } /*if (procStatus.equals("ERROR")) { log.error("Error reported by Ont web Service " + procMessage); } else if (procStatus.equals("WARNING")) { log.error("Warning reported by Ont web Service" + procMessage); }*/ } catch (JAXBUtilException e) { log.error(e.getMessage()); } return timeout; }