use of org.directwebremoting.extend.Converter in project ma-core-public by infiniteautomation.
the class BlabberConverterManager method getConverter.
/**
* @param paramType
* The type to find a converter for
* @return The converter for the given type, or null if one can't be found
*/
public Converter getConverter(Class<?> paramType) {
// Can we find a converter assignable to paramType in the HashMap?
Converter converter = getConverterAssignableFrom(paramType);
if (converter != null) {
return converter;
}
String lookup = paramType.getName();
// dynamic proxies
if (lookup.startsWith("$Proxy")) {
converter = converters.get("$Proxy*");
if (converter != null) {
return converter;
}
}
while (true) {
// Can we find a converter using wildcards?
converter = converters.get(lookup + ".*");
if (converter != null) {
return converter;
}
// Arrays can have wildcards like [L* so we don't require a '.'
converter = converters.get(lookup + '*');
if (converter != null) {
return converter;
}
// Give up if the name is now empty
if (lookup.length() == 0) {
break;
}
// Strip of the component after the last .
int lastdot = lookup.lastIndexOf('.');
if (lastdot != -1) {
lookup = lookup.substring(0, lastdot);
} else {
int arrayMarkers = 0;
while (lookup.charAt(arrayMarkers) == '[') {
arrayMarkers++;
}
if (arrayMarkers == 0) {
// bail out.
break;
}
// We want to keep the type marker too
lookup = lookup.substring(arrayMarkers - 1, arrayMarkers + 1);
// Now can we find it?
converter = converters.get(lookup);
if (converter != null) {
return converter;
}
}
}
return null;
}
use of org.directwebremoting.extend.Converter in project ma-core-public by infiniteautomation.
the class BlabberConverterManager method addConverter.
/*
* (non-Javadoc)
*
* @see org.directwebremoting.ConverterManager#addConverter(java.lang.String, org.directwebremoting.Converter)
*/
public void addConverter(String match, Converter converter) throws IllegalArgumentException {
// Check that we don't have this one already
Converter other = converters.get(match);
if (other != null) {
log.warn("Clash of converters for " + match + ". Using " + converter.getClass().getName() + " in place of " + other.getClass().getName());
}
log.debug("- adding converter: " + LocalUtil.getShortClassName(converter.getClass()) + " for " + match);
converters.put(match, converter);
}
use of org.directwebremoting.extend.Converter in project ma-core-public by infiniteautomation.
the class DefaultConverterManager method getNamedConverter.
/**
* When we are using typed Javascript names we sometimes want to get a
* specially named converter
* @param paramType The class that we are converting to
* @param type The type name as passed in from the client
* @return The Converter that matches this request (if any)
* @throws MarshallException
*/
protected Converter getNamedConverter(Class paramType, String type) throws MarshallException {
if (type.startsWith("Object_")) {
// Extract the JavaScript classname from the inbound type
String javascriptClassName = type.substring("Object_".length());
// Locate a converter for this JavaScript classname
synchronized (converters) {
Iterator it = converters.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String match = (String) entry.getKey();
Converter conv = (Converter) entry.getValue();
// JavaScript mapping is only applicable for compound converters
if (conv instanceof NamedConverter) {
NamedConverter boConv = (NamedConverter) conv;
if (boConv.getJavascript() != null && boConv.getJavascript().equals(javascriptClassName)) {
// parameter type?
try {
Class inboundClass = LocalUtil.classForName(match);
if (paramType.isAssignableFrom(inboundClass)) {
// Hack: We also want to make sure that the
// converter creates its object based on the
// inbound class instead of the parameter
// type, and we have to use the other ref
// for this:
boConv.setInstanceType(inboundClass);
return boConv;
}
} catch (ClassNotFoundException ex) {
throw new MarshallException(paramType, ex);
}
}
}
}
}
}
return null;
}
use of org.directwebremoting.extend.Converter in project ma-core-public by infiniteautomation.
the class DefaultConverterManager method getConverter.
/**
* @param paramType The type to find a converter for
* @return The converter for the given type, or null if one can't be found
*/
private Converter getConverter(Class paramType) {
// Can we find a converter assignable to paramType in the HashMap?
Converter converter = getConverterAssignableFrom(paramType);
if (converter != null) {
return converter;
}
String lookup = paramType.getName();
// dynamic proxies
if (lookup.startsWith("$Proxy")) {
converter = (Converter) converters.get("$Proxy*");
if (converter != null) {
return converter;
}
}
while (true) {
// Can we find a converter using wildcards?
converter = (Converter) converters.get(lookup + ".*");
if (converter != null) {
return converter;
}
// Arrays can have wildcards like [L* so we don't require a '.'
converter = (Converter) converters.get(lookup + '*');
if (converter != null) {
return converter;
}
// Give up if the name is now empty
if (lookup.length() == 0) {
break;
}
// Strip of the component after the last .
int lastdot = lookup.lastIndexOf('.');
if (lastdot != -1) {
lookup = lookup.substring(0, lastdot);
} else {
int arrayMarkers = 0;
while (lookup.charAt(arrayMarkers) == '[') {
arrayMarkers++;
}
if (arrayMarkers == 0) {
// bail out.
break;
}
// We want to keep the type marker too
lookup = lookup.substring(arrayMarkers - 1, arrayMarkers + 1);
// Now can we find it?
converter = (Converter) converters.get(lookup);
if (converter != null) {
return converter;
}
}
}
return null;
}
use of org.directwebremoting.extend.Converter in project ma-core-public by infiniteautomation.
the class DefaultConverterManager method getConverterAssignableFrom.
/**
* @param paramType The type to find a converter for
* @return The converter assignable for the given type, or null if one can't be found
*/
private Converter getConverterAssignableFrom(Class paramType) {
if (paramType == null) {
return null;
}
String lookup = paramType.getName();
// Can we find the converter for paramType in the converters HashMap?
Converter converter = null;
synchronized (this.converters) {
converter = (Converter) converters.get(lookup);
if (converter != null) {
return converter;
}
// Lookup all of the interfaces of this class for a match
Class[] interfaces = paramType.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
converter = getConverterAssignableFrom(interfaces[i]);
if (converter != null) {
converters.put(lookup, converter);
return converter;
}
}
// Let's search it in paramType superClass
converter = getConverterAssignableFrom(paramType.getSuperclass());
if (converter != null) {
converters.put(lookup, converter);
}
}
return converter;
}
Aggregations