public static void BindClass( XmlNode node, PersistentClass model, Mappings mapping )
		{
			string className = node.Attributes[ "name" ] == null ? null : FullClassName( node.Attributes[ "name" ].Value, mapping );

			//CLASS
			model.MappedClass = ClassForFullNameChecked( className, "persistent class {0} not found" );

			//PROXY INTERFACE
			XmlAttribute proxyNode = node.Attributes[ "proxy" ];
			XmlAttribute lazyNode = node.Attributes[ "lazy" ];
			bool lazyTrue = lazyNode != null && "true".Equals( lazyNode.Value );
			if( proxyNode != null && ( lazyNode == null || lazyTrue ) )
			{
				model.ProxyInterface = ClassForNameChecked( proxyNode.Value, mapping,
				                                            "proxy class not found: {0}" );
			}
			if( proxyNode == null && lazyTrue )
			{
				model.ProxyInterface = model.MappedClass;
			}

			//DISCRIMINATOR
			XmlAttribute discriminatorNode = node.Attributes[ "discriminator-value" ];
			model.DiscriminatorValue = ( discriminatorNode == null )
				? model.Name
				: discriminatorNode.Value;

			//DYNAMIC UPDATE
			XmlAttribute dynamicNode = node.Attributes[ "dynamic-update" ];
			model.DynamicUpdate = ( dynamicNode == null )
				? false :
				"true".Equals( dynamicNode.Value );

			//DYNAMIC INSERT
			XmlAttribute insertNode = node.Attributes[ "dynamic-insert" ];
			model.DynamicInsert = ( insertNode == null ) ?
				false :
				"true".Equals( insertNode.Value );

			//IMPORT

			// we automatically want to add an import of the Assembly Qualified Name (includes version, 
			// culture, public-key) to the className supplied in the hbm.xml file.  The most common use-case
			// will have it contain the "FullClassname, AssemblyName", it might contain version, culture, 
			// public key, etc...) but should not assume it does.
			mapping.AddImport( model.MappedClass.AssemblyQualifiedName, StringHelper.GetFullClassname( className ) );

			// if we are supposed to auto-import the Class then add an import to get from the Classname
			// to the Assembly Qualified Class Name
			if( mapping.IsAutoImport )
			{
				mapping.AddImport( model.MappedClass.AssemblyQualifiedName, StringHelper.GetClassname( className ) );
			}

			//BATCH SIZE
			XmlAttribute batchNode = node.Attributes[ "batch-size" ];
			if( batchNode != null )
			{
				model.BatchSize = int.Parse( batchNode.Value );
			}

			//SELECT BEFORE UPDATE
			XmlAttribute sbuNode = node.Attributes[ "select-before-update" ];
			if( sbuNode != null )
			{
				model.SelectBeforeUpdate = "true".Equals( sbuNode.Value );
			}

			//OPTIMISTIC LOCK MODE
			XmlAttribute olNode = node.Attributes[ "optimistic-lock" ];
			model.OptimisticLockMode = GetOptimisticLockMode( olNode );

			//META ATTRIBUTES
			model.MetaAttributes = GetMetas( node );

			//PERSISTER
			XmlAttribute persisterNode = node.Attributes[ "persister" ];
			if( persisterNode == null )
			{
				//persister = typeof( EntityPersister );
			}
			else
			{
				model.ClassPersisterClass = ClassForNameChecked(
					persisterNode.Value, mapping,
					"could not instantiate persister class: {0}" );
			}
		}
		public static void BindRoot( XmlDocument doc, Mappings model )
		{
			XmlNode hmNode = doc.DocumentElement;
			XmlAttribute schemaNode = hmNode.Attributes[ "schema" ];
			model.SchemaName = ( schemaNode == null ) ? null : schemaNode.Value;
			XmlAttribute dcNode = hmNode.Attributes[ "default-cascade" ];
			model.DefaultCascade = ( dcNode == null ) ? "none" : dcNode.Value;
			XmlAttribute daNode = hmNode.Attributes[ "default-access" ];
			model.DefaultAccess = ( daNode == null ) ? "property" : daNode.Value;
			XmlAttribute aiNode = hmNode.Attributes[ "auto-import" ];
			model.IsAutoImport = ( aiNode == null ) ? true : "true".Equals( aiNode.Value );
			XmlAttribute nsNode = hmNode.Attributes[ "namespace" ];
			model.DefaultNamespace = ( nsNode == null ) ? null : nsNode.Value;
			XmlAttribute assemblyNode = hmNode.Attributes[ "assembly" ];
			model.DefaultAssembly = ( assemblyNode == null ) ? null : assemblyNode.Value;

			nsmgr = new XmlNamespaceManager( doc.NameTable );
			// note that the prefix has absolutely nothing to do with what the user
			// selects as their prefix in the document.  It is the prefix we use to 
			// build the XPath and the nsmgr takes care of translating our prefix into
			// the user defined prefix...
			nsmgr.AddNamespace( nsPrefix, Configuration.MappingSchemaXMLNS );

			foreach( XmlNode n in hmNode.SelectNodes( nsClass, nsmgr ) )
			{
				RootClass rootclass = new RootClass();
				Binder.BindRootClass( n, rootclass, model );
				model.AddClass( rootclass );
			}

			foreach( XmlNode n in hmNode.SelectNodes( nsSubclass, nsmgr ) )
			{
				PersistentClass superModel = GetSuperclass( model, n );
				HandleSubclass( superModel, model, n );
			}

			foreach( XmlNode n in hmNode.SelectNodes( nsJoinedSubclass, nsmgr ) )
			{
				PersistentClass superModel = GetSuperclass( model, n );
				HandleJoinedSubclass( superModel, model, n );
			}

			foreach( XmlNode n in hmNode.SelectNodes( nsQuery, nsmgr ) )
			{
				string qname = n.Attributes[ "name" ].Value;
				string query = n.InnerText;
				log.Debug( "Named query: " + qname + " -> " + query );
				model.AddQuery( qname, query );
			}

			foreach( XmlNode n in hmNode.SelectNodes( nsSqlQuery, nsmgr ) )
			{
				string qname = n.Attributes[ "name" ].Value;
				NamedSQLQuery namedQuery = new NamedSQLQuery( n.InnerText );

				foreach( XmlNode returns in n.SelectNodes( nsReturn, nsmgr ) )
				{
					string alias = returns.Attributes[ "alias" ].Value;
					System.Type clazz = ClassForNameChecked(
						returns.Attributes[ "class" ].Value, model,
						"class not found: {0} for alias " + alias );
					namedQuery.AddAliasedClass( alias, clazz );
				}

				foreach( XmlNode table in n.SelectNodes( nsSynchronize, nsmgr ) )
				{
					namedQuery.AddSynchronizedTable( table.Attributes[ "table" ].Value );
				}

				log.Debug( "Named sql query: " + qname + " -> " + namedQuery.QueryString );
				model.AddSQLQuery( qname, namedQuery );
			}

			foreach( XmlNode n in hmNode.SelectNodes( nsImport, nsmgr ) )
			{
				string className = FullClassName( n.Attributes[ "class" ].Value, model );
				XmlAttribute renameNode = n.Attributes[ "rename" ];
				string rename = ( renameNode == null ) ? StringHelper.GetClassname( className ) : renameNode.Value;
				log.Debug( "Import: " + rename + " -> " + className );
				model.AddImport( className, rename );
			}
		}
Esempio n. 3
0
		public static void BindRoot(XmlDocument doc, Mappings mappings)
		{
			nsmgr = BuildNamespaceManager(doc.NameTable);
			XmlNode hmNode = doc.DocumentElement;
			ExtractRootAttributes(hmNode, mappings);

			foreach (XmlNode n in hmNode.SelectNodes(HbmConstants.nsFilterDef, nsmgr))
			{
				ParseFilterDef(n, mappings);
			}

			foreach (XmlNode n in hmNode.SelectNodes(HbmConstants.nsClass, nsmgr))
			{
				RootClass rootclass = new RootClass();
				BindRootClass(n, rootclass, mappings);
				mappings.AddClass(rootclass);
			}

			foreach (XmlNode n in hmNode.SelectNodes(HbmConstants.nsSubclass, nsmgr))
			{
				PersistentClass superModel = GetSuperclass(mappings, n);
				HandleSubclass(superModel, mappings, n);
			}

			foreach (XmlNode n in hmNode.SelectNodes(HbmConstants.nsJoinedSubclass, nsmgr))
			{
				PersistentClass superModel = GetSuperclass(mappings, n);
				HandleJoinedSubclass(superModel, mappings, n);
			}

			foreach (XmlNode n in hmNode.SelectNodes(HbmConstants.nsQuery, nsmgr))
			{
				BindNamedQuery(n, null, mappings);
			}

			foreach (XmlNode n in hmNode.SelectNodes(HbmConstants.nsSqlQuery, nsmgr))
			{
				BindNamedSQLQuery(n, null, mappings);
			}

			foreach (XmlNode n in hmNode.SelectNodes(HbmConstants.nsImport, nsmgr))
			{
				string className = FullClassName(n.Attributes["class"].Value, mappings);
				XmlAttribute renameNode = n.Attributes["rename"];
				string rename = (renameNode == null) ? StringHelper.GetClassname(className) : renameNode.Value;
				log.Debug("Import: " + rename + " -> " + className);
				mappings.AddImport(className, rename);
			}

			foreach (XmlNode n in hmNode.SelectNodes(HbmConstants.nsDatabaseObject, nsmgr))
			{
				BindAuxiliaryDatabaseObject(n, mappings);
			}

			foreach (XmlNode n in hmNode.SelectNodes(HbmConstants.nsResultset, nsmgr))
			{
				BindResultSetMappingDefinition(n, null, mappings);
			}
		}