mongo-dart / lib / objectory / Objectory.dart

typedef PersistentObject FactoryMethod();
class ClassSchema{
  static final SimpleProperty = 0;
  static final InternalObject = 1;
  static final ExternalObject = 2;
  String className;
  FactoryMethod factoryMethod;
  Set<String> properties;
  Map<String,String> components;
  Map<String,String> links;
  ClassSchema(this.className,this.factoryMethod,List<String> propertyList,    
    [this.components,this.links]){
    properties = new Set<String>.from(propertyList);
    if (components !== null){
      properties.addAll(components.getKeys());
    }
    if (links !== null){
      properties.addAll(links.getKeys());
    }
  }    
  void property(String propertyName, String className, [int type = SimpleProperty]){
    
  }
}
interface Objectory{  
  void registerClass(ClassSchema schema);
  PersistentObject newInstance(String className);
  PersistentObject map2Object(String className, Map map);  
  Future<PersistentObject> findOne(String className,[Map selector]);
  Future<List<PersistentObject>> find(String className,[Map selector]);
  void save(PersistentObject persistentObject);
  void remove(PersistentObject persistentObject);
  Future<bool> open([String database, String url]);
  Future<bool> dropDb();
  ClassSchema getSchema(String className);
  void close();
}
abstract class ObjectoryBaseImpl implements Objectory{
  Map<String,ClassSchema> schemata;
  ObjectoryBaseImpl(){
    schemata = new  Map<String,ClassSchema>();
  }
  ClassSchema getSchema(String className){
    return schemata[className];
  }
  PersistentObject newInstance(String className){
    if (schemata.containsKey(className)){
      return schemata[className].factoryMethod();
    }
    throw "Class $className have not been registered in Objectory";
  }
  PersistentObject map2Object(String className, Map map){
    var result = newInstance(className);
    result.map = map;
    if (result.isRoot()){
      result.id = map["_id"];    
    }      
    ClassSchema classSchema = schemata[className];
    if (classSchema.components !== null){      
      classSchema.components.forEach((property,componentClass){
        PersistentObject component = map2Object(componentClass,map[property]);
        result.setProperty(property,component);
        result.clearDirtyStatus();
      });
    }
    if (classSchema.links !== null){      
      classSchema.links.forEach((property,linkClass){
      //  print(property);
        ObjectId linkId = map[property];
        if (linkId !== null){
          RootPersistentObject link = newInstance(linkClass);
          link.id = linkId;
          result.setProperty(property,link);
          result.clearDirtyStatus();
        }          
      });
    }
    return result;
  }
  void clearSchemata(){
    schemata.clear();
  }
  void registerClass(ClassSchema schema){
    schemata[schema.className] = schema;
  }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.