/// <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 Protocol Handler Configuration /// </summary> /// <param name="context">HTTP Context</param> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> public BaseProtocolHandlerConfiguration(HttpContext 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, ConfigurationLoader.CreateConfigurationNode(g, 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, 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> /// Serializes the connection's configuration /// </summary> /// <param name="context">Configuration Serialization Context</param> public void SerializeConfiguration(ConfigurationSerializationContext context) { INode manager = context.NextSubject; INode rdfType = context.Graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); INode rdfsLabel = context.Graph.CreateUriNode(new Uri(NamespaceMapper.RDFS + "label")); INode dnrType = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyType); INode genericManager = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.ClassGenericManager); INode store = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyStore); context.Graph.Assert(new Triple(manager, rdfType, genericManager)); context.Graph.Assert(new Triple(manager, rdfsLabel, context.Graph.CreateLiteralNode(this.ToString()))); context.Graph.Assert(new Triple(manager, dnrType, context.Graph.CreateLiteralNode(this.GetType().FullName))); context.Graph.Assert(new Triple(manager, store, context.Graph.CreateLiteralNode(this._storename))); if (this._username != null && this._password != null) { INode username = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyUser); INode pwd = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyPassword); context.Graph.Assert(new Triple(manager, username, context.Graph.CreateLiteralNode(this._username))); context.Graph.Assert(new Triple(manager, pwd, context.Graph.CreateLiteralNode(this._password))); } }
/// <summary> /// Serializes the connection's configuration /// </summary> /// <param name="context">Configuration Serialization Context</param> public override void SerializeConfiguration(ConfigurationSerializationContext context) { //Firstly need to ensure our object factory has been referenced context.EnsureObjectFactory(typeof(AdoObjectFactory)); //Then serialize the actual configuration INode dnrType = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyType); INode rdfType = context.Graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); INode manager = context.NextSubject; INode rdfsLabel = context.Graph.CreateUriNode(new Uri(NamespaceMapper.RDFS + "label")); INode genericManager = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.ClassGenericManager); INode server = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyServer); INode db = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyDatabase); INode encrypt = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyEncryptConnection); context.Graph.Assert(new Triple(manager, rdfType, genericManager)); context.Graph.Assert(new Triple(manager, rdfsLabel, context.Graph.CreateLiteralNode(this.ToString()))); context.Graph.Assert(new Triple(manager, dnrType, context.Graph.CreateLiteralNode(this.GetType().FullName + ", dotNetRDF.Data.Sql"))); context.Graph.Assert(new Triple(manager, server, context.Graph.CreateLiteralNode(this._server))); context.Graph.Assert(new Triple(manager, db, context.Graph.CreateLiteralNode(this._db))); if (this._encrypt) { context.Graph.Assert(new Triple(manager, encrypt, this._encrypt.ToLiteral(context.Graph))); } if (this.AccessMode != AdoAccessMode.Streaming) { INode loadMode = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyLoadMode); context.Graph.Assert(new Triple(manager, loadMode, context.Graph.CreateLiteralNode(this.AccessMode.ToString()))); } if (this._user != null && this._password != null) { INode username = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyUser); INode pwd = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyPassword); context.Graph.Assert(new Triple(manager, username, context.Graph.CreateLiteralNode(this._user))); context.Graph.Assert(new Triple(manager, pwd, context.Graph.CreateLiteralNode(this._password))); } }
/// <summary> /// Serializes the connection's configuration /// </summary> /// <param name="context">Configuration Serialization Context</param> public void SerializeConfiguration(ConfigurationSerializationContext context) { INode manager = context.NextSubject; INode rdfType = context.Graph.CreateUriNode(UriFactory.Create(RdfSpecsHelper.RdfType)); INode rdfsLabel = context.Graph.CreateUriNode(UriFactory.Create(NamespaceMapper.RDFS + "label")); INode dnrType = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyType); INode genericManager = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.ClassGenericManager); INode server = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyServer); INode queryPath = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyQueryPath); INode updatePath = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyUpdatePath); context.Graph.Assert(new Triple(manager, rdfType, genericManager)); context.Graph.Assert(new Triple(manager, rdfsLabel, context.Graph.CreateLiteralNode(this.ToString()))); context.Graph.Assert(new Triple(manager, dnrType, context.Graph.CreateLiteralNode(this.GetType().FullName))); context.Graph.Assert(new Triple(manager, server, context.Graph.CreateLiteralNode(this._baseUri))); context.Graph.Assert(new Triple(manager, queryPath, context.Graph.CreateLiteralNode(this._queryService))); if (this._updateService != null) { context.Graph.Assert(new Triple(manager, updatePath, context.Graph.CreateLiteralNode(this._updateService))); } base.SerializeProxyConfig(manager, context); }
/// <summary> /// Serializes the Configuration of the Manager /// </summary> /// <param name="context">Configuration Serialization Context</param> public virtual void SerializeConfiguration(ConfigurationSerializationContext context) { INode manager = context.NextSubject; INode rdfType = context.Graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); INode rdfsLabel = context.Graph.CreateUriNode(new Uri(NamespaceMapper.RDFS + "label")); INode dnrType = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyType); INode genericManager = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyGenericManager); context.Graph.Assert(manager, rdfType, ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.ClassGenericManager)); context.Graph.Assert(manager, dnrType, context.Graph.CreateLiteralNode(this.GetType().ToString())); context.Graph.Assert(manager, rdfsLabel, context.Graph.CreateLiteralNode(this.ToString())); if (this._manager is IConfigurationSerializable) { INode managerObj = context.Graph.CreateBlankNode(); context.NextSubject = managerObj; ((IConfigurationSerializable)this._manager).SerializeConfiguration(context); context.Graph.Assert(manager, genericManager, managerObj); } else { throw new DotNetRdfConfigurationException("Unable to serialize configuration as the underlying IGenericIOManager is not serializable"); } }
/// <summary> /// Serializes the connection's configuration /// </summary> /// <param name="context">Configuration Serialization Context</param> public virtual void SerializeConfiguration(ConfigurationSerializationContext context) { INode manager = context.NextSubject; INode rdfType = context.Graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); INode rdfsLabel = context.Graph.CreateUriNode(new Uri(NamespaceMapper.RDFS + "label")); INode dnrType = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyType); INode sqlManager = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.ClassSqlManager); INode server = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyServer); INode database = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyDatabase); context.Graph.Assert(new Triple(manager, rdfType, sqlManager)); context.Graph.Assert(new Triple(manager, rdfsLabel, context.Graph.CreateLiteralNode(this.ToString()))); context.Graph.Assert(new Triple(manager, dnrType, context.Graph.CreateLiteralNode(this.GetType().FullName))); context.Graph.Assert(new Triple(manager, server, context.Graph.CreateLiteralNode(this._dbserver))); context.Graph.Assert(new Triple(manager, database, context.Graph.CreateLiteralNode(this._dbname))); if (this._dbuser != null && this._dbpwd != null) { INode username = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyUser); INode pwd = ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyPassword); context.Graph.Assert(new Triple(manager, username, context.Graph.CreateLiteralNode(this._dbuser))); context.Graph.Assert(new Triple(manager, pwd, context.Graph.CreateLiteralNode(this._dbpwd))); } }
/// <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 Endpoint: String endpointUri = ConfigurationLoader.GetConfigurationValue(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpointUri)); if (endpointUri == null) { return(false); } //Get Default/Named Graphs if specified IEnumerable <String> defaultGraphs = from n in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri)) select n.ToString(); IEnumerable <String> namedGraphs = from n in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyNamedGraphUri)) select n.ToString(); endpoint = new SparqlRemoteEndpoint(new Uri(endpointUri), defaultGraphs, namedGraphs); break; #if !SILVERLIGHT case FederatedEndpoint: IEnumerable <INode> endpoints = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, 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:endpoint property points to an Object which cannot be loaded as an object which is a SparqlRemoteEndpoint"); } } break; #endif } 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); } #if !NO_PROXY //Is there a Proxy Server specified INode proxyNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyProxy)); if (proxyNode != null) { Object proxy = ConfigurationLoader.LoadObject(g, proxyNode); if (proxy is WebProxy) { endpoint.Proxy = (WebProxy)proxy; //Are we supposed to use the same credentials for the proxy as for the endpoint? bool useCredentialsForProxy = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, 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"); } } #endif } obj = endpoint; return(endpoint != null); }
/// <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; try { output = (IGraph)Activator.CreateInstance(targetType); } 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, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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; #if !NO_DATA && !NO_STORAGE //Load from Databases IEnumerable <INode> dbs = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromDatabase)); dbs.All(db => !ConfigurationLoader.CheckCircularReference(objNode, db, "dnr:fromDatabase")); connections = dbs.Select(db => ConfigurationLoader.LoadObject(g, db)); sources = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyWithUri)); foreach (Object db in connections) { if (db is ISqlIOManager) { SqlReader reader = new SqlReader((ISqlIOManager)db); foreach (INode source in sources) { if (source.NodeType == NodeType.Uri || source.NodeType == NodeType.Literal) { output.Merge(reader.Load(source.ToString())); } else { throw new DotNetRdfConfigurationException("Unable to load data from a database 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 database for the Graph identified by the Node '" + objNode.ToString() + "' as one of the values of the dnr:fromDatabase property points to an Object which cannot be loaded as an object which implements the ISqlIOManager interface"); } } #endif #if !NO_STORAGE //Load from Stores IEnumerable <INode> stores = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromStore)); stores.All(s => !ConfigurationLoader.CheckCircularReference(objNode, s, "dnr:fromStore")); connections = stores.Select(s => ConfigurationLoader.LoadObject(g, s)); sources = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyWithUri)); foreach (Object store in connections) { if (store is IGenericIOManager) { foreach (INode source in sources) { if (source.NodeType == NodeType.Uri || source.NodeType == NodeType.Literal) { ((IGenericIOManager)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).Graph(((IUriNode)source).Uri)); } else if (source.NodeType == NodeType.Literal) { output.Merge(((ITripleStore)store).Graph(new Uri(((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 IGenericIOManager/ITripleStore interface"); } } #endif //Finally load from Remote URIs sources = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromUri)); foreach (INode source in sources) { if (source.NodeType == NodeType.Uri) { #if !SILVERLIGHT UriLoader.Load(output, ((IUriNode)source).Uri); #else throw new PlatformNotSupportedException("Loading Data into a Graph from a remote URI is not currently supported under Silverlight/Windows Phone 7"); #endif } else if (source.NodeType == NodeType.Literal) { #if !SILVERLIGHT UriLoader.Load(output, new Uri(((ILiteralNode)source).Value)); #else throw new PlatformNotSupportedException("Loading Data into a Graph from a remote URI is not currently supported under Silverlight/Windows Phone 7"); #endif } 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, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAssignUri)); if (baseUri != null) { if (baseUri.NodeType == NodeType.Uri) { output.BaseUri = ((IUriNode)baseUri).Uri; } else if (baseUri.NodeType == NodeType.Literal) { output.BaseUri = new Uri(((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, ConfigurationLoader.CreateConfigurationNode(g, 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> /// 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(HttpContext 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, ConfigurationLoader.CreateConfigurationNode(g, 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, 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(); } } } //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 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; switch (targetType.FullName) { case LeviathanQueryProcessor: INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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; #if !NO_STORAGE case GenericQueryProcessor: INode managerObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); if (managerObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, managerObj); if (temp is IQueryableGenericIOManager) { processor = new GenericQueryProcessor((IQueryableGenericIOManager)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 IQueryableGenericIOManager interface"); } break; #endif #if !SILVERLIGHT case RemoteQueryProcessor: 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) { 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, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer)); if (server == null) { return(false); } String kb = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStore)); if (kb == null) { return(false); } processor = new PelletQueryProcessor(new Uri(server), kb); break; #endif } obj = processor; return(processor != null); }
/// <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; bool isAsync; Object temp; //Get Property Nodes we need INode propSqlManager = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertySqlManager), propGenericManager = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager), propAsync = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAsync); //Instantiate the Store Class switch (targetType.FullName) { case TripleStore: store = new TripleStore(); break; #if !SILVERLIGHT case WebDemandTripleStore: store = new WebDemandTripleStore(); break; #endif #if !NO_DATA && !NO_STORAGE case SqlTripleStore: case ThreadedSqlTripleStore: case OnDemandTripleStore: subObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propSqlManager); if (subObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, subObj); if (temp is ISqlIOManager) { if (targetType.FullName.Equals(SqlTripleStore)) { store = new SqlTripleStore((ISqlIOManager)temp); } else if (targetType.FullName.Equals(OnDemandTripleStore)) { store = new OnDemandTripleStore((ISqlIOManager)temp); } else if (temp is IThreadedSqlIOManager) { isAsync = ConfigurationLoader.GetConfigurationBoolean(g, objNode, propAsync, false); store = new ThreadedSqlTripleStore((IThreadedSqlIOManager)temp, isAsync); } else { throw new DotNetRdfConfigurationException("Unable to load a SQL Triple Store identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:sqlManager property points to an Object which could not be loaded as an object which implements either the ISqlIOManager/IThreadedSqlIOManager interface"); } } else { throw new DotNetRdfConfigurationException("Unable to load a SQL Triple Store identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:sqlManager property points to an Object which could not be loaded as an object which implements either the ISqlIOManager interface"); } break; #endif #if !NO_STORAGE case NativeTripleStore: subObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propGenericManager); if (subObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, subObj); if (temp is IQueryableGenericIOManager) { store = new NativeTripleStore((IQueryableGenericIOManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load a Native Triple Store identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which could not be loaded as an object which implements the IQueryableGenericIOManager interface"); } break; case PersistentTripleStore: subObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propGenericManager); if (subObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, subObj); if (temp is IGenericIOManager) { store = new PersistentTripleStore((IGenericIOManager)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 IGenericIOManager interface"); } break; #endif } //Read in additional data to be added to the Store if (store != null) { IEnumerable <INode> sources = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:usingGraph")); //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, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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> /// 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> /// Attempts to load an Object of the given type identified by the given Node and returned as the Type that this loader generates /// </summary> /// <param name="g">Configuration Graph</param> /// <param name="objNode">Object Node</param> /// <param name="targetType">Target Type</param> /// <param name="obj">Created Object</param> /// <returns>True if the loader succeeded in creating an Object</returns> public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj) { obj = null; INode managerNode; Object temp; //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); switch (targetType.FullName) { case MicrosoftAdoDataset: managerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); if (managerNode != null) { temp = ConfigurationLoader.LoadObject(g, managerNode); if (temp is MicrosoftAdoManager) { obj = new MicrosoftAdoDataset((MicrosoftAdoManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the object identified by the Node '" + objNode.ToString() + "' since the object pointed to by the dnr:genericManager property could not be loaded as an instance of the required MicrosoftAdoManager class"); } } else { throw new DotNetRdfConfigurationException("Unable to load the object identified by the Node '" + objNode.ToString() + "' as it specified a dnr:type of MicrosoftAdoDataset but failed to specify a dnr:genericManager property to point to a MicrosoftAdoManager"); } break; case AzureAdoManager: case MicrosoftAdoManager: //Get Server and Database details String server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer); if (server == null) { server = "localhost"; } String db = ConfigurationLoader.GetConfigurationString(g, objNode, propDb); if (db == null) { return(false); } //Get user credentials String user, pwd; ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd); bool encrypt = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEncryptConnection), false); String mode = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode)); AdoAccessMode accessMode = (mode != null ? (AdoAccessMode)Enum.Parse(typeof(AdoAccessMode), mode) : AdoAccessMode.Streaming); //Create the Manager if (user != null && pwd != null) { if (targetType.FullName.Equals(MicrosoftAdoManager)) { obj = new MicrosoftAdoManager(server, db, user, pwd, encrypt, accessMode); } else { obj = new AzureAdoManager(server, db, user, pwd, accessMode); } } else { if (targetType.FullName.Equals(AzureAdoManager)) { throw new DotNetRdfConfigurationException("Unable to load the object identified by the Node '" + objNode.ToString() + "' as an AzureAdoManager as the required dnr:user and dnr:password properties were missing"); } obj = new MicrosoftAdoManager(server, db, encrypt, accessMode); } break; case MicrosoftAdoOptimiser: managerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); if (managerNode != null) { temp = ConfigurationLoader.LoadObject(g, managerNode); if (temp is MicrosoftAdoManager) { obj = new MicrosoftAdoOptimiser((MicrosoftAdoManager)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the object identified by the Node '" + objNode.ToString() + "' since the object pointed to by the dnr:genericManager property could not be loaded as a MicrosoftAdoManager instance"); } } else { throw new DotNetRdfConfigurationException("Unable to load the object identified by the Node '" + objNode.ToString() + "' as it specified a dnr:type of AdoOptimiser but failed to specify a dnr:genericManager property to point to a MicrosoftAdoManager instance"); } 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) { #if !SILVERLIGHT case PelletReasonerType: String server = ConfigurationLoader.GetConfigurationValue(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer)); if (server == null) { return(false); } String kb = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStore)); if (kb == null) { return(false); } output = new PelletReasoner(UriFactory.Create(server), kb); break; #endif case OwlReasonerWrapperType: INode reasonerNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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); }
/// <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(HttpContext context, IGraph config, INode objNode) : base(context, config, objNode) { INode datasetNode = ConfigurationLoader.GetConfigurationNode(config, objNode, ConfigurationLoader.CreateConfigurationNode(config, 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> /// Tries to load a Permission 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; IPermission result = null; switch (targetType.FullName) { case Permission: String action = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAction)); result = new Permission(action); break; case PermissionSet: IEnumerable <String> actions = from n in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAction)) where n.NodeType == NodeType.Literal select((ILiteralNode)n).Value; result = new PermissionSet(actions); break; } obj = result; return(result != null); }
/// <summary> /// Tries to load a User Group 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; UserGroup result = null; switch (targetType.FullName) { case UserGroup: result = new UserGroup(); //Get the members of the Group IEnumerable <INode> members = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyMember)); foreach (INode member in members) { String username, password; ConfigurationLoader.GetUsernameAndPassword(g, member, true, out username, out password); if (username != null && password != null) { result.AddUser(new NetworkCredential(username, password)); } else { throw new DotNetRdfConfigurationException("Unable to load the User identified by the Node '" + member.ToString() + "' as there does not appear to be a valid username and password specified for this User either via the dnr:user and dnr:password properties or via a dnr:credentials property"); } } //Get the allow list for the Group IEnumerable <INode> allowed = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAllow)); foreach (INode allow in allowed) { Object temp = ConfigurationLoader.LoadObject(g, allow); if (temp is IPermission) { result.AddAllowedAction((IPermission)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Permission identified by the Node '" + allow.ToString() + "' as the Object specified could not be loaded as an object which implements the IPermission interface"); } } //Get the deny list for the Group IEnumerable <INode> denied = ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDeny)); foreach (INode deny in denied) { Object temp = ConfigurationLoader.LoadObject(g, deny); if (temp is IPermission) { result.AddDeniedAction((IPermission)temp); } else { throw new DotNetRdfConfigurationException("Unable to load the Permission identified by the Node '" + deny.ToString() + "' as the Object specified could not be loaded as an object which implements the IPermission interface"); } } //Does the User Group require authentication? result.AllowGuests = !ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyRequiresAuthentication), true); //Is there a permission model specified? String mode = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPermissionModel)); if (mode != null) { #if SILVERLIGHT result.PermissionModel = (PermissionModel)Enum.Parse(typeof(PermissionModel), mode, false); #else result.PermissionModel = (PermissionModel)Enum.Parse(typeof(PermissionModel), mode); #endif } break; } obj = result; return(result != 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; 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 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); }
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; }
/// <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); } } }
public void SerializeConfiguration(ConfigurationSerializationContext context) { INode subj = context.NextSubject; context.Graph.Assert(subj, context.Graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)), ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.ClassTripleStore)); context.Graph.Assert(subj, ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyType), context.Graph.CreateLiteralNode(this._store.GetType().FullName)); }
/// <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 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, ConfigurationLoader.CreateConfigurationNode(g, 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); } }
/// <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; switch (targetType.FullName) { case LeviathanUpdateProcessor: INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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; #if !NO_STORAGE case GenericUpdateProcessor: INode managerObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); if (managerObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, managerObj); if (temp is IGenericIOManager) { processor = new GenericUpdateProcessor((IGenericIOManager)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 IGenericIOManager interface"); } break; #endif } obj = processor; return(processor != 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; switch (targetType.FullName) { case ProtocolToUpdateProcessor: INode qNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryProcessor)); INode uNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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, ConfigurationLoader.CreateConfigurationNode(g, 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; #if !NO_STORAGE case GenericProtocolProcessor: INode managerObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager)); if (managerObj == null) { return(false); } temp = ConfigurationLoader.LoadObject(g, managerObj); if (temp is IGenericIOManager) { processor = new GenericProtocolProcessor((IGenericIOManager)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 IGenericIOManager interface"); } break; #endif } obj = processor; return(processor != 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> /// Serializes the Optimisers Configuration /// </summary> /// <param name="context">Serialization Context</param> public void SerializeConfiguration(ConfigurationSerializationContext context) { context.EnsureObjectFactory(typeof(FullTextObjectFactory)); INode optObj = context.NextSubject; context.Graph.Assert(optObj, context.Graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)), ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.ClassAlgebraOptimiser)); context.Graph.Assert(optObj, ConfigurationLoader.CreateConfigurationNode(context.Graph, ConfigurationLoader.PropertyType), context.Graph.CreateLiteralNode(this.GetType().FullName + ", dotNetRDF.Query.FullText")); if (this._provider is IConfigurationSerializable) { INode searcherObj = context.Graph.CreateBlankNode(); context.NextSubject = searcherObj; ((IConfigurationSerializable)this._provider).SerializeConfiguration(context); context.Graph.Assert(optObj, context.Graph.CreateUriNode(new Uri(FullTextHelper.PropertySearcher)), searcherObj); } else { throw new DotNetRdfConfigurationException("Unable to serialize configuration for this Full Text Optimiser as the Search Provider used does not implement the required IConfigurationSerializable interface"); } }