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 );
			}
		}
		private static void BindNamedQuery(XmlNode queryElem, string path, Mappings mappings)
		{
			string queryName = queryElem.Attributes["name"].Value;
			if (path != null)
			{
				queryName = path + '.' + queryName;
			}
			string query = queryElem.InnerText;
			log.Debug("Named query: " + queryName + " -> " + query);

			bool cacheable = "true".Equals(XmlHelper.GetAttributeValue(queryElem, "cacheable"));
			string region = XmlHelper.GetAttributeValue(queryElem, "cache-region");
			XmlAttribute tAtt = queryElem.Attributes["timeout"];
			int timeout = tAtt == null ? -1 : int.Parse(tAtt.Value);
			XmlAttribute fsAtt = queryElem.Attributes["fetch-size"];
			int fetchSize = fsAtt == null ? -1 : int.Parse(fsAtt.Value);
			XmlAttribute roAttr = queryElem.Attributes["read-only"];
			bool readOnly = roAttr != null && "true".Equals(roAttr.Value);
			XmlAttribute cacheModeAtt = queryElem.Attributes["cache-mode"];
			string cacheMode = cacheModeAtt == null ? null : cacheModeAtt.Value;
			XmlAttribute cmAtt = queryElem.Attributes["comment"];
			string comment = cmAtt == null ? null : cmAtt.Value;

			NamedQueryDefinition namedQuery = new NamedQueryDefinition(
				query,
				cacheable,
				region,
				timeout,
				fetchSize,
				GetFlushMode(XmlHelper.GetAttributeValue(queryElem, "flush-mode")),
				//GetCacheMode(cacheMode),
				readOnly,
				comment,
				GetParameterTypes(queryElem)
				);

			mappings.AddQuery(queryName, namedQuery);
		}