Hyperjaxb/lombok : how to force Hyperjaxb generate annotations mapping on attributes and not on the methods? - attributes

I would like jpa annotations on my attributes, not on getter and setter. It is possible to configure hyperjaxb for this ?
I want this because I use lombok in order to avoid getter and setter code and have "#getter" "#setter" above attributes.
thank you

This is not supported out of the box at the moment (please file an issue if you need this functionality).
However you can do it by writing and overriding your own implementation of org.jvnet.hyperjaxb3.ejb.strategy.annotate.AnnotateOutline. See https://svn.java.net/svn/hj3~svn/trunk/ejb/tests/custom-naming/ for an example of overriding a strategy.
But be aware that Hyperjaxb has to use getters/setters to workaround some of the JAXB/JPA incompatibilities (for example simple type which is not supported by JPA). If you put annotations on fields, this won't work.

Related

What is the "binding" property of controls and how do you use it?

The "binding" basic property is described as a property that "Specifies an expression that binds a control to a particular control property". I tried to google and read at HCL docs but there is no example on how to use it.
The binding property allows you to specify an object property (say, on a managed bean or dataContext) that will be set to the specified component. For example, you could do:
<xp:inputText binding="#{someBean.textField}"/>
...and that would call someBean.setTextField(XspInputText inputText).
All that said, it's kind of an edge-case property. I've made good use of it, but it's largely an artifact of earlier JSF revisions, when it was more common to have backing logic that "knew" about the front-end XPage explicitly.
In general, it's better design to stick to value bindings like value="#{someBean.firstName}" and not make your backing objects aware of the front-end UI, unless you have an explicit reason to do otherwise.

JAXB how to remove anything from JDefinedClass

i am using jaxb to generate code from an xsd.
The generated code contains a lot of annotations; for classes and fields.
I am trying to use com.sun.tools.internal.xjc.Plugin to modify the generated code.
In the plugin run() method we are given an Outline class from which we can get ClassOutline. ClassOutline has an JDefinedClass final member which has the info about actual class which will be generated.
If i want to add anything, there are apis in JDefinedClass which can be used. But if i want to remove something, there is no way.
e.g. i cannot clear annotations, because the JDefinedClass.annotations() method returns an UnmodifiableCollection. so i cannot clear it or remove anything from it.
i tried to create another JDefinedClass by invoking the _class method but the ClassOutline.implClass variable is final, so i cannot set it.
how to get a JDefinedClass which does not have any annotations?
is there another phase of code generation which i can trap into to really control the generation of JDefinedClass?
The code model is, indeed mostly "write only". But, speaking of annotations, you have probably missed the methods like com.sun.codemodel.JDefinedClass.removeAnnotation(JAnnotationUse) and com.sun.codemodel.JMethod.removeAnnotation(JAnnotationUse) (implemented from com.sun.codemodel.JAnnotatable.removeAnnotation(JAnnotationUse)).
So they're there. You can remove annotations with the normal CodeModel API.
As I can see, you can also remove fields and methods from classes. So what exactly are you missing?
JDefinedClass.annotations() It return an unmodifiable collection object and you cannot modify them.
So work around for this, you can restrict annotation addition/deletion at class and field level before building JCodeModel.
You need to create a custom Jackson2Annotator class which extends Jackson2Annotator and override their methods according to your requirement.
Following are few methods which are being used for specific type of annotation property:
propertyOrder(OTB JsonPropertyOrder)
propertyInclusion(OTB JsonInclude)
propertyField(can be used for custom defined annotation at field level)
More you can discover by looking Jackson2Annotator class what fit into your need.

How to document a type in enunciate?

How to get the description field on a type populated in the generated enunciate documentation?
We are generating classes from jaxb using jaxb2-maven-plugin. No matter how I document a element either using the <xsd:documentation></xsd:documentation> or the
<xsd:appinfo>
<jaxb:class>
<jaxb:javadoc>
</jaxb:javadoc>
</jaxb:class>
</xsd:appinfo>
it is overwritten in the generated classes. Can I somehow disable the this auto-generated javadoc from this plugin? Or what does enunciate really expect me to do let me document on a field level?
Note that the comment I write on class-level/type does show up in the generated class and in the enunciated generated documentation.
We are using enunciate (v.1.26.2) and jaxb2-maven-plugin (v. 1.5)
So you're wondering how to get Enunciate to not use the Javadocs on the class?
One way might be to compile the JAXB-generated classes and run Enunciate against the compiled classes instead of the source code.

Get attribute name from proxy type without using reflections

We use early-bound class for development. But occasionally we use attribute names.
There is a way to do it using reflections, but reflections are not allowed in sandbox plugins.
What are the approaches to getting an attribute from proxy types without relying on reflections?
Opportunity.OpportunityId.AttributeName
You have a couple options:
You can use a RetrieveEntityMetadata to the list of attributes that the entity contains. You won't be able to use any early binding here, but you can inspect the results at run time to see what are valid attributes for the entity.
You could also create a simple utility that uses reflection to auto-generate a class or enum that contains the list of attributes before you actually deploy. Just add the class to your plugin dll and you'd have the benefits of early binding of entity attributes when developing your plugin, without having to do reflection at runtime.

Can we get declared properties of a Groovy class by its order?

I created a plain Groovy class (i.e Person class)with some properties. Now I want to get those declared attributes (which I've defined in my class) with their order, but I don't know how to do it.
I've tried to use Person.metaClass.getProperties() but it retrieves not only declared properties but also built-in Groovy ones.
Could you please help me on this: just get declared properties by its order when declaring.
Thank you so much!
I can't see a use case, but the compiler could reorder all fields declaration while creating bytecode. I'm pretty sure ordering is not a constraint on fields though it should mostly be the case for not modified/enhanced class
As per the JVM spec, generated fields should be marked SYNTHETIC (like generated methods) in the bytecode, so you can test with :
Person.getDeclaredFields().grep { !it.synthetic }
and filter the base Groovy fields like ClassInfo,metaClass and others beginning by __timestamp
But I'm not a specialist, there could be another way I don't think of
There was a question about this on the mailing list back in February of this year
The answer is, no. There is no way to get properties in the order they are declared in the class without doing some extra work.
You could parse the source file for the class, and generate an ordered list of property names from that
You could write a custom annotation, and annotate the fields with this annotation ie: #Order(1) String prop
You could make all of the classes where this matters implement an interface which forces them to have a method that returns the names of the properties in order.
Other than that, you probably want to have a re-think :-(

Resources