Index: DefaultMapContextManager.java
===================================================================
--- DefaultMapContextManager.java	(revision 43779)
+++ DefaultMapContextManager.java	(revision 43780)
@@ -35,6 +35,7 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import org.apache.commons.lang3.StringUtils;
@@ -96,11 +97,11 @@
 
     private Class drawerClazz = DefaultMapContextDrawer.class;
 
-    private Map legends = Collections.synchronizedMap(new HashMap());
+    private final Map legends = new HashMap();
 
-    private Map legendReaders = Collections.synchronizedMap(new HashMap());
+    private final Map<String, Class<ILegendReader>> legendReaders = new LinkedHashMap<>();
 
-    private Map legendWriters = Collections.synchronizedMap(new HashMap());
+    private final Map<String, Map<Class<ILegend>,Class<ILegendWriter>>> legendWriters = new LinkedHashMap<>();
 
     private String defaultVectorLegend;
 
@@ -325,6 +326,38 @@
 
     // =============================================================
     // Legend reading/writing
+
+    private Map<Class<ILegend>,Class<ILegendWriter>> getLegendWritersForFormat(String format) {
+        synchronized(legendWriters) {
+            return legendWriters.get(format);
+        }
+    }
+
+    private Class<ILegendReader> getLegendReaderForFormat(String format) {
+        synchronized(legendReaders) {
+            return legendReaders.get(format);
+        }
+    }
+
+    @Override
+    public List<String> getLegendReadingFormats() {
+        synchronized(legendReaders) {
+            List<String> resp = new ArrayList();
+            resp.addAll(legendReaders.keySet());
+            return resp;
+        }
+    }
+
+    @Override
+    public List<String> getLegendWritingFormats() {
+        synchronized(legendWriters) {
+            List<String> resp = new ArrayList();
+            resp.addAll(legendWriters.keySet());
+            return resp;
+        }
+    }
+    
+    @Override
     public void registerLegendReader(String format, Class readerClass)
             throws MapContextRuntimeException {
         if (readerClass == null
@@ -332,35 +365,17 @@
             throw new InvalidRegisteredClassException(ILegendReader.class,
                     readerClass, format);
         }
-
-        legendReaders.put(format, readerClass);
+        synchronized (legendReaders) {
+            legendReaders.put(format, readerClass);
+        }
         notifyObservers(REGISTER_LEGEND_READER, format, readerClass);
     }
 
-    public ILegendReader createLegendReader(String format)
-            throws MapContextRuntimeException {
-        Class legendReaderClazz = (Class) legendReaders.get(format);
-
-        if (legendReaderClazz != null) {
-            try {
-                ILegendReader reader = (ILegendReader) legendReaderClazz.newInstance();
-                return (ILegendReader) notifyObservers(CREATE_LEGEND_READER, reader).getValue();
-            } catch (InstantiationException e) {
-                throw new RegisteredClassInstantiationException(
-                        ILegendReader.class, legendReaderClazz, format, e);
-            } catch (IllegalAccessException e) {
-                throw new RegisteredClassInstantiationException(
-                        ILegendReader.class, legendReaderClazz, format, e);
-            }
-        }
-        return null;
-    }
-
+    @Override
     public void registerLegendWriter(Class legendClass, String format,
             Class writerClass) throws MapContextRuntimeException {
-        if (writerClass == null
+        if (writerClass == null || legendClass == null
                 || !ILegendWriter.class.isAssignableFrom(writerClass)
-                || legendClass == null
                 || !ILegend.class.isAssignableFrom(legendClass)) {
 
             throw new InvalidRegisteredClassException(ILegendWriter.class,
@@ -368,18 +383,35 @@
                             legendClass == null ? "Null" : legendClass.getName()));
         }
 
-        Map legendFormatWriters = (Map) legendWriters.get(format);
-
         synchronized (legendWriters) {
-            if (legendFormatWriters == null) {
-                legendFormatWriters = Collections.synchronizedMap(new HashMap());
-                legendWriters.put(format, legendFormatWriters);
+            Map<Class<ILegend>, Class<ILegendWriter>> legendWriterOfFormat = legendWriters.get(format);
+            if (legendWriterOfFormat == null) {
+                legendWriterOfFormat = new LinkedHashMap();
+                legendWriters.put(format, legendWriterOfFormat);
             }
+            legendWriterOfFormat.put(legendClass, writerClass);
         }
-        legendFormatWriters.put(legendClass, writerClass);
         notifyObservers(REGISTER_LEGEND_WRITER, format, writerClass);
     }
 
+    @Override
+    public ILegendReader createLegendReader(String format)
+            throws MapContextRuntimeException {
+        Class<ILegendReader> legendReaderClazz = getLegendReaderForFormat(format);
+
+        if (legendReaderClazz != null) {
+            try {
+                ILegendReader reader = (ILegendReader) legendReaderClazz.newInstance();
+                return (ILegendReader) notifyObservers(CREATE_LEGEND_READER, reader).getValue();
+            } catch (InstantiationException|IllegalAccessException e) {
+                throw new RegisteredClassInstantiationException(
+                        ILegendReader.class, legendReaderClazz, format, e);
+            }
+        }
+        return null;
+    }
+
+    @Override
     public ILegendWriter createLegendWriter(Class legendClass, String format)
             throws MapContextRuntimeException {
 
@@ -387,12 +419,10 @@
             return null;
         }
 
-        Map legendFormatWriters = getLegendWritersForFormat(format);
+        Map<Class<ILegend>, Class<ILegendWriter>> legendFormatWriters = getLegendWritersForFormat(format);
 
         if (legendFormatWriters != null) {
-            Class legendWriterClazz = (Class) legendFormatWriters
-                    .get(legendClass);
-
+            Class<ILegendWriter> legendWriterClazz = legendFormatWriters.get(legendClass);
             if (legendWriterClazz != null) {
                 /*
                  * Found exact match
@@ -400,16 +430,13 @@
                 try {
                     ILegendWriter writer = (ILegendWriter) legendWriterClazz.newInstance();
                     return (ILegendWriter) notifyObservers(CREATE_LEGEND_READER, writer).getValue();
-                } catch (InstantiationException e) {
+                } catch (InstantiationException|IllegalAccessException e) {
                     throw new RegisteredClassInstantiationException(
-                            ILegendWriter.class, legendWriterClazz, format
-                            .concat("-").concat(
-                                    legendClass == null ? "Null" : legendClass.getName()), e);
-                } catch (IllegalAccessException e) {
-                    throw new RegisteredClassInstantiationException(
-                            ILegendWriter.class, legendWriterClazz, format
-                            .concat("-").concat(
-                                    legendClass == null ? "Null" : legendClass.getName()), e);
+                            ILegendWriter.class, 
+                            legendWriterClazz,
+                            format.concat("-").concat(legendClass.getName()), 
+                            e
+                    );
                 }
             } else {
                 /*
@@ -425,14 +452,9 @@
         return null;
     }
 
-    private ILegendWriter getSuperClassLegendWriter(Map clsToWtr, Class legclass)
+    private ILegendWriter getSuperClassLegendWriter(Map<Class<ILegend>, Class<ILegendWriter>> clsToWtr, Class<ILegend> legclass)
             throws Exception {
 
-        if (!ILegend.class.isAssignableFrom(legclass)) {
-            // Class is not a legend
-            return null;
-        }
-
         Iterator kiter = clsToWtr.keySet().iterator();
         Object oitem = null;
         Class citem = null;
@@ -455,27 +477,6 @@
         return null;
     }
 
-    private Map getLegendWritersForFormat(String format) {
-        return (Map) legendWriters.get(format);
-    }
-
-    public List getLegendReadingFormats() {
-        List resp = new ArrayList();
-        Iterator iter = legendReaders.keySet().iterator();
-        while (iter.hasNext()) {
-            resp.add(iter.next());
-        }
-        return resp;
-    }
-
-    public List getLegendWritingFormats() {
-        List resp = new ArrayList();
-        Iterator iter = legendWriters.keySet().iterator();
-        while (iter.hasNext()) {
-            resp.add(iter.next());
-        }
-        return resp;
-    }
     // =============================================================
 
     public IMultiLayerSymbol createMultiLayerSymbol(int shapeType)
