package com.thinkaurelius.titan.tinkerpop.rexster;

import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.rexster.RexsterApplicationGraph;
import com.tinkerpop.rexster.server.AbstractMapRexsterApplication;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * Custom RexsterApplication implementation that auto-allows all extensions in the classpath.
 *
 * Should replace this with the DefaultRexsterApplication class in Rexster 2.4.0.  That class will basically do
 * what this one does to help those doing embedding to auto-configure extensions.
 *
 * @author Stephen Mallette (http://stephen.genoprime.com)
 */
public class TitanRexsterApplication extends AbstractMapRexsterApplication {

    private static final Logger logger = Logger.getLogger(TitanRexsterApplication.class);

    /**
     * Constructs the TitanRexsterApplication.
     *
     * @param graphName the name the graph will have in various Rexster contexts.
     * @param graph a graph instance.
     */
    public TitanRexsterApplication(final String graphName, final Graph graph, final List<HierarchicalConfiguration> extensionConfigurations) {
        final RexsterApplicationGraph rag = new RexsterApplicationGraph(graphName, graph);

        allowAllExtensions(rag);
        configureExtensions(extensionConfigurations, rag);

        this.graphs.put(graphName, rag);
        logger.info(String.format("Graph [%s] loaded", rag.getGraph()));
    }

    private static void configureExtensions(final List<HierarchicalConfiguration> extensionConfigurations, final RexsterApplicationGraph rag) {
        if (extensionConfigurations != null) {
            //TODO
            //rag.loadExtensionsConfigurations(extensionConfigurations);
        }
    }

    private static void allowAllExtensions(final RexsterApplicationGraph rag) {
        final List<String> allowableNamespaces = new ArrayList<String>() {{
            add("*:*");
        }};
        //TODO
        //rag.loadAllowableExtensions(allowableNamespaces);
    }
}

@@ -1216,24 +1216,137 @@
 urations) %7B%0A
+        final List%3CString%3E allowableNamespaces = new ArrayList%3CString%3E() %7B%7B%0A            add(%22*:*%22);%0A        %7D%7D;%0A%0A
         fina
@@ -1425,73 +1425,31 @@
 raph
-);%0A%0A        allowAllExtensions(rag);%0A        configureExtensions(
+, allowableNamespaces, 
 exte
@@ -1471,17 +1471,11 @@
 ions
-, rag
 );%0A
-%0A
     
@@ -1593,581 +1593,7 @@
    %7D
-%0A%0A    private static void configureExtensions(final List%3CHierarchicalConfiguration%3E extensionConfigurations, final RexsterApplicationGraph rag) %7B%0A        if (extensionConfigurations != null) %7B%0A            //TODO%0A            //rag.loadExtensionsConfigurations(extensionConfigurations);%0A        %7D%0A    %7D%0A%0A    private static void allowAllExtensions(final RexsterApplicationGraph rag) %7B%0A        final List%3CString%3E allowableNamespaces = new ArrayList%3CString%3E() %7B%7B%0A            add(%22*:*%22);%0A        %7D%7D;%0A        //TODO%0A        //rag.loadAllowableExtensions(allowableNamespaces);%0A    %7D
 %0A%7D%0A

Use new constructor for RexsterApplicationGraph.