org.umlg.runtime.collection.persistent.UmlgBagClosableIterableImpl Maven / Gradle / Ivy
package org.umlg.runtime.collection.persistent;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.umlg.runtime.collection.UmlgBag;
import org.umlg.runtime.collection.UmlgRuntimeProperty;
import org.umlg.runtime.domain.UmlgMetaNode;
import org.umlg.runtime.domain.UmlgNode;
import java.lang.reflect.Method;
import java.util.Iterator;
public class UmlgBagClosableIterableImpl extends BaseBag implements UmlgBag {
private Iterator closeableIterator;
public UmlgBagClosableIterableImpl(Iterator closeableIterator, UmlgRuntimeProperty umlgRuntimeProperty) {
super(umlgRuntimeProperty);
this.closeableIterator = closeableIterator;
}
@Override
protected Iterator getEdges() {
return null;
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void loadFromVertex() {
for (Iterator iter = this.closeableIterator; iter.hasNext(); ) {
Vertex vertex = iter.next();
E node;
try {
Class> c = Class.forName((String) vertex.value("className"));
if (c.isEnum()) {
throw new RuntimeException();
// Object value = vertex.value(getPersistentName());
// node = (E) Enum.valueOf((Class extends Enum>) c, (String) value);
// putToInternalMap(node, vertex);
} else if (UmlgMetaNode.class.isAssignableFrom(c)) {
Method m = c.getDeclaredMethod("getInstance", new Class[0]);
node = (E) m.invoke(null);
} else if (UmlgNode.class.isAssignableFrom(c)) {
node = (E) c.getConstructor(Vertex.class).newInstance(vertex);
} else {
throw new RuntimeException();
// Object value = vertex.value(getPersistentName());
// node = (E) value;
// putToInternalMap(value, vertex);
}
this.internalCollection.add(node);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}
}