use of org.directwebremoting.extend.ConverterManager in project ma-core-public by infiniteautomation.
the class AnnotationsConfigurator method processConvert.
/**
* Process the @DataTransferObject annotaion on a given class
* @param clazz The class annotated with @DataTransferObject
* @param convertAnn The annotation
* @param container The IoC container to configure
* @throws InstantiationException
* @throws IllegalAccessException
*/
private void processConvert(Class<?> clazz, DataTransferObject convertAnn, Container container) throws InstantiationException, IllegalAccessException {
Class<? extends Converter> converter = convertAnn.converter();
String converterClass = converter.getName();
Map<String, String> params = getParamsMap(convertAnn.params());
ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
String converterName = LocalUtil.replace(converterClass, ".", "_");
converterManager.addConverterType(converterName, converterClass);
if (BeanConverter.class.isAssignableFrom(converter)) {
StringBuilder properties = new StringBuilder();
Set<Field> fields = new HashSet<Field>();
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
fields.addAll(Arrays.asList(clazz.getFields()));
for (Field field : fields) {
if (field.getAnnotation(RemoteProperty.class) != null) {
properties.append(',').append(field.getName());
}
}
Method[] methods = clazz.getMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getAnnotation(RemoteProperty.class) != null) {
String name = methods[i].getName();
if (name.startsWith(METHOD_PREFIX_GET) || name.startsWith(METHOD_PREFIX_IS)) {
if (name.startsWith(METHOD_PREFIX_GET)) {
name = name.substring(3);
} else {
name = name.substring(2);
}
name = Introspector.decapitalize(name);
properties.append(',').append(name);
}
}
}
if (properties.length() > 0) {
properties.deleteCharAt(0);
params.put("include", properties.toString());
}
}
converterManager.addConverter(clazz.getName(), converterName, params);
}
use of org.directwebremoting.extend.ConverterManager in project ma-core-public by infiniteautomation.
the class SpringConfigurator method configure.
/* (non-Javadoc)
* @see org.directwebremoting.Configurator#configure(org.directwebremoting.Container)
*/
public void configure(Container container) {
AccessControl accessControl = (AccessControl) container.getBean(AccessControl.class.getName());
AjaxFilterManager ajaxFilterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
// Configure the creator types
if (creatorTypes != null) {
for (Iterator it = creatorTypes.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String typeName = (String) entry.getKey();
String className = (String) entry.getValue();
creatorManager.addCreatorType(typeName, className);
}
}
// Configure the converter types
if (converterTypes != null) {
for (Iterator it = converterTypes.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String typeName = (String) entry.getKey();
String className = (String) entry.getValue();
converterManager.addConverterType(typeName, className);
}
}
// Configure the creators
if (creators != null) {
try {
for (Iterator it = creators.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String scriptName = (String) entry.getKey();
CreatorConfig creatorConfig = (CreatorConfig) entry.getValue();
if (creatorConfig.getCreator() != null) {
Creator creator = creatorConfig.getCreator();
creatorManager.addCreator(scriptName, creator);
} else {
String creatorName = creatorConfig.getCreatorType();
Map params = creatorConfig.getParams();
creatorManager.addCreator(scriptName, creatorName, params);
}
List excludes = creatorConfig.getExcludes();
for (Iterator eit = excludes.iterator(); eit.hasNext(); ) {
String exclude = (String) eit.next();
accessControl.addExcludeRule(scriptName, exclude);
}
List includes = creatorConfig.getIncludes();
for (Iterator iit = includes.iterator(); iit.hasNext(); ) {
String include = (String) iit.next();
accessControl.addIncludeRule(scriptName, include);
}
Properties auth = creatorConfig.getAuth();
for (Iterator ait = auth.entrySet().iterator(); ait.hasNext(); ) {
Map.Entry aentry = (Map.Entry) ait.next();
String methodName = (String) aentry.getKey();
String role = (String) aentry.getValue();
accessControl.addRoleRestriction(scriptName, methodName, role);
}
List filters = creatorConfig.getFilters();
for (Iterator fit = filters.iterator(); fit.hasNext(); ) {
Object obj = fit.next();
if (obj instanceof String) {
String filterName = (String) obj;
AjaxFilter filter = (AjaxFilter) LocalUtil.classNewInstance(filterName, filterName, AjaxFilter.class);
if (filter != null) {
ajaxFilterManager.addAjaxFilter(filter, scriptName);
}
} else if (obj instanceof AjaxFilter) {
AjaxFilter filter = (AjaxFilter) obj;
ajaxFilterManager.addAjaxFilter(filter, scriptName);
} else {
throw new IllegalArgumentException(Messages.getString("SpringConfigurator.InvalidFilter", scriptName, obj));
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
throw new IllegalArgumentException(ex.toString());
}
}
// Configure the converters
if (converters != null) {
try {
for (Iterator it = converters.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String match = (String) entry.getKey();
ConverterConfig converterConfig = (ConverterConfig) entry.getValue();
Map params = converterConfig.getParams();
if (converterConfig.getIncludes().size() > 0) {
params.put("include", StringUtils.collectionToCommaDelimitedString(converterConfig.getIncludes()));
}
if (converterConfig.getExcludes().size() > 0) {
params.put("exclude", StringUtils.collectionToCommaDelimitedString(converterConfig.getExcludes()));
}
// params.put("force", Boolean.valueOf(converterConfig.isForce()));
if (StringUtils.hasText(converterConfig.getJavascriptClassName())) {
params.put("javascript", converterConfig.getJavascriptClassName());
}
converterManager.addConverter(match, converterConfig.getType(), params);
}
} catch (Exception ex) {
throw new IllegalArgumentException(Messages.getString("SpringConfigurator.ConfigureConverterError"));
}
}
// Configure the signatures
if (StringUtils.hasText(signatures)) {
SignatureParser sigp = new SignatureParser(converterManager, creatorManager);
sigp.parse(signatures);
}
}
use of org.directwebremoting.extend.ConverterManager in project ma-core-public by infiniteautomation.
the class DwrXmlConfigurator method configure.
/* (non-Javadoc)
* @see org.directwebremoting.Configurator#configure(org.directwebremoting.Container)
*/
public void configure(Container container) {
accessControl = (AccessControl) container.getBean(AccessControl.class.getName());
ajaxFilterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
Element root = document.getDocumentElement();
NodeList rootChildren = root.getChildNodes();
for (int i = 0; i < rootChildren.getLength(); i++) {
Node node = rootChildren.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element child = (Element) node;
if (child.getNodeName().equals(ELEMENT_INIT)) {
loadInits(child);
} else if (child.getNodeName().equals(ELEMENT_ALLOW)) {
loadAllows(child);
} else if (child.getNodeName().equals(ELEMENT_SIGNATURES)) {
loadSignature(child);
}
}
}
}
use of org.directwebremoting.extend.ConverterManager in project ma-core-public by infiniteautomation.
the class DwrConvertTag method doStartTag.
@Override
public int doStartTag() throws JspException {
ServletContext servletContext = pageContext.getServletContext();
Container container = (Container) servletContext.getAttribute("DwrContainer");
if (container == null)
throw new JspException("Can't find 'DwrContainer' in servlet context");
ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
final ScriptBuffer scriptBuffer = new ScriptBuffer();
scriptBuffer.appendScript("return ");
scriptBuffer.appendData(obj);
WebContextBuilder webContextBuilder = (WebContextBuilder) servletContext.getAttribute(WebContextBuilder.class.getName());
try {
webContextBuilder.set((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse(), null, servletContext, container);
JspWriter out = pageContext.getOut();
out.write("function() {");
out.write(ScriptBufferUtil.createOutput(scriptBuffer, converterManager));
out.write(";}()");
} catch (IOException e) {
throw new JspException("Error writing tag content", e);
} catch (MarshallException e) {
throw new JspException("Error marshalling object data", e);
} finally {
webContextBuilder.unset();
}
return EVAL_PAGE;
}
use of org.directwebremoting.extend.ConverterManager in project ma-core-public by infiniteautomation.
the class ContainerUtil method debugConfig.
/**
* Create a bunch of debug information about a container
* @param container The container to print debug information about
*/
public static void debugConfig(Container container) {
if (log.isDebugEnabled()) {
// Container level debug
log.debug("Container");
log.debug(" Type: " + container.getClass().getName());
Collection beanNames = container.getBeanNames();
for (Iterator it = beanNames.iterator(); it.hasNext(); ) {
String name = (String) it.next();
Object object = container.getBean(name);
if (object instanceof String) {
log.debug(" Param: " + name + " = " + object + " (" + object.getClass().getName() + ")");
} else {
log.debug(" Bean: " + name + " = " + object + " (" + object.getClass().getName() + ")");
}
}
// AccessControl debugging
AccessControl accessControl = (AccessControl) container.getBean(AccessControl.class.getName());
log.debug("AccessControl");
log.debug(" Type: " + accessControl.getClass().getName());
// AjaxFilterManager debugging
AjaxFilterManager ajaxFilterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
log.debug("AjaxFilterManager");
log.debug(" Type: " + ajaxFilterManager.getClass().getName());
// ConverterManager debugging
ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
log.debug("ConverterManager");
log.debug(" Type: " + converterManager.getClass().getName());
// CreatorManager debugging
CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
log.debug("CreatorManager");
log.debug(" Type: " + creatorManager.getClass().getName());
Collection creatorNames = creatorManager.getCreatorNames();
for (Iterator it = creatorNames.iterator(); it.hasNext(); ) {
String creatorName = (String) it.next();
Creator creator = creatorManager.getCreator(creatorName);
log.debug(" Creator: " + creatorName + " = " + creator + " (" + creator.getClass().getName() + ")");
}
}
}
Aggregations