package org.simpleframework.xml.core;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.ValidationTestCase;
import org.simpleframework.xml.transform.Matcher;
import org.simpleframework.xml.transform.Transform;

public class MatcherTest extends ValidationTestCase {
   
   @Root
   @Namespace(prefix="foo", reference="http://www.domain.com/value")
   private static class Example {
      
      @Element
      private Integer value;
      
      @Attribute
      private Integer attr;
      
      public Example() {
         super();
      }
      
      public Example(Integer value, Integer attr) {
         this.value = value;
         this.attr = attr;
      }
   }
   
   private static class ExampleMatcher implements Matcher, Transform<Integer> {

      public Transform match(Class type) throws Exception {
         if(type == Integer.class) {
            return this;
         }
         return null;
      }

      public Integer read(String value) throws Exception {
         return Integer.valueOf(value);
      }

      public String write(Integer value) throws Exception {
         return "12345";
      }
   }
   
   public void testMatcher() throws Exception {
      Matcher matcher = new ExampleMatcher();
      Serializer serializer = new Persister(matcher);
      Example example = new Example(1, 9999);
      
      serializer.write(example, System.out);
    
      validate(serializer, example);
   }

}

@@ -32,16 +32,46 @@
 .core;%0A%0A
+import java.io.StringWriter;%0A%0A
 import o
@@ -879,24 +879,33 @@
  %7D%0A   %7D%0A   %0A
+   @Root%0A
    private s
@@ -921,419 +921,1654 @@
 ss E
-xampleMatcher implements Matcher, Transform%3CInteger%3E %7B%0A%0A      public Transform match(Class type) throws Exception %7B%0A         if(type == Integer.class) %7B%0A            return this;%0A         %7D%0A         return null;%0A      %7D%0A%0A      public Integer read(String value) throws Exception %7B%0A         return Integer.valueOf(value);%0A      %7D%0A%0A      public String write(Integer value) throws Exception %7B%0A         return %2212345%22
+mptyStringExample %7B%0A      %0A      @Element(required=false)%0A      private String emptyValue;%0A      %0A      @Element(required=false)%0A      private String nullValue;%0A      %0A      public EmptyStringExample() %7B%0A         super();%0A      %7D%0A      %0A      public EmptyStringExample(String emptyValue, String nullValue) %7B%0A         this.emptyValue = emptyValue;%0A         this.nullValue = nullValue;%0A      %7D%0A   %7D%0A   %0A   private static class ExampleIntegerMatcher implements Matcher, Transform%3CInteger%3E %7B%0A%0A      public Transform match(Class type) throws Exception %7B%0A         if(type == Integer.class) %7B%0A            return this;%0A         %7D%0A         return null;%0A      %7D%0A%0A      public Integer read(String value) throws Exception %7B%0A         return Integer.valueOf(value);%0A      %7D%0A%0A      public String write(Integer value) throws Exception %7B%0A         return %2212345%22;%0A      %7D%0A   %7D%0A   %0A   private static class ExampleStringMatcher implements Matcher, Transform%3CString%3E %7B%0A%0A      public Transform match(Class type) throws Exception %7B%0A         if(type == String.class) %7B%0A            return this;%0A         %7D%0A         return null;%0A      %7D%0A%0A      public String read(String value) throws Exception %7B         %0A         if(value != null) %7B%0A            if(value.equals(%22%5B%5BNULL%5D%5D%22)) %7B%0A               return null;%0A            %7D%0A            if(value.equals(%22%5B%5BEMPTY%5D%5D%22)) %7B%0A               return %22%22;%0A            %7D%0A         %7D%0A         return value;%0A      %7D%0A%0A      public String write(String value) throws Exception %7B%0A         if(value == null) %7B%0A            return %22%5B%5BNULL%5D%5D%22;%0A         %7D%0A         if(value.equals(%22%22)) %7B%0A            return %22%5B%5BEMPTY%5D%5D%22;%0A         %7D%0A         return value
 ;%0A  
@@ -2665,16 +2665,23 @@
  Example
+Integer
 Matcher(
@@ -2881,12 +2881,650 @@
 e);%0A   %7D
+%0A   %0A   public void testStringMatcher() throws Exception %7B%0A      Matcher matcher = new ExampleStringMatcher();%0A      Serializer serializer = new Persister(matcher);%0A      EmptyStringExample original = new EmptyStringExample(%22%22, null);%0A      StringWriter writer = new StringWriter();%0A      %0A      serializer.write(original, writer);%0A      %0A      String text = writer.toString();%0A      System.out.println(text);%0A      %0A      EmptyStringExample recovered = serializer.read(EmptyStringExample.class, text);%0A      %0A      assertEquals(recovered.emptyValue, original.emptyValue);%0A      assertEquals(recovered.nullValue, original.nullValue);%0A   %7D
 %0A%0A%7D%0A

Fix the matcher example