Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.tinkerpop.blueprints.impls.neo4j2.rexster;
 

Author(s):
Stephen Mallette (http://stephen.genoprime.com)
public class Neo4j2GraphConfiguration implements GraphConfiguration {
        final String graphFile = context.getProperties().getString(.);
        if (graphFile == null || graphFile.length() == 0) {
            throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + .);
        }
        final boolean highAvailabilityMode = context.getProperties().getBoolean(.false);
        // get the <properties> section of the xml configuration
        final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfigurationcontext.getProperties();
        SubnodeConfiguration neo4jSpecificConfiguration;
        try {
            neo4jSpecificConfiguration = graphSectionConfig.configurationAt(.);
        } catch (IllegalArgumentException iae) {
            throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + .);
        }
        try {
            // properties to initialize the neo4j instance.
            final HashMap<StringStringneo4jProperties = new HashMap<StringString>();
            // read the properties from the xml file and convert them to properties
            // to be injected into neo4j.
            final Iterator<Stringneo4jSpecificConfigurationKeys = neo4jSpecificConfiguration.getKeys();
            while (neo4jSpecificConfigurationKeys.hasNext()) {
                String key = neo4jSpecificConfigurationKeys.next();
                // replace the ".." put in play by apache commons configuration.  that's expected behavior
                // due to parsing key names to xml.
                neo4jProperties.put(key.replace("..""."), neo4jSpecificConfiguration.getString(key));
            }
            if (highAvailabilityMode) {
                if (!neo4jProperties.containsKey("ha.machine_id")) {
                    throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.machine_id] in the <properties> of the configuration");
                }
                if (!neo4jProperties.containsKey("ha.server")) {
                    throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.server] <properties> of the configuration");
                }
                if (!neo4jProperties.containsKey("ha.initial_hosts")) {
                    throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.initial_hosts] <properties> of the configuration");
                }
                return new Neo4j2HaGraph(graphFileneo4jProperties);
            } else {
                return new Neo4j2Graph(graphFileneo4jProperties);
            }
        } catch (GraphConfigurationException gce) {
            throw gce;
        } catch (Exception ex) {
            throw new GraphConfigurationException(ex);
        }
    }
New to GrepCode? Check out our FAQ X