Re: [Simple-support] Limiting CycleStrategy to affect only objects of a certain type
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2008-02-12 18:21:22
|
Hi,
Yes you can, I use a filter like pattern to do this.
For example if you wrote the following.
public class AttributeModifier implements Strategy {
private Strategy strategy;
public AttributeModifier(Strategy strategy) {
this.strategy = strategy;
}
// remainder here...
public boolean setElement(Class field, Object
value, NodeMap node, Map map) throws Exception;
boolean result = strategy.setElement(field,
value, node, map);
Node node = node.remove("id");
if(MyClass.class.isInstance(value)) {
node.put(node.getValue());
}
return result;
}
}
Here you can just pass this strategy in to the
persister instead of directly using the CycleStrategy.
This will remove "id" from all by your desirec
classes. Here in this example I assume MyClass.class
is the only class with which "id" attributes are used.
If you really want limited "id" attributes you could
serialize twice, once to collect "id" and "reference"
labels the second time to ensure if a "reference" did
not exist for the "id" then the "id" is removed. A
simple HashMap could do this, but it would require you
to extend the Persister object, to capture the
reference cycles before the second serialization to
right only limited "id" and references.
Niall
--- Stanislaw Osinski <sta...@ca...>
wrote:
> Hi again,
>
> One more question: is there any simple way of having
> CycleStrategy append id
> attributes/ resolve references only for objects of
> certain (known at
> compilation time) type(s)? The general motivation is
> that the produced XML
> is intended to be read/ modified by humans, so I'd
> like to avoid polluting
> it with id attributes for object that do not need
> reference resolution.
>
> Cheers,
>
> Staszek
> >
-------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio
> 2008.
>
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/>
_______________________________________________
> Simple-support mailing list
> Sim...@li...
>
https://lists.sourceforge.net/lists/listinfo/simple-support
>
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
|