All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.umlg.runtime.collection.persistent.UmlgBagClosableIterableImpl Maven / Gradle / Ivy

There is a newer version: 2.0.15
Show newest version
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) 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);
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy