commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maciek Kolesnik <mkoles...@gmail.com>
Subject [betwixt] serialization suppression in betwixt
Date Thu, 13 Oct 2005 20:37:18 GMT
 Hi,
 I recently downloaded v0.7 of the betwixt. The tool does really a great job
- highly customizable and easy to use.
I do have a suggestion for a small improvement though:
As far as I know currently it is impossible to intercept the process of
descending into the object graph by a custom code.
Changing signature of these 2 methods

writeElement(...) (2 signatures)

to protected would give me ability to suppress the descent into children
when contextually my code determines that it does not need to go any deeper
(optimization measure). Any other similar scheme where execution of
writeElement(...) can be conditionally prevented could do a job too i think.

Here is how I would like to use it:
protected void writeElement(String namespaceUri, String localName, String
qualifiedName, ElementDescriptor elementDescriptor, Context context) throws
IOException, SAXException, IntrospectionException {

String currentPath = (String) BeanSerializer.PATH.get();

try {

BeanSerializer.PATH.set(currentPath + "/" + localName);
  //filter the descriptor based on in-context filter spec - cached by spec
id

FilterSpec filterSpec = (FilterSpec)
CallContext.getCurrentContext().getAttribute(
FilterSpec.ATTR_XML_FILTER);

if (filterSpec != null
&& filterSpec.isSuppressed((String)BeanSerializer.PATH.get())) {
return;
}

super.writeElement(namespaceUri, localName, qualifiedName,
elementDescriptor,
context);
  } finally {
BeanSerializer.PATH.set(currentPath);
}
}
  MyBeanSerializer.PATH is a ThreadLocal string that specifies current path
(like /A/B/C/D) and my isSuppressed method compares current path with a list
of paths to-be-suppressed.

Regards,
Maciek

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message