openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From allee8...@apache.org
Subject svn commit: r1413918 - in /openjpa/site/trunk: WhoIsWorkingOnWhat.txt content/banner.mdtext content/bean-validation-primer.mdtext content/css/type-settings.css content/images/ig_domain_model.gif
Date Mon, 26 Nov 2012 23:10:07 GMT
Author: allee8285
Date: Mon Nov 26 23:10:06 2012
New Revision: 1413918

URL: http://svn.apache.org/viewvc?rev=1413918&view=rev
Log:
CMS migration updates.

Added:
    openjpa/site/trunk/content/images/ig_domain_model.gif   (with props)
Modified:
    openjpa/site/trunk/WhoIsWorkingOnWhat.txt
    openjpa/site/trunk/content/banner.mdtext
    openjpa/site/trunk/content/bean-validation-primer.mdtext
    openjpa/site/trunk/content/css/type-settings.css

Modified: openjpa/site/trunk/WhoIsWorkingOnWhat.txt
URL: http://svn.apache.org/viewvc/openjpa/site/trunk/WhoIsWorkingOnWhat.txt?rev=1413918&r1=1413917&r2=1413918&view=diff
==============================================================================
--- openjpa/site/trunk/WhoIsWorkingOnWhat.txt (original)
+++ openjpa/site/trunk/WhoIsWorkingOnWhat.txt Mon Nov 26 23:10:06 2012
@@ -3,12 +3,12 @@ User/done	| Page
 ==============================================================
 done			2.1-roadmap.mdtext
 done			apache-nexus-release-process-(1.2.x-2.1.x).mdtext
-			apidiscussionfollowup.mdtext
+done			apidiscussionfollowup.mdtext
 done			apply-an-eclipse-patch.mdtext
 done			architecture-notes.mdtext
 done			automated-builds.mdtext
-			banner.mdtext
-			bean-validation-primer.mdtext
+done			banner.mdtext
+done			bean-validation-primer.mdtext
 done			beginners-performance-guide.mdtext
 			begin-using-openjpa---the-basics.mdtext
 done			build-and-runtime-dependencies.mdtext

Modified: openjpa/site/trunk/content/banner.mdtext
URL: http://svn.apache.org/viewvc/openjpa/site/trunk/content/banner.mdtext?rev=1413918&r1=1413917&r2=1413918&view=diff
==============================================================================
--- openjpa/site/trunk/content/banner.mdtext (original)
+++ openjpa/site/trunk/content/banner.mdtext Mon Nov 26 23:10:06 2012
@@ -1,15 +1,15 @@
 Title: Banner
-{html:output=html|noPanel=true}
-	<div id="header_background">
-	    <div id="openjpa_logo">
-		<a style="float:left;
+<a name="Banner"></a>
+
+<div id="header_background">
+  <div id="openjpa_logo">
+	<a style="float:left;
 width:280px;display:block;text-indent:-5000px;text-decoration:none;line-height:60px;
 margin-top:10px; margin-left:100px;"
 href="http://openjpa.apache.org">OpenJPA</a>
-	    </div>
-	  <div id="copyright" style="text-align: center;">
+  </div>
+  <div id="copyright" style="text-align: center;">
 	      Apache, Apache OpenJPA, and the Apache feather are trademarks
 of The Apache Software Foundation.  
-	  </div>	 
-	</div>
-{html}
+  </div>	 
+</div>

Modified: openjpa/site/trunk/content/bean-validation-primer.mdtext
URL: http://svn.apache.org/viewvc/openjpa/site/trunk/content/bean-validation-primer.mdtext?rev=1413918&r1=1413917&r2=1413918&view=diff
==============================================================================
--- openjpa/site/trunk/content/bean-validation-primer.mdtext (original)
+++ openjpa/site/trunk/content/bean-validation-primer.mdtext Mon Nov 26 23:10:06 2012
@@ -1,17 +1,17 @@
 Title: Bean Validation Primer
 <a name="BeanValidationPrimer-OpenJPABeanValidationPrimer"></a>
-## OpenJPA Bean Validation Primer
+# OpenJPA Bean Validation Primer
 
 A new feature defined by the JPA 2.0 specification is the ability to
 seamlessly integrate with a [JSR-303](http://jcp.org/en/jsr/detail?id=303)
- bean validation provider.   With minimal effort, [OpenJPA 2.0|http://openjpa.apache.org/openjpa-200.html]
- can be coupled with a [JSR-303|http://jcp.org/en/jsr/detail?id=303]
+ bean validation provider.   With minimal effort, [OpenJPA 2.0](http://openjpa.apache.org/openjpa-200.html)
+ can be coupled with a [JSR-303](http://jcp.org/en/jsr/detail?id=303)
  validation provider to provide runtime data validation.  By combining
 these two technologies, you get a standardized persistence solution with
 the added ability to perform standardized java bean validation.
 
 <a name="BeanValidationPrimer-WhatisBeanValidation?"></a>
-### What is Bean Validation?
+## What is Bean Validation?
 
 Most applications, especially those that gather input from a user, contain
 a significant amount of code to perform data validation.  It is typically
@@ -24,8 +24,8 @@ layer can lead to an unforseen breakage 
 The Bean Validation API was designed to provide a standardized method for
 validating data within Java beans.  As an added feature, it seemlessly
 integrates with several JEE6 technologies including [JPA 2.0](http://jcp.org/en/jsr/detail?id=317)
-, [JCA 1.6|http://jcp.org/en/jsr/summary?id=322]
-, and [JSF 2.0|http://jcp.org/en/jsr/detail?id=314]
+, [JCA 1.6](http://jcp.org/en/jsr/summary?id=322)
+, and [JSF 2.0](http://jcp.org/en/jsr/detail?id=314)
 .  Additionally, JEE6 complaint servers are required to support bean
 validation and must include a validation provider.  While a JEE6
 environment provides some simplified packaging and configuration benefits,
@@ -41,7 +41,7 @@ integrated environment like JPA, you wil
 with the validator; simplifying things even further.
 
 <a name="BeanValidationPrimer-ValidationConstraints"></a>
-### Validation Constraints
+## Validation Constraints
 
 Constraints are a fundamental component of bean validation.  Constraints
 can be placed on Java beans and/or fields and properties (collectively
@@ -56,7 +56,7 @@ Let's start by looking at some simple co
 some custom constraints.
 
 <a name="BeanValidationPrimer-ConstraininganEntity"></a>
-### Constraining an Entity
+## Constraining an Entity
 
 For the purposes of an example, let's start building the JPA domain model
 for a digital image storage system. For the sake of simplicity, we'll start
@@ -67,9 +67,7 @@ must include a valid JPEG or GIF extensi
 annotated Image entity with some built-in bean validation constraints
 applied.
 
-  
-  
-<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Image.java|borderStyle=solid</B></DIV><DIV
class="codeContent panelContent">
+    
     package org.apache.openjpa.example.gallery.model;
     
     import javax.persistence.Entity;
@@ -86,71 +84,66 @@ applied.
         private long id;
         private ImageType type;
         private String fileName;
-        private byte[]
- data;
+        private byte[] data;
     
         @Id
         @GeneratedValue
         public long getId() {
-    	return id;
+        	return id;
         }
     
         public void setId(long id) {
-    	this.id = id;
+        	this.id = id;
         }
     
         @NotNull(message="Image type must be specified.")
         @Enumerated(EnumType.STRING)
         public ImageType getType() {
-    	return type;
+        	return type;
         }
     
         public void setType(ImageType type) {
-    	this.type = type;
+        	this.type = type;
         }
     
         @Pattern(regexp = ".*\\.jpg|.*\\.jpeg|.*\\.gif",
-    	message="Only images of type JPEG or GIF are supported.")
+    	         message="Only images of type JPEG or GIF are supported.")
         public String getFileName() {
-    	return fileName;
+        	return fileName;
         }
     
         public void setFileName(String fileName) {
-    	this.fileName = fileName;
+    	    this.fileName = fileName;
         }
     
-        public byte[]
- getData() {
-    	return data;
+        public byte[] getData() {
+    	    return data;
         }
     
-        public void setData(byte[]
- data) {
-    	this.data = data;
+        public void setData(byte[] data) {
+    	    this.data = data;
         }
     }
-
-
   
   
 The [Image](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/model/Image.java)
  class uses two built in constraints @NotNull and @Pattern. The @NotNull
-constraint ensures that an [ImageType|http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/ImageType.java]
+constraint ensures that an [ImageType](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/ImageType.java)
  is specified and @Pattern constraint uses regular expression pattern
 matching to ensure the image file name is suffixed with a supported image
 format.  Each constraint has corresponding validation logic that gets
 executed at runtime when the Image entity is validated.  If either
 constraint is not met, the JPA provider will throw a
-ConstraintViolationException with the defined message.	The [JSR-303 specification|http://jcp.org/en/jsr/detail?id=303]
+ConstraintViolationException with the defined message.	The [JSR-303 specification](http://jcp.org/en/jsr/detail?id=303)
  also makes provisions for the use of a variable within the message
 attribute.  The variable references a keyed message in a resource bundle. 
 That allows for environment specific messages and localization of messages.
- See the [JSR-303 specification|http://jcp.org/en/jsr/detail?id=303]
+ See the [JSR-303 specification](http://jcp.org/en/jsr/detail?id=303)
 , section 4.1.3 for additional details regarding the customization and
 localization of messages.
 
 <a name="BeanValidationPrimer-CustomConstraintsandValidators"></a>
-### Custom Constraints and Validators
+## Custom Constraints and Validators
 
 If the built-in constraints do not meet your needs, you can create your own
 custom validators and constraints.  In our previous example, the Image
@@ -159,12 +152,9 @@ entity used the @Pattern constraint to v
 pattern-based constraint could potentially be used, but this is rather
 inflexible and will get messy.	A custom constraint and validator provides
 a more robust and flexible solution.  First, let's create a custom method
-level constraint annotation named [ImageContent](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageContent.java)
-.
+level constraint annotation named [ImageContent](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageContent.java).
 
   
-  
-<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>ImageContent.java|borderStyle=solid</B></DIV><DIV
class="codeContent panelContent">
     package org.apache.openjpa.example.gallery.constraint;
     
     import java.lang.annotation.Documented;
@@ -185,12 +175,9 @@ level constraint annotation named [Image
     @Retention(RUNTIME)
     public @interface ImageContent {
         String message() default "Image data is not a supported format.";
-        Class<?>[]
- groups() default {};
-        Class<? extends Payload>[]
- payload() default {};
-        ImageType[]
- value() default { ImageType.GIF, ImageType.JPEG };
+        Class<?>[] groups() default {};
+        Class<? extends Payload>[] payload() default {};
+        ImageType[] value() default { ImageType.GIF, ImageType.JPEG };
     }
 
   
@@ -202,9 +189,6 @@ when the constraint is validated.  Notic
 the constraint annotation via the validatedBy attribute on the @Constraint
 annotation.
 
-  
-  
-<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>ImageContentValidator.java|borderStyle=solid</B></DIV><DIV
class="codeContent panelContent">
     package org.apache.openjpa.example.gallery.constraint;
     
     import java.util.Arrays;
@@ -218,8 +202,7 @@ annotation.
     /**
      * Simple check that file format is of a supported type
      */
-    public class ImageContentValidator implements ConstraintValidator<ImageContent, byte[]
-> {
+    public class ImageContentValidator implements ConstraintValidator<ImageContent, byte[]
{
         private List<ImageType> allowedTypes = null;
         /**
          * Configure the constraint validator based on the image
@@ -227,85 +210,68 @@ annotation.
          * @param constraint the constraint definition
          */
         public void initialize(ImageContent constraint) {
-    	allowedTypes = Arrays.asList(constraint.value());
+    	    allowedTypes = Arrays.asList(constraint.value());
         }
     
         /**
          * Validate a specified value.
          */
-        public boolean isValid(byte[]
- value, ConstraintValidatorContext context) {
-    	if (value == null) {
-    	    return false;
-    	}
-    	// Verify the GIF header is either GIF87 or GIF89
-    	if (allowedTypes.contains(ImageType.GIF)) {
-    	    String gifHeader = new String(value, 0, 6);
-    	    if (value.length >= 6 &&
-    		(gifHeader.equalsIgnoreCase("GIF87a") ||
-    		 gifHeader.equalsIgnoreCase("GIF89a"))) {
-    		return true;
+        public boolean isValid(byte[] value, ConstraintValidatorContext context) {
+        	if (value == null) {
+        	    return false;
     	    }
-    	}
-    	// Verify the JPEG begins with SOI & ends with EOI
-    	if (allowedTypes.contains(ImageType.JPEG)) {
-    	    if (value.length >= 4 &&
-                    value[0]
- == 0xff && value[1] == 0xd8 &&
-                    value[value.length - 2]
- == 0xff &&
-                    value[value.length -1]
- == 0xd9) {
-    		return true;
+        	// Verify the GIF header is either GIF87 or GIF89
+        	if (allowedTypes.contains(ImageType.GIF)) {
+    	        String gifHeader = new String(value, 0, 6);
+    	        if (value.length >= 6 &&
+        		(gifHeader.equalsIgnoreCase("GIF87a") ||
+        		 gifHeader.equalsIgnoreCase("GIF89a"))) {
+    	    	return true;
+    	        }
     	    }
-    	}
-    	// Unknown file format
-    	return false;
+        	// Verify the JPEG begins with SOI & ends with EOI
+        	if (allowedTypes.contains(ImageType.JPEG)) {
+    	        if (value.length >= 4 &&
+                    value[0] == 0xff && value[1] == 0xd8 &&
+                    value[value.length - 2] == 0xff &&
+                    value[value.length -1] == 0xd9) {
+    		        return true;
+    	        }
+        	}
+        	// Unknown file format
+    	    return false;
         }
     }
 
-  
-  
 
 Finally, let's apply the new constraint to the getData() method on our
 Image class.
 
   
-  
-
         @ImageContent
-        public byte[]
- getData() {
-    	return data;
+        public byte[] getData() {
+    	    return data;
         }
-
-  
   
 
 When validation of the "data" attribute occurs, the isValid() method in our [ImageContentValidator](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageContentValidator.java)
  will fire.  This method contains logic for performing simple validation of
  the format of the binary image data.  A potentially overlooked feature in
-the [ImageContentValidator|http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageContentValidator.java]
+the [ImageContentValidator](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageContentValidator.java)
  is that it can also validate for a specific image type.  By definition, it
 accepts for JPEG or GIF formats, but it can also validate for a specific
 format.  For example, by changing the annotation to:
 
-  
-  
 
         @ImageContent(ImageType.JPEG)
-        public byte[]
- getData() {
-    	return data;
+        public byte[] getData() {
+    	    return data;
         }
 
-  
-  
-
 instructs the validator to only permit image data with valid JPEG content.
 
 <a name="BeanValidationPrimer-Type-levelConstraints"></a>
-### Type-level Constraints
+## Type-level Constraints
 
 The examples thus far have shown the use of validation constraints on
 individual attributes.	That is sufficient in many cases, but validation
@@ -323,8 +289,6 @@ use a custom type-level constraint.  Her
 the new type-level constraint.
 
   
-  
-<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>Image.java|borderStyle=solid</B></DIV><DIV
class="codeContent panelContent">
     package org.apache.openjpa.example.gallery.model;
     
     import javax.persistence.Embedded;
@@ -347,53 +311,47 @@ the new type-level constraint.
         private long id;
         private ImageType type;
         private String fileName;
-        private byte[]
- data;
+        private byte[] data;
     
         @Id
         @GeneratedValue
         public long getId() {
-    	return id;
+    	    return id;
         }
     
         public void setId(long id) {
-    	this.id = id;
+    	    this.id = id;
         }
     
         @NotNull(message="Image type must be specified.")
         @Enumerated(EnumType.STRING)
         public ImageType getType() {
-    	return type;
+    	    return type;
         }
     
         public void setType(ImageType type) {
-    	this.type = type;
+    	    this.type = type;
         }
     
         @NotNull(message="Image file name must not be null.")
         public String getFileName() {
-    	return fileName;
+    	    return fileName;
         }
     
         public void setFileName(String fileName) {
-    	this.fileName = fileName;
+    	    this.fileName = fileName;
         }
     
         @NotNull(message="Image data must not be null.")
-        public byte[]
- getData() {
-    	return data;
+        public byte[] getData() {
+    	    return data;
         }
     
-        public void setData(byte[]
- data) {
-    	this.data = data;
+        public void setData(byte[] data) {
+    	    this.data = data;
         }
     }
 
-  
-  
-
 Notice that the @Pattern and @ImageContent were replaced by @NotNull
 constraints.  The new class level constraint will perform the duties
 previously performed by @Pattern and @ImageContent.  The @NotNull
@@ -405,9 +363,6 @@ groups and group sequences.  These conce
 Here is the code for the new [ImageConstraint](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageConstraint.java)
  annotation:
 
-  
-  
-<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>ImageConstraint.java|borderStyle=solid</B></DIV><DIV
class="codeContent panelContent">
     package org.apache.openjpa.example.gallery.constraint;
     
     import java.lang.annotation.Documented;
@@ -427,27 +382,19 @@ Here is the code for the new [ImageConst
     @Retention(RUNTIME)
     public @interface ImageConstraint {
         String message() default "Image data is not a supported format.";
-        Class<?>[]
- groups() default {};
-        Class<? extends Payload>[]
- payload() default {};
-        ImageType[]
- value() default { ImageType.GIF, ImageType.JPEG };
+        Class<?>[] groups() default {};
+        Class<? extends Payload>[] payload() default {};
+        ImageType[] value() default { ImageType.GIF, ImageType.JPEG };
     }
 
-  
-  
 
 Unlike the [ImageContent](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageContent.java)
- constraint, [ImageConstraint|http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageConstraint.java]
+ constraint, [ImageConstraint](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageConstraint.java)
  is targeted for a TYPE.  This allows this annotation to be applied at a
 type level (class or interface).  This constraint has a new validator
-class, [ImageValidator|http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageValidator.java]
+class, [ImageValidator](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageValidator.java)
 .
 
-  
-  
-<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>ImageValidator.java|borderStyle=solid</B></DIV><DIV
class="codeContent panelContent">
     package org.apache.openjpa.example.gallery.constraint;
     
     import java.util.Arrays;
@@ -462,8 +409,7 @@ class, [ImageValidator|http://svn.apache
     /**
      * Simple check that an Image is consistent in type, name, and format.
      */
-    public class ImageValidator implements ConstraintValidator<ImageConstraint,
-Image> {
+    public class ImageValidator implements ConstraintValidator<ImageConstraint,Image>
{
         private List<ImageType> allowedTypes = null;
         /**
          * Configure the constraint validator based on the image
@@ -471,62 +417,54 @@ Image> {
          * @param constraint the constraint definition
          */
         public void initialize(ImageConstraint constraint) {
-    	allowedTypes = Arrays.asList(constraint.value());
+    	    allowedTypes = Arrays.asList(constraint.value());
         }
     
         /**
          * Validate a specified value.
          */
-        public boolean isValid(Image value, ConstraintValidatorContext context)
-{
-    	if (value == null) {
-    	    return true;
-    	}
+        public boolean isValid(Image value, ConstraintValidatorContext context) {
+    	    if (value == null) {
+    	        return true;
+    	    }
     
-    	// All these fields will be pre-validated with @NotNull constraints
-    	// so they are safe to use without null checks.
-            byte[]
- data = value.getData();
-    	String fileName = value.getFileName();
-    	ImageType type = value.getType();
-    
-    	// Verify the GIF type is correct, has the correct extension and
-    	// the data header is either GIF87 or GIF89
-    	if (allowedTypes.contains(ImageType.GIF) &&
-    	    type == ImageType.GIF &&
-    	    fileName.endsWith(".gif")) {
-    	    if (data != null && data.length >= 6) {
-    		String gifHeader = new String(data, 0, 6);
-    		if (gifHeader.equalsIgnoreCase("GIF87a") ||
-    		     gifHeader.equalsIgnoreCase("GIF89a")) {
-    		    return true;
-    		}
+    	    // All these fields will be pre-validated with @NotNull constraints
+    	    // so they are safe to use without null checks.
+            byte[] data = value.getData();
+    	    String fileName = value.getFileName();
+    	    ImageType type = value.getType();
+    
+        	// Verify the GIF type is correct, has the correct extension and
+        	// the data header is either GIF87 or GIF89
+    	    if (allowedTypes.contains(ImageType.GIF) &&
+    	        type == ImageType.GIF &&
+        	    fileName.endsWith(".gif")) {
+        	    if (data != null && data.length >= 6) {
+    	    	    String gifHeader = new String(data, 0, 6);
+        		    if (gifHeader.equalsIgnoreCase("GIF87a") ||
+        		         gifHeader.equalsIgnoreCase("GIF89a")) {
+    	    	        return true;
+        		    }
+        	    }
     	    }
-    	}
-    	// Verify the JPEG type is correct, has the correct extension and
-    	// the data begins with SOI & ends with EOI markers
-    	if (allowedTypes.contains(ImageType.JPEG) &&
-    		value.getType() == ImageType.JPEG &&
-    		(fileName.endsWith(".jpg") ||
-    		 fileName.endsWith(".jpeg"))) {
-    	    if (data.length >= 4 &&
-                        data[0]
- == 0xff && data[1] == 0xd8 &&
-                        data[data.length - 2]
- == 0xff &&
-                        data[data.length - 1]
- == 0xd9) {
-    		return true;
+        	// Verify the JPEG type is correct, has the correct extension and
+        	// the data begins with SOI & ends with EOI markers
+    	    if (allowedTypes.contains(ImageType.JPEG) &&
+    		    value.getType() == ImageType.JPEG &&
+        		(fileName.endsWith(".jpg") ||
+        		 fileName.endsWith(".jpeg"))) {
+    	        if (data.length >= 4 &&
+                    data[0] == 0xff && data[1] == 0xd8 &&
+                    data[data.length - 2] == 0xff &&
+                    data[data.length - 1] == 0xd9) {
+    		        return true;
+    	        }
     	    }
-    	}
-    	// Unknown file format
-    	return false;
+    	    // Unknown file format
+    	    return false;
         }
     }
 
-  
-  
-
 One thing that must be considered in a JPA environment is the load state of
 the attributes of an entity when doing type-level validation.  Simply
 accessing attributes can have some side effects.  If the attribute is
@@ -538,19 +476,13 @@ likely due to detachment) you'll be vali
 manager is not necessary.  Here is an example of how PersistenceUtil could
 be used in the ImageValidator.
 
-  
-  
 
-            byte[]
- data = value.getData();
+        byte[] data = value.getData();
     	PersistenceUtil putil = Persistence.getPersistenceUtil();
     	if (!putil.isLoaded(value, "data")) {
     	    // don't validate the data
     	}
 
-  
-  
-
 <a name="BeanValidationPrimer-TheCompleteDomainModel"></a>
 ### The Complete Domain Model
 
@@ -558,11 +490,11 @@ Now that some of the basics of bean vali
 the domain model for our simple application and then get into JPA specifics
 through an example.
 
-!ig_domain_model.gif!
+![ig_domain_model.gif](images/ig_domain_model.gif)
 
 The persistent types [Album](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/model/Album.java)
-, [Creator|http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/model/Creator.java]
-, and [Location|http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/model/Location.java]
+, [Creator](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/model/Creator.java)
+, and [Location](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/model/Location.java)
  are new to the domain model.  An Album entity contains a reference to
 collection of its Image entities.  The Creator entity contains a reference
 to the Album album entities the image Creator contributed to and a
@@ -578,24 +510,18 @@ annotation to validate embedded objects.
 an image a new field and corresponding persistent properties were added to
 the Image class:
 
-  
-  
-
         private Location location;
     
         @Valid
         @Embedded
         public Location getLocation() {
-    	return location;
+        	return location;
         }
     
         public void setLocation(Location location) {
-    	this.location = location;
+        	this.location = location;
         }
 
-  
-  
-
 Notice the use of the @Valid annotation.  This provides chained validation
 of embeddables within a JPA environment.  Thus, when Image is validated,
 any constraints on the Location it references are also validated.  If
@@ -605,7 +531,7 @@ embeddables.  Referenced entities and co
 separately in order to prevent circular validation.
 
 <a name="BeanValidationPrimer-ValidationGroups"></a>
-### Validation Groups
+## Validation Groups
 
 Bean validation uses validation groups to determine what and when
 validation occurs.  There are no special interfaces to implement or
@@ -618,35 +544,24 @@ pollute the object model of another appl
 classes and logic that do not make sense for the application. By default,
 if a validation group or multiple groups is not specified on an individual
 constraint, it will be validated using the
-*javax.validation.groups.Default* group.  Creating a custom group is as
+**javax.validation.groups.Default** group.  Creating a custom group is as
 simple as creating a new interface definition.
-
   
-  
-<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>ImageGroup.java|borderStyle=solid</B></DIV><DIV
class="codeContent panelContent">
     package org.apache.openjpa.example.gallery.constraint;
     
     public interface ImageGroup {
     
     }
 
-  
-  
-
 This new [ImageGroup](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageGroup.java)
  validation group can now be applied to a constraint.
 
-  
-  
-
-        @ImageContent(groups={Default.class,ImageGroup.class})
-        public byte[]
- getData() {
-    	return data;
-        }
+    @ImageContent(groups={Default.class,ImageGroup.class})
+    public byte[] getData() {
+	    return data;
+    }
 
   
-  
 
 This @ImageContent constraint in this example will validate when either or
 both the Default and/or [ImageGroup](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/main/java/org/apache/openjpa/example/gallery/constraint/ImageGroup.java)
@@ -668,9 +583,6 @@ validation group) before validating its 
 Sequenced validation can be accomplished by defining a new validation
 group.
 
-  
-  
-<DIV class="code panel" style="border-style: solid;border-width: 1px;"><DIV class="codeHeader
panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;"><B>SequencedImageGroup.java|borderStyle=solid</B></DIV><DIV
class="codeContent panelContent">
     package org.apache.openjpa.example.gallery.constraint;
     
     import javax.validation.GroupSequence;
@@ -680,8 +592,6 @@ group.
     public interface SequencedImageGroup {
     
     }
-
-  
   
 
 This group is then specified during validation.  How to specify which
@@ -689,7 +599,7 @@ groups will be validated in a JPA enviro
 to follow.
 
 <a name="BeanValidationPrimer-JPAIntegration"></a>
-### JPA Integration
+## JPA Integration
 
 The JPA 2.0 specification makes integration with JSR-303 very simple.  In a
 JSE environment all you need to do is provide the JSR-303 API and a JSR-303
@@ -704,8 +614,6 @@ disable validation.  Besides adding the 
 your classpath, enabling validation in an existing 1.0 application may be
 as simple as modifying the root element of your persistence.xml to:
 
-  
-  
 
     <?xml version="1.0" encoding="UTF-8"?>
     <persistence xmlns="http://java.sun.com/xml/ns/persistence"
@@ -716,19 +624,22 @@ as simple as modifying the root element 
     ...
     </persistence>
 
-  
-  
 
-{info:title="Note"}While the JPA 2.0 specification is backward compatible
+<table class="info"><tr>
+  <td valign="top"><img src="images/information.gif" width="16" height="16" border="0">
+  <td><b>**NOTE**</b><br/>
+While the JPA 2.0 specification is backward compatible
 with JPA 1.0, there are some OpenJPA specific extensions that are not.	By
 switching to a 2.0 persistence.xml, in some cases you may need to specify
 compatibility flags in order to get OpenJPA 1.0 behavior.  See the [migration considerations](http://openjpa.apache.org/builds/latest/docs/manual/migration_considerations.html)
- section of the [OpenJPA 2.x manual|http://openjpa.apache.org/builds/latest/docs/manual/main.html]
- for additional information.
-{info}
+section of the [OpenJPA 2.x manual](http://openjpa.apache.org/builds/latest/docs/manual/main.html)
+for additional information.
+</tr></table>
+
+
 
 <a name="BeanValidationPrimer-ValidationModes"></a>
-##### Validation Modes
+### Validation Modes
 
 Bean validation provides three modes of operation within the JPA
 environment: _auto_, _callback_, and _none_.  As you may have guessed,
@@ -754,37 +665,28 @@ simplest is to add a validation-mode ele
 the desired validation mode.
 
   
-  
-
         <persistence-unit name="auto-validation">
-    	...
-    	<!-- Validation modes: AUTO, CALLBACK, NONE -->
-    	<validation-mode>AUTO</validation-mode>
-    	...
+    	    ...
+    	    <!-- Validation modes: AUTO, CALLBACK, NONE -->
+    	    <validation-mode>AUTO</validation-mode>
+    	    ...
         </persistence-unit>
 
-  
-  
 
 In addition, the validation mode can be configured programmatically by
-specifying the *javax.persistence.validation.mode* property with value
+specifying the **javax.persistence.validation.mode** property with value
 _auto_, _callback_, or _none_ when creating a new JPA entity manager
 factory.
 
-  
-  
 
     	Map<String, String> props = new HashMap<String,String>();
     	props.put("javax.persistence.validation.mode", "callback");
     	EntityManagerFactory emf = 
     	    Persistence.createEntityManagerFactory("validation", props);
-    
-
-  
   
 
 <a name="BeanValidationPrimer-ValidationinJPA"></a>
-##### Validation in JPA
+### Validation in JPA
 
 We've covered the basics of constraints and validation configuration, now
 on to actually doing some validation within JPA.  Bean validation within
@@ -799,25 +701,19 @@ PreRemove event you can specify the vali
 lifecycle event in the [persistence.xml](http://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/image-gallery/src/test/resources/META-INF/persistence.xml)
 .
 
-  
-  
 
-        <persistence-unit name="non-default-validation-groups">
-    	<class>my.Entity</class>
-    	<validation-mode>CALLBACK</validation-mode>
-    	<properties>
-    	    <property name="javax.persistence.validation.group.pre-persist"
-    	    
-value="org.apache.openjpa.example.gallery.constraint.SequencedImageGroup"/>
-    	    <property name="javax.persistence.validation.group.pre-update"
-    	    
-value="org.apache.openjpa.example.gallery.constraint.SequencedImageGroup"/>
-    	    <property name="javax.persistence.validation.group.pre-remove"
-    	     value="javax.validation.groups.Default"/>
-    	</properties>
-        </persistence-unit>
-
-  
+       <persistence-unit name="non-default-validation-groups">
+       	<class>my.Entity</class>
+       	<validation-mode>CALLBACK</validation-mode>
+   	    <properties>
+   	        <property name="javax.persistence.validation.group.pre-persist"
+                value="org.apache.openjpa.example.gallery.constraint.SequencedImageGroup"/>
+   	        <property name="javax.persistence.validation.group.pre-update"
+                value="org.apache.openjpa.example.gallery.constraint.SequencedImageGroup"/>
+   	        <property name="javax.persistence.validation.group.pre-remove"
+   	            value="javax.validation.groups.Default"/>
+	    </properties>
+    </persistence-unit>
   
 
 Now that we've gone through validation basics and JPA configuration
@@ -826,8 +722,6 @@ need to handle validation exceptions tha
 operations.  Here are some simple examples for the persist, update, and
 remove operations.  We'll get to more in-depth exception handling in a
 moment.
-
-  
   
 
     	EntityManagerFactory emf = 
@@ -875,8 +769,7 @@ moment.
     	    // was already rolled back.
     	    handleConstraintViolation(cve);
     	}
-    	// The update failure caused img to be detached. It must be merged
-back 
+    	// The update failure caused img to be detached. It must be merged back 
     	// into the persistence context.
     	img = em.merge(img);
     
@@ -894,11 +787,9 @@ back 
     	em.close();
     	emf.close();
 
-  
-  
 
 <a name="BeanValidationPrimer-ExceptionHandling"></a>
-##### Exception Handling
+### Exception Handling
 
 If one or more constraints fail to validate during a lifecycle event, a
 ConstraintViolationException is thrown by the JPA provider.  The
@@ -909,30 +800,22 @@ bean (JPA entity), the leaf bean (useful
 the attribute which failed to validate, and the value that caused the
 failure.  Here is a sample exception handling routine:
 
-  
-  
 
-        private void handleConstraintViolation(ConstraintViolationException
-cve) {
-          Set<ConstraintViolation<?>> cvs = cve.getConstraintViolations();
-          for (ConstraintViolation<?> cv : cvs) {
-    	 
-System.out.println("------------------------------------------------");
-    	  System.out.println("Violation: " + cv.getMessage());
-    	  System.out.println("Entity: " +
-cv.getRootBeanClass().getSimpleName());
-    	  // The violation occurred on a leaf bean (embeddable)
-    	  if (cv.getLeafBean() != null && cv.getRootBean() !=
-cv.getLeafBean()) {
-    	      System.out.println("Embeddable: " +
-cv.getLeafBean().getClass().getSimpleName());
-    	  }
-    	  System.out.println("Attribute: " + cv.getPropertyPath());
-    	  System.out.println("Invalid value: " + cv.getInvalidValue());
-          }
+    private void handleConstraintViolation(ConstraintViolationException cve) {
+        Set<ConstraintViolation<?>> cvs = cve.getConstraintViolations();
+        for (ConstraintViolation<?> cv : cvs) {    	 
+            System.out.println("------------------------------------------------");
+            System.out.println("Violation: " + cv.getMessage());
+    	    System.out.println("Entity: " + cv.getRootBeanClass().getSimpleName());
+    	    // The violation occurred on a leaf bean (embeddable)
+    	    if (cv.getLeafBean() != null && cv.getRootBean() != cv.getLeafBean()) {
+    	        System.out.println("Embeddable: " +
+                    cv.getLeafBean().getClass().getSimpleName());
+    	    }
+    	    System.out.println("Attribute: " + cv.getPropertyPath());
+    	    System.out.println("Invalid value: " + cv.getInvalidValue());
         }
-
-  
+    }
   
 
 Constraint violation processing is not quite as straight forward when using
@@ -947,7 +830,7 @@ the [JSR-303 specification](http://jcp.o
 .
 
 <a name="BeanValidationPrimer-OpenJPAandApacheBeanValidationLibraries"></a>
-### OpenJPA and Apache Bean Validation Libraries
+## OpenJPA and Apache Bean Validation Libraries
 
 If you are not using a maven build environment, the use of bean validation
 in a JPA environment requires a 2.0 level JPA provider and a bean
@@ -966,33 +849,26 @@ does publish nightly snapshots of the co
 extensions.  Until a binary package is available from the [Apache Bean Validation site](http://projects.apache.org/projects/bean_validation__incubating_.html)
 . You can obtain the core library, JSR-303 packages, and Geronimo JSR-303
 spec API directly from the maven repository.
-** [Apache Bean Validation Core](https://repository.apache.org/content/groups/public/org/apache/bval/bval-core/0.1-incubating/bval-core-0.1-incubating.jar)
-** [Apache Bean Validation JSR-303](https://repository.apache.org/content/groups/public/org/apache/bval/bval-jsr303/0.1-incubating/bval-jsr303-0.1-incubating.jar)
-** [Apache Geronimo Bean Validation Spec API](https://repository.apache.org/content/groups/public/org/apache/geronimo/specs/geronimo-validation_1.0_spec/1.1/geronimo-validation_1.0_spec-1.1.jar
)
-** [Apache Commons Bean Utils](http://commons.apache.org/beanutils/download_beanutils.cgi)
- - Extract the distribution and include commons-beanutils-1.8.3.jar on your
-runtime classpath.
-** [Apache Commons Lang](http://archive.apache.org/dist/commons/lang/binaries/commons-lang-2.4-bin.zip)
- - Extract the distribution and *include commons-lang-2.4.jar in your
-classpath before openjpa-all-2.0.0.jar*.
+
+    * [Apache Bean Validation Core](https://repository.apache.org/content/groups/public/org/apache/bval/bval-core/0.1-incubating/bval-core-0.1-incubating.jar)
+    * [Apache Bean Validation JSR-303](https://repository.apache.org/content/groups/public/org/apache/bval/bval-jsr303/0.1-incubating/bval-jsr303-0.1-incubating.jar)
+    * [Apache Geronimo Bean Validation Spec API](https://repository.apache.org/content/groups/public/org/apache/geronimo/specs/geronimo-validation_1.0_spec/1.1/geronimo-validation_1.0_spec-1.1.jar
)
+    * [Apache Commons Bean Utils](http://commons.apache.org/beanutils/download_beanutils.cgi)
- Extract the distribution and include commons-beanutils-1.8.3.jar on your runtime classpath.
+    * [Apache Commons Lang](http://archive.apache.org/dist/commons/lang/binaries/commons-lang-2.4-bin.zip)
- Extract the distribution and **include commons-lang-2.4.jar in your
+classpath before openjpa-all-2.0.0.jar**.
 
 <a name="BeanValidationPrimer-MavenConfiguration"></a>
-### Maven Configuration
+## Maven Configuration
 
 If you are a maven user, dependency management is much simpler.  Here are
 the dependencies you'll need in order to use OpenJPA 2.0 and the current
 (as of this writing) snapshot of Apache Bean Validation.
-
-  
   
 
       <dependencies>
-        <!-- When using OpenJPA 2.0.0 with bval, commons-lang must be in the
-dependency -->
-        <!-- tree before openjpa-all-2.0.0 since openjpa-all bundles
-commons-lang 2.1   -->
-        <!-- and bval requires version 2.4					   
-	-->
+        <!-- When using OpenJPA 2.0.0 with bval, commons-lang must be in the dependency
-->
+        <!-- tree before openjpa-all-2.0.0 since openjpa-all bundles commons-lang 2.1
  -->
+        <!-- and bval requires version 2.4					                        	-->
         <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
@@ -1023,85 +899,79 @@ commons-lang 2.1   -->
         </dependency>
       </dependencies>
 
-  
-  
 
 <a name="BeanValidationPrimer-GettingtheSampleApplication"></a>
-### Getting the Sample Application
+## Getting the Sample Application
 
 The code for the example provided in this primer is currently available
 from the OpenJPA subversion repository.  Obtaining, building and running
 the example requires [Subversion](http://subversion.apache.org)
-, [Maven|http://maven.apache.org/download.html]
+, [Maven](http://maven.apache.org/download.html)
  version 2.2.1 or later and JDK version 1.6.  Be sure to set your JAVA_HOME
 environment variable to the location of the 1.6 JDK.  To get and run the
 sample you must first get the source for OpenJPA via:
 
-*svn co* http://svn.apache.org/repos/asf/openjpa/trunk
+**svn co** <http://svn.apache.org/repos/asf/openjpa/trunk>
 
 Next, from the trunk directory, run a quick build to generate the OpenJPA
 provider jars.
 
-*_mvn -Dtest install -DfailIfNoTests=false -Dmaven.test.skip=true_*
+**mvn -Dtest install -DfailIfNoTests=false -Dmaven.test.skip=true**
 
 <a name="BeanValidationPrimer-RunningtheSampleApplication"></a>
-### Running the Sample Application
+## Running the Sample Application
 
 Currently, the sample only runs a jUnit which shows how bean validation can
 be used within the context of JPA persist, update, and remove operations. 
 To build and run the sample using maven:
 
-1. Goto the *openjpa-parent/openjpa-examples/image-gallery* directory
+1. Goto the **openjpa-parent/openjpa-examples/image-gallery** directory
 within the source tree you downloaded in the previous section.
 
-2. Run: *_mvn clean install_*
+2. Run: **mvn clean install**
 
 This command builds the image-gallery sample, enhances the entity classes,
 and runs the jUnits.  Within the Maven output, you should see output
 similar to the following.
 
   
-  
-{quote}
-Persisting an entity with non-matching extension and type
-------------------------------------------------
-Violation: Image data is not a supported format.
-Entity: Image
-Attribute:
-Invalid value: org.apache.openjpa.example.gallery.model.Image@8d5aad
-------------------------------------------------
-Fixing the file type and re-attempting the persist.
-Persist was successful
-Modifying file name to use an extension that does not
-match the file type.  This will cause a CVE.
-Update failed as expected
-------------------------------------------------
-Violation: Image data is not a supported format.
-Entity: Image
-Attribute:
-Invalid value: org.apache.openjpa.example.gallery.model.Image@8d5aad
-------------------------------------------------
-Setting the type to an invalid type.  This will cause a
-validation exception upon removal
-Remove failed as expected
-------------------------------------------------
-Violation: Image type must be specified.
-Entity: Image
-Attribute: type
-Invalid value: null
-------------------------------------------------
-Done
-{quote}
-  
+    Persisting an entity with non-matching extension and type
+    ------------------------------------------------
+    Violation: Image data is not a supported format.
+    Entity: Image
+    Attribute:
+    Invalid value: org.apache.openjpa.example.gallery.model.Image@8d5aad
+    ------------------------------------------------
+    Fixing the file type and re-attempting the persist.
+    Persist was successful
+    Modifying file name to use an extension that does not
+    match the file type.  This will cause a CVE.
+    Update failed as expected
+    ------------------------------------------------
+    Violation: Image data is not a supported format.
+    Entity: Image
+    Attribute:
+    Invalid value: org.apache.openjpa.example.gallery.model.Image@8d5aad
+    ------------------------------------------------
+    Setting the type to an invalid type.  This will cause a
+    validation exception upon removal
+    Remove failed as expected
+    ------------------------------------------------
+    Violation: Image type must be specified.
+    Entity: Image
+    Attribute: type
+    Invalid value: null
+    ------------------------------------------------
+    Done
   
 
 <a name="BeanValidationPrimer-ImportingtheSampleintoEclipse"></a>
-### Importing the Sample into Eclipse
+## Importing the Sample into Eclipse
 
 If you'd like to import the sample into Eclipse, from the image-gallery
 directory run:
 
-*mvn eclipse:eclipse*
+**mvn eclipse:eclipse**
 
 This will generate the necessary Eclipse project files.  Next, direct
 Eclipse to import a project from this directory.  You'll need to set the
@@ -1109,9 +979,9 @@ M2_REPO path variable to point at the lo
 repository in order to get the project to build.
 
 <a name="BeanValidationPrimer-References"></a>
-### References
+## References
 
-[JSR-317 - JPA 2.0 Specification](http://jcp.org/en/jsr/detail?id=317)
-[JSR-303 - Bean Validation Specification](http://jcp.org/en/jsr/detail?id=303)
-[OpenJPA 2.0 Release](http://openjpa.apache.org/openjpa-200.html)
-[Apache Bean Validation Home](http://projects.apache.org/projects/bean_validation__incubating_.html)
+   * [JSR-317 - JPA 2.0 Specification](http://jcp.org/en/jsr/detail?id=317)
+   * [JSR-303 - Bean Validation Specification](http://jcp.org/en/jsr/detail?id=303)
+   * [OpenJPA 2.0 Release](http://openjpa.apache.org/openjpa-200.html)
+   * [Apache Bean Validation Home](http://projects.apache.org/projects/bean_validation__incubating_.html)

Modified: openjpa/site/trunk/content/css/type-settings.css
URL: http://svn.apache.org/viewvc/openjpa/site/trunk/content/css/type-settings.css?rev=1413918&r1=1413917&r2=1413918&view=diff
==============================================================================
--- openjpa/site/trunk/content/css/type-settings.css (original)
+++ openjpa/site/trunk/content/css/type-settings.css Mon Nov 26 23:10:06 2012
@@ -2,7 +2,7 @@
 	Override default elements
 */
 
-h1, h2 {
+h1, h2, h3 {
     border-bottom: 1px dotted #660033;
 }
 

Added: openjpa/site/trunk/content/images/ig_domain_model.gif
URL: http://svn.apache.org/viewvc/openjpa/site/trunk/content/images/ig_domain_model.gif?rev=1413918&view=auto
==============================================================================
Binary file - no diff available.

Propchange: openjpa/site/trunk/content/images/ig_domain_model.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message