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); } }
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); } }
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); } }
/** * @see org.apache.tuscany.sca.databinding.PushTransformer#transform(java.lang.Object, java.lang.Object, org.apache.tuscany.sca.databinding.TransformationContext) */ public void transform(Object source, ContentHandler target, TransformationContext tContext) { try { JAXBContext context = contextHelper.createJAXBContext(tContext, true); Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source); Marshaller marshaller = contextHelper.getMarshaller(context); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); try { marshaller.marshal(jaxbElement, target); } finally { contextHelper.releaseJAXBMarshaller(context, marshaller); } } catch (Exception e) { throw new TransformationException(e); } }
/** * @see org.apache.tuscany.sca.databinding.PushTransformer#transform(java.lang.Object, java.lang.Object, org.apache.tuscany.sca.databinding.TransformationContext) */ public void transform(Object source, OutputStream target, TransformationContext tContext) { try { JAXBContext context = contextHelper.createJAXBContext(tContext, true); Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source); Marshaller marshaller = contextHelper.getMarshaller(context); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); try { marshaller.marshal(jaxbElement, target); } finally { contextHelper.releaseJAXBMarshaller(context, marshaller); } } 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); } }
@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); } }
/** * @see org.apache.tuscany.sca.databinding.PushTransformer#transform(java.lang.Object, java.lang.Object, org.apache.tuscany.sca.databinding.TransformationContext) */ public void transform(Object source, ContentHandler target, TransformationContext tContext) { try { JAXBContext context = contextHelper.createJAXBContext(tContext, true); Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source); Marshaller marshaller = contextHelper.getMarshaller(context); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); try { marshaller.marshal(jaxbElement, target); } finally { contextHelper.releaseJAXBMarshaller(context, marshaller); } } catch (Exception e) { throw new TransformationException(e); } }
/** * @see org.apache.tuscany.sca.databinding.PushTransformer#transform(java.lang.Object, java.lang.Object, org.apache.tuscany.sca.databinding.TransformationContext) */ public void transform(Object source, OutputStream target, TransformationContext tContext) { try { JAXBContext context = contextHelper.createJAXBContext(tContext, true); Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source); Marshaller marshaller = contextHelper.getMarshaller(context); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); try { marshaller.marshal(jaxbElement, target); } finally { contextHelper.releaseJAXBMarshaller(context, marshaller); } } catch (Exception e) { throw new TransformationException(e); } }
@SuppressWarnings("unchecked") public Map transform(Map sourceMap, TransformationContext context) { try { if (sourceMap == null) { return null; } DataType<DataType> sourceType = context.getSourceDataType(); DataType<DataType> targetType = context.getTargetDataType(); Map targetMap = createMap(targetType.getPhysical()); for (Object sourceItem : sourceMap.entrySet()) { Map.Entry entry = (Map.Entry)sourceItem; Object targetValue = mediator.mediate(entry.getValue(), sourceType.getLogical(), targetType.getLogical(), context .getMetadata()); targetMap.put(entry.getKey(), targetValue); } return targetMap; } catch (Exception e) { throw new TransformationException(e); } }
public XMLStreamReader transform(Object source, TransformationContext context) { try { javax.xml.namespace.QName name = null; if (context != null) { Object logical = context.getSourceDataType().getLogical(); if (logical instanceof XMLType) { name = ((XMLType)logical).getElementName(); } } return new BeanXMLStreamReaderImpl(name, source); } catch (Exception e) { throw new TransformationException(e); } }
public XMLStreamReader transform(Object source, TransformationContext context) { try { javax.xml.namespace.QName name = null; if (context != null) { Object logical = context.getSourceDataType().getLogical(); if (logical instanceof XMLType) { name = ((XMLType)logical).getElementName(); } } return new BeanXMLStreamReaderImpl(name, source); } catch (Exception e) { throw new TransformationException(e); } }
@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()); }
@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; }
@SuppressWarnings("unchecked") public Collection transform(Collection sourceCollection, TransformationContext context) { try { if (sourceCollection == null) { return null; } DataType<DataType> sourceType = context.getSourceDataType(); DataType<DataType> targetType = context.getTargetDataType(); Collection targetCollection = createCollection(targetType.getPhysical()); for (Object sourceItem : sourceCollection) { Object targetItem = mediator.mediate(sourceItem, sourceType.getLogical(), targetType.getLogical(), context .getMetadata()); targetCollection.add(targetItem); } return targetCollection; } 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 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); }