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);
 }
 public void AddProtocolMappingSilentlyOverwritesExistingProtocol()
 {
     ResourceHandlerRegistry.RegisterResourceHandler("beep", typeof(FileSystemResource));
     // overwrite, must not complain...
     ResourceHandlerRegistry.RegisterResourceHandler("beep", typeof(AssemblyResource));
     IResource res = new ConfigurableResourceLoader().GetResource("beep://Spring.Core.Tests/Spring/TestResource.txt");
     Assert.IsNotNull(res, "Resource must not be null");
     Assert.AreEqual(typeof(AssemblyResource), res.GetType(),
         "The original IResource Type associated with the 'beep' protocol " +
         "must have been overwritten; expecting an AssemblyResource 'cos " +
         "we registered it last under the 'beep' protocol.");
 }
示例#4
0
        public void AddProtocolMappingSilentlyOverwritesExistingProtocol()
        {
            ResourceHandlerRegistry.RegisterResourceHandler("beep", typeof(FileSystemResource));
            // overwrite, must not complain...
            ResourceHandlerRegistry.RegisterResourceHandler("beep", typeof(AssemblyResource));
            IResource res = new ConfigurableResourceLoader().GetResource("beep://Spring.Core.Tests/Spring/TestResource.txt");

            Assert.IsNotNull(res, "Resource must not be null");
            Assert.AreEqual(typeof(AssemblyResource), res.GetType(),
                            "The original IResource Type associated with the 'beep' protocol " +
                            "must have been overwritten; expecting an AssemblyResource 'cos " +
                            "we registered it last under the 'beep' protocol.");
        }
		/// <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();
            }
		}
 /// <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);
     }
 }
 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>
        /// 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>
        /// Creates a new resource that is relative to this resource based on the
        /// supplied <paramref name="resourceName"/>.
        /// </summary>
        /// <remarks>
        /// <p>
        /// This method can accept either a fully qualified resource name or a
        /// relative resource name as it's parameter.
        /// </p>
        /// <p>
        /// A fully qualified resource is one that has a protocol prefix and
        /// all elements of the resource name. All other resources are treated
        /// as relative to this resource, and the following rules are used to
        /// locate a relative resource:
        /// </p>
        /// <list type="bullet">
        ///     <item>
        ///     If the <paramref name="resourceName"/> starts with <c>'..'</c>,
        ///     the current resource path is navigated backwards before the
        ///     <paramref name="resourceName"/> is concatenated to the current
        ///     <see cref="Spring.Core.IO.AbstractResource.ResourcePath"/> of
        ///     this resource.
        ///     </item>
        ///     <item>
        ///     If the <paramref name="resourceName"/> starts with '/', the
        ///     current resource path is ignored and a new resource name is
        ///     appended to the
        ///     <see cref="Spring.Core.IO.AbstractResource.RootLocation"/> of
        ///     this resource.
        ///     </item>
        ///     <item>
        ///     If the <paramref name="resourceName"/> starts with '.' or a
        ///     letter, a new path is appended to the current
        ///     <see cref="Spring.Core.IO.AbstractResource.ResourcePath"/> of
        ///     this resource.
        ///     </item>
        /// </list>
        /// </remarks>
        /// <param name="resourceName">
        /// The name of the resource to create.
        /// </param>
        /// <returns>The relative resource.</returns>
        /// <exception cref="System.UriFormatException">
        /// If the process of resolving the relative resource yielded an
        /// invalid URI.
        /// </exception>
        /// <exception cref="System.NotSupportedException">
        /// If this resource does not support the resolution of relative
        /// resources (as determined by the value of the
        /// <see cref="Spring.Core.IO.AbstractResource.SupportsRelativeResources"/>
        /// property).
        /// </exception>
        /// <seealso cref="Spring.Core.IO.AbstractResource.ResourcePath"/>
        public virtual IResource CreateRelative(string resourceName)
        {
            AssertUtils.ArgumentNotNull(resourceName, "relativePath");

            // try to create fully qualified resource...
            IResourceLoader loader = GetResourceLoader();

            if (ConfigurableResourceLoader.HasProtocol(resourceName))
            {
                IResource resource = loader.GetResource(resourceName);
                if (resource != null)
                {
                    return(resource);
                }
            }
            if (!SupportsRelativeResources)
            {
                throw new NotSupportedException(GetType().Name +
                                                " does not support relative resources. Please use fully qualified resource name.");
            }

            StringBuilder fullResourceName = new StringBuilder(256);

            if (Protocol != null && Protocol != String.Empty)
            {
                fullResourceName.Append(Protocol).Append(ConfigurableResourceLoader.ProtocolSeparator);
            }

            if (!IsRelativeResource(resourceName))
            {
                fullResourceName.Append(resourceName);
            }
            else
            {
                string targetResource;
                string resourcePath;
                int    n = resourceName.LastIndexOfAny(new char[] { '/', '\\' });
                if (n >= 0)
                {
                    targetResource = resourceName.Substring(n + 1);
                    resourcePath   = CalculateResourcePath(resourceName.Substring(0, n + 1));
                }
                else // only resource name is specified, so current path should be used
                {
                    targetResource = resourceName;
                    resourcePath   = ResourcePath;
                }

                fullResourceName.Append(RootLocation.TrimEnd('\\', '/'));
                if (resourcePath != null && resourcePath != String.Empty)
                {
                    fullResourceName.Append('/').Append(resourcePath);
                }
                fullResourceName.Append('/').Append(targetResource);
            }

            string resultResourceName = fullResourceName.ToString();

            if (!ConfigurableResourceLoader.HasProtocol(resultResourceName))
            {
                // give derived resource classes a chance to create an instance on their own
                IResource resultResource = CreateResourceInstance(resultResourceName);
                if (resultResource != null)
                {
                    return(resultResource);
                }
            }

            // create resource instance using default loader
            return(loader.GetResource(resultResourceName));
        }
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Core.IO.AbstractResource"/> class.
 /// </summary>
 /// <remarks>
 /// <p>
 /// This is an <see langword="abstract"/> class, and as such exposes no
 /// public constructors.
 /// </p>
 /// </remarks>
 /// <param name="resourceName">
 /// A string representation of the resource.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// If the supplied <paramref name="resourceName"/> is
 /// <see langword="null"/> or contains only whitespace character(s).
 /// </exception>
 protected AbstractResource(string resourceName)
 {
     AssertUtils.ArgumentHasText(resourceName, "resourceName");
     this.protocol     = ConfigurableResourceLoader.GetProtocol(resourceName);
     this.resourceName = resourceName;
 }
        /// <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);
        }
 public void SetUp()
 {
     loader = new ConfigurableResourceLoader();
 }
示例#13
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)
							{
								#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 });
							}

							IList<string> dbProviderNames = ctx.GetObjectNames<IDbProvider>();
							if (log.IsInfoEnabled)
							{
								log.Info(String.Format("{0} DbProviders Available. [{1}]", dbProviderNames.Count, StringUtils.CollectionToCommaDelimitedString(dbProviderNames)));
							}
						}
						catch (Exception e)
						{
							log.Error("Error processing " + DBPROVIDER_DEFAULT_RESOURCE_NAME, e);
							throw;
						}
					}					
				}
            }
        }
 public void SetUp()
 {
     loader = new ConfigurableResourceLoader();
 }