How To Write A Validator In Java 1.1.1



Similar documents
JSR-303 Bean Validation

How To Write A Contract On A Microsoft System.Io (For Free)

Hibernate Validator. Olivier Devoisin Kevin Gallardo. Université Pierre et Marie Curie. 9 Decembre 2014

The Java EE 6 Platform. Alexis Moussine-Pouchkine GlassFish Team

OpenShift is FanPaaStic For Java EE. By Shekhar Gulati Promo Code JUDCON.IN

Gurkensalat statt Spaghetticode. Stuttgarter Testtage 2013

Tobias Flohre codecentric AG. Ein Standard für die Batch- Entwicklung JSR-352

Open Text Social Media. Actual Status, Strategy and Roadmap

J2EE-Application Server

CSE 308. Coding Conventions. Reference

Java and RDBMS. Married with issues. Database constraints

<Insert Picture Here> Oracle Direct Potsdam

Semantic Web. Semantic Web: Resource Description Framework (RDF) cont. Resource Description Framework (RDF) W3C Definition:

Java EE 6 development with Eclipse, Netbeans, IntelliJ and GlassFish. Ludovic Champenois Oracle Corporation

How To Learn More About Openstack From A Computer Science Course

Martin Käser. Single Sign-on mit OpenSAML

Spring 3.1 to 3.2 in a Nutshell. Sam Brannen Senior Software Consultant

JSR 82 BT APIs Prof. Dr. S. Heiss / 1. Bluetooth. JSR 82 Java APIs for Bluetooth Wireless Technology

JSR 375 (EE Security API) Review

Understanding Tomcat Security

Contents. What is Wirtschaftsmathematik?

Call Info: The agent can display the call information including Call Center name, wait time, the number of calls in queue, and longest wait time.

AP Computer Science Java Subset

Aufgabenstellung. Aufgabenstellung

Beschleunigen von Algorithmen mit High-Level Synthese auf Xilinx Zynq

VMware Mirage Centralized Desktop Management with local Execution

2010 Users Symposium Berlin

Instant SQL Programming

APPLICATION SETUP DOCUMENT

Enterprise Java Web Application Frameworks & Sample Stack Implementation

TIn 1: Lecture 3: Lernziele. Lecture 3 The Belly of the Architect. Basic internal components of the Pointers and data storage in memory

Design REST Services with CXF JAX- RS implementation: best practices and lessons learned

Klasse: Z_LDAP_TELEFONBUCH

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

Project 4 DB A Simple database program

Implementing Rexx Handlers in NetRexx/Java/Rexx

Medientechnik. Übung MVC

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

How To Run A Test File Extension On A Rexx (Unix) On A Microsoft Linux (Amd64) (Orchestra) (For Windows) (

Introduction to Python

Erfolgreiche Zusammenarbeit:

Deutsche Bank Finance IT Migration Oracle Exadata

JBoss Enterprise App. Platforms Roadmap. Rich Sharples Director of Product Management, Red Hat 4th April 2011

Asterisk und Mediagateways

1. Seam Mail Introduction 2. Configuration 3. Core Usage 4. Templating 5. Advanced Features

2. Installieren des MySQL Workbench (Version ) 3. Unter Database > Manage Connection folgende Werte eintragen

Database Query 1: SQL Basics

A: Ein ganz normaler Prozess B: Best Practices in BPMN 1.x. ITAB / IT Architekturbüro Rüdiger Molle März 2009

Framework Adoption for Java Enterprise Application Development

OpenReports: Users Guide

How To Manage Office Space

for High Performance Computing

repositor.io Simple Repository Management Jürgen Brunk München, 03/2015

Enterprise User Security

Spring Data JDBC Extensions Reference Documentation

Mit einem Auge auf den mathema/schen Horizont: Was der Lehrer braucht für die Zukun= seiner Schüler

VSTO 3.0 In Action mit Outlook Lars Keller netcreate OHG

Tivoli Storage Manager - Produktübersicht

Customer Intimacy Analytics

For the next three questions, consider the class declaration: Member function implementations put inline to save space.

Assignment 3 Version 2.0 Reactive NoSQL Due April 13

JBoss SOAP Web Services User Guide. Version: M5

Java Server Pages combined with servlets in action. Generals. Java Servlets

Building an Architecture Model Entwerfen Sie mit AxiomSys ein Kontextdiagramm, das folgendermaßen aussieht:

e ag u g an L g ter lvin v E ram Neal G g ro va P Ja

JavaServer Faces 2.0. Bernd Bohmann. Matthias Weßendorf. Agenda. Agenda. IRIAN Deutschland Apache MyFaces Tobago CORE. Mehr als nur ein Web-Framework

Official Android Coding Style Conventions

Extracting translation relations for humanreadable dictionaries from bilingual text

OpenVMS Security Update

Aspect Oriented Programming. with. Spring

Unit Testing & JUnit

Status by end of March 2015

How To Create A Model In Ruby (Orm)

C:\Documents and Settings\Gijs\Desktop\src\client\Client.java dinsdag 3 november :50

SINGLE SIGNON FUNCTIONALITY IN HATS USING MICROSOFT SHAREPOINT PORTAL

Kaseya 2. Quick Start Guide. for VSA 6.3

Overview WebServices Web Services Choreography Languages. WebServices. Jan Krüger

Cloud OS Network. Uwe Lüthy, Die Bedeutung einer Partner Managed Cloud für Kunden. Partner Technology Strategiest

Transcription:

Bean Validation 1.1 What's cooking? 05.04.2013 Gunnar Morling JBoss, by Red Hat

Bean Validation 1.1 JSR 349 Final Approval Ballot nächste Woche! Vollständig offen Issue-Tracker Mailingliste GitHub: Spezifikation Referenzimplementierung TCK Website 05.04.2013 Bean Validation 1.1 What's cooking? 2/13

Dependency Injection Dependency Injection via CDI ConstraintValidator-Implementierungen public class PastValidator implements ConstraintValidator<Past, Date> { @Inject private TimeService timeservice; public void initialize(past constraintannotation) { public boolean isvalid(date date, ConstraintValidatorContext context) { if ( date == null ) { return true; return date.before( timeservice.getcurrenttime() ); MessageInterpolator, TraversableResolver, ConstraintValidatorFactory etc. 05.04.2013 Bean Validation 1.1 What's cooking? 3/13

Methodenvalidierung (I) Validierung von Methodenparametern und -rückgabewerten beim Aufruf Erfordert Interceptor, AOP, Proxy etc. 05.04.2013 Bean Validation 1.1 What's cooking? 4/13

Methodenvalidierung (II) Parameterprüfung old school /** * Places an order. * * @param customercode Must not be null and between 3 and 20 characters. * @param item Must not be null. * @param quantity Must be larger or equal than 1. */ public void placeorder(string customercode, Item item, int quantity) { validatecustomercode(customercode); if(item == null) throw new IllegalArgumentException(); if(quantity < 1) throw new IllegalArgumentException(); //Actual business logic... Nachteile Manuelle Prüfung Redundanz Schnell uneinheitlich 05.04.2013 Bean Validation 1.1 What's cooking? 5/13

Methodenvalidierung (III) Parameterprüfung Bean Validation way public void placeorder( //... @NotNull @Size(min=3, max=20) String customercode, @NotNull Item item, @Min(1) int quantity) { Vorteile Validierung einheitlich als Aspekt implementiert Constraints Teil der JavaDoc Programming by Contract Aktiv per Default für CDI Beans und JAX-RS Resourcen 05.04.2013 Bean Validation 1.1 What's cooking? 6/13

Methodenvalidierung (IV) Objektgraphen public void placeorder( @NotNull @Size(min=3, max=20) String customercode, @NotNull @Valid Item item, @Min(1) int quantity) { //... 05.04.2013 Bean Validation 1.1 What's cooking? 7/13

Methodenvalidierung (IV) Objektgraphen public void placeorder( @NotNull @Size(min=3, max=20) String customercode, @NotNull @Valid Item item, @Min(1) int quantity) { //... Rückgabewerte @NotNull @RetailOrder @Valid public Order placeorder( @NotNull @Size(min=3, max=20) String customercode, @NotNull @Valid Item item, @Min(1) int quantity) { //... 05.04.2013 Bean Validation 1.1 What's cooking? 7/13

Methodenvalidierung (V) Konstruktoren @Valid public OrderService(@NotNull @Valid OrderDao orderdao) { //... 05.04.2013 Bean Validation 1.1 What's cooking? 8/13

Methodenvalidierung (V) Konstruktoren @Valid public OrderService(@NotNull @Valid OrderDao orderdao) { //... Cross-parameter Constraints @PasswordsMatch public void resetpassword(@notnull password, @NotNull passwordconfirmation) {... @SupportedValidationTarget(value = ValidationTarget.PARAMETERS) public class PasswordsMatchValidator implements ConstraintValidator<PasswordsMatch, Object[]> { @Override public void initialize(passwordsmatch constraintannotation) { @Override public boolean isvalid(object[] value, ConstraintValidatorContext context) { return value[0].equals(value[1]); 05.04.2013 Bean Validation 1.1 What's cooking? 8/13

EL-Ausdrücke in Fehlermeldungen (I) Dynamische Fehlermeldungen mittels Unified EL (JSR 341) public class Foo { @DecimalMin(value="10.0", inclusive=true) private BigDecimal number; ValidationMessages.properties: javax.validation.constraints.decimalmax.message = must be less than ${inclusive == true? 'or equal to ' : ''{value 05.04.2013 Bean Validation 1.1 What's cooking? 9/13

EL-Ausdrücke in Fehlermeldungen (II) Ausgabe des validierten Werts public class Shop { @ValidUser( minage=18, message="user must at least be ${minage, but is ${validatedvalue.age." ) private User user; //... 05.04.2013 Bean Validation 1.1 What's cooking? 10/13

EL-Ausdrücke in Fehlermeldungen (II) Ausgabe des validierten Werts public class Shop { @ValidUser( minage=18, message="user must at least be ${minage, but is ${validatedvalue.age." ) private User user; //... Formatierung mit Formatter-Object public class Bar { @Min( value=100, message="value ${formatter.format('%1$.2f', validatedvalue) is too small" ) private double number = 98.12345678d; // ==> "Value 98.12 is too small" 05.04.2013 Bean Validation 1.1 What's cooking? 10/13

Gruppenkonvertierung (I) @Valid-Annotation zur Validierung von Objektgraphen public class Address { @NotEmpty(message="Street must not be empty") private String street; public class Customer { @Valid private final Address address = new Address(); 05.04.2013 Bean Validation 1.1 What's cooking? 11/13

Gruppenkonvertierung (I) @Valid-Annotation zur Validierung von Objektgraphen public class Address { @NotEmpty(message="Street must not be empty") private String street; public class Customer { @Valid private final Address address = new Address(); Fehlertext in Abhängigkeit der Rolle eines Objekts? public class Customer { @Valid private final Address homeaddress = new Address(); @Valid private final Address officeaddress = new Address(); 05.04.2013 Bean Validation 1.1 What's cooking? 11/13

Gruppenkonvertierung (II) Validierungsgruppen definieren public interface HomeChecks{ public interface OfficeChecks{ @ConvertGroup zur Konvertierung von Gruppen public class Address { @NotEmpty.List({ @NotEmpty(message="Home street may not be empty", groups=homechecks.class), @NotEmpty(message="Office street may not be empty", groups=officechecks.class) ) private String street; public class Customer { @Valid @ConvertGroup(from=Default.class, to = HomeChecks.class) private Address homeaddress = new Address(); @Valid @ConvertGroup(from=Default.class, to = OfficeChecks.class) private Address officeaddress = new Address(); 05.04.2013 Bean Validation 1.1 What's cooking? 12/13

Fragen & Antworten?! 05.04.2013 Bean Validation 1.1 What's cooking? 13/13

Referenzen Alles rund um BV: http://www.beanvalidation.org/ JSR 349: Bean Validation : http://jcp.org/en/jsr/detail?id=349 Hibernate Validator: http://www.hibernate.org/subprojects/validator.html Forum zu Hibernate Validator: https://forum.hibernate.org/viewforum.php?f=9 Hibernate Team Blog: http://in.relation.to/ 05.04.2013 Bean Validation 1.1 What's cooking? 14/13