public Object convertInbound(Class<?> typeInfo, InboundVariable data) throws ConversionException { try { return getConverter().convertInbound(typeInfo, data); } catch (ClassCastException e) { throw new ConversionException(type, e); } }
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws ConversionException { try { return getConverter().convertOutbound(type.cast(data), outctx); } catch (ClassCastException e) { throw new ConversionException(type, e); } }
private Converter getConverter() { Converter converter = provider.get(); if (calledSetConverterManager.compareAndSet(false, true)) { converter.setConverterManager(converterManager); } return converter; }
public void addConverter(Class<?> clazz, Converter converter) { // Check that we don't have this one already Converter other = convertersByClass.get(clazz); if (other != null) { Loggers.STARTUP.warn("Clash of converters for " + clazz.getName() + ". Using " + converter.getClass().getName() + " in place of " + other.getClass().getName()); } Loggers.STARTUP.debug("- adding converter: " + converter.getClass().getSimpleName() + " for " + clazz.getName()); converter.setConverterManager(this); if (converter instanceof NamedConverter) { NamedConverter namedConverter = (NamedConverter) converter; setUpClassMapping(namedConverter, clazz); } convertersByClass.put(clazz, converter); converterCache.clear(); }
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); }
converted = converter.convertInbound(paramType, data); context.popContext();
public void addConverter(String match, String type, @SuppressWarnings("rawtypes") Map params) throws IllegalArgumentException, InstantiationException, IllegalAccessException { Class<Converter> clazz = converterTypes.get(type); if (clazz == null) { log.info("Probably not an issue: " + match + " is not available so the " + type + " converter will not load. This is only an problem if you wanted to use it."); return; } //TODO fix this by modifying the ma-priv code, but until we have a good copy this is my plan! // String js = match.substring(match.lastIndexOf(".")+1); // params.put("javascript", js); Converter converter = clazz.newInstance(); converter.setConverterManager(this); LocalUtil.setParams(converter, params, ignore); // add the converter for the specified match addConverter(match, converter); }
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 Object convertInbound(@SuppressWarnings("rawtypes") Class paramType, InboundVariable iv, InboundContext inctx, TypeHintContext incc) throws MarshallException { Object converted = inctx.getConverted(iv, paramType); if (converted == null) { // Was the inbound variable marshalled as an Object in the client // (could mean that this is an instance of one of our generated // JavaScript classes) Converter converter = getNamedConverter(paramType, iv.getType()); // Fall back to the standard way of locating a converter if we // didn't find anything above if (converter == null) { converter = getConverter(paramType); } if (converter == null) { throw new MarshallException(paramType, Messages.getString("DefaultConverterManager.MissingConverter", paramType)); } // We only think about doing a null conversion ourselves once we are // sure that there is a converter available. This prevents hackers // from passing null to things they are not allowed to convert if (iv.isNull()) { return null; } inctx.pushContext(incc); converted = converter.convertInbound(paramType, iv, inctx); inctx.popContext(); } return converted; }
converter.setConverterManager(this);