Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheritance Plugin Question #513

Open
SebasHein opened this issue Feb 27, 2024 · 6 comments
Open

Inheritance Plugin Question #513

SebasHein opened this issue Feb 27, 2024 · 6 comments
Labels
question xjc-plugins Issue concerns basics plugins

Comments

@SebasHein
Copy link

I try to let two generated classes implement their own interface.
Example
Class A should implement IA
Class B should implement IB

This is working so far (wiht XInheritance plugin) as long as class A and B are implementing their interfaces.
But the interfaces are not used:
e.g. the object factory returns on createA and createB methods A / B classes instead of IA and IB.
Even worse:
If class A holds a List of type B then the created get method is
public List getBs instead of public List getBs.

Is there a way to achieve this?
Or is XInheritance in general only focusing on the class specified in the bindings file and not taken care of the references to the given class?

For me and my current situation: I can work around this because B is not necessarily forced to implement IB.
But it would be nicer to work on interfaces everywhere possilbe so I wanted to ask and clarify.
If this is not possible at the moment then just tell me and close the issue.

@laurentschoelens laurentschoelens added question xjc-plugins Issue concerns basics plugins labels Feb 28, 2024
@laurentschoelens
Copy link
Collaborator

I think this was by design since (not sure but if not it should) you could define 2 or more interface for the same base class with the inheritance plugin.

Moreover, you could downcast by calling methods with interface signature (IA) when using objects (A).

The goal of inheritance plugin is to give you ability to specify a special base class (extends) or base interface (implements) in generated code from xjc maven-plugin.

@laurentschoelens
Copy link
Collaborator

@mattrpav could you confirm ?

@SebasHein
Copy link
Author

@laurentschoelens I can confirm that it is doeing what you described. If intention is to have only a e.g. abstract base class or interface for a class (or all classes) that works fine (and is the way I used in the past). Nevertheless, now I stumbled over the case I described above. No need to have two interfaces implemented. But rather the need to have the specified interface used throughout the references of a class everywhere within the generated code (e.g. ObjectFactory and Classes referencing the class with Interface instead of classname...)

@mattrpav
Copy link
Collaborator

mattrpav commented Feb 28, 2024

@laurentschoelens @SebasHein XSD has a gap in the spec where there is not a way to define an 'interface' type concept.

Order
  + Collection<Item> getItems() <--- where Item is an interface.

The inheritance plugin allows you to apply existing interfaces to model classes or define classes to extend.

To replace return types on a xjc generated class, you'd need to do the following:

  1. Create the interface class in the model project (or dependency)
  2. Use inheritance plugin to have models implement the interface
  3. Use some OTHER xjc plugin to replace the references of the abstract/base type models with the interface class.

@SebasHein
Copy link
Author

Ok thanks
This is what I wanted to know :-) After reading documentation and some trial and error I was not able to found a solution.
As written above I just wanted to clarify wether this is possible or not.
And, unfortunately, its not (at least not with XInheritance).
@mattrpav : Any suggestions what to use instead?

@laurentschoelens
Copy link
Collaborator

If it's a need, it could be somewhat a new feature of the plugin ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question xjc-plugins Issue concerns basics plugins
Projects
None yet
Development

No branches or pull requests

3 participants