jaxb-visitor icon indicating copy to clipboard operation
jaxb-visitor copied to clipboard

Limit Visitor to a Particaular type

Open bghost4 opened this issue 6 years ago • 5 comments

is there a way to limit the visitor to a particular type? I saw an IncludeType command line arg, but that doesn't take any arguments itself.

For example if you had something that contained a list of substitutionGroup it would be nice to have the visitor work on just that substitution group. not for every type in the schema.

bghost4 avatar Mar 09 '18 15:03 bghost4

After looking through the code base, I'd like to add some more info. possibly just add visitors for SubstuituionGroups or Choice.

The work you have done on this is awesome. Keep up the good work.

bghost4 avatar Mar 09 '18 17:03 bghost4

I think the includeType was a patch because some schemas have a massive amount of methods and in one case a user reported a problem with too many overloaded methods all named "visit". This param will instead generate methods with the prefix of visit plus the type name.

If you provide a test case for the substitution groups then I could have a look. I need to better understand the requirement. Perhaps specifying a filter via xpath or similar might work.

massfords avatar Mar 17 '18 00:03 massfords

Revisiting this after updating the code a little.

The current behavior is to generate a single Visitor interface with a visit method for each concrete bean.

I can see adding some options to the plugin to further restrict the classes that we visit (and also traverse). I believe this could be done by simply filtering the outline that the plugin is given to remove any classes that we discover that shouldn't be included.

I'm not sure how this filter would be expressed. If the schemas are large or external like the OGC schemas then it's possible that there isn't a naming convention so a filter based on the fully qualified name isn't suitable.

The OGC schemas also aren't well suited to this use case since their schemas result in a generic class for operations like BinaryComparisonOpType that has a property indicating the type of the operation. This repeats for other types in that schema as well. This isn't as useful as having top level classes to visit for separate operation types since each visit implementation effectively has to test the operation name to know what to do.

I think with a cleaner set of schemas, it could be possible to have the filter include only concrete types that are referenced from some base type via an XmlSeeAlso or similar. It's also worth considering if this option emits multiple visitors, one for each group of related types.

massfords avatar Jul 27 '22 17:07 massfords

I've implemented this in a local copy; I added -Xvisitor-subtypesOf-exact:... and -XVisitor-subtypesOf:.... Both can be repeated and will match on types whose name (partially) match any of the provided value, or that of any of the types they inherit/implement. Just some food for thought; I can share the implementation if interested.

Warpten avatar Jul 13 '23 09:07 Warpten

@Warpten feel free to create a PR or drop a link to your implementation.

massfords avatar Jul 22 '23 19:07 massfords