You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2012/03/17 01:51:25 UTC

svn commit: r1301848 - in /commons/sandbox/graph/branches/drop-marker-interfaces-feature/src: main/java/org/apache/commons/graph/export/ test/java/org/apache/commons/graph/export/

Author: simonetripodi
Date: Sat Mar 17 00:51:24 2012
New Revision: 1301848

URL: http://svn.apache.org/viewvc?rev=1301848&view=rev
Log:
initial proposal for exporter: reorganized exporters with SAX-alike APIs, managed Vertices/Edges properties with existing Mapper, GaphML is still a TODO

Added:
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/EdgeMapperSelector.java   (with props)
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/VertexMapperSelector.java   (with props)
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeLabelMapper.java   (with props)
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeWeightMapper.java   (with props)
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/VertexLabelMapper.java   (with props)
Modified:
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/AbstractExporter.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DefaultNamedExportSelector.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DefaultToStreamBuilder.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DotExporter.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/ExportSelctor.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/ToStreamBuilder.java
    commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/ExportTestCase.java

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/AbstractExporter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/AbstractExporter.java?rev=1301848&r1=1301847&r2=1301848&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/AbstractExporter.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/AbstractExporter.java Sat Mar 17 00:51:24 2012
@@ -19,10 +19,18 @@ package org.apache.commons.graph.export;
  * under the License.
  */
 
+import static java.lang.String.format;
+
 import java.io.IOException;
 import java.io.Writer;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Mapper;
+import org.apache.commons.graph.VertexPair;
 
 abstract class AbstractExporter<V, E>
 {
@@ -33,12 +41,21 @@ abstract class AbstractExporter<V, E>
 
     private final Writer writer;
 
+    private final Map<String, Mapper<V, ?>> vertexProperties;
+
+    private final Map<String, Mapper<E, ?>> edgeProperties;
+
     private final String name;
 
-    public AbstractExporter( Graph<V, E> graph, Writer writer, String name )
+    public AbstractExporter( Graph<V, E> graph, Writer writer,
+                             Map<String, Mapper<V, ?>> vertexProperties,
+                             Map<String, Mapper<E, ?>> edgeProperties,
+                             String name )
     {
         this.graph = graph;
         this.writer = writer;
+        this.vertexProperties = vertexProperties;
+        this.edgeProperties = edgeProperties;
         this.name = name != null ? name : G;
     }
 
@@ -52,17 +69,53 @@ abstract class AbstractExporter<V, E>
         return writer;
     }
 
-    protected final String getName()
-    {
-        return name;
-    }
-
     public final void export()
         throws GraphExportException
     {
         try
         {
-            internalExport();
+            startSerialization();
+            comment( format( "Graph generated by Apache Commons Graph on %s%n", new Date() ) );
+
+            startGraph( name );
+
+            // this is basically for the GraphML
+
+            
+
+            // END
+
+            for ( V vertex : graph.getVertices() )
+            {
+                Map<String, Object> properties = new HashMap<String, Object>( vertexProperties.size() );
+
+                for ( Entry<String, Mapper<V, ?>> vertexProperty : vertexProperties.entrySet() )
+                {
+                    properties.put( vertexProperty.getKey(),
+                                    vertexProperty.getValue().map( vertex ) );
+                }
+
+                vertex( vertex, properties );
+            }
+
+            for ( E edge : graph.getEdges() )
+            {
+                VertexPair<V> vertices = graph.getVertices( edge );
+
+                Map<String, Object> properties = new HashMap<String, Object>( edgeProperties.size() );
+
+                for ( Entry<String, Mapper<E, ?>> edgeProperty : edgeProperties.entrySet() )
+                {
+                    properties.put( edgeProperty.getKey(),
+                                    edgeProperty.getValue().map( edge ) );
+                }
+
+                edge( edge, vertices.getHead(), vertices.getTail(), properties );
+            }
+
+            endGraph();
+
+            endSerialization();
         }
         catch ( Exception e )
         {
@@ -84,7 +137,31 @@ abstract class AbstractExporter<V, E>
         }
     }
 
-    protected abstract void internalExport()
+    protected abstract void startSerialization()
+        throws Exception;
+
+    protected abstract void endSerialization()
+        throws Exception;
+
+    protected abstract void startGraph( String name )
+        throws Exception;
+
+    protected abstract void endGraph()
+        throws Exception;
+
+    protected abstract void comment( String text )
+        throws Exception;
+
+    protected abstract void enlistVerticesProperty( String name, Class<?> type )
+        throws Exception;
+
+    protected abstract void enlistEdgesProperty( String name, Class<?> type )
+        throws Exception;
+
+    protected abstract void vertex( V vertex, Map<String, Object> properties )
+        throws Exception;
+
+    protected abstract void edge( E edge, V head, V tail, Map<String, Object> properties )
         throws Exception;
 
 }

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DefaultNamedExportSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DefaultNamedExportSelector.java?rev=1301848&r1=1301847&r2=1301848&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DefaultNamedExportSelector.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DefaultNamedExportSelector.java Sat Mar 17 00:51:24 2012
@@ -19,9 +19,16 @@ package org.apache.commons.graph.export;
  * under the License.
  */
 
+import static org.apache.commons.graph.utils.Assertions.*;
+
 import java.io.Writer;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
 
 import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Mapper;
 
 final class DefaultNamedExportSelector<V, E>
     implements NamedExportSelctor<V, E>
@@ -31,6 +38,10 @@ final class DefaultNamedExportSelector<V
 
     private final Writer writer;
 
+    private final Map<String, Mapper<V, ?>> vertexProperties = new HashMap<String, Mapper<V,?>>();
+
+    private final Map<String, Mapper<E, ?>> edgeProperties = new HashMap<String, Mapper<E,?>>();
+
     private final String name;
 
     public DefaultNamedExportSelector( Graph<V, E> graph, Writer writer )
@@ -48,13 +59,13 @@ final class DefaultNamedExportSelector<V
     public void usingDotNotation()
         throws GraphExportException
     {
-        new DotExporter<V, E>( graph, writer, name ).export();
+        new DotExporter<V, E>( graph, writer, vertexProperties, edgeProperties, name ).export();
     }
 
     public void usingGraphMLFormat()
         throws GraphExportException
     {
-        new GraphMLExporter<V, E>( graph, writer, name ).export();
+        new GraphMLExporter<V, E>( graph, writer, vertexProperties, edgeProperties, name ).export();
     }
 
     public ExportSelctor<V, E> withName( String name )
@@ -62,4 +73,36 @@ final class DefaultNamedExportSelector<V
         return new DefaultNamedExportSelector<V, E>( graph, writer, name );
     }
 
+    public EdgeMapperSelector<V, E> withEdgeProperty( String name )
+    {
+        final String checkedName = checkNotNull( name, "Null Edge property not admitted" );
+        return new EdgeMapperSelector<V, E>()
+        {
+
+            public ExportSelctor<V, E> expandedBy( Mapper<E, ?> mapper )
+            {
+                mapper = checkNotNull( mapper, "Null Edge mapper for property %s not admitted", checkedName );
+                edgeProperties.put( checkedName, mapper );
+                return DefaultNamedExportSelector.this;
+            }
+
+        };
+    }
+
+    public VertexMapperSelector<V, E> withVertexProperty( String name )
+    {
+        final String checkedName = checkNotNull( name, "Null Vertex property not admitted" );
+        return new VertexMapperSelector<V, E>()
+        {
+
+            public ExportSelctor<V, E> expandedBy( Mapper<V, ?> mapper )
+            {
+                mapper = checkNotNull( mapper, "Null Vertex mapper for property %s not admitted", checkedName );
+                vertexProperties.put( checkedName, mapper );
+                return DefaultNamedExportSelector.this;
+            }
+
+        };
+    }
+
 }

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DefaultToStreamBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DefaultToStreamBuilder.java?rev=1301848&r1=1301847&r2=1301848&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DefaultToStreamBuilder.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DefaultToStreamBuilder.java Sat Mar 17 00:51:24 2012
@@ -41,7 +41,7 @@ public final class DefaultToStreamBuilde
         this.graph = graph;
     }
 
-    public NamedExportSelctor<V, E> to( File outputFile )
+    public ExportSelctor<V, E> to( File outputFile )
     {
         try
         {
@@ -53,12 +53,13 @@ public final class DefaultToStreamBuilde
         }
     }
 
-    public NamedExportSelctor<V, E> to( OutputStream outputStream )
+    public ExportSelctor<V, E> to( OutputStream outputStream )
     {
-        return to( new OutputStreamWriter( checkNotNull( outputStream, "Impossibe to export the graph in a null stream" ) ) );
+        return to( new OutputStreamWriter(
+                                           checkNotNull( outputStream, "Impossibe to export the graph in a null stream" ) ) );
     }
 
-    public NamedExportSelctor<V, E> to( Writer writer )
+    public ExportSelctor<V, E> to( Writer writer )
     {
         writer = checkNotNull( writer, "Impossibe to export the graph in a null stream" );
         return new DefaultNamedExportSelector<V, E>( graph, writer );

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DotExporter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DotExporter.java?rev=1301848&r1=1301847&r2=1301848&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DotExporter.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/DotExporter.java Sat Mar 17 00:51:24 2012
@@ -21,12 +21,20 @@ package org.apache.commons.graph.export;
 
 import java.io.PrintWriter;
 import java.io.Writer;
-import java.util.Date;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import org.apache.commons.graph.DirectedGraph;
 import org.apache.commons.graph.Graph;
-import org.apache.commons.graph.VertexPair;
+import org.apache.commons.graph.Mapper;
 
+/**
+ * This class is NOT thread-safe!
+ *
+ * @param <V>
+ * @param <E>
+ */
 final class DotExporter<V, E>
     extends AbstractExporter<V, E>
 {
@@ -39,17 +47,37 @@ final class DotExporter<V, E>
 
     private static final String DICONNECTOR = "->";
 
-    public DotExporter( Graph<V, E> graph, Writer writer, String name )
+    public DotExporter( Graph<V, E> graph, Writer writer,
+                        Map<String, Mapper<V, ?>> vertexProperties,
+                        Map<String, Mapper<E, ?>> edgeProperties,
+                        String name )
     {
-        super( graph, writer, name );
+        super( graph, writer, vertexProperties, edgeProperties, name );
+    }
+
+    private PrintWriter printWriter;
+
+    private String connector;
+
+    @Override
+    protected void startSerialization()
+        throws Exception
+    {
+        printWriter = new PrintWriter( getWriter() );
     }
 
     @Override
-    protected void internalExport()
+    protected void endSerialization()
+        throws Exception
+    {
+        // do nothing?
+    }
+
+    @Override
+    protected void startGraph( String name )
         throws Exception
     {
         String graphDeclaration;
-        String connector;
 
         if ( getGraph() instanceof DirectedGraph )
         {
@@ -62,59 +90,77 @@ final class DotExporter<V, E>
             connector = CONNECTOR;
         }
 
-        PrintWriter printWriter = new PrintWriter( getWriter() );
+        printWriter.format( "%s %s {%n", graphDeclaration, name );
+    }
 
-        printWriter.format( "# Graph generated by Apache Commons Graph on %s%n", new Date() );
-        printWriter.format( "%s %s {%n", graphDeclaration, getName() );
+    @Override
+    protected void endGraph()
+        throws Exception
+    {
+        printWriter.write( '}' );
+    }
 
-        for ( V vertex : getGraph().getVertices() )
-        {
-            printWriter.format( "  %s [label=\"%s\"];%n", vertex.hashCode(), vertex.toString() );
-        }
+    @Override
+    protected void comment( String text )
+        throws Exception
+    {
+        printWriter.write( text );
+    }
 
-        for ( E edge : getGraph().getEdges() )
-        {
-            VertexPair<V> vertexPair = getGraph().getVertices( edge );
+    @Override
+    protected void enlistVerticesProperty( String name, Class<?> type )
+        throws Exception
+    {
+        // not needed in DOT
+    }
 
-            printWriter.format( "  %s %s %s",
-                                vertexPair.getHead().hashCode(),
-                                connector,
-                                vertexPair.getTail().hashCode() );
+    @Override
+    protected void enlistEdgesProperty( String name, Class<?> type )
+        throws Exception
+    {
+        // not needed in DOT
 
-            boolean attributesFound = false;
+    }
+
+    @Override
+    protected void vertex( V vertex, Map<String, Object> properties )
+        throws Exception
+    {
+        printWriter.format( "  %s", vertex.hashCode() );
 
-            /*if ( edge instanceof Labeled )
+        if ( !properties.isEmpty() )
+        {
+            printWriter.write( '[' );
+
+            for ( Entry<String, Object> property : properties.entrySet() )
             {
-                attributesFound = true;
-                printWriter.format( " [label=\"%s\"", ( (Labeled) edge ).getLabel() );
+                printWriter.format( "\"%s\"=%s", property.getKey(), property.getValue() );
             }
-            if ( edge instanceof WeightedEdge )
-            {
-                Object weight = ( (WeightedEdge<?>) edge ).getWeight();
 
-                if ( weight instanceof Number )
-                {
-                    printWriter.format( " " );
-
-                    if ( !attributesFound )
-                    {
-                        printWriter.format( "[" );
-                        attributesFound = true;
-                    }
-
-                    printWriter.format( "weight=%f", ( (Number) weight ).doubleValue() );
-                }
-            }*/
+            printWriter.format( "];%n" );
+        }
+    }
+
+    @Override
+    protected void edge( E edge, V head, V tail, Map<String, Object> properties )
+        throws Exception
+    {
+        printWriter.format( "  %s %s %s",
+                            head.hashCode(),
+                            connector,
+                            tail.hashCode() );
+
+        if ( !properties.isEmpty() )
+        {
+            printWriter.write( '[' );
 
-            if ( attributesFound )
+            for ( Entry<String, Object> property : properties.entrySet() )
             {
-                printWriter.format( "]" );
+                printWriter.format( "\"%s\"=%s", property.getKey(), property.getValue() );
             }
 
-            printWriter.format( "%n" );
+            printWriter.format( "];%n" );
         }
-
-        printWriter.write( '}' );
     }
 
 }

Added: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/EdgeMapperSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/EdgeMapperSelector.java?rev=1301848&view=auto
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/EdgeMapperSelector.java (added)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/EdgeMapperSelector.java Sat Mar 17 00:51:24 2012
@@ -0,0 +1,32 @@
+package org.apache.commons.graph.export;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Mapper;
+
+/**
+ *
+ */
+public interface EdgeMapperSelector<V, E>
+{
+
+    ExportSelctor<V, E> expandedBy( Mapper<E, ?> mapper );
+
+}

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/EdgeMapperSelector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/EdgeMapperSelector.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/EdgeMapperSelector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/ExportSelctor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/ExportSelctor.java?rev=1301848&r1=1301847&r2=1301848&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/ExportSelctor.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/ExportSelctor.java Sat Mar 17 00:51:24 2012
@@ -1,5 +1,7 @@
 package org.apache.commons.graph.export;
 
+import org.apache.commons.graph.Mapper;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -22,6 +24,10 @@ package org.apache.commons.graph.export;
 public interface ExportSelctor<V, E>
 {
 
+    VertexMapperSelector<V, E> withVertexProperty( String name );
+
+    EdgeMapperSelector<V, E> withEdgeProperty( String name );
+
     /**
      * Export Graphs in <a href="http://en.wikipedia.org/wiki/DOT_language">DOT language</a>.
      */

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java?rev=1301848&r1=1301847&r2=1301848&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/GraphMLExporter.java Sat Mar 17 00:51:24 2012
@@ -19,17 +19,12 @@ package org.apache.commons.graph.export;
  * under the License.
  */
 
-import static java.lang.String.format;
-
 import java.io.Writer;
-import java.util.Date;
-import java.util.HashMap;
+import java.util.Collection;
 import java.util.Map;
 
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamWriter;
-
 import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Mapper;
 
 final class GraphMLExporter<V, E>
     extends AbstractExporter<V, E>
@@ -83,128 +78,84 @@ final class GraphMLExporter<V, E>
 
     private static final String WEIGHT = "weight";
 
-    public GraphMLExporter( Graph<V, E> graph, Writer writer, String name )
+    public GraphMLExporter( Graph<V, E> graph, Writer writer,
+                            Map<String, Mapper<V, ?>> vertexProperties,
+                            Map<String, Mapper<E, ?>> edgeProperties,
+                            String name )
     {
-        super( graph, writer, name );
+        super( graph, writer, vertexProperties, edgeProperties, name );
     }
 
     @Override
-    protected void internalExport()
+    protected void startSerialization()
         throws Exception
     {
-        // scan graph and print TYPES description for vertex AND edges' properties
-        Map<String, String> edgeKeyTypes = new HashMap<String, String>();
+        // TODO Auto-generated method stub
 
-        for ( E edge : getGraph().getEdges() )
-        {
-            /* if ( edge instanceof Labeled )
-            {
-                if ( !edgeKeyTypes.containsKey( LABEL ) )
-                {
-                    edgeKeyTypes.put( LABEL, getStringType( ( (Labeled) edge ).getLabel() ) );
-                }
-            }
-
-            if ( edge instanceof Weighted )
-            {
-                if ( !edgeKeyTypes.containsKey( WEIGHT ) )
-                {
-                    edgeKeyTypes.put( WEIGHT, getStringType( ( (Weighted<?>) edge ).getWeight() ) );
-                }
-            } */
-        }
+    }
 
-        // scan vertices
-        Map<String, String> vertexKeyTypes = new HashMap<String, String>();
+    @Override
+    protected void endSerialization()
+        throws Exception
+    {
+        // TODO Auto-generated method stub
 
-        for ( V vertex : getGraph().getVertices() )
-        {
-            /* if ( vertex instanceof Labeled )
-            {
-                if ( !vertexKeyTypes.containsKey( LABEL ) )
-                {
-                    vertexKeyTypes.put( LABEL, getStringType( ( (Labeled) vertex ).getLabel() ) );
-                }
-            } */
-        }
+    }
 
-        XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( getWriter() );
+    @Override
+    protected void startGraph( String name )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
 
-        // start document tokens
-        xmlWriter.writeStartDocument();
+    }
 
-        xmlWriter.writeComment( format( "Graph generated by Apache Commons Graph on %s%n", new Date() ) );
+    @Override
+    protected void endGraph()
+        throws Exception
+    {
+        // TODO Auto-generated method stub
 
-        xmlWriter.writeStartElement( GRAPHML );
-        xmlWriter.writeAttribute( XMLNS, GRAPHML_XMLNS );
+    }
 
-        xmlWriter.writeStartElement( GRAPH );
-        xmlWriter.writeAttribute( ID, getName() );
-        xmlWriter.writeAttribute( EDGEDEFAULT, DIRECTED );
+    @Override
+    protected void comment( String text )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
 
-        // write EDGE key types
-        for ( Map.Entry<String, String> entry : edgeKeyTypes.entrySet() )
-        {
-            xmlWriter.writeStartElement( KEY );
-            xmlWriter.writeAttribute( ID, entry.getKey() );
-            xmlWriter.writeAttribute( FOR, EDGE );
-            xmlWriter.writeAttribute( ATTR_NAME, entry.getKey() );
-            xmlWriter.writeAttribute( ATTR_TYPE, entry.getValue() );
-            xmlWriter.writeEndElement();
-        }
+    }
 
-        // write VERTICES' key types
-        for ( Map.Entry<String, String> entry : vertexKeyTypes.entrySet() )
-        {
-            xmlWriter.writeStartElement( KEY );
-            xmlWriter.writeAttribute( ID, entry.getKey() );
-            xmlWriter.writeAttribute( FOR, NODE );
-            xmlWriter.writeAttribute( ATTR_NAME, entry.getKey() );
-            xmlWriter.writeAttribute( ATTR_TYPE, entry.getValue() );
-            xmlWriter.writeEndElement();
-        }
+    @Override
+    protected void enlistVerticesProperty( String name, Class<?> type )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
 
-        for ( V vertex : getGraph().getVertices() )
-        {
-            xmlWriter.writeStartElement( NODE );
-            xmlWriter.writeAttribute( ID, String.valueOf( vertex.hashCode() ) );
+    }
 
-            /* if ( vertex instanceof Labeled )
-            {
-                String label = ( (Labeled) vertex ).getLabel();
-                xmlWriter.writeStartElement( DATA );
-                xmlWriter.writeAttribute( KEY, LABEL );
-                xmlWriter.writeCharacters( label );
-                xmlWriter.writeEndElement();
-            } */
+    @Override
+    protected void enlistEdgesProperty( String name, Class<?> type )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
 
-            xmlWriter.writeEndElement();
-        }
+    }
 
-        for ( E edge : getGraph().getEdges() )
-        {
-            xmlWriter.writeStartElement( EDGE );
-            xmlWriter.writeAttribute( ID, String.valueOf( edge.hashCode() ) );
-            xmlWriter.writeAttribute( SOURCE, String.valueOf( getGraph().getVertices( edge ).getHead().hashCode() ) );
-            xmlWriter.writeAttribute( TARGET, String.valueOf( getGraph().getVertices( edge ).getTail().hashCode() ) );
-
-            /* if ( edge instanceof Labeled )
-            {
-                xmlWriter.writeAttribute( LABEL, ( (Labeled) edge ).getLabel() );
-            }
-            if ( edge instanceof Weighted )
-            {
-                xmlWriter.writeAttribute( WEIGHT, ( (Weighted<?>) edge ).getWeight().toString() );
-            } */
-            xmlWriter.writeEndElement();
-        }
+    @Override
+    protected void vertex( V vertex, Map<String, Object> properties )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
 
-        xmlWriter.writeEndElement(); // graph
-        xmlWriter.writeEndElement(); // graphml
-        xmlWriter.writeEndDocument();
+    }
+
+    @Override
+    protected void edge( E edge, V head, V tail, Map<String, Object> properties )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
 
-        xmlWriter.flush();
-        xmlWriter.close();
     }
 
     private static <O> String getStringType( O object )

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/ToStreamBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/ToStreamBuilder.java?rev=1301848&r1=1301847&r2=1301848&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/ToStreamBuilder.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/ToStreamBuilder.java Sat Mar 17 00:51:24 2012
@@ -32,7 +32,7 @@ public interface ToStreamBuilder<V, E>
      * @param outputFile the file where exporting the Graph to
      * @return
      */
-    NamedExportSelctor<V, E> to( File outputFile );
+    ExportSelctor<V, E> to( File outputFile );
 
     /**
      * Export the input Graph to an {@link OutputStream}.
@@ -40,7 +40,7 @@ public interface ToStreamBuilder<V, E>
      * @param outputStream the output stream where exporting the Graph to
      * @return
      */
-    NamedExportSelctor<V, E> to( OutputStream outputStream );
+    ExportSelctor<V, E> to( OutputStream outputStream );
 
     /**
      * Export the input Graph to a {@link Writer}.
@@ -48,6 +48,6 @@ public interface ToStreamBuilder<V, E>
      * @param writer the writer where exporting the Graph to
      * @return
      */
-    NamedExportSelctor<V, E> to( Writer writer );
+    ExportSelctor<V, E> to( Writer writer );
 
 }

Added: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/VertexMapperSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/VertexMapperSelector.java?rev=1301848&view=auto
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/VertexMapperSelector.java (added)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/VertexMapperSelector.java Sat Mar 17 00:51:24 2012
@@ -0,0 +1,32 @@
+package org.apache.commons.graph.export;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Mapper;
+
+/**
+ *
+ */
+public interface VertexMapperSelector<V, E>
+{
+
+    ExportSelctor<V, E> expandedBy( Mapper<V, ?> mapper );
+
+}

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/VertexMapperSelector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/VertexMapperSelector.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/main/java/org/apache/commons/graph/export/VertexMapperSelector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeLabelMapper.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeLabelMapper.java?rev=1301848&view=auto
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeLabelMapper.java (added)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeLabelMapper.java Sat Mar 17 00:51:24 2012
@@ -0,0 +1,35 @@
+package org.apache.commons.graph.export;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Mapper;
+import org.apache.commons.graph.model.BaseLabeledWeightedEdge;
+
+public final class EdgeLabelMapper
+    implements Mapper<BaseLabeledWeightedEdge<Double>, String>
+{
+
+    @Override
+    public String map( BaseLabeledWeightedEdge<Double> input )
+    {
+        return input.getLabel();
+    }
+
+}

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeLabelMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeLabelMapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeLabelMapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeWeightMapper.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeWeightMapper.java?rev=1301848&view=auto
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeWeightMapper.java (added)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeWeightMapper.java Sat Mar 17 00:51:24 2012
@@ -0,0 +1,35 @@
+package org.apache.commons.graph.export;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Mapper;
+import org.apache.commons.graph.model.BaseLabeledWeightedEdge;
+
+public final class EdgeWeightMapper
+    implements Mapper<BaseLabeledWeightedEdge<Double>, Double>
+{
+
+    @Override
+    public Double map( BaseLabeledWeightedEdge<Double> input )
+    {
+        return input.getWeight();
+    }
+
+}

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeWeightMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeWeightMapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/EdgeWeightMapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/ExportTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/ExportTestCase.java?rev=1301848&r1=1301847&r2=1301848&view=diff
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/ExportTestCase.java (original)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/ExportTestCase.java Sat Mar 17 00:51:24 2012
@@ -22,12 +22,14 @@ package org.apache.commons.graph.export;
 import static org.apache.commons.graph.CommonsGraph.export;
 import static org.apache.commons.graph.CommonsGraph.newUndirectedMutableGraph;
 
+import org.apache.commons.graph.Mapper;
 import org.apache.commons.graph.builder.AbstractGraphConnection;
 import org.apache.commons.graph.model.BaseLabeledVertex;
 import org.apache.commons.graph.model.BaseLabeledWeightedEdge;
 import org.apache.commons.graph.model.UndirectedMutableGraph;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class ExportTestCase {
@@ -67,7 +69,23 @@ public class ExportTestCase {
     public void shouldPrintDotFormat()
         throws Exception
     {
-        export( actual ).to( System.out ).usingDotNotation();
+        export( actual ).to( System.out )
+                        .withVertexProperty( "label" ).expandedBy( new VertexLabelMapper() )
+                        .withEdgeProperty( "label" ).expandedBy( new EdgeLabelMapper() )
+                        .withEdgeProperty( "weight" ).expandedBy( new EdgeWeightMapper() )
+                        .usingDotNotation();
+    }
+
+    @Test
+    @Ignore
+    public void shouldPrintGraphML()
+        throws Exception
+    {
+        export( actual ).to( System.out )
+                        .withVertexProperty( "label" ).expandedBy( new VertexLabelMapper() )
+                        .withEdgeProperty( "label" ).expandedBy( new EdgeLabelMapper() )
+                        .withEdgeProperty( "weight" ).expandedBy( new EdgeWeightMapper() )
+                        .usingGraphMLFormat();
     }
 
     @Test

Added: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/VertexLabelMapper.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/VertexLabelMapper.java?rev=1301848&view=auto
==============================================================================
--- commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/VertexLabelMapper.java (added)
+++ commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/VertexLabelMapper.java Sat Mar 17 00:51:24 2012
@@ -0,0 +1,35 @@
+package org.apache.commons.graph.export;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Mapper;
+import org.apache.commons.graph.model.BaseLabeledVertex;
+
+public final class VertexLabelMapper
+    implements Mapper<BaseLabeledVertex, String>
+{
+
+    @Override
+    public String map( BaseLabeledVertex input )
+    {
+        return input.getLabel();
+    }
+
+}

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/VertexLabelMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/VertexLabelMapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/branches/drop-marker-interfaces-feature/src/test/java/org/apache/commons/graph/export/VertexLabelMapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain