Initial revision of the examples/moxy/bean-validation example.
Signed-off-by: John Clingan <john.clingan@oracle.com>
Reviewed-by: Marcel Valovy <marcel.valovy@oracle.com>
Reviewed-by: Martin Grebac <martin.grebac@oracle.com>
diff --git a/moxy/bean-validation/.gitignore b/moxy/bean-validation/.gitignore
new file mode 100644
index 0000000..430b1ae
--- /dev/null
+++ b/moxy/bean-validation/.gitignore
@@ -0,0 +1,3 @@
+.classpath
+.project
+.settings
diff --git a/moxy/bean-validation/GenerateJavaClasses.cmd b/moxy/bean-validation/GenerateJavaClasses.cmd
new file mode 100755
index 0000000..5ad402c
--- /dev/null
+++ b/moxy/bean-validation/GenerateJavaClasses.cmd
@@ -0,0 +1,37 @@
+@echo off
+
+if NOT EXIST target\schema1.xsd (
+ echo.
+ echo "First run 'mvn install' to generate target/schema1.xsd"
+ echo.
+ GOTO END
+)
+
+SET OUTPUT_DIR=target\out
+
+if EXIST out (
+ RMDIR /S /Q %OUTPUT_DIR%
+)
+MKDIR %OUTPUT_DIR%
+
+if NOT DEFINED ECLIPSELINK_HOME (
+ echo.
+ echo "Please set ECLIPSELINK_HOME to the EclipseLink home directory"
+ echo.
+ GOTO END
+)
+
+IF NOT DEFINED JAVA_HOME (
+ echo.
+ echo "Please set JAVA_HOME to the top-level JDK directory"
+ echo.
+ GOTO END
+)
+
+%ECLIPSELINK_HOME%\bin\jaxb-compiler.cmd -XBeanVal -d %OUTPUT_DIR% -p eclipselink.example.moxy.beanvalidation.simple.model target/schema1.xsd
+
+echo.
+REM echo "View eclipselink/example/moxy/beanvalidation/simple/model/Customer.java to see the generated Customer.java with bean validation constraints"
+echo.
+
+:END
diff --git a/moxy/bean-validation/GenerateJavaClasses.sh b/moxy/bean-validation/GenerateJavaClasses.sh
new file mode 100755
index 0000000..8979482
--- /dev/null
+++ b/moxy/bean-validation/GenerateJavaClasses.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+if [ ! -f target/schema1.xsd ];
+then
+ echo
+ echo "First run 'mvn install' to generate target/schema1.xsd"
+ echo
+ exit 1
+fi
+
+OUTPUT_DIR=target/out
+rm -rf ${OUTPUT_DIR}
+mkdir ${OUTPUT_DIR}
+
+if [ -z ${ECLIPSELINK_HOME} ] || [ ! -f ${ECLIPSELINK_HOME}/bin/jaxb-compiler.sh ];
+then
+ echo
+ echo "Please set ECLIPSELINK_HOME to top-level eclipselink directory"
+ echo
+ exit 2
+fi
+
+if [ -z ${JAVA_HOME} ] || ! [ -d ${JAVA_HOME} ];
+then
+ echo
+ echo "Please set JAVA_HOME to top-level java directory"
+ echo
+ exit 3
+fi
+
+$ECLIPSELINK_HOME/bin/jaxb-compiler.sh \
+ -XBeanVal \
+ -d ${OUTPUT_DIR} \
+ -p eclipselink.example.moxy.beanvalidation.simple.model \
+ target/schema1.xsd
+
+echo
+echo "View ${OUTPUT_DIR}/eclipselink/example/moxy/beanvalidation/simple/model/Customer.java to see the generated Customer.java with bean validation constraints"
+echo
diff --git a/moxy/bean-validation/README.md b/moxy/bean-validation/README.md
new file mode 100644
index 0000000..a14d3e0
--- /dev/null
+++ b/moxy/bean-validation/README.md
@@ -0,0 +1,24 @@
+EclipseLink MOXy Bean Validation Example
+----------------------------------------
+
+This example will demonstrate how to use EclipseLink MOXy to generate an XML schema with element constraints from a Java Class with Bean Validation constraints.In particular, see the firstName field in Customer.java
+
+This example will also demonstrate the reverse - generating a Java Class with Bean Validation constraints from an XML schema with element constraints.
+
+Support for Bean Validation constraints with XML Schema is a feature specific
+to EclipseLink.
+
+Running the Example
+-------------------
+To generate an XML Schema from a Java class, execute:
+
+ mvn install
+
+The generated XML schema (schema1.xsd) will be in the target directory:
+ target/schema1.xsd
+
+To generate Java classes from an XML schema, follow these two steps:
+ 1) Set ECLIPSELINK_HOME to your EclipseLink 2.6.0+ installation
+ 2) Execute GenerateJavaClasses.sh (or .cmd on Windows) to generate the
+ model from the schema1.xsd (generated from 'mvn install' above). The
+ generated class, Customer.java will be under the 'out' directory
diff --git a/moxy/bean-validation/pom.xml b/moxy/bean-validation/pom.xml
new file mode 100644
index 0000000..ad64c6b
--- /dev/null
+++ b/moxy/bean-validation/pom.xml
@@ -0,0 +1,105 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>eclipselink.example.moxy</groupId>
+ <artifactId>beanvalidation-simple</artifactId>
+ <version>2.6.0</version>
+
+ <name>EclipseLink MOXy Bean Validation Example</name>
+ <url>http://wiki.eclipse.org/EclipseLink/Examples/MOXy</url>
+
+ <scm>
+ <connection>git://git.eclipse.org/gitroot/eclipselink/examples.git</connection>
+ <url>http://git.eclipse.org/c/eclipselink/examples.git/</url>
+ </scm>
+
+ <licenses>
+ <license>
+ <name>EPL: Eclipse Public License</name>
+ <url>http://www.eclipse.org/legal/epl-v10.html</url>
+ </license>
+ <license>
+ <name>EDL: Eclipse Distribution License</name>
+ <url>http://www.eclipse.org/org/documents/edl-v10.php</url>
+ </license>
+ </licenses>
+
+ <developers>
+ <developer>
+ <name>John Clingan</name>
+ <organization>Oracle</organization>
+ <email>john.clingan@oracle.com</email>
+ </developer>
+ </developers>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <eclipselink.groupid>org.eclipse.persistence</eclipselink.groupid>
+ <eclipselink.artifactid>eclipselink</eclipselink.artifactid>
+ <eclipselink.version>2.6.0</eclipselink.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>${eclipselink.groupid}</groupId>
+ <artifactId>${eclipselink.artifactid}</artifactId>
+ <version>${eclipselink.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>commonj.sdo</artifactId>
+ <groupId>commonj.sdo</groupId>
+ </exclusion>
+ </exclusions>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>7.0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.3.2</version>
+ <executions>
+ <execution>
+ <phase>install</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <classpathScope>test</classpathScope>
+ <mainClass>eclipselink.example.moxy.beanvalidation.simple.Main</mainClass>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.2</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
diff --git a/moxy/bean-validation/src/main/java/eclipselink/example/moxy/beanvalidation/simple/Main.java b/moxy/bean-validation/src/main/java/eclipselink/example/moxy/beanvalidation/simple/Main.java
new file mode 100644
index 0000000..a198694
--- /dev/null
+++ b/moxy/bean-validation/src/main/java/eclipselink/example/moxy/beanvalidation/simple/Main.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ ******************************************************************************/
+package eclipselink.example.moxy.beanvalidation.simple;
+
+import org.eclipse.persistence.jaxb.compiler.Generator;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
+
+
+import eclipselink.example.moxy.beanvalidation.simple.model.Customer;
+
+/**
+ * Main example execution.
+ *
+ * @author johnclingan
+ * @since EclipseLink 2.6.0
+ */
+public class Main {
+ public static void main(String[] args) throws Exception {
+ System.out.println();
+ System.out.println("Running EclipseLink MOXy Bean Validation Example");
+ System.out.println("See target/schema1.xsd for XML Element constraints");
+
+ JavaModelImpl javaModel = new JavaModelImpl(Thread.currentThread().getContextClassLoader());
+ JavaModelInputImpl modelInput = new JavaModelInputImpl(new Class[] { Customer.class}, javaModel);
+ modelInput.setFacets(true);
+ Generator gen = new Generator(modelInput);
+ gen.generateSchemaFiles("target", null);
+
+ System.out.println();
+ System.out.println();
+ }
+
+}
diff --git a/moxy/bean-validation/src/main/java/eclipselink/example/moxy/beanvalidation/simple/model/Customer.java b/moxy/bean-validation/src/main/java/eclipselink/example/moxy/beanvalidation/simple/model/Customer.java
new file mode 100644
index 0000000..ac7aa38
--- /dev/null
+++ b/moxy/bean-validation/src/main/java/eclipselink/example/moxy/beanvalidation/simple/model/Customer.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ ******************************************************************************/
+package eclipselink.example.moxy.beanvalidation.simple.model;
+
+import java.util.List;
+import javax.xml.bind.annotation.*;
+import javax.validation.constraints.Size;
+
+/*
+ * Customer class with Bean Validation constraints
+ *
+ * @author johnclingan
+ * @since EclipseLink 2.6.0
+ */
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Customer {
+
+ @XmlAttribute
+ private int id;
+
+ @Size(min=3, max=10)
+ @XmlElement
+ private String firstName;
+
+ @XmlElement(nillable = true)
+ private String lastName;
+}