Michael Ludwig  committed 5946c7d

Simplify mapping file to only require class name and not need a key

  • Participants
  • Parent commits 483f401
  • Branches default

Comments (0)

Files changed (4)

File src/main/java/com/lhkbob/entreri/

  * canonical name <var>C</var> by adding the file META-INF/entreri/mapping/C to the
  * classpath, where its contents must be:
  * <pre>
- *     mapping=P
  * </pre>
- * where P is the binary name of the property suitable for passing into {@link
- * Class#forName(String)}.
+ * where the value is suitable for passing into {@link Class#forName(String)}.
  * <p/>
  * The generated proxies will implement equals() and hashCode() based on their type and
  * the id of their owning entity. The {@link ComponentIterator} class creates flyweight

File src/main/java/com/lhkbob/entreri/impl/

 import java.util.Enumeration;
-import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
  * consistent mapping from Java type to an associated Property type that wraps that data.
  * Primitive and plain Object wrapping is built-in. A property can be overridden for a
  * class by placing the file META-INF/entreri/mapping/&lt;CANONICAL CLASS NAME&gt; in the
- * class path, with a single property value of mapping=&lt;BINARY CLASS NAME OF
- * PROPERTY&gt;.
+ * class path, with a single string &lt;BINARY CLASS NAME OF PROPERTY&gt;.
  * @author Michael Ludwig
 public final class TypePropertyMapping {
     public static final String MAPPING_DIR = "META-INF/entreri/mapping/";
-    public static final String KEY = "mapping";
     private static final ConcurrentHashMap<Class<?>, Class<? extends Property>> typeMapping;
                                                    " present in classpath");
-                    InputStream in = mapping.openStream();
-                    Properties p = new Properties();
-                    p.load(in);
+                    BufferedReader in = new BufferedReader(
+                            new InputStreamReader(mapping.openStream()));
+                    String line;
+                    StringBuilder className = new StringBuilder();
+                    // be somewhat permissive of whitespace (any other input most likely
+                    // will fail to load a class)
+                    while ((line = in.readLine()) != null) {
+                        className.append(line);
+                    }
                     // use the type's class loader so that the loaded property is tied to
                     // the same loader
                     try {
                         pType = (Class<? extends Property>) type.getClassLoader()
-                                                                .loadClass(p.getProperty(
-                                                                        KEY));
+                                                                .loadClass(className
+                                                                                   .toString()
+                                                                                   .trim());
                         // store the mapping for later as well, this is safe because
                         // a class's loader is part of its identity and the property impl

File src/test/resources/META-INF/entreri/mapping/com.lhkbob.entreri.components.CustomProperty.Bletch


File src/test/resources/META-INF/entreri/mapping/com.lhkbob.entreri.components.NoFactoryProperty.Crass