/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.core;

import java.util.Collections;
import java.util.Map;

public class SimpleFacetManager
  implements FacetManager
{

  public Object getInstanceOf(Object value, Class type, X x) {
    return create(type, x);
  }

  public <T> T create(Class<T> type, X x) {
    return create(type, Collections.<String, Object>emptyMap(), x);
  }

  public <T> T create(Class<T> type, Map<String, Object> args, X x) {
    try {
      // Automatically load FooImpl if Foo is abstract.
      // KGR: Why/where do we do this?
      if ( java.lang.reflect.Modifier.isAbstract(type.getModifiers()) ) {
        type = (Class<T>) Class.forName(type.getName() + "Impl");
      }

      try {
        java.lang.reflect.Method method = type.getMethod("getOwnClassInfo");
        ClassInfo classInfo = (ClassInfo)method.invoke(null);

        Object f = null;
        if ( x.get(classInfo.getId() + "_Factory") != null ) {
          f = x.get(classInfo.getId() + "_Factory");
        } else if ( classInfo.getAxiomsByClass(ContextFactory.class).size() == 1 ) {
          f = classInfo.getAxiomsByClass(ContextFactory.class).get(0);
        }

        if (f != null) {
          return ((ContextFactory<T>)f).getInstance(args, x);
        }

      } catch (NoSuchMethodException e) { }

      T obj = type.newInstance();

      if ( obj instanceof ContextAware ) ((ContextAware)obj).setX(x);

      if ( obj instanceof FObject ) {
        for (Map.Entry<String, Object> entry : args.entrySet()) {
          ((FObject)obj).setProperty(entry.getKey(), entry.getValue());
        }
      }

      return obj;
    } catch (java.lang.Exception e) {
      throw new RuntimeException(e);
    }
  }
}

@@ -936,24 +936,321 @@
 oke(null);%0A%0A
+        // First check the context for a custom factory for this type of object.%0A        // If there's nothing in the context, check the ClassInfo for an axiom%0A        // that creates instances of this type of object. Singletons and%0A        // multitons are common examples of this type of axiom.%0A
         Obje
@@ -1557,16 +1557,17 @@
     if (
+ 
 f != nul
@@ -1567,16 +1567,17 @@
  != null
+ 
 ) %7B%0A    

Add a comment in the SimpleFacetManager explaining what is happening with these ContextFactories. Also fix some spacing.