I'd planned to support annotations for schema constraints at some point,
and it shouldn't be a huge job to add them in. It would involve changes
to the actual code generation, though, and could not be handled by
simple extensions.

I'm not sure that JSR-303 is my preferred implementation, either. As I
understand it, it's based on using a Validator to check for constraint
violations. That seems fundamentally flawed to me, I'd much rather see
constraints enforced at the time values are set (immediate fail). If a
value is supposed to be non-null, why should a set method support
setting a null value? So although it would be nice to support generating
JSR-303 annotations, I'd prefer to generate smart set methods that
forbid violating a constraint.

Right now the constraint work is not a priority for me, but I can point
you at where you'd need to add support and provide some pointers in how
it should be done. Or if you have a need for this feature and a budget
for some paid work that would make it a priority. :-)

  - Dennis

Dennis M. Sosnoski
Java SOA and Web Services Consulting <http://www.sosnoski.com/consult.html>
Axis2/CXF/Metro SOA and Web Services Training
<http://www.sosnoski.com/training.html>
Web Services Jump-Start <http://www.sosnoski.com/jumpstart.html>


On 01/01/2011 05:54 AM, jcaristi wrote:
> We are using JiBX CodeGen to go from XML schema to Java for Axis2 web
> services. We code our XSD files with the appropriate constraints on each
> field. However, we are doing all of our request validation on the server
> side in Java. We want our validation logic to be executed in the business
> tier so we can provide precise, contextual, localized error coding and error
> messages on the response. For this we are using the Spring Validator
> framework, which really simplifies the task.  
>
> One problem with this approach is that we have to code the constraints
> twice, once in the XSD and once in Java. This means that we also have to
> keep them in sync, which is hard.  Now that Spring supports JSR-303, we
> could eliminate the Java coding of basic validation by using annotations on
> our entity classes (example below). If these could be derived from our XML
> schema, it would be great!
>
> I know that there has been some discussion about JiBX and JSR-303, but
> nothing recently. Has any progress been made on this?  Has anyone come up
> with a solution?  Is there any way to generate an import and an annotation
> via CodeGen?
>
> JSR-303 EXAMPLE:
>
> import javax.validation.constraints.NotNull;
> import javax.validation.constraints.Size;
>
> public class Car {
>
>     @NotNull
>     private String manufacturer;
>
>     @NotNull
>     @Size(min = 2, max = 14)
>     private String licensePlate;
>
>     public Car(String manufacturer, String licencePlate) {
>
>         super();
>         this.manufacturer = manufacturer;
>         this.licensePlate = licencePlate;
>     }
>
>     //getters and setters ...
>
> }
>  
>   
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to