public void ConfigurationLookupNode4() { Graph g = new Graph(); INode value = ConfigurationLoader.GetConfigurationNode(g, g.CreateBlankNode("a"), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyType))); Assert.Null(value); }
public void ConfigurationLookupNode9() { Graph g = new Graph(); INode value = ConfigurationLoader.GetConfigurationNode(g, g.CreateBlankNode("a"), new INode[] { }); Assert.Null(value); }
/// <summary> /// Tries to load a SPARQL Query/Algebra Optimiser based on information from the Configuration Graph. /// </summary> /// <param name="g">Configuration Graph.</param> /// <param name="objNode">Object Node.</param> /// <param name="targetType">Target Type.</param> /// <param name="obj">Output Object.</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; Object temp; switch (targetType.FullName) { case QueryOptimiserDefault: obj = new DefaultOptimiser(); break; case QueryOptimiserNoReorder: obj = new NoReorderOptimiser(); break; case QueryOptimiserWeighted: INode statsObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingGraph))); if (statsObj != null) { temp = ConfigurationLoader.LoadObject(g, statsObj); if (temp is IGraph) { obj = new WeightedOptimiser((IGraph)temp); } else { throw new DotNetRdfConfigurationException("Unable to create the Weighted Query Optimiser identified by the Node '" + objNode.ToString() + "' since the dnr:usingGraph property points to an object that cannot be loaded as an Object that imlements the required IGraph interface"); } } else { obj = new WeightedOptimiser(); } break; default: // Try and create an Algebra Optimiser try { obj = (IAlgebraOptimiser)Activator.CreateInstance(targetType); } catch { // Any error means this loader can't load this type return(false); } break; } // Return true only if we've loaded something into the output object if (obj != null) { return(true); } else { return(false); } }
public void ConfigurationLookupNode8() { Graph g = new Graph(); g.NamespaceMap.AddNamespace("dnr", UriFactory.Create(ConfigurationLoader.ConfigurationNamespace)); INode value = ConfigurationLoader.GetConfigurationNode(g, g.CreateBlankNode("a"), new INode[] { g.CreateUriNode("dnr:missing"), g.CreateUriNode("dnr:type"), g.CreateUriNode("dnr:other") }); Assert.Null(value); }
/// <summary> /// Creates a new Update Handler Configuration /// </summary> /// <param name="context">HTTP Context</param> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> public BaseUpdateHandlerConfiguration(IHttpContext context, IGraph g, INode objNode) : base(context, g, objNode) { // Then get the Update Processor to be used ISparqlUpdateProcessor processor; INode procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateProcessor))); if (procNode == null) { throw new DotNetRdfConfigurationException("Unable to load Update Handler Configuration as the RDF configuration file does not specify a dnr:updateProcessor property for the Handler"); } Object temp = ConfigurationLoader.LoadObject(g, procNode); if (temp is ISparqlUpdateProcessor) { processor = (ISparqlUpdateProcessor)temp; } else { throw new DotNetRdfConfigurationException("Unable to load Update Handler Configuration as the RDF configuration file specifies a value for the Handlers dnr:updateProcessor property which cannot be loaded as an object which implements the ISparqlUpdateProcessor interface"); } this._processor = processor; // Handler Settings this._showUpdateForm = ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyShowUpdateForm)), this._showUpdateForm); String defUpdateFile = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultUpdateFile))); if (defUpdateFile != null) { defUpdateFile = ConfigurationLoader.ResolvePath(defUpdateFile); if (File.Exists(defUpdateFile)) { using (StreamReader reader = new StreamReader(defUpdateFile)) { this._defaultUpdate = reader.ReadToEnd(); reader.Close(); } } } // Get the Service Description Graph INode descripNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyServiceDescription))); if (descripNode != null) { Object descrip = ConfigurationLoader.LoadObject(g, descripNode); if (descrip is IGraph) { this._serviceDescription = (IGraph)descrip; } else { throw new DotNetRdfConfigurationException("Unable to set the Service Description Graph for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:serviceDescription property points to an Object which could not be loaded as an object which implements the required IGraph interface"); } } }
/// <summary> /// Tries to load a SPARQL Dataset based on information from the Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Output Object</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; INode storeNode; switch (targetType.FullName) { case InMemoryDataset: storeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore)); if (storeNode == null) { obj = new InMemoryDataset(); } else { Object temp = ConfigurationLoader.LoadObject(g, storeNode); if (temp is IInMemoryQueryableStore) { obj = new InMemoryDataset((IInMemoryQueryableStore)temp); return(true); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:usingStore property could not be loaded as an object which implements the IInMemoryQueryableStore interface"); } } break; case InMemoryQuadDataset: storeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore)); if (storeNode == null) { obj = new InMemoryQuadDataset(); } else { Object temp = ConfigurationLoader.LoadObject(g, storeNode); if (temp is IInMemoryQueryableStore) { obj = new InMemoryQuadDataset((IInMemoryQueryableStore)temp); return(true); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:usingStore property could not be loaded as an object which implements the IInMemoryQueryableStore interface"); } } break; } return(false); }
/// <summary> /// Tries to load a SPARQL Dataset based on information from the Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Output Object</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; switch (targetType.FullName) { case InMemoryDataset: INode storeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore)); if (storeNode == null) { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Dataset identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:usingStore"); } else { Object temp = ConfigurationLoader.LoadObject(g, storeNode); if (temp is IInMemoryQueryableStore) { obj = new InMemoryDataset((IInMemoryQueryableStore)temp); return(true); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:usingStore property could not be loaded as an object which implements the IInMemoryQueryableStore interface"); } } #if !NO_DATA && !NO_STORAGE case SqlDataset: INode sqlManager = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertySqlManager)); if (sqlManager == null) { throw new DotNetRdfConfigurationException("Unable to load the SQL Dataset identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:sqlManager"); } else { Object temp = ConfigurationLoader.LoadObject(g, sqlManager); if (temp is IDotNetRDFStoreManager) { obj = new SqlDataset((IDotNetRDFStoreManager)temp); return(true); } else { throw new DotNetRdfConfigurationException("Unable to load the SQL Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:sqlManager property could not be laoded as an object which implements the IDotNetRDFStoreManager interface"); } } #endif } return(false); }
public void ConfigurationLookupNode2() { String graph = Prefixes + @" _:a dnr:type <http://uri> ."; Graph g = new Graph(); g.LoadFromString(graph); INode value = ConfigurationLoader.GetConfigurationNode(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.Equal(NodeType.Uri, value.NodeType); Assert.True(EqualityHelper.AreUrisEqual(new Uri("http://uri"), ((IUriNode)value).Uri)); }
public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { switch (targetType.FullName) { case FileManager: String storeID = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase)); if (storeID != null) { //Supports using dnr:loadMode to specify the indexes to be used String indices = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); if (indices == null) { obj = new AlexandriaFileManager(ConfigurationLoader.ResolvePath(storeID)); } else { obj = new AlexandriaFileManager(ConfigurationLoader.ResolvePath(storeID), this.ParseIndexTypes(indices)); } return true; } //If we get here then the required dnr:database property was missing throw new DotNetRdfConfigurationException("Unable to load the File Manager identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:database"); break; case FileDataset: INode managerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:genericManager")); if (managerNode == null) { throw new DotNetRdfConfigurationException("Unable to load the File Dataset identified by the Node '" + objNode.ToString() + "' since there we no value for the required property dnr:genericManager"); } Object temp = ConfigurationLoader.LoadObject(g, managerNode); if (temp is AlexandriaFileManager) { obj = new AlexandriaFileDataset((AlexandriaFileManager)temp); return true; } else { throw new DotNetRdfConfigurationException("Unable to load the File Dataset identified by the Node '" + objNode.ToString() + "' since the value for the dnr:genericManager property pointed to an Object which could not be loaded as an object of type AlexandriaFileManager"); } break; } obj = null; return false; }
public void ConfigurationLookupNode1() { String graph = Prefixes + @" _:a dnr:type ""literal"" ."; Graph g = new Graph(); g.LoadFromString(graph); INode value = ConfigurationLoader.GetConfigurationNode(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.Equal(NodeType.Literal, value.NodeType); Assert.Equal("literal", ((ILiteralNode)value).Value); }
public void ConfigurationLookupNode3() { String graph = Prefixes + @" _:a dnr:type <appsetting:ConfigurationLookupNode3> ."; Graph g = new Graph(); g.LoadFromString(graph); System.Configuration.ConfigurationManager.AppSettings["ConfigurationLookupNode3"] = "literal"; INode value = ConfigurationLoader.GetConfigurationNode(g, g.GetBlankNode("a"), g.CreateUriNode("dnr:type")); Assert.AreEqual(NodeType.Literal, value.NodeType); Assert.AreEqual("literal", ((ILiteralNode)value).Value); }
/// <summary> /// Creates a new Graph Handler Configuration /// </summary> /// <param name="context">HTTP Context</param> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> public BaseGraphHandlerConfiguration(HttpContext context, IGraph g, INode objNode) : base(context, g, objNode) { INode graphNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingGraph)); if (graphNode == null) { throw new DotNetRdfConfigurationException("Unable to load Graph Handler Configuration as the required dnr:usingGraph property does not exist"); } //Load the Graph Object temp = ConfigurationLoader.LoadObject(g, graphNode); if (temp is IGraph) { this._g = (IGraph)temp; } else { throw new DotNetRdfConfigurationException("Unable to load Graph Handler Configuration as the dnr:usingGraph property points to an Object which cannot be loaded as an object which implements the IGraph interface"); } }
/// <summary> /// Creates a new Dataset Handler configuration /// </summary> /// <param name="context">HTTP Context</param> /// <param name="config">Configuration Graph</param> /// <param name="objNode">Object Node</param> public BaseDatasetHandlerConfiguration(IHttpContext context, IGraph config, INode objNode) : base(context, config, objNode) { INode datasetNode = ConfigurationLoader.GetConfigurationNode(config, objNode, config.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingDataset))); if (datasetNode == null) { throw new DotNetRdfConfigurationException("Unable to load Dataset Handler Configuration as there is no value given for the required dnr:usingDataset property"); } // Load the Dataset Object temp = ConfigurationLoader.LoadObject(config, datasetNode); if (temp is ISparqlDataset) { this._dataset = (ISparqlDataset)temp; } else { throw new DotNetRdfConfigurationException("Unable to load Dataset Handler Configuration as the dnr:usingDatset property points to an Object which cannot be loaded as an object which implements the ISparqlDataset interface"); } }
/// <summary> /// Creates a new Protocol Handler Configuration /// </summary> /// <param name="context">HTTP Context</param> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> public BaseProtocolHandlerConfiguration(IHttpContext context, IGraph g, INode objNode) : base(context, g, objNode) { // Then get the Protocol Processor to be used ISparqlHttpProtocolProcessor processor; INode procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyProtocolProcessor))); if (procNode == null) { throw new DotNetRdfConfigurationException("Unable to load Protocol Handler Configuration as the RDF configuration file does not specify a dnr:protocolProcessor property for the Handler"); } Object temp = ConfigurationLoader.LoadObject(g, procNode); if (temp is ISparqlHttpProtocolProcessor) { processor = (ISparqlHttpProtocolProcessor)temp; } else { throw new DotNetRdfConfigurationException("Unable to load Protocol Handler Configuration as the RDF configuration file specifies a value for the Handlers dnr:protocolProcessor property which cannot be loaded as an object which implements the ISparqlHttpProtocolProcessor interface"); } this._processor = processor; // Get the Service Description Graph INode descripNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyServiceDescription))); if (descripNode != null) { Object descrip = ConfigurationLoader.LoadObject(g, descripNode); if (descrip is IGraph) { this._serviceDescription = (IGraph)descrip; } else { throw new DotNetRdfConfigurationException("Unable to set the Service Description Graph for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:serviceDescription property points to an Object which could not be loaded as an object which implements the required IGraph interface"); } } }
/// <summary> /// Populates the settings from an existing serialized configuration /// </summary> /// <param name="g">Graph</param> /// <param name="objNode">Object Node</param> public virtual void PopulateFrom(IGraph g, INode objNode) { foreach (PropertyInfo property in this._properties.Keys) { ConnectionAttribute attr = this._properties[property]; if (!String.IsNullOrEmpty(attr.PopulateFrom)) { INode n = objNode; if (!String.IsNullOrEmpty(attr.PopulateVia)) { n = ConfigurationLoader.GetConfigurationNode(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateVia))); if (n == null) { continue; } } switch (attr.Type) { case ConnectionSettingType.Boolean: bool b = ConfigurationLoader.GetConfigurationBoolean(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateFrom)), (bool)property.GetValue(this, null)); property.SetValue(this, b, null); break; case ConnectionSettingType.File: case ConnectionSettingType.Password: case ConnectionSettingType.String: String s = ConfigurationLoader.GetConfigurationString(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateFrom))); if (!String.IsNullOrEmpty(s)) { property.SetValue(this, s, null); } else { //May be a URI as the object IUriNode u = ConfigurationLoader.GetConfigurationNode(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateFrom))) as IUriNode; if (u != null) { property.SetValue(this, u.Uri.AbsoluteUri, null); } } break; case ConnectionSettingType.Integer: int i = ConfigurationLoader.GetConfigurationInt32(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateFrom)), (int)property.GetValue(this, null)); property.SetValue(this, i, null); break; case ConnectionSettingType.Enum: String enumStr = ConfigurationLoader.GetConfigurationString(g, n, g.CreateUriNode(UriFactory.Create(attr.PopulateFrom))); if (!String.IsNullOrEmpty(enumStr)) { try { Object val = Enum.Parse(property.GetValue(this, null).GetType(), enumStr, false); property.SetValue(this, val, null); } catch { //Ignore errors } } break; } } } }
/// <summary> /// Tries to load a Graph based on information from the Configuration Graph. /// </summary> /// <param name="g">Configuration Graph.</param> /// <param name="objNode">Object Node.</param> /// <param name="targetType">Target Type.</param> /// <param name="obj">Output Object.</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; IGraph output; // Check whether to use a specific Triple Collection INode collectionNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingTripleCollection))); try { if (collectionNode == null) { // Simple Graph creation output = (IGraph)Activator.CreateInstance(targetType); } else { // Graph with custom triple collection BaseTripleCollection tripleCollection = ConfigurationLoader.LoadObject(g, collectionNode) as BaseTripleCollection; if (tripleCollection == null) { throw new DotNetRdfConfigurationException("Unable to load the Graph identified by the Node '" + objNode.ToString() + "' as the dnr:usingTripleCollection points to an object which cannot be loaded as an instance of the required type BaseTripleCollection"); } output = (IGraph)Activator.CreateInstance(targetType, new Object[] { tripleCollection }); } } catch { // Any error means this loader can't load this type return(false); } // Now we want to find out where the data for the Graph is coming from // Data Source loading order is Graphs, Files, Strings, Databases, Stores, URIs IEnumerable <INode> sources; // Load from Graphs sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromGraph))); foreach (INode source in sources) { ConfigurationLoader.CheckCircularReference(objNode, source, "dnr:fromGraph"); Object graph = ConfigurationLoader.LoadObject(g, source); if (graph is IGraph) { output.Merge((IGraph)graph); } else { throw new DotNetRdfConfigurationException("Unable to load data from another Graph for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:fromGraph property points to an Object that cannot be loaded as an object which implements the IGraph interface"); } } // Load from Embedded Resources sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromEmbedded))); foreach (INode source in sources) { if (source.NodeType == NodeType.Literal) { EmbeddedResourceLoader.Load(output, ((ILiteralNode)source).Value); } else { throw new DotNetRdfConfigurationException("Unable to load data from an Embedded Resource for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:fromEmbedded property is not a Literal Node as required"); } } // Load from Files sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromFile))); foreach (INode source in sources) { if (source.NodeType == NodeType.Literal) { FileLoader.Load(output, ConfigurationLoader.ResolvePath(((ILiteralNode)source).Value)); } else { throw new DotNetRdfConfigurationException("Unable to load data from a file for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:fromFile property is not a Literal Node as required"); } } // Load from Strings sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromString))); foreach (INode source in sources) { if (source.NodeType == NodeType.Literal) { StringParser.Parse(output, ((ILiteralNode)source).Value); } else { throw new DotNetRdfConfigurationException("Unable to load data from a string for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:fromString property is not a Literal Node as required"); } } IEnumerable <Object> connections; // Load from Stores IEnumerable <INode> stores = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromStore))); stores.All(s => !ConfigurationLoader.CheckCircularReference(objNode, s, "dnr:fromStore")); connections = stores.Select(s => ConfigurationLoader.LoadObject(g, s)); sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyWithUri))); foreach (Object store in connections) { if (store is IStorageProvider) { foreach (INode source in sources) { if (source.NodeType == NodeType.Uri || source.NodeType == NodeType.Literal) { ((IStorageProvider)store).LoadGraph(output, source.ToString()); } else { throw new DotNetRdfConfigurationException("Unable to load data from a Generic Store for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:withUri property is not a URI/Literal Node as required"); } } } else if (store is ITripleStore) { foreach (INode source in sources) { if (source.NodeType == NodeType.Uri) { output.Merge(((ITripleStore)store)[((IUriNode)source).Uri]); } else if (source.NodeType == NodeType.Literal) { output.Merge(((ITripleStore)store)[UriFactory.Create(((ILiteralNode)source).Value)]); } else { throw new DotNetRdfConfigurationException("Unable to load data from a Store for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:withUri property is not a URI/Literal Node as required"); } } } else { throw new DotNetRdfConfigurationException("Unable to load data from a Store for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values of the dnr:fromStore property points to an Object which cannot be loaded as an object which implements either the IStorageProvider/ITripleStore interface"); } } // Load from Datasets IEnumerable <INode> ds = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromDataset))); ds.All(d => !ConfigurationLoader.CheckCircularReference(objNode, d, ConfigurationLoader.PropertyFromDataset)); IEnumerable <Object> datasets = ds.Select(d => ConfigurationLoader.LoadObject(g, d)); sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyWithUri))); foreach (Object dataset in datasets) { if (dataset is ISparqlDataset) { foreach (INode source in sources) { if (source.NodeType == NodeType.Uri) { output.Merge(((ISparqlDataset)dataset)[((IUriNode)sources).Uri]); } else if (source.NodeType == NodeType.Literal) { output.Merge(((ISparqlDataset)dataset)[UriFactory.Create(((ILiteralNode)source).Value)]); } else { throw new DotNetRdfConfigurationException("Unable to load data from a Dataset for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:withUri property is not a URI/Literal Node as required"); } } } else { throw new DotNetRdfConfigurationException("Unable to load data from a Dataset for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values of the dnr:fromDataset property points to an Object which cannot be loaded as an object which implements the required ISparqlDataset interface"); } } // Finally load from Remote URIs sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromUri))); foreach (INode source in sources) { if (source.NodeType == NodeType.Uri) { UriLoader.Load(output, ((IUriNode)source).Uri); } else if (source.NodeType == NodeType.Literal) { UriLoader.Load(output, UriFactory.Create(((ILiteralNode)source).Value)); } else { throw new DotNetRdfConfigurationException("Unable to load data from a URI for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:fromUri property is not a URI/Literal Node as required"); } } // Then are we assigning a Base URI to this Graph which overrides any existing Base URI? INode baseUri = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyAssignUri))); if (baseUri != null) { if (baseUri.NodeType == NodeType.Uri) { output.BaseUri = ((IUriNode)baseUri).Uri; } else if (baseUri.NodeType == NodeType.Literal) { output.BaseUri = UriFactory.Create(((ILiteralNode)baseUri).Value); } else { throw new DotNetRdfConfigurationException("Unable to assign a new Base URI for the Graph identified by the Node '" + objNode.ToString() + "' as the value for the dnr:assignUri property is not a URI/Literal Node as required"); } } // Finally we'll apply any reasoners IEnumerable <INode> reasoners = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyReasoner))); foreach (INode reasoner in reasoners) { Object temp = ConfigurationLoader.LoadObject(g, reasoner); if (temp is IInferenceEngine) { ((IInferenceEngine)temp).Apply(output); } else { throw new DotNetRdfConfigurationException("Unable to apply a reasoner for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:reasoner property points to an Object which cannot be loaded as an object which implements the IInferenceEngine interface"); } } obj = output; return(true); }
/// <summary> /// Tries to load a Triple Store based on information from the Configuration Graph. /// </summary> /// <param name="g">Configuration Graph.</param> /// <param name="objNode">Object Node.</param> /// <param name="targetType">Target Type.</param> /// <param name="obj">Output Object.</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; ITripleStore store = null; INode subObj; Object temp; // Get Property Nodes we need INode propStorageProvider = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStorageProvider)), propAsync = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyAsync)); // Check whether to use a specific Graph Collection INode collectionNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingGraphCollection))); // Instantiate the Store Class switch (targetType.FullName) { case TripleStore: if (collectionNode == null) { store = new TripleStore(); } else { BaseGraphCollection graphCollection = ConfigurationLoader.LoadObject(g, collectionNode) as BaseGraphCollection; if (graphCollection == null) { throw new DotNetRdfConfigurationException("Unable to load the Triple Store identified by the Node '" + objNode.ToString() + "' as the dnr:usingGraphCollection points to an object which cannot be loaded as an instance of the required type BaseGraphCollection"); } store = new TripleStore(graphCollection); } break; case WebDemandTripleStore: store = new WebDemandTripleStore(); break; case PersistentTripleStore: subObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider); if (subObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, subObj); if (temp is IStorageProvider) { store = new PersistentTripleStore((IStorageProvider)temp); } else { throw new DotNetRdfConfigurationException("Unable to load a Persistent Triple Store identified by the Node '" + objNode.ToString() + "' as the value given the for dnr:genericManager property points to an Object which could not be loaded as an object which implements the IStorageProvider interface"); } break; } // Read in additional data to be added to the Store if (store != null) { IEnumerable <INode> sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingGraph))); // Read from Graphs foreach (INode source in sources) { temp = ConfigurationLoader.LoadObject(g, source); if (temp is IGraph) { store.Add((IGraph)temp); } else { throw new DotNetRdfConfigurationException("Unable to load data from a Graph for the Triple Store identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:usingGraph property points to an Object that cannot be loaded as an object which implements the IGraph interface"); } } // Load from Embedded Resources sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromEmbedded))); foreach (INode source in sources) { if (source.NodeType == NodeType.Literal) { EmbeddedResourceLoader.Load(store, ((ILiteralNode)source).Value); } else { throw new DotNetRdfConfigurationException("Unable to load data from an Embedded Resource for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:fromEmbedded property is not a Literal Node as required"); } } // Read from Files - we assume these files are Dataset Files sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromFile))); foreach (INode source in sources) { if (source.NodeType == NodeType.Literal) { FileLoader.Load(store, ConfigurationLoader.ResolvePath(((ILiteralNode)source).Value)); } else { throw new DotNetRdfConfigurationException("Unable to load data from a file for the Triple Store identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:fromFile property is not a Literal Node as required"); } } // Finally we'll apply any reasoners if (store is IInferencingTripleStore) { IEnumerable <INode> reasoners = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyReasoner))); foreach (INode reasoner in reasoners) { temp = ConfigurationLoader.LoadObject(g, reasoner); if (temp is IInferenceEngine) { ((IInferencingTripleStore)store).AddInferenceEngine((IInferenceEngine)temp); } else { throw new DotNetRdfConfigurationException("Unable to apply a reasoner for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:reasoner property points to an Object which cannot be loaded as an object which implements the IInferenceEngine interface"); } } } // And as an absolute final step if the store is transactional we'll flush any changes we've made if (store is ITransactionalStore) { ((ITransactionalStore)store).Flush(); } } obj = store; return(store != null); }
/// <summary> /// Tries to load a SPARQL Query Processor based on information from the Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Output Object</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; ISparqlQueryProcessor processor = null; INode storeObj; Object temp; INode propStorageProvider = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStorageProvider)); switch (targetType.FullName) { case LeviathanQueryProcessor: INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingDataset))); if (datasetObj != null) { temp = ConfigurationLoader.LoadObject(g, datasetObj); if (temp is ISparqlDataset) { processor = new LeviathanQueryProcessor((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Leviathan Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface"); } } else { // If no dnr:usingDataset try dnr:usingStore instead storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore))); if (storeObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IInMemoryQueryableStore) { processor = new LeviathanQueryProcessor((IInMemoryQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Leviathan Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface"); } } break; case SimpleQueryProcessor: storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore))); if (storeObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is INativelyQueryableStore) { processor = new SimpleQueryProcessor((INativelyQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Simple Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the INativelyQueryableStore interface"); } break; case GenericQueryProcessor: INode managerObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider); if (managerObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, managerObj); if (temp is IQueryableStorage) { processor = new GenericQueryProcessor((IQueryableStorage)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Generic Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object that cannot be loaded as an object which implements the IQueryableStorage interface"); } break; case RemoteQueryProcessor: INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint))); if (endpointObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteEndpoint) { processor = new RemoteQueryProcessor((SparqlRemoteEndpoint)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Remote Query Processor identified by the Node '" + objNode.ToSafeString() + "' as the value given for the dnr:endpoint property points to an Object that cannot be loaded as an object which is a SparqlRemoteEndpoint"); } break; case PelletQueryProcessor: String server = ConfigurationLoader.GetConfigurationValue(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyServer))); if (server == null) { return(false); } String kb = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStore))); if (kb == null) { return(false); } processor = new PelletQueryProcessor(UriFactory.Create(server), kb); break; } obj = processor; return(processor != null); }
/// <summary> /// Tries to load a triple/graph collection which is specified in the given configuration graph. /// </summary> /// <param name="g">Configuration Graph.</param> /// <param name="objNode">Object Node.</param> /// <param name="targetType">Target type.</param> /// <param name="obj">Returned Object.</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; INode wrapsNode; Object wrappedCollection; if (_tripleCollectionType.IsAssignableFrom(targetType)) { wrapsNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingTripleCollection))); if (wrapsNode == null) { // Simple Triple Collection creation try { obj = (BaseTripleCollection)Activator.CreateInstance(targetType); } catch { return(false); } } else { // Wrapped Triple Collection creation wrappedCollection = ConfigurationLoader.LoadObject(g, wrapsNode) as BaseTripleCollection; if (wrappedCollection == null) { throw new DotNetRdfConfigurationException("Unable to load the Triple Collection identified by the Node '" + objNode.ToString() + "' as the dnr:usingTripleCollection points to an object which cannot be loaded as an instance of the required type BaseTripleCollection for this collection to wrap"); } try { obj = (BaseTripleCollection)Activator.CreateInstance(targetType, new Object[] { wrappedCollection }); } catch { return(false); } } } else if (_graphCollectionType.IsAssignableFrom(targetType)) { wrapsNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingGraphCollection))); if (wrapsNode == null) { // Simple Graph Collection creation try { obj = (BaseGraphCollection)Activator.CreateInstance(targetType); } catch { return(false); } } else { // Wrapped Graph Collection creation wrappedCollection = ConfigurationLoader.LoadObject(g, wrapsNode) as BaseGraphCollection; if (wrappedCollection == null) { throw new DotNetRdfConfigurationException("Unable to load the Graph Collection identified by the Node '" + objNode.ToString() + "' as the dnr:usingGraphCollection points to an object which cannot be loaded as an instance of the required type BaseGraphCollection for this collection to wrap"); } try { obj = (BaseGraphCollection)Activator.CreateInstance(targetType, new Object[] { wrappedCollection }); } catch { return(false); } } } return(obj != null); }
/// <summary> /// Tries to load a SPARQL Update based on information from the Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Output Object</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; ISparqlUpdateProcessor processor = null; INode storeObj; Object temp; INode propStorageProvider = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStorageProvider)); switch (targetType.FullName) { case LeviathanUpdateProcessor: INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingDataset))); if (datasetObj != null) { temp = ConfigurationLoader.LoadObject(g, datasetObj); if (temp is ISparqlDataset) { processor = new LeviathanUpdateProcessor((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Leviathan Update Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface"); } } else { storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore))); if (storeObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IInMemoryQueryableStore) { processor = new LeviathanUpdateProcessor((IInMemoryQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Leviathan Update Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface"); } } break; case SimpleUpdateProcessor: storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore))); if (storeObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IUpdateableTripleStore) { processor = new SimpleUpdateProcessor((IUpdateableTripleStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Simple Update Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IUpdateableTripleStore interface"); } break; case GenericUpdateProcessor: INode managerObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider); if (managerObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, managerObj); if (temp is IStorageProvider) { processor = new GenericUpdateProcessor((IStorageProvider)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Generic Update Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object that cannot be loaded as an object which implements the IStorageProvider interface"); } break; } obj = processor; return(processor != null); }
/// <summary> /// Tries to load a SPARQL Dataset based on information from the Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Output Object</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; bool unionDefGraph = ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUnionDefaultGraph)), false); INode defaultGraphNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultGraphUri))); Uri defaultGraph = (defaultGraphNode != null && defaultGraphNode.NodeType == NodeType.Uri ? ((IUriNode)defaultGraphNode).Uri : null); INode storeNode; switch (targetType.FullName) { case InMemoryDataset: storeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore))); if (storeNode == null) { obj = new InMemoryDataset(); } else { Object temp = ConfigurationLoader.LoadObject(g, storeNode); if (temp is IInMemoryQueryableStore) { if (unionDefGraph) { obj = new InMemoryDataset((IInMemoryQueryableStore)temp, unionDefGraph); } else if (defaultGraph != null) { obj = new InMemoryDataset((IInMemoryQueryableStore)temp, defaultGraph); } else { obj = new InMemoryDataset((IInMemoryQueryableStore)temp); } } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:usingStore property could not be loaded as an object which implements the IInMemoryQueryableStore interface"); } } break; case InMemoryQuadDataset: storeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore))); if (storeNode == null) { obj = new InMemoryQuadDataset(); } else { Object temp = ConfigurationLoader.LoadObject(g, storeNode); if (temp is IInMemoryQueryableStore) { obj = new InMemoryQuadDataset((IInMemoryQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:usingStore property could not be loaded as an object which implements the IInMemoryQueryableStore interface"); } } break; case WebDemandDataset: storeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingDataset))); if (storeNode == null) { obj = new WebDemandDataset(new InMemoryQuadDataset()); } else { Object temp = ConfigurationLoader.LoadObject(g, storeNode); if (temp is ISparqlDataset) { obj = new WebDemandDataset((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Web Demand Dataset identified by the Node '" + objNode.ToString() + "' since the Object pointed to by the dnr:usingDataset property could not be loaded as an object which implements the ISparqlDataset interface"); } } break; } return(obj != null); }
/// <summary> /// Tries to load a SPARQL Endpoint based on information from the Configuration Graph. /// </summary> /// <param name="g">Configuration Graph.</param> /// <param name="objNode">Object Node.</param> /// <param name="targetType">Target Type.</param> /// <param name="obj">Output Object.</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { BaseEndpoint endpoint = null; obj = null; switch (targetType.FullName) { case QueryEndpoint: String queryEndpointUri = ConfigurationLoader.GetConfigurationValue(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) }); if (queryEndpointUri == null) { return(false); } // Get Default/Named Graphs if specified IEnumerable <String> defaultGraphs = from n in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultGraphUri))) select n.ToString(); IEnumerable <String> namedGraphs = from n in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyNamedGraphUri))) select n.ToString(); endpoint = new SparqlRemoteEndpoint(UriFactory.Create(queryEndpointUri), defaultGraphs, namedGraphs); break; case UpdateEndpoint: String updateEndpointUri = ConfigurationLoader.GetConfigurationValue(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) }); if (updateEndpointUri == null) { return(false); } endpoint = new SparqlRemoteUpdateEndpoint(UriFactory.Create(updateEndpointUri)); break; case FederatedEndpoint: IEnumerable <INode> endpoints = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpoint))) .Concat(ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)))); foreach (INode e in endpoints) { Object temp = ConfigurationLoader.LoadObject(g, e); if (temp is SparqlRemoteEndpoint) { if (endpoint == null) { endpoint = new FederatedSparqlRemoteEndpoint((SparqlRemoteEndpoint)temp); } else { ((FederatedSparqlRemoteEndpoint)endpoint).AddEndpoint((SparqlRemoteEndpoint)temp); } } else { throw new DotNetRdfConfigurationException("Unable to load the SPARQL Endpoint identified by the Node '" + e.ToString() + "' as one of the values for the dnr:queryEndpoint/dnr:endpoint property points to an Object which cannot be loaded as an object which is a SparqlRemoteEndpoint"); } } break; } if (endpoint != null) { // Are there any credentials specified? String user, pwd; ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { endpoint.SetCredentials(user, pwd); } // Is there a Proxy Server specified INode proxyNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyProxy))); if (proxyNode != null) { Object proxy = ConfigurationLoader.LoadObject(g, proxyNode); if (proxy is IWebProxy) { endpoint.Proxy = (IWebProxy)proxy; // Are we supposed to use the same credentials for the proxy as for the endpoint? bool useCredentialsForProxy = ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUseCredentialsForProxy)), false); if (useCredentialsForProxy) { endpoint.UseCredentialsForProxy = true; } } else { throw new DotNetRdfConfigurationException("Unable to load SPARQL Endpoint identified by the Node '" + objNode.ToString() + "' as the value for the dnr:proxy property points to an Object which cannot be loaded as an object of type WebProxy"); } } } obj = endpoint; return(endpoint != null); }
public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { switch (targetType.FullName) { case MongoDBManager: String server = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer)); String storeID = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase)); String collectionID = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog)); String loadMode = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); MongoDBSchemas schema = MongoDBDocumentManager.DefaultSchema; if (loadMode != null) { switch (loadMode) { case "GraphCentric": schema = MongoDBSchemas.GraphCentric; break; case "TripleCentric": schema = MongoDBSchemas.TripleCentric; break; } } if (storeID != null) { AlexandriaMongoDBManager manager; if (server == null) { if (collectionID == null) { manager = new AlexandriaMongoDBManager(storeID, schema); } else { manager = new AlexandriaMongoDBManager(new MongoDBDocumentManager(new MongoConfiguration(), storeID, collectionID, schema)); } } else { //Have a Custom Connection String if (collectionID == null) { manager = new AlexandriaMongoDBManager(new MongoDBDocumentManager(server, storeID, schema)); } else { manager = new AlexandriaMongoDBManager(new MongoDBDocumentManager(server, storeID, collectionID, schema)); } } obj = manager; return(true); } //If we get here then the required dnr:database property was missing throw new DotNetRdfConfigurationException("Unable to load the MongoDB Manager identified by the Node '" + objNode.ToString() + "' since there was no value given for the required property dnr:database"); break; case MongoDBDataset: INode managerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:genericManager")); if (managerNode == null) { throw new DotNetRdfConfigurationException("Unable to load the MongoDB Dataset identified by the Node '" + objNode.ToString() + "' since there we no value for the required property dnr:genericManager"); } Object temp = ConfigurationLoader.LoadObject(g, managerNode); if (temp is AlexandriaMongoDBManager) { obj = new AlexandriaMongoDBDataset((AlexandriaMongoDBManager)temp); return(true); } else { throw new DotNetRdfConfigurationException("Unable to load the MongoDB Dataset identified by the Node '" + objNode.ToString() + "' since the value for the dnr:genericManager property pointed to an Object which could not be loaded as an object of type AlexandriaMongoDBManager"); } break; } obj = null; return(false); }
/// <summary> /// Tries to load a Generic IO Manager based on information from the Configuration Graph. /// </summary> /// <param name="g">Configuration Graph.</param> /// <param name="objNode">Object Node.</param> /// <param name="targetType">Target Type.</param> /// <param name="obj">Output Object.</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { IStorageProvider storageProvider = null; IStorageServer storageServer = null; SparqlConnectorLoadMethod loadMode; obj = null; String server, user, pwd, store, catalog, loadModeRaw; Object temp; INode storeObj; // Create the URI Nodes we're going to use to search for things INode propServer = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyServer)), propDb = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDatabase)), propStore = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStore)), propAsync = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyAsync)), propStorageProvider = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStorageProvider)); switch (targetType.FullName) { case AllegroGraph: // Get the Server, Catalog and Store server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } catalog = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyCatalog))); store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } // Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { storageProvider = new AllegroGraphConnector(server, catalog, store, user, pwd); } else { storageProvider = new AllegroGraphConnector(server, catalog, store); } break; case AllegroGraphServer: // Get the Server, Catalog and User Credentials server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } catalog = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyCatalog))); ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { storageServer = new AllegroGraphServer(server, catalog, user, pwd); } else { storageServer = new AllegroGraphServer(server, catalog); } break; case DatasetFile: // Get the Filename and whether the loading should be done asynchronously String file = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromFile))); if (file == null) { return(false); } file = ConfigurationLoader.ResolvePath(file); bool isAsync = ConfigurationLoader.GetConfigurationBoolean(g, objNode, propAsync, false); storageProvider = new DatasetFileManager(file, isAsync); break; case Dydra: throw new DotNetRdfConfigurationException("DydraConnector is no longer supported by dotNetRDF and is considered obsolete"); case FourStore: // Get the Server and whether Updates are enabled server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } bool enableUpdates = ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEnableUpdates)), true); storageProvider = new FourStoreConnector(server, enableUpdates); break; case Fuseki: // Get the Server URI server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } storageProvider = new FusekiConnector(server); break; case InMemory: // Get the Dataset/Store INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingDataset))); if (datasetObj != null) { temp = ConfigurationLoader.LoadObject(g, datasetObj); if (temp is ISparqlDataset) { storageProvider = new InMemoryManager((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface"); } } else { // If no dnr:usingDataset try dnr:usingStore instead storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore))); if (storeObj != null) { temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IInMemoryQueryableStore) { storageProvider = new InMemoryManager((IInMemoryQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface"); } } else { // If no dnr:usingStore either then create a new empty store storageProvider = new InMemoryManager(); } } break; case ReadOnly: // Get the actual Manager we are wrapping storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider); temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IStorageProvider) { storageProvider = new ReadOnlyConnector((IStorageProvider)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IStorageProvider interface"); } break; case ReadOnlyQueryable: // Get the actual Manager we are wrapping storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider); temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IQueryableStorage) { storageProvider = new QueryableReadOnlyConnector((IQueryableStorage)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Queryable Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IQueryableStorage interface"); } break; case Sesame: case SesameV5: case SesameV6: // Get the Server and Store ID server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { storageProvider = (IStorageProvider)Activator.CreateInstance(targetType, new Object[] { server, store, user, pwd }); } else { storageProvider = (IStorageProvider)Activator.CreateInstance(targetType, new Object[] { server, store }); } break; case SesameServer: // Get the Server and User Credentials server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { storageServer = new SesameServer(server, user, pwd); } else { storageServer = new SesameServer(server); } break; case Sparql: // Get the Endpoint URI or the Endpoint server = ConfigurationLoader.GetConfigurationString(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) }); // What's the load mode? loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyLoadMode))); loadMode = SparqlConnectorLoadMethod.Construct; if (loadModeRaw != null) { try { loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw); } catch { throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid"); } } if (server == null) { INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpoint)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)) }); if (endpointObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteEndpoint) { storageProvider = new SparqlConnector((SparqlRemoteEndpoint)temp, loadMode); } else { throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint"); } } else { // Are there any Named/Default Graph URIs IEnumerable <Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultGraphUri))) where def.NodeType == NodeType.Uri select((IUriNode)def).Uri; IEnumerable <Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyNamedGraphUri))) where named.NodeType == NodeType.Uri select((IUriNode)named).Uri; if (defGraphs.Any() || namedGraphs.Any()) { storageProvider = new SparqlConnector(new SparqlRemoteEndpoint(UriFactory.Create(server), defGraphs, namedGraphs), loadMode); } else { storageProvider = new SparqlConnector(UriFactory.Create(server), loadMode); } } break; case ReadWriteSparql: SparqlRemoteEndpoint queryEndpoint; SparqlRemoteUpdateEndpoint updateEndpoint; // Get the Query Endpoint URI or the Endpoint server = ConfigurationLoader.GetConfigurationString(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) }); // What's the load mode? loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyLoadMode))); loadMode = SparqlConnectorLoadMethod.Construct; if (loadModeRaw != null) { try { loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw); } catch { throw new DotNetRdfConfigurationException("Unable to load the ReadWriteSparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid"); } } if (server == null) { INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpoint)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)) }); if (endpointObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteEndpoint) { queryEndpoint = (SparqlRemoteEndpoint)temp; } else { throw new DotNetRdfConfigurationException("Unable to load the ReadWriteSparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:queryEndpoint/dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint"); } } else { // Are there any Named/Default Graph URIs IEnumerable <Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultGraphUri))) where def.NodeType == NodeType.Uri select((IUriNode)def).Uri; IEnumerable <Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyNamedGraphUri))) where named.NodeType == NodeType.Uri select((IUriNode)named).Uri; if (defGraphs.Any() || namedGraphs.Any()) { queryEndpoint = new SparqlRemoteEndpoint(UriFactory.Create(server), defGraphs, namedGraphs); ; } else { queryEndpoint = new SparqlRemoteEndpoint(UriFactory.Create(server)); } } // Find the Update Endpoint or Endpoint URI server = ConfigurationLoader.GetConfigurationString(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) }); if (server == null) { INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpoint)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)) }); if (endpointObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteUpdateEndpoint) { updateEndpoint = (SparqlRemoteUpdateEndpoint)temp; } else { throw new DotNetRdfConfigurationException("Unable to load the ReadWriteSparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:updateEndpoint/dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteUpdateEndpoint"); } } else { updateEndpoint = new SparqlRemoteUpdateEndpoint(UriFactory.Create(server)); } storageProvider = new ReadWriteSparqlConnector(queryEndpoint, updateEndpoint, loadMode); break; case SparqlHttpProtocol: // Get the Service URI server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } storageProvider = new SparqlHttpProtocolConnector(UriFactory.Create(server)); break; case Stardog: case StardogV1: case StardogV2: case StardogV3: // Get the Server and Store server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } // Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); // Get Reasoning Mode StardogReasoningMode reasoning = StardogReasoningMode.None; String mode = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyLoadMode))); if (mode != null) { try { reasoning = (StardogReasoningMode)Enum.Parse(typeof(StardogReasoningMode), mode, true); } catch { reasoning = StardogReasoningMode.None; } } if (user != null && pwd != null) { switch (targetType.FullName) { case StardogV1: storageProvider = new StardogV1Connector(server, store, reasoning, user, pwd); break; case StardogV2: storageProvider = new StardogV2Connector(server, store, reasoning, user, pwd); break; case StardogV3: storageProvider = new StardogV3Connector(server, store, user, pwd); break; case Stardog: default: storageProvider = new StardogConnector(server, store, user, pwd); break; } } else { switch (targetType.FullName) { case StardogV1: storageProvider = new StardogV1Connector(server, store, reasoning); break; case StardogV2: storageProvider = new StardogV2Connector(server, store, reasoning); break; case StardogV3: storageProvider = new StardogV3Connector(server, store); break; case Stardog: default: storageProvider = new StardogConnector(server, store); break; } } break; case StardogServer: case StardogServerV1: case StardogServerV2: case StardogServerV3: // Get the Server and User Credentials server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { switch (targetType.FullName) { case StardogServerV1: storageServer = new StardogV1Server(server, user, pwd); break; case StardogServerV2: storageServer = new StardogV2Server(server, user, pwd); break; case StardogServerV3: storageServer = new StardogV3Server(server, user, pwd); break; case StardogServer: default: storageServer = new StardogServer(server, user, pwd); break; } } else { switch (targetType.FullName) { case StardogServerV1: storageServer = new StardogV1Server(server); break; case StardogServerV2: storageServer = new StardogV2Server(server); break; case StardogServerV3: storageServer = new StardogV3Server(server); break; case StardogServer: default: storageServer = new StardogServer(server); break; } } break; } // Set the return object if one has been loaded if (storageProvider != null) { obj = storageProvider; } else if (storageServer != null) { obj = storageServer; } // Check whether this is a standard HTTP manager and if so load standard configuration if (obj is BaseHttpConnector) { BaseHttpConnector connector = (BaseHttpConnector)obj; int timeout = ConfigurationLoader.GetConfigurationInt32(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyTimeout)), 0); if (timeout > 0) { connector.Timeout = timeout; } INode proxyNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyProxy))); if (proxyNode != null) { temp = ConfigurationLoader.LoadObject(g, proxyNode); if (temp is IWebProxy) { connector.Proxy = (IWebProxy)temp; } else { throw new DotNetRdfConfigurationException("Unable to load storage provider/server identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:proxy property pointed to an Object which could not be loaded as an object of the required type WebProxy"); } } } return(obj != null); }
/// <summary> /// Tries to load a SPARQL Graph Store HTTP Protocol Processor based on information from the Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Output Object</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; ISparqlHttpProtocolProcessor processor = null; Object temp; INode propStorageProvider = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStorageProvider)); switch (targetType.FullName) { case ProtocolToUpdateProcessor: INode qNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryProcessor))); INode uNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateProcessor))); if (qNode == null || uNode == null) { return(false); } Object queryProc = ConfigurationLoader.LoadObject(g, qNode); Object updateProc = ConfigurationLoader.LoadObject(g, uNode); if (queryProc is ISparqlQueryProcessor) { if (updateProc is ISparqlUpdateProcessor) { processor = new ProtocolToUpdateProcessor((ISparqlQueryProcessor)queryProc, (ISparqlUpdateProcessor)updateProc); } else { throw new DotNetRdfConfigurationException("Unable to load the SPARQL HTTP Protocol Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:updateProcessor property points to an Object that cannot be loaded as an object which implements the ISparqlUpdateProcessor interface"); } } else { throw new DotNetRdfConfigurationException("Unable to load the SPARQL HTTP Protocol Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:queryProcessor property points to an Object that cannot be loaded as an object which implements the ISparqlQueryProcessor interface"); } break; case LeviathanProtocolProcessor: INode datasetNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingDataset))); if (datasetNode != null) { temp = ConfigurationLoader.LoadObject(g, datasetNode); if (temp is ISparqlDataset) { processor = new LeviathanProtocolProcessor((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Leviathan Protocol Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface"); } } else { INode storeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore))); if (storeNode == null) { return(false); } Object store = ConfigurationLoader.LoadObject(g, storeNode); if (store is IInMemoryQueryableStore) { processor = new LeviathanProtocolProcessor((IInMemoryQueryableStore)store); } else { throw new DotNetRdfConfigurationException("Unable to load the SPARQL HTTP Protocol Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface"); } } break; case GenericProtocolProcessor: INode managerObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider); if (managerObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, managerObj); if (temp is IStorageProvider) { processor = new GenericProtocolProcessor((IStorageProvider)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Generic Protocol Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object that cannot be loaded as an object which implements the IStorageProvider interface"); } break; } obj = processor; return(processor != null); }
/// <summary> /// Creates a new Base Handler Configuration which loads common Handler settings from a Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> public BaseHandlerConfiguration(IGraph g, INode objNode) { //Are there any User Groups associated with this Handler? IEnumerable <INode> groups = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:userGroup")); foreach (INode group in groups) { Object temp = ConfigurationLoader.LoadObject(g, group); if (temp is UserGroup) { this._userGroups.Add((UserGroup)temp); } else { throw new DotNetRdfConfigurationException("Unable to load Handler Configuration as the RDF Configuration file specifies a value for the Handlers dnr:userGroup property which cannot be loaded as an object which is a UserGroup"); } } //General Handler Settings this._showErrors = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyShowErrors), this._showErrors); String introFile = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyIntroFile)); if (introFile != null) { introFile = ConfigurationLoader.ResolvePath(introFile); if (File.Exists(introFile)) { using (StreamReader reader = new StreamReader(introFile)) { this._introText = reader.ReadToEnd(); reader.Close(); } } } this._stylesheet = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStylesheet)).ToSafeString(); this._corsEnabled = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEnableCors), true); //Cache Settings this._cacheDuration = ConfigurationLoader.GetConfigurationInt32(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCacheDuration), this._cacheDuration); if (this._cacheDuration < MinimumCacheDuration) { this._cacheDuration = MinimumCacheDuration; } if (this._cacheDuration > MaximumCacheDuration) { this._cacheDuration = MaximumCacheDuration; } this._cacheSliding = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCacheSliding), this._cacheSliding); //SPARQL Expression Factories IEnumerable <INode> factories = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyExpressionFactory)); foreach (INode factory in factories) { Object temp = ConfigurationLoader.LoadObject(g, factory); if (temp is ISparqlCustomExpressionFactory) { this._expressionFactories.Add((ISparqlCustomExpressionFactory)temp); } else { throw new DotNetRdfConfigurationException("Unable to load Handler Configuration as the RDF Configuration file specifies a value for the Handlers dnr:expressionFactory property which cannot be loaded as an object which is a SPARQL Expression Factory"); } } //Writer Properties this._writerCompressionLevel = ConfigurationLoader.GetConfigurationInt32(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCompressionLevel), this._writerCompressionLevel); this._writerDtds = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDtdWriting), this._writerDtds); this._writerHighSpeed = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyHighSpeedWriting), this._writerHighSpeed); this._writerMultiThreading = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyMultiThreadedWriting), this._writerMultiThreading); this._writerPrettyPrinting = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPrettyPrinting), this._writerPrettyPrinting); this._writerAttributes = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAttributeWriting), this._writerAttributes); //Load in the Default Namespaces if specified INode nsNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyImportNamespacesFrom)); if (nsNode != null) { Object nsTemp = ConfigurationLoader.LoadObject(g, nsNode); if (nsTemp is IGraph) { this._defaultNamespaces.Import(((IGraph)nsTemp).NamespaceMap); } } }
/// <summary> /// Creates a new Base SPARQL Server Configuration based on information from a Configuration Graph /// </summary> /// <param name="context">HTTP Context</param> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> public BaseSparqlServerConfiguration(HttpContext context, IGraph g, INode objNode) : base(context, g, objNode) { //Get the Query Processor to be used INode procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryProcessor)); if (procNode != null) { Object temp = ConfigurationLoader.LoadObject(g, procNode); if (temp is ISparqlQueryProcessor) { this._queryProcessor = (ISparqlQueryProcessor)temp; } else { throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file specifies a value for the Handlers dnr:queryProcessor property which cannot be loaded as an object which implements the ISparqlQueryProcessor interface"); } } //SPARQL Query Default Config this._defaultGraph = ConfigurationLoader.GetConfigurationValue(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri)).ToSafeString(); this._defaultTimeout = ConfigurationLoader.GetConfigurationInt64(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyTimeout), this._defaultTimeout); this._defaultPartialResults = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPartialResults), this._defaultPartialResults); //Handler Configuration this._showQueryForm = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyShowQueryForm), this._showQueryForm); String defQueryFile = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultQueryFile)); if (defQueryFile != null) { defQueryFile = ConfigurationLoader.ResolvePath(defQueryFile); if (File.Exists(defQueryFile)) { using (StreamReader reader = new StreamReader(defQueryFile)) { this._defaultQuery = reader.ReadToEnd(); reader.Close(); } } } //Get Query Syntax to use try { String syntaxSetting = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertySyntax)); if (syntaxSetting != null) { this._syntax = (SparqlQuerySyntax)Enum.Parse(typeof(SparqlQuerySyntax), syntaxSetting); } } catch (Exception ex) { throw new DotNetRdfConfigurationException("Unable to set the Syntax for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:syntax property was not a valid value from the enum VDS.RDF.Parsing.SparqlQuerySyntax", ex); } //Get the SPARQL Describe Algorithm INode describeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDescribeAlgorithm)); if (describeNode != null) { if (describeNode.NodeType == NodeType.Literal) { String algoClass = ((ILiteralNode)describeNode).Value; try { Object desc = Activator.CreateInstance(Type.GetType(algoClass)); if (desc is ISparqlDescribe) { this._describer = (ISparqlDescribe)desc; } else { throw new DotNetRdfConfigurationException("Unable to set the Describe Algorithm for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:describeAlgorithm property was not a type name of a type that implements the ISparqlDescribe interface"); } } catch (DotNetRdfConfigurationException) { throw; } catch (Exception ex) { throw new DotNetRdfConfigurationException("Unable to set the Describe Algorithm for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:describeAlgorithm property was not a type name for a type that can be instantiated", ex); } } } //Get the Query Optimiser INode queryOptNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryOptimiser)); if (queryOptNode != null) { Object queryOpt = ConfigurationLoader.LoadObject(g, queryOptNode); if (queryOpt is IQueryOptimiser) { this._queryOptimiser = (IQueryOptimiser)queryOpt; } else { throw new DotNetRdfConfigurationException("Unable to set the Query Optimiser for the HTTP Handler identified by the Node '" + queryOptNode.ToString() + "' as the value given for the dnr:queryOptimiser property points to an Object which could not be loaded as an object which implements the required IQueryOptimiser interface"); } } //Get the Algebra Optimisers foreach (INode algOptNode in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAlgebraOptimiser))) { Object algOpt = ConfigurationLoader.LoadObject(g, algOptNode); if (algOpt is IAlgebraOptimiser) { this._algebraOptimisers.Add((IAlgebraOptimiser)algOpt); } else { throw new DotNetRdfConfigurationException("Unable to set the Algebra Optimiser for the HTTP Handler identified by the Node '" + algOptNode.ToString() + "' as the value given for the dnr:algebraOptimiser property points to an Object which could not be loaded as an object which implements the required IAlgebraOptimiser interface"); } } //Then get the Update Processor to be used procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUpdateProcessor)); if (procNode != null) { Object temp = ConfigurationLoader.LoadObject(g, procNode); if (temp is ISparqlUpdateProcessor) { this._updateProcessor = (ISparqlUpdateProcessor)temp; } else { throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file specifies a value for the Handlers dnr:updateProcessor property which cannot be loaded as an object which implements the ISparqlUpdateProcessor interface"); } } //Handler Settings this._showUpdateForm = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyShowUpdateForm), this._showUpdateForm); String defUpdateFile = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultUpdateFile)); if (defUpdateFile != null) { defUpdateFile = ConfigurationLoader.ResolvePath(defUpdateFile); if (File.Exists(defUpdateFile)) { using (StreamReader reader = new StreamReader(defUpdateFile)) { this._defaultUpdate = reader.ReadToEnd(); reader.Close(); } } } //Then get the Protocol Processor to be used procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyProtocolProcessor)); if (procNode != null) { Object temp = ConfigurationLoader.LoadObject(g, procNode); if (temp is ISparqlHttpProtocolProcessor) { this._protocolProcessor = (ISparqlHttpProtocolProcessor)temp; } else { throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file specifies a value for the Handlers dnr:protocolProcessor property which cannot be loaded as an object which implements the ISparqlHttpProtocolProcessor interface"); } } if (this._queryProcessor == null && this._updateProcessor == null && this._protocolProcessor == null) { throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file does not specify at least one of a Query/Update/Protocol processor for the server using the dnr:queryProcessor/dnr:updateProcessor/dnr:protocolProcessor properties"); } //Get the Service Description Graph INode descripNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServiceDescription)); if (descripNode != null) { Object descrip = ConfigurationLoader.LoadObject(g, descripNode); if (descrip is IGraph) { this._serviceDescription = (IGraph)descrip; } else { throw new DotNetRdfConfigurationException("Unable to set the Service Description Graph for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:serviceDescription property points to an Object which could not be loaded as an object which implements the required IGraph interface"); } } }
/// <summary> /// Tries to load a Generic IO Manager based on information from the Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Output Object</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { IGenericIOManager manager = null; obj = null; String server, user, pwd, store; bool isAsync; Object temp; INode storeObj; //Create the URI Nodes we're going to use to search for things INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer), propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase), propStore = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStore), propAsync = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAsync); switch (targetType.FullName) { #if !NO_SYNC_HTTP case AllegroGraph: //Get the Server, Catalog and Store server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } String catalog = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog)); store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } //Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { manager = new AllegroGraphConnector(server, catalog, store, user, pwd); } else { manager = new AllegroGraphConnector(server, catalog, store); } break; #endif case DatasetFile: //Get the Filename and whether the loading should be done asynchronously String file = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromFile)); if (file == null) { return(false); } file = ConfigurationLoader.ResolvePath(file); isAsync = ConfigurationLoader.GetConfigurationBoolean(g, objNode, propAsync, false); manager = new DatasetFileManager(file, isAsync); break; #if !NO_SYNC_HTTP case Dydra: //Get the Account Name and Store String account = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog)); if (account == null) { return(false); } store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } //Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null) { manager = new DydraConnector(account, store, user); } else { manager = new DydraConnector(account, store); } break; case FourStore: //Get the Server and whether Updates are enabled server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } bool enableUpdates = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEnableUpdates), true); manager = new FourStoreConnector(server, enableUpdates); break; case Fuseki: //Get the Server URI server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } manager = new FusekiConnector(server); break; #endif case InMemory: //Get the Dataset/Store INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingDataset)); if (datasetObj != null) { temp = ConfigurationLoader.LoadObject(g, datasetObj); if (temp is ISparqlDataset) { manager = new InMemoryManager((ISparqlDataset)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface"); } } else { //If no dnr:usingDataset try dnr:usingStore instead storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore)); if (storeObj != null) { temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IInMemoryQueryableStore) { manager = new InMemoryManager((IInMemoryQueryableStore)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface"); } } else { //If no dnr:usingStore either then create a new empty store manager = new InMemoryManager(); } } break; #if !NO_SYNC_HTTP case Joseki: //Get the Query and Update URIs server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } String queryService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryPath)); if (queryService == null) { return(false); } String updateService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUpdatePath)); if (updateService == null) { manager = new JosekiConnector(server, queryService); } else { manager = new JosekiConnector(server, queryService, updateService); } break; #endif case ReadOnly: //Get the actual Manager we are wrapping storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IGenericIOManager) { manager = new ReadOnlyConnector((IGenericIOManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IGenericIOManager interface"); } break; case ReadOnlyQueryable: //Get the actual Manager we are wrapping storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); temp = ConfigurationLoader.LoadObject(g, storeObj); if (temp is IQueryableGenericIOManager) { manager = new QueryableReadOnlyConnector((IQueryableGenericIOManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Queryable Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IQueryableGenericIOManager interface"); } break; #if !NO_SYNC_HTTP case Sesame: case SesameV5: case SesameV6: //Get the Server and Store ID server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { manager = (IGenericIOManager)Activator.CreateInstance(targetType, new Object[] { server, store, user, pwd }); } else { manager = (IGenericIOManager)Activator.CreateInstance(targetType, new Object[] { server, store }); } break; case Sparql: //Get the Endpoint URI or the Endpoint server = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpointUri)); //What's the load mode? String loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); SparqlConnectorLoadMethod loadMode = SparqlConnectorLoadMethod.Construct; if (loadModeRaw != null) { try { #if SILVERLIGHT loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw, false); #else loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw); #endif } catch { throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid"); } } if (server == null) { INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpoint)); if (endpointObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, endpointObj); if (temp is SparqlRemoteEndpoint) { manager = new SparqlConnector((SparqlRemoteEndpoint)temp, loadMode); } else { throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint"); } } else { //Are there any Named/Default Graph URIs IEnumerable <Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri)) where def.NodeType == NodeType.Uri select((IUriNode)def).Uri; IEnumerable <Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyNamedGraphUri)) where named.NodeType == NodeType.Uri select((IUriNode)named).Uri; if (defGraphs.Any() || namedGraphs.Any()) { manager = new SparqlConnector(new SparqlRemoteEndpoint(UriFactory.Create(server), defGraphs, namedGraphs), loadMode); } else { manager = new SparqlConnector(UriFactory.Create(server), loadMode); } } break; case SparqlHttpProtocol: //Get the Service URI server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } manager = new SparqlHttpProtocolConnector(UriFactory.Create(server)); break; case Stardog: //Get the Server and Store server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { return(false); } store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } //Get User Credentials ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); //Get Reasoning Mode StardogReasoningMode reasoning = StardogReasoningMode.None; String mode = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); if (mode != null) { try { reasoning = (StardogReasoningMode)Enum.Parse(typeof(StardogReasoningMode), mode); } catch { reasoning = StardogReasoningMode.None; } } if (user != null && pwd != null) { manager = new StardogConnector(server, store, reasoning, user, pwd); } else { manager = new StardogConnector(server, store, reasoning); } break; case Talis: //Get the Store Name and User credentials store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore); if (store == null) { return(false); } ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); if (user != null && pwd != null) { manager = new TalisPlatformConnector(store, user, pwd); } else { manager = new TalisPlatformConnector(store); } break; #endif } #if !NO_PROXY //Check whether this is a proxyable manager and if we need to load proxy settings if (manager is BaseHttpConnector) { INode proxyNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyProxy)); if (proxyNode != null) { temp = ConfigurationLoader.LoadObject(g, proxyNode); if (temp is WebProxy) { ((BaseHttpConnector)manager).Proxy = (WebProxy)temp; } else { throw new DotNetRdfConfigurationException("Unable to load Generic Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:proxy property pointed to an Object which could not be loaded as an object of the required type WebProxy"); } } } #endif obj = manager; return(manager != null); }
/// <summary> /// Tries to load an object based on information from the Configuration Graph /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Output Object</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; INode index = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "index")); //INode indexer = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "indexer")); INode searcher = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "searcher")); INode analyzer = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "analyzer")); INode schema = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "schema")); INode version = g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "version")); Object tempIndex, tempAnalyzer, tempSchema; int ver = 2900; //Always check for the version ver = ConfigurationLoader.GetConfigurationInt32(g, objNode, version, 2900); switch (targetType.FullName) { case DefaultIndexSchema: obj = new DefaultIndexSchema(); break; case FullTextOptimiser: //Need to get the Search Provider INode providerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, searcher); if (providerNode == null) { throw new DotNetRdfConfigurationException("Unable to load the Full Text Optimiser specified by the Node '" + objNode.ToString() + "' as there was no value specified for the required dnr-ft:searcher property"); } Object tempSearcher = ConfigurationLoader.LoadObject(g, providerNode); if (tempSearcher is IFullTextSearchProvider) { obj = new FullTextOptimiser((IFullTextSearchProvider)tempSearcher); } else { throw new DotNetRdfConfigurationException("Unable to load the Full Text Optimiser specified by the Node '" + objNode.ToString() + "' as the value specified for the dnr-ft:searcher property pointed to an object which could not be loaded as a type that implements the required IFullTextSearchProvider interface"); } break; case LuceneObjectsIndexer: case LucenePredicatesIndexer: case LuceneSubjectsIndexer: case LuceneSearchProvider: //For any Lucene Indexer/Search Provider need to know the Index, Analyzer and Schema to be used //Then get the Index tempIndex = ConfigurationLoader.GetConfigurationNode(g, objNode, index); if (tempIndex == null) { throw new DotNetRdfConfigurationException("Unable to load the Lucene Indexer specified by the Node '" + objNode.ToString() + "' as there was no value specified for the required dnr-ft:index property"); } tempIndex = ConfigurationLoader.LoadObject(g, (INode)tempIndex); if (tempIndex is Directory) { //Next get the Analyzer (assume Standard if none specified) tempAnalyzer = ConfigurationLoader.GetConfigurationNode(g, objNode, analyzer); if (tempAnalyzer == null) { tempAnalyzer = new StandardAnalyzer(this.GetLuceneVersion(ver)); } else { tempAnalyzer = ConfigurationLoader.LoadObject(g, (INode)tempAnalyzer); } if (tempAnalyzer is Analyzer) { //Finally get the Schema (assume Default if none specified) tempSchema = ConfigurationLoader.GetConfigurationNode(g, objNode, schema); if (tempSchema == null) { tempSchema = new DefaultIndexSchema(); } else { tempSchema = ConfigurationLoader.LoadObject(g, (INode)tempSchema); } if (tempSchema is IFullTextIndexSchema) { //Now we can create the Object switch (targetType.FullName) { case LuceneObjectsIndexer: obj = new LuceneObjectsIndexer((Directory)tempIndex, (Analyzer)tempAnalyzer, (IFullTextIndexSchema)tempSchema); break; case LucenePredicatesIndexer: obj = new LucenePredicatesIndexer((Directory)tempIndex, (Analyzer)tempAnalyzer, (IFullTextIndexSchema)tempSchema); break; case LuceneSubjectsIndexer: obj = new LuceneSubjectsIndexer((Directory)tempIndex, (Analyzer)tempAnalyzer, (IFullTextIndexSchema)tempSchema); break; case LuceneSearchProvider: //Before the Search Provider has been loaded determine whether we need to carry out auto-indexing List <INode> sources = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "buildIndexFor"))).ToList(); if (sources.Count > 0) { //If there are sources to index ensure we have an indexer to index with INode indexerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "buildIndexWith"))); if (indexerNode == null) { throw new DotNetRdfConfigurationException("Unable to load the Lucene Search Provider specified by the Node '" + objNode.ToString() + "' as there were values specified for the dnr-ft:buildIndexFor property but no dnr-ft:buildIndexWith property was found"); } IFullTextIndexer indexer = ConfigurationLoader.LoadObject(g, indexerNode) as IFullTextIndexer; if (indexer == null) { throw new DotNetRdfConfigurationException("Unable to load the Lucene Search Provider specified by the Node '" + objNode.ToString() + "' as the value given for the dnr-ft:buildIndexWith property pointed to an Object which could not be loaded as a type that implements the required IFullTextIndexer interface"); } try { //For Each Source load it and Index it foreach (INode sourceNode in sources) { Object source = ConfigurationLoader.LoadObject(g, sourceNode); if (source is ISparqlDataset) { indexer.Index((ISparqlDataset)source); } else if (source is ITripleStore) { foreach (IGraph graph in ((ITripleStore)source).Graphs) { indexer.Index(graph); } } else if (source is IGraph) { indexer.Index((IGraph)source); } else { throw new DotNetRdfConfigurationException("Unable to load the Lucene Search Provider specified by the Node '" + objNode.ToString() + "' as a value given for the dnr-ft:buildIndexFor property ('" + sourceNode.ToString() + "') pointed to an Object which could not be loaded as a type that implements one of the required interfaces: IGraph, ITripleStore or ISparqlDataset"); } } } finally { indexer.Dispose(); } } //Then we actually load the Search Provider obj = new LuceneSearchProvider(this.GetLuceneVersion(ver), (Directory)tempIndex, (Analyzer)tempAnalyzer, (IFullTextIndexSchema)tempSchema); break; } } else { throw new DotNetRdfConfigurationException("Unable to load the Lucene Indexer specified by the Node '" + objNode.ToString() + "' as the value given for the dnr-ft:schema property pointed to an Object which could not be loaded as a type that implements the required IFullTextIndexSchema interface"); } } else { throw new DotNetRdfConfigurationException("Unable to load the Lucene Indexer specified by the Node '" + objNode.ToString() + "' as the value given for the dnr-ft:analyzer property pointed to an Object which could not be loaded as a type that derives from the required Lucene.Net.Analysis.Analyzer type"); } } else { throw new DotNetRdfConfigurationException("Unable to load the Lucene Indexer specified by the Node '" + objNode.ToString() + "' as the value given for the dnr-ft:index property pointed to an Object which could not be loaded as a type that derives from the required Lucene.Net.Store.Directory type"); } break; default: try { if (this._luceneAnalyzerType.IsAssignableFrom(targetType)) { if (targetType.GetConstructor(new Type[] { typeof(LucVersion) }) != null) { obj = Activator.CreateInstance(targetType, new Object[] { this.GetLuceneVersion(ver) }); } else { obj = Activator.CreateInstance(targetType); } } else if (this._luceneDirectoryType.IsAssignableFrom(targetType)) { String dir = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromFile)); if (dir != null) { try { obj = Activator.CreateInstance(targetType, new Object[] { dir }); } catch { MethodInfo method = targetType.GetMethod("Open", new Type[] { typeof(DirInfo) }); if (method != null) { obj = method.Invoke(null, new Object[] { new DirInfo(ConfigurationLoader.ResolvePath(dir)) }); } } } else { obj = Activator.CreateInstance(targetType); } //Ensure the Index if necessary if (obj != null) { if (ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(new Uri(FullTextHelper.FullTextConfigurationNamespace + "ensureIndex")), false)) { IndexWriter writer = new IndexWriter((Directory)obj, new StandardAnalyzer(this.GetLuceneVersion(ver))); writer.Close(); } } } } catch { //Since we know we don't allow loading of all analyzers and directories we allow for users to inject other object factories //which may know how to load those specific instances obj = null; } break; } return(obj != null); }
/// <summary> /// Tries to load a Reasoner based on information from the Configuration Graph. /// </summary> /// <param name="g">Configuration Graph.</param> /// <param name="objNode">Object Node.</param> /// <param name="targetType">Target Type.</param> /// <param name="obj">Output Object.</param> /// <returns></returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; Object output; switch (targetType.FullName) { case PelletReasonerType: String server = ConfigurationLoader.GetConfigurationValue(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyServer))); if (server == null) return false; String kb = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStore))); if (kb == null) return false; output = new PelletReasoner(UriFactory.Create(server), kb); break; case OwlReasonerWrapperType: INode reasonerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyOwlReasoner))); if (reasonerNode == null) return false; Object reasoner = ConfigurationLoader.LoadObject(g, reasonerNode); if (reasoner is IOwlReasoner) { output = new OwlReasonerWrapper((IOwlReasoner)reasoner); } else { throw new DotNetRdfConfigurationException("Unable to load configuration for the OWL Reasoner Wrapper identified by the Node '" + objNode.ToString() + "' as the value for the dnr:owlReasoner property points to an Object which cannot be loaded as an object which implements the IOwlReasoner interface"); } break; default: // Otherwise we'll just attempt to load this as an instance of an IInferenceEngine try { output = (IInferenceEngine)Activator.CreateInstance(targetType); } catch { // Any error means this loader can't load this type return false; } break; } if (output != null) { if (output is IInferenceEngine) { // Now initialise with any specified Graphs IEnumerable<INode> rulesGraphs = ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingGraph))); foreach (INode rulesGraph in rulesGraphs) { Object temp = ConfigurationLoader.LoadObject(g, rulesGraph); if (temp is IGraph) { ((IInferenceEngine)output).Initialise((IGraph)temp); } else { throw new DotNetRdfConfigurationException("Unable to load Configuration for the Forward Chaining Reasoner identified by the Node '" + objNode.ToString() + "' as one of the values for the dnr:usingGraph property points to an Object which cannot be loaded as an object which implements the IGraph interface"); } } } } obj = output; return true; }