Title: [2127] trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended: Extract inner class into own file.
Revision
2127
Author
joehni
Date
2013-09-24 19:22:18 -0500 (Tue, 24 Sep 2013)

Log Message

Extract inner class into own file.

Modified Paths


Added Paths

Diff

Modified: trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/ToAttributedValueConverter.java (2126 => 2127)


--- trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/ToAttributedValueConverter.java	2013-09-25 00:21:11 UTC (rev 2126)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/ToAttributedValueConverter.java	2013-09-25 00:22:18 UTC (rev 2127)
@@ -29,14 +29,11 @@
 import com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.DuplicateFieldException;
 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
 import com.thoughtworks.xstream.core.JVM;
-import com.thoughtworks.xstream.core.util.DependencyInjectionFactory;
 import com.thoughtworks.xstream.core.util.FastField;
 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
 import com.thoughtworks.xstream.core.util.Primitives;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
-import com.thoughtworks.xstream.mapper.AttributeMapper;
-import com.thoughtworks.xstream.mapper.DefaultMapper;
 import com.thoughtworks.xstream.mapper.Mapper;
 
 
@@ -63,6 +60,7 @@
     /**
      * Creates a new ToAttributedValueConverter instance.
      * 
+     * @param type the type that is handled by this converter instance
      * @param mapper the mapper in use
      * @param reflectionProvider the reflection provider in use
      * @param lookup the converter lookup in use
@@ -77,6 +75,7 @@
     /**
      * Creates a new ToAttributedValueConverter instance.
      * 
+     * @param type the type that is handled by this converter instance
      * @param mapper the mapper in use
      * @param reflectionProvider the reflection provider in use
      * @param lookup the converter lookup in use
@@ -106,23 +105,9 @@
             }
             this.valueField = field;
         }
-        enumMapper = JVM.is15() ? createEnumMapper(mapper) : null;
+        enumMapper = JVM.is15() ? UseAttributeForEnumMapper.createEnumMapper(mapper) : null;
     }
 
-    private Mapper createEnumMapper(final Mapper mapper) {
-        try {
-            Class enumMapperClass = Class.forName(
-                "com.thoughtworks.xstream.mapper.EnumMapper", true,
-                Mapper.class.getClassLoader());
-            return (Mapper)DependencyInjectionFactory.newInstance(
-                enumMapperClass,
-                new Object[]{new UseAttributeForEnumMapper(mapper
-                    .lookupMapperOfType(DefaultMapper.class))});
-        } catch (Exception e) {
-            return null;
-        }
-    }
-
     public boolean canConvert(final Class type) {
         return this.type == type;
     }
@@ -156,7 +141,7 @@
                     throw exception;
                 }
 
-                ConverterMatcher converter = isEnum(type)
+                ConverterMatcher converter = UseAttributeForEnumMapper.isEnum(type)
                     ? (ConverterMatcher)enumMapper.getConverterFromItemType(null, type, null)
                     : (ConverterMatcher)mapper.getLocalConverter(definedIn, fieldName);
                 if (converter == null) {
@@ -242,7 +227,7 @@
 
                 Class type = field.getType();
                 final Class declaringClass = field.getDeclaringClass();
-                ConverterMatcher converter = isEnum(type)
+                ConverterMatcher converter = UseAttributeForEnumMapper.isEnum(type)
                     ? (ConverterMatcher)enumMapper.getConverterFromItemType(null, type, null)
                     : (ConverterMatcher)mapper.getLocalConverter(declaringClass, fieldName);
                 if (converter == null) {
@@ -340,36 +325,4 @@
         return valueField.getName().equals(field.getName())
             && valueField.getDeclaringClass().getName().equals(field.getDeclaringClass());
     }
-    
-    private static boolean isEnum(Class type) {
-        while(type != null && type != Object.class) {
-            if (type.getName().equals("java.lang.Enum")) {
-                return true;
-            }
-            type = type.getSuperclass();
-        }
-        return false;
-    }
-    
-    private static class UseAttributeForEnumMapper extends AttributeMapper {
-
-        public UseAttributeForEnumMapper(Mapper wrapped) {
-            super(wrapped, null, null);
-        }
-
-        public boolean shouldLookForSingleValueConverter(String fieldName, Class type,
-            Class definedIn) {
-            return isEnum(type);
-        }
-
-        public SingleValueConverter getConverterFromItemType(String fieldName, Class type,
-            Class definedIn) {
-            return null;
-        }
-
-        public SingleValueConverter getConverterFromAttribute(Class definedIn,
-            String attribute, Class type) {
-            return null;
-        }
-    }
 }

Added: trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/UseAttributeForEnumMapper.java (0 => 2127)


--- trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/UseAttributeForEnumMapper.java	                        (rev 0)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/UseAttributeForEnumMapper.java	2013-09-25 00:22:18 UTC (rev 2127)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2013 XStream Committers.
+ * All rights reserved.
+ *
+ * The software in this package is published under the terms of the BSD
+ * style license a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ * 
+ * Created on 25. September 2013 by Joerg Schaible
+ */
+package com.thoughtworks.xstream.converters.extended;
+
+import com.thoughtworks.xstream.converters.SingleValueConverter;
+import com.thoughtworks.xstream.core.util.DependencyInjectionFactory;
+import com.thoughtworks.xstream.mapper.AttributeMapper;
+import com.thoughtworks.xstream.mapper.DefaultMapper;
+import com.thoughtworks.xstream.mapper.Mapper;
+
+class UseAttributeForEnumMapper extends AttributeMapper {
+
+    public UseAttributeForEnumMapper(Mapper wrapped) {
+        super(wrapped, null, null);
+    }
+
+    /**
+     * @deprecated only used for Java 1.4 support 
+     */
+    public static boolean isEnum(Class type) {
+        while(type != null && type != Object.class) {
+            if (type.getName().equals("java.lang.Enum")) {
+                return true;
+            }
+            type = type.getSuperclass();
+        }
+        return false;
+    }
+
+    public boolean shouldLookForSingleValueConverter(String fieldName, Class type,
+        Class definedIn) {
+        return isEnum(type);
+    }
+
+    public SingleValueConverter getConverterFromItemType(String fieldName, Class type,
+        Class definedIn) {
+        return null;
+    }
+
+    public SingleValueConverter getConverterFromAttribute(Class definedIn,
+        String attribute, Class type) {
+        return null;
+    }
+
+    static Mapper createEnumMapper(final Mapper mapper) {
+        try {
+            Class enumMapperClass = Class.forName(
+                "com.thoughtworks.xstream.mapper.EnumMapper", true,
+                Mapper.class.getClassLoader());
+            return (Mapper)DependencyInjectionFactory.newInstance(
+                enumMapperClass,
+                new Object[]{new UseAttributeForEnumMapper(mapper
+                    .lookupMapperOfType(DefaultMapper.class))});
+        } catch (Exception e) {
+            return null;
+        }
+    }
+}
\ No newline at end of file
Property changes on: trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/UseAttributeForEnumMapper.java
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to