Пример #1
0
		private static void HandleSubclass( PersistentClass model, Mappings mappings, XmlNode subnode )
		{
			Subclass subclass = new Subclass( model );
			BindSubclass( subnode, subclass, mappings );
			model.AddSubclass( subclass );
			mappings.AddClass( subclass );
		}
Пример #2
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 );
			}
		}
Пример #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);
			}
		}