public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
            {
                IResourceLoader resourceLoader = new ConfigurableResourceLoader();
                IResource       resource       = resourceLoader.GetResource(absoluteUri.AbsoluteUri);

                return(resource.InputStream);
                //return base.GetEntity( absoluteUri, role, ofObjectToReturn );
            }
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="ReadOnlyXmlTestResource"/> class.
 /// </summary>
 /// <param name="fileName">
 /// The filename/resourcename (e.g. foo.txt) of the XML file containing the object
 /// definitions.
 /// </param>
 public ReadOnlyXmlTestResource(string fileName)
 {
     if (ConfigurableResourceLoader.HasProtocol(fileName))
     {
         ConfigurableResourceLoader loader = new ConfigurableResourceLoader();
         _underlyingResource = loader.GetResource(fileName);
     }
     _underlyingResource = new FileSystemResource(fileName);
 }
Ejemplo n.º 3
0
        public void DoNothing()
        {
            ConfigurableResourceLoader loader = new ConfigurableResourceLoader();
            Configuration c            = new Configuration();
            String        resourceName =
                "assembly://Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate/TestObject.hbm.xml";

            c.AddInputStream(loader.GetResource(resourceName).InputStream);
            ISessionFactory sf = c.BuildSessionFactory();
        }
        /// <summary>
        /// Register a schema as well-known
        /// </summary>
        /// <param name="namespaceUri"></param>
        /// <param name="schemaLocation"></param>
        private static void RegisterSchema(string namespaceUri, string schemaLocation)
        {
            IResourceLoader resourceLoader = new ConfigurableResourceLoader();
            IResource       schema         = resourceLoader.GetResource(schemaLocation);

            try
            {
                XmlTextReader schemaDocument = new XmlTextReader(schema.Uri.AbsoluteUri, schema.InputStream);
                schemas.Add(namespaceUri, schemaDocument);
            }
            catch (Exception e)
            {
                throw new ArgumentException("Could not load schema from resource = " + schema, e);
            }
        }
Ejemplo n.º 5
0
        //TODO GetDbProviderClasses
        private static void InitializeDbProviderFactoryIfNeeded()
        {
            if (ctx == null)
            {
                lock (typeof(DbProviderFactory))
                {
                    if (ctx == null)
                    {
                        try
                        {
                            //TODO get from well know location in app.config....
                            ConfigurableResourceLoader loader = new ConfigurableResourceLoader(DBPROVIDER_ADDITIONAL_RESOURCE_NAME);


                            if (loader.GetResource(DBPROVIDER_ADDITIONAL_RESOURCE_NAME).Exists)
                            {
                                #region Instrumentation
                                if (log.IsDebugEnabled)
                                {
                                    log.Debug("Loading additional DbProviders from " + DBPROVIDER_ADDITIONAL_RESOURCE_NAME);
                                }
                                #endregion
                                ctx = new XmlApplicationContext(DBPROVIDER_CONTEXTNAME, true, new string[] { DBPROVIDER_DEFAULT_RESOURCE_NAME,
                                                                                                             DBPROVIDER_ADDITIONAL_RESOURCE_NAME });
                            }
                            else
                            {
                                ctx = new XmlApplicationContext(DBPROVIDER_CONTEXTNAME, true, new string[] { DBPROVIDER_DEFAULT_RESOURCE_NAME });
                            }

                            string[] dbProviderNames = ctx.GetObjectNamesForType(typeof(IDbProvider));
                            if (log.IsInfoEnabled)
                            {
                                log.Info(String.Format("{0} DbProviders Available. [{1}]", dbProviderNames.Length, StringUtils.ArrayToCommaDelimitedString(dbProviderNames)));
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Error processing " + DBPROVIDER_DEFAULT_RESOURCE_NAME, e);
                            throw;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new instance of the
        /// <see cref="Spring.Objects.Factory.Support.AbstractObjectDefinitionReader"/>
        /// class.
        /// </summary>
        /// <param name="registry">
        /// The <see cref="Spring.Objects.Factory.Support.IObjectDefinitionRegistry"/>
        /// instance that this reader works on.
        /// </param>
        /// <param name="domain">
        /// The <see cref="System.AppDomain"/> against which any class names
        /// will be resolved into <see cref="System.Type"/> instances.
        /// </param>
        /// <remarks>
        /// <p>
        /// This is an <see langword="abstract"/> class, and as such exposes no public constructors.
        /// </p>
        /// </remarks>
        protected AbstractObjectDefinitionReader(
            IObjectDefinitionRegistry registry,
            AppDomain domain)
        {
            log = LogManager.GetLogger(this.GetType());

            AssertUtils.ArgumentNotNull(registry, "registry", "IObjectDefinitionRegistry must not be null");
            _registry = registry;
            _domain   = domain;
            if (registry is IResourceLoader)
            {
                _resourceLoader = registry as IResourceLoader;
            }
            else
            {
                _resourceLoader = new ConfigurableResourceLoader();
            }
        }
Ejemplo n.º 7
0
        //TODO GetDbProviderClasses
        private static void InitializeDbProviderFactoryIfNeeded()
        {
            if (ctx == null)
            {
                lock (typeof(DbProviderFactory))
                {
                    if (ctx == null)
                    {
                        try
                        {
                            ConfigurableResourceLoader loader = new ConfigurableResourceLoader(DBPROVIDER_ADDITIONAL_RESOURCE_NAME);


                            if (loader.GetResource(DBPROVIDER_ADDITIONAL_RESOURCE_NAME).Exists)
                            {
                                if (log.IsDebugEnabled)
                                {
                                    log.Debug("Loading additional DbProviders from " + DBPROVIDER_ADDITIONAL_RESOURCE_NAME);
                                }

                                ctx = new XmlApplicationContext(DBPROVIDER_CONTEXTNAME, true, new string[] { DBPROVIDER_DEFAULT_RESOURCE_NAME,
                                                                                                             DBPROVIDER_ADDITIONAL_RESOURCE_NAME });
                            }
                            else
                            {
                                ctx = new XmlApplicationContext(DBPROVIDER_CONTEXTNAME, true, new string[] { DBPROVIDER_DEFAULT_RESOURCE_NAME });
                            }

                            if (log.IsInfoEnabled)
                            {
                                var dbProviderNames = ctx.GetObjectNames <IDbProvider>();
                                log.Info(
                                    $"{dbProviderNames.Count} DbProviders Available. [{StringUtils.CollectionToCommaDelimitedString(dbProviderNames)}]");
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Error processing " + DBPROVIDER_DEFAULT_RESOURCE_NAME, e);
                            throw;
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initialize the SessionFactory for the given or the
        /// default location.
        /// </summary>
        public virtual void AfterPropertiesSet()
        {
            // Create Configuration instance.
            Configuration config = NewConfiguration();


            if (this.dbProvider != null)
            {
                config.SetProperty(Environment.ConnectionString,
                                   dbProvider.ConnectionString);
                config.SetProperty(Environment.ConnectionProvider, typeof(DbProviderWrapper).AssemblyQualifiedName);
            }

            if (ExposeTransactionAwareSessionFactory)
            {
                // Set ICurrentSessionContext implementation,
                // providng the Spring-managed ISession s current Session.
                // Can be overridden by a custom value for the corresponding Hibernate property
                config.SetProperty(Environment.CurrentSessionContextClass,
                                   "Spring.Data.NHibernate.SpringSessionContext, Spring.Data.NHibernate12");
            }

            if (this.hibernateProperties != null)
            {
                if (config.GetProperty(Environment.ConnectionProvider) != null &&
                    hibernateProperties.Contains(Environment.ConnectionProvider))
                {
                    #region Logging
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Overriding use of Spring's Hibernate Connection Provider with [" +
                                 hibernateProperties[Environment.ConnectionProvider] + "]");
                    }
                    #endregion
                    config.Properties.Remove(Environment.ConnectionProvider);
                }
                config.AddProperties(hibernateProperties);
            }
            if (this.mappingAssemblies != null)
            {
                foreach (string assemblyName in mappingAssemblies)
                {
                    config.AddAssembly(assemblyName);
                }
            }


            IResourceLoader resourceLoader = new ConfigurableResourceLoader();

            if (this.mappingResources != null)
            {
                IResourceLoader loader = this.ResourceLoader;
                if (loader == null)
                {
                    loader = this.applicationContext;
                }

                foreach (string resourceName in mappingResources)
                {
                    config.AddInputStream(loader.GetResource(resourceName).InputStream);
                }
            }

            if (configFilenames != null)
            {
                foreach (string configFilename in configFilenames)
                {
                    config.Configure(configFilename);
                }
            }

            // Perform custom post-processing in subclasses.
            PostProcessConfiguration(config);

            // Build SessionFactory instance.
            log.Info("Building new Hibernate SessionFactory");
            this.configuration  = config;
            this.sessionFactory = NewSessionFactory(config);
        }
        /// <summary>
        /// Initialize the SessionFactory for the given or the
        /// default location.
        /// </summary>
        public void AfterPropertiesSet()
        {
            // Create Configuration instance.
            Configuration config = NewConfiguration();


            if (this.dbProvider != null)
            {
                config.SetProperty(Environment.ConnectionString, dbProvider.ConnectionString);
                config.SetProperty(Environment.ConnectionProvider, typeof(DbProviderWrapper).AssemblyQualifiedName);
            }

            if (this.hibernateProperties != null)
            {
                if (config.GetProperty(Environment.ConnectionProvider) != null &&
                    hibernateProperties.Contains(Environment.ConnectionProvider))
                {
                    #region Logging
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Overriding use of Spring's Hibernate Connection Provider with [" +
                                 hibernateProperties[Environment.ConnectionProvider] + "]");
                    }
                    #endregion
                    config.Properties.Remove(Environment.ConnectionProvider);
                }
                config.AddProperties(hibernateProperties);
            }
            if (this.mappingAssemblies != null)
            {
                foreach (string assemblyName in mappingAssemblies)
                {
                    config.AddAssembly(assemblyName);
                }
            }

            IResourceLoader resourceLoader = new ConfigurableResourceLoader();

            if (this.mappingResources != null)
            {
                foreach (string resourceName in mappingResources)
                {
                    config.AddInputStream(resourceLoader.GetResource(resourceName).InputStream);
                }
            }

            if (configFilenames != null)
            {
                foreach (string configFilename in configFilenames)
                {
                    config.Configure(configFilename);
                }
            }

            // Perform custom post-processing in subclasses.
            PostProcessConfiguration(config);

            // Build SessionFactory instance.
            log.Info("Building new Hibernate SessionFactory");
            this.configuration  = config;
            this.sessionFactory = NewSessionFactory(config);
        }