/*
 *  Copyright (C) 2011 The Animo Project
 *  http://animotron.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 3
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.animotron.graph;

import org.animotron.Statement;
import org.animotron.Statements;
import org.animotron.operator.Relation;
import org.animotron.operator.THE;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;

/**
 * @author <a href="mailto:gazdovskyd@gmail.com">Evgeny Gazdovsky</a>
 * 
 */
public abstract class AbstractGraphSerializer implements GraphHandler {
	
	final public void serialize(Relationship r) {
		startDocument();
		build(r);
		endDocument();
	}
	
	private void build(Relationship r) {
		
		RelationshipType type = r.getType();
		Statement statement = type.name().startsWith(THE.PREFIX + ":") ? THE.getInstance() : Statements.relationshipType(type);
		
		if (statement == null)
			return;
		
		start(statement, r);
		
		if (!(r instanceof Relation)) {
			for(Relationship i : r.getEndNode().getRelationships(Direction.OUTGOING)){
				build(i);
			}
		}
		
		end(statement, r);
	}
		
}

@@ -1291,16 +1291,18 @@
 p r) %7B%0A%09
+//
 %09startDo
@@ -1324,16 +1324,18 @@
 ld(r);%0A%09
+//
 %09endDocu
@@ -1593,16 +1593,18 @@
 n;%0A%09%09%0A%09%09
+//
 start(st
@@ -1622,18 +1622,96 @@
 ;%0A%09%09
-%0A%09%09if (!(r
+System.out.print(%22%5B%22 + statement.name() + %22 %22 + statement.name(r));%0A%09%09%0A%09%09if (!(statement
  ins
@@ -1837,16 +1837,43 @@
 %09%7D%0A%09%09%0A%09%09
+System.out.print(%22%5D%22);%0A%09%09//
 end(stat

fix one bug and show another