@SuppressWarnings("unchecked") public Throwable transform(Throwable source, TransformationContext context) { DataType<DataType> sourceType = context.getSourceDataType(); DataType<DataType> targetType = context.getTargetDataType(); Object sourceFaultInfo = faultExceptionMapper.getFaultInfo(source, sourceType.getLogical().getPhysical(), context.getSourceOperation()); Object targetFaultInfo = mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); Throwable targetException = faultExceptionMapper.wrapFaultInfo(targetType, source.getMessage(), targetFaultInfo, source.getCause(), context.getTargetOperation()); // FIXME return targetException == null ? source : targetException; }
@SuppressWarnings("unchecked") public Object transform(Object source, TransformationContext context) { DataType<DataType> sourceType = context.getSourceDataType(); DataType<DataType> targetType = context.getTargetDataType(); return mediator.mediate(source, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); }
public Object transform(String source, TransformationContext context) { try { Class<?> type = null; if (context != null && context.getTargetDataType() != null) { type = context.getTargetDataType().getPhysical(); } return JSONHelper.toJSON(source, type); } catch (Exception e) { throw new TransformationException(e); } }
public Object transform(T source, TransformationContext context) { XMLType xmlType = (XMLType)context.getSourceDataType().getLogical(); QName type = (xmlType != null) ? xmlType.getTypeName() : null; if (type == null) { xmlType = (XMLType)context.getTargetDataType().getLogical(); type = (xmlType != null) ? xmlType.getTypeName() : null; } Object result = mapper.toJavaObject(type, getText(source), context); close(source); return result; }
public String transform(Object source, TransformationContext tContext) { try { JAXBContext context = contextHelper.createJAXBContext(tContext, true); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source); Marshaller marshaller = contextHelper.getMarshaller(context); try { marshaller.marshal(jaxbElement, result); } finally { contextHelper.releaseJAXBMarshaller(context, marshaller); } return writer.toString(); } catch (Exception e) { throw new TransformationException(e); } }
(NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null); return printQName((QName)obj, namespaceContext);
@SuppressWarnings("unchecked") public Object transform(Object source, TransformationContext context) { DataType<DataType> sourceType = context.getSourceDataType(); DataType<DataType> targetType = context.getTargetDataType(); return mediator.mediate(source, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); }
public Object transform(XMLStreamReader source, TransformationContext context) { try { StringWriter writer = new StringWriter(); XMLStreamWriter jsonWriter = new BadgerFishXMLStreamWriter(writer); staxHelper.save(source, jsonWriter); source.close(); Class type = null; if (context != null && context.getTargetDataType() != null) { type = context.getTargetDataType().getPhysical(); } return JSONHelper.toJSON(writer.toString(), type); } catch (Exception e) { throw new TransformationException(e); } }
public Object transform(T source, TransformationContext context) { XMLType xmlType = (XMLType)context.getSourceDataType().getLogical(); QName type = (xmlType != null) ? xmlType.getTypeName() : null; if (type == null) { xmlType = (XMLType)context.getTargetDataType().getLogical(); type = (xmlType != null) ? xmlType.getTypeName() : null; } Object result = mapper.toJavaObject(type, getText(source), context); close(source); return result; }
public String transform(Object source, TransformationContext tContext) { try { JAXBContext context = contextHelper.createJAXBContext(tContext, true); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source); Marshaller marshaller = contextHelper.getMarshaller(context); try { marshaller.marshal(jaxbElement, result); } finally { contextHelper.releaseJAXBMarshaller(context, marshaller); } return writer.toString(); } catch (Exception e) { throw new TransformationException(e); } }
} else if (type.equals(XSD_QNAME)) { NamespaceContext namespaceContext = (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null); return parseQName(value, namespaceContext); } else if (type.equals(XSD_NOTATION)) { NamespaceContext namespaceContext = (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null); return parseQName(value, namespaceContext); } else if (type.equals(XSD_YEAR)) {
@SuppressWarnings("unchecked") public Throwable transform(Throwable source, TransformationContext context) { DataType<DataType> sourceType = context.getSourceDataType(); DataType<DataType> targetType = context.getTargetDataType(); Object sourceFaultInfo = faultExceptionMapper.getFaultInfo(source, sourceType.getLogical().getPhysical(), context.getSourceOperation()); Object targetFaultInfo = mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); Throwable targetException = faultExceptionMapper.wrapFaultInfo(targetType, source.getMessage(), targetFaultInfo, source.getCause(), context.getTargetOperation()); // FIXME return targetException == null ? source : targetException; }
@SuppressWarnings("unchecked") public Object transform(Object array, TransformationContext context) { try { if (array == null) { return null; } DataType<DataType> sourceType = context.getSourceDataType(); DataType<DataType> targetType = context.getTargetDataType(); int length = Array.getLength(array); Object targetArray = Array.newInstance(targetType.getPhysical().getComponentType(), length); for (int i = 0; i < length; i++) { Object sourceItem = Array.get(array, i); Object targetItem = mediator.mediate(sourceItem, sourceType.getLogical(), targetType.getLogical(), context .getMetadata()); Array.set(targetArray, i, targetItem); } return targetArray; } catch (Exception e) { throw new TransformationException(e); } }
public Object transform(Object source, TransformationContext context) { if (source == null) { return null; } try { Class<?> cls = context.getTargetDataType().getPhysical(); ObjectMapper mapper = JacksonHelper.createObjectMapper(cls); JavaType javaType = mapper.constructType(context.getTargetDataType().getGenericType()); if (source instanceof String) { String sourceString = (String) source; if(sourceString.isEmpty()) { return sourceString; } else { return mapper.readValue((String)source, javaType); } } else if (source instanceof JsonNode) { return mapper.readValue((JsonNode)source, javaType); } else if (source instanceof JsonParser) { return mapper.readValue((JsonParser)source, javaType); } else { return mapper.readValue(source.toString(), javaType); } } catch (Exception e) { throw new TransformationException(e); } }
public Object transform(T source, TransformationContext context) { //FIXME why is the logical type sometimes a Class instead of an XMLType? if (context.getSourceDataType().getLogical() instanceof XMLType) { XMLType xmlType = (XMLType) context.getSourceDataType().getLogical(); return toJavaObject(xmlType.getTypeName(), getRootElement(source), context); } else { return toJavaObject(null, getRootElement(source), context); } }
} else if (type.equals(XSD_QNAME)) { NamespaceContext namespaceContext = (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null); return parseQName(value, namespaceContext); } else if (type.equals(XSD_NOTATION)) { NamespaceContext namespaceContext = (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null); return parseQName(value, namespaceContext); } else if (type.equals(XSD_YEAR)) {
public JAXBContext createJAXBContext(TransformationContext tContext, boolean source) throws JAXBException { if (tContext == null) throw new TransformationException("JAXB context is not set for the transformation."); // TODO: [rfeng] Need to figure out what's the best granularity to create the JAXBContext // per interface, operation or parameter Operation op = source ? tContext.getSourceOperation() : tContext.getTargetOperation(); if (op != null) { synchronized (op) { JAXBContext context = op.getInputType().getMetaData(JAXBContext.class); if (context == null) { context = createJAXBContext(getDataTypes(op, true)); op.getInputType().setMetaData(JAXBContext.class, context); } return context; } } // For property transformation, the operation can be null DataType<?> dataType = source ? tContext.getSourceDataType() : tContext.getTargetDataType(); return createJAXBContext(dataType); }
@SuppressWarnings("unchecked") public Object transform(Object array, TransformationContext context) { try { if (array == null) { return null; } DataType<DataType> sourceType = context.getSourceDataType(); DataType<DataType> targetType = context.getTargetDataType(); int length = Array.getLength(array); Object targetArray = Array.newInstance(targetType.getPhysical().getComponentType(), length); for (int i = 0; i < length; i++) { Object sourceItem = Array.get(array, i); Object targetItem = mediator.mediate(sourceItem, sourceType.getLogical(), targetType.getLogical(), context .getMetadata()); Array.set(targetArray, i, targetItem); } return targetArray; } catch (Exception e) { throw new TransformationException(e); } }
public Object transform(final String source, final TransformationContext context) { if (source == null) { return null; } try { JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false); StreamSource streamSource = new StreamSource(new StringReader(source)); Unmarshaller unmarshaller = contextHelper.getUnmarshaller(jaxbContext); try { Object result = unmarshaller.unmarshal(streamSource, JAXBContextHelper.getJavaType(context.getTargetDataType())); return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result); } finally { contextHelper.releaseJAXBUnmarshaller(jaxbContext, unmarshaller); } } catch (Exception e) { throw new TransformationException(e); } }
public Object transform(T source, TransformationContext context) { //FIXME why is the logical type sometimes a Class instead of an XMLType? if (context.getSourceDataType().getLogical() instanceof XMLType) { XMLType xmlType = (XMLType) context.getSourceDataType().getLogical(); return toJavaObject(xmlType.getTypeName(), getRootElement(source), context); } else { return toJavaObject(null, getRootElement(source), context); } }