/** * If outline then we need a variable so we can be referred to */ protected String getVariableName() { if (varName == null) { varName = context.getNextVariableName(); } return varName; }
/** * Is there something (like JSON mode) that forces us to inline or maybe we * are referred to by multiple other things */ protected boolean isInline() { return context.isJsonMode() || !referenced; }
@Override public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException { final QName name = (QName) data; // // Where we collect out converted children final Map<String, OutboundVariable> ovs = new TreeMap<String, OutboundVariable>(); // We need to do this before collecing the children to save recurrsion final ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx); outctx.put(data, ov); if (!StringUtils.isEmpty(name.getNamespaceURI())) { ovs.put("namespaceURI", getConverterManager() //$NON-NLS-1$ .convertOutbound(name.getNamespaceURI(), outctx)); } ovs.put("localPart", getConverterManager().convertOutbound(name.getLocalPart(), outctx)); //$NON-NLS-1$ if (!StringUtils.isEmpty(name.getPrefix())) { ovs.put("prefix", getConverterManager().convertOutbound(name.getPrefix(), outctx)); //$NON-NLS-1$ } ov.init(ovs, null); return ov; }
public OutboundVariable convertOutbound(Object data, OutboundContext converted) throws ConversionException { if (data == null) { return new NonNestedOutboundVariable("null"); } // Check to see if we have done this one already if (!converted.isJsonMode()) { OutboundVariable ov = converted.get(data); if (ov != null) { // So the object as been converted already, we just need to refer to it. return ov.getReferenceVariable(); } } // So we will have to do the conversion Converter converter = getConverter(data); if (converter == null) { String message = "No outbound converter found for '" + data.getClass().getName() + "'"; log.error(message); return new ErrorOutboundVariable(message); } return converter.convertOutbound(data, converted); }
public OutboundVariable convertOutbound(Object object, OutboundContext outctx) throws MarshallException { if (object == null) { return new SimpleOutboundVariable("null", outctx, true); } // Check to see if we have done this one already OutboundVariable ov = outctx.get(object); if (ov != null) { // So the object as been converted already, we just need to refer to it. return ov.getReferenceVariable(); } // So we will have to do the conversion Converter converter = getConverter(object); if (converter == null) { log.error(Messages.getString("DefaultConverterManager.MissingConverter", object.getClass().getName())); return new SimpleOutboundVariable("null", outctx, true); } return converter.convertOutbound(object, outctx); }
OutboundContext context = new OutboundContext(jsonOutput); List<OutboundVariable> scriptParts = new ArrayList<OutboundVariable>(); boolean outboundError = false;
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws ConversionException { if (!data.getClass().isArray()) { throw new ConversionException(data.getClass()); } ArrayOutboundVariable ov = new ArrayOutboundVariable(outctx); outctx.put(data, ov); // Convert all the data members int size = Array.getLength(data); List<OutboundVariable> ovs = new ArrayList<OutboundVariable>(); for (int i = 0; i < size; i++) { OutboundVariable nested; try { nested = converterManager.convertOutbound(Array.get(data, i), outctx); } catch (Exception ex) { String errorMessage = "Conversion error for " + data.getClass().getName() + "."; log.warn(errorMessage, ex); nested = new ErrorOutboundVariable(errorMessage); } ovs.add(nested); } // Group the list of converted objects into this OutboundVariable ov.setChildren(ovs); return ov; }
@Override public OutboundVariable convertOutbound(Object paramObject, OutboundContext paramOutboundContext) throws MarshallException { //Convert from Unit to String // Check to see if we have done this one already OutboundVariable ov = paramOutboundContext.get(paramObject); if (ov != null) { // So the object as been converted already, we just need to refer to it. return ov.getReferenceVariable(); } if(paramObject instanceof Unit<?>){ Unit<?> unit = (Unit<?>)paramObject; String unitString = UnitUtil.formatLocal(unit); if(unit == unit.ONE) unitString = "ONE"; return new SimpleOutboundVariable("'" + unitString + "';",paramOutboundContext,false); }else{ throw new MarshallException(paramObject.getClass()); } }
outctx.put(data, ov);
/** * Are we in JSON mode, and therefore must quote property names? */ public boolean isJsonMode() { return context.isJsonMode(); }
outctx.put(data, ov);
/** * Constructor for when we have a Javascript type to populate */ public ObjectOutboundVariable(OutboundContext context, Class<?> type, String scriptClassName) { super(context); if (context.isJsonMode()) { if (scriptClassName != null) { throw new JsonModeMarshallException(type, "Can't used named Javascript objects in JSON mode"); } } this.scriptClassName = scriptClassName; this.isNamed = scriptClassName != null && scriptClassName.length() > 0; }
@Override public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException { final JAXBElement<?> element = (JAXBElement<?>) data; // // Where we collect out converted children final Map<String, OutboundVariable> ovs = new TreeMap<String, OutboundVariable>(); // We need to do this before collecing the children to save recurrsion final ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx); outctx.put(data, ov); ovs.put("name", getConverterManager().convertOutbound(element.getName(), outctx)); //$NON-NLS-1$ ovs.put("value", getConverterManager().convertOutbound(element.getValue(), outctx)); //$NON-NLS-1$ ov.init(ovs, null); return ov; }
outctx.put(data, ov);
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws ConversionException { // Where we collect out converted children Map<String, OutboundVariable> ovs = new TreeMap<String, OutboundVariable>(); // We need to do this before collecting the children to save recursion ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx, data.getClass(), getJavascript()); outctx.put(data, ov); try { Map<String, Property> properties = getPropertyMapFromObject(data, true, false); for (Entry<String, Property> entry : properties.entrySet()) { String name = entry.getKey(); Property property = entry.getValue(); Object value = property.getValue(data); OutboundVariable nested = getConverterManager().convertOutbound(value, outctx); ovs.put(name, nested); } } catch (ConversionException ex) { throw ex; } catch (Exception ex) { throw new ConversionException(data.getClass(), ex); } ov.setChildren(ovs); return ov; }
outctx.put(data, ov);
outctx.put(data, ov);
@Override public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException { @SuppressWarnings("unchecked") final G coordinateInfo = (G) data; final C coordinates = createCoordinates(coordinateInfo); // // Where we collect out converted children final Map<String, OutboundVariable> ovs = new TreeMap<String, OutboundVariable>(); // We need to do this before collecing the children to save recurrsion final ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx); outctx.put(data, ov); ovs.put("type", getConverterManager().convertOutbound(getGeometryType(), outctx)); //$NON-NLS-1$ ovs.put("coordinates", getConverterManager().convertOutbound(coordinates, outctx)); //$NON-NLS-1$ ov.init(ovs, null); return ov; } // @Override
@Override public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException { @SuppressWarnings("unchecked") final G coordinateInfo = (G) data; final C coordinates = createCoordinates(coordinateInfo); // // Where we collect out converted children final Map<String, OutboundVariable> ovs = new TreeMap<String, OutboundVariable>(); // We need to do this before collecing the children to save recurrsion final ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx); outctx.put(data, ov); ovs.put("type", getConverterManager().convertOutbound(getGeometryType(), outctx)); //$NON-NLS-1$ ovs.put("coordinates", getConverterManager().convertOutbound(coordinates, outctx)); //$NON-NLS-1$ ov.init(ovs, null); return ov; }
outctx.put(data, ov);