Esempio n. 1
0
        /// <summary>
        /// Tries to load a SPARQL Query/Algebra Optimiser based on information from the Configuration Graph.
        /// </summary>
        /// <param name="g">Configuration Graph.</param>
        /// <param name="objNode">Object Node.</param>
        /// <param name="targetType">Target Type.</param>
        /// <param name="obj">Output Object.</param>
        /// <returns></returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            obj = null;
            Object temp;

            switch (targetType.FullName)
            {
            case QueryOptimiserDefault:
                obj = new DefaultOptimiser();
                break;

            case QueryOptimiserNoReorder:
                obj = new NoReorderOptimiser();
                break;

            case QueryOptimiserWeighted:
                INode statsObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingGraph)));
                if (statsObj != null)
                {
                    temp = ConfigurationLoader.LoadObject(g, statsObj);
                    if (temp is IGraph)
                    {
                        obj = new WeightedOptimiser((IGraph)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to create the Weighted Query Optimiser identified by the Node '" + objNode.ToString() + "' since the dnr:usingGraph property points to an object that cannot be loaded as an Object that imlements the required IGraph interface");
                    }
                }
                else
                {
                    obj = new WeightedOptimiser();
                }
                break;

            default:
                // Try and create an Algebra Optimiser
                try
                {
                    obj = (IAlgebraOptimiser)Activator.CreateInstance(targetType);
                }
                catch
                {
                    // Any error means this loader can't load this type
                    return(false);
                }
                break;
            }

            // Return true only if we've loaded something into the output object
            if (obj != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <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;
            }
        }