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(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(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(final Reader source, final TransformationContext context) { if (source == null) { return null; } try { StreamSource streamSource = new StreamSource(source); JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false); 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(final InputStream source, final TransformationContext context) { if (source == null) { return null; } try { JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false); StreamSource streamSource = new StreamSource(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(final Reader source, final TransformationContext context) { if (source == null) { return null; } try { StreamSource streamSource = new StreamSource(source); JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false); 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); } }
/** * @param context * @param element */ public static void adjustElementName(TransformationContext context, OMElement element) { if (context != null) { DataType dataType = context.getTargetDataType(); Object logical = dataType == null ? null : dataType.getLogical(); if (!(logical instanceof XMLType)) { return; } XMLType xmlType = (XMLType)logical; if (xmlType.isElement() && !xmlType.getElementName().equals(element.getQName())) { // FIXME:: Throw exception or switch to the new Element? OMFactory factory = OMAbstractFactory.getOMFactory(); QName name = xmlType.getElementName(); OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); element.setNamespace(namespace); element.setLocalName(name.getLocalPart()); } } }
public T transform(Object source, TransformationContext context) { QName rootElement = null; if (context != null) { DataType<?> type = context.getTargetDataType(); if (type != null) { Object logical = type.getLogical(); if (logical instanceof XMLType) { rootElement = ((XMLType)logical).getElementName(); } } } //FIXME See how/if we still need to get the metadata here //QName rootElementName = (QName)context.getTargetDataType().getMetadata("RootElementName"); //if (rootElementName == null) { QName rootElementName = new QName(resolveRootElementName(source.getClass())); //} T root = createElement(rootElementName); appendChildElements(root, resolveElementName(source.getClass()), source.getClass(), source, context); return root; }
public T transform(Object source, TransformationContext context) { QName rootElement = null; if (context != null) { DataType<?> type = context.getTargetDataType(); if (type != null) { Object logical = type.getLogical(); if (logical instanceof XMLType) { rootElement = ((XMLType)logical).getElementName(); } } } //FIXME See how/if we still need to get the metadata here //QName rootElementName = (QName)context.getTargetDataType().getMetadata("RootElementName"); //if (rootElementName == null) { QName rootElementName = new QName(resolveRootElementName(source.getClass())); //} T root = createElement(rootElementName); appendChildElements(root, resolveElementName(source.getClass()), source.getClass(), source, context); return root; }
public T transform(Object source, TransformationContext context) { XMLType xmlType = (XMLType) context.getTargetDataType().getLogical(); String text = mapper.toXMLLiteral(xmlType.getTypeName(), source, context); return createElement(xmlType.getElementName(), text, context); }
@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()); }
@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 toJavaObject(QName xmlType, T xmlElement, TransformationContext context) { if (xmlType != null && mapper.isSimpleXSDType(xmlType)) { return mapper.toJavaObject(xmlType, getText(xmlElement), context); } else { Class<?> javaType = (Class<?>)context.getTargetDataType().getPhysical(); return createJavaObject(xmlElement, javaType, context); } }
public T transform(Object source, TransformationContext context) { XMLType xmlType = (XMLType) context.getTargetDataType().getLogical(); String text = mapper.toXMLLiteral(xmlType.getTypeName(), source, context); return createElement(xmlType.getElementName(), text, context); }
public Object toJavaObject(QName xmlType, T xmlElement, TransformationContext context) { if (xmlType != null && mapper.isSimpleXSDType(xmlType)) { return mapper.toJavaObject(xmlType, getText(xmlElement), context); } else { Class<?> javaType = (Class<?>)context.getTargetDataType().getPhysical(); return createJavaObject(xmlElement, javaType, context); } }
@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 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; }
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 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 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); }