From: <hib...@li...> - 2006-03-28 18:59:47
|
Author: ste...@jb... Date: 2006-03-28 13:59:42 -0500 (Tue, 28 Mar 2006) New Revision: 9703 Modified: branches/Branch_3_1/Hibernate3/src/org/hibernate/cfg/HbmBinder.java Log: HHH-1175 : hibernate-mapping sub-element ordering insensitivity Modified: branches/Branch_3_1/Hibernate3/src/org/hibernate/cfg/HbmBinder.java =================================================================== --- branches/Branch_3_1/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-03-27 23:13:39 UTC (rev 9702) +++ branches/Branch_3_1/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-03-28 18:59:42 UTC (rev 9703) @@ -122,125 +122,117 @@ } Element hmNode = doc.getRootElement(); - inheritedMetas = getMetas( hmNode, inheritedMetas, true ); // get meta's from - // <hibernate-mapping> + // get meta's from <hibernate-mapping> + inheritedMetas = getMetas( hmNode, inheritedMetas, true ); extractRootAttributes( hmNode, mappings ); - Iterator filterDefs = hmNode.elementIterator( "filter-def" ); - while ( filterDefs.hasNext() ) { - parseFilterDef( (Element) filterDefs.next(), mappings ); - } + Iterator rootChildren = hmNode.elementIterator(); + while ( rootChildren.hasNext() ) { + final Element element = (Element) rootChildren.next(); + final String elementName = element.getName(); - Iterator typeDefs = hmNode.elementIterator( "typedef" ); - while ( typeDefs.hasNext() ) { - Element typeDef = (Element) typeDefs.next(); - String typeClass = typeDef.attributeValue( "class" ); - String typeName = typeDef.attributeValue( "name" ); - Iterator paramIter = typeDef.elementIterator( "param" ); - Properties parameters = new Properties(); - while ( paramIter.hasNext() ) { - Element param = (Element) paramIter.next(); - parameters.setProperty( param.attributeValue( "name" ), param.getTextTrim() ); + if ( "filter-def".equals( elementName ) ) { + parseFilterDef( element, mappings ); } - - mappings.addTypeDef( typeName, typeClass, parameters ); + else if ( "typedef".equals( elementName ) ) { + bindTypeDef( element, mappings ); + } + else if ( "class".equals( elementName ) ) { + RootClass rootclass = new RootClass(); + bindRootClass( element, rootclass, mappings, inheritedMetas ); + mappings.addClass( rootclass ); + } + else if ( "subclass".equals( elementName ) ) { + PersistentClass superModel = getSuperclass( mappings, element ); + handleSubclass( superModel, mappings, element, inheritedMetas ); + } + else if ( "joined-subclass".equals( elementName ) ) { + PersistentClass superModel = getSuperclass( mappings, element ); + handleJoinedSubclass( superModel, mappings, element, inheritedMetas ); + } + else if ( "union-subclass".equals( elementName ) ) { + PersistentClass superModel = getSuperclass( mappings, element ); + handleUnionSubclass( superModel, mappings, element, inheritedMetas ); + } + else if ( "query".equals( elementName ) ) { + bindNamedQuery( element, null, mappings ); + } + else if ( "sql-query".equals( elementName ) ) { + bindNamedSQLQuery( element, null, mappings ); + } + else if ( "resultset".equals( elementName ) ) { + bindResultSetMappingDefinition( element, null, mappings ); + } + else if ( "import".equals( elementName ) ) { + bindImport( element, mappings ); + } + else if ( "database-object".equals( elementName ) ) { + bindAuxiliaryDatabaseObject( element, mappings ); + } + else { + throw new MappingException( "Unrecognized element [hibernate-mapping/" + elementName + "]" ); + } } + } - Iterator nodes = hmNode.elementIterator( "class" ); - while ( nodes.hasNext() ) { - Element n = (Element) nodes.next(); - RootClass rootclass = new RootClass(); - bindRootClass( n, rootclass, mappings, inheritedMetas ); - mappings.addClass( rootclass ); - } + private static void bindImport(Element importNode, Mappings mappings) { + String className = getClassName( importNode.attribute( "class" ), mappings ); + Attribute renameNode = importNode.attribute( "rename" ); + String rename = ( renameNode == null ) ? + StringHelper.unqualify( className ) : + renameNode.getValue(); + log.debug( "Import: " + rename + " -> " + className ); + mappings.addImport( className, rename ); + } - Iterator subclassnodes = hmNode.elementIterator( "subclass" ); - while ( subclassnodes.hasNext() ) { - Element subnode = (Element) subclassnodes.next(); - PersistentClass superModel = getSuperclass( mappings, subnode ); - handleSubclass( superModel, mappings, subnode, inheritedMetas ); + private static void bindTypeDef(Element typedefNode, Mappings mappings) { + String typeClass = typedefNode.attributeValue( "class" ); + String typeName = typedefNode.attributeValue( "name" ); + Iterator paramIter = typedefNode.elementIterator( "param" ); + Properties parameters = new Properties(); + while ( paramIter.hasNext() ) { + Element param = (Element) paramIter.next(); + parameters.setProperty( param.attributeValue( "name" ), param.getTextTrim() ); } + mappings.addTypeDef( typeName, typeClass, parameters ); + } - Iterator joinedsubclassnodes = hmNode.elementIterator( "joined-subclass" ); - while ( joinedsubclassnodes.hasNext() ) { - Element subnode = (Element) joinedsubclassnodes.next(); - PersistentClass superModel = getSuperclass( mappings, subnode ); - handleJoinedSubclass( superModel, mappings, subnode, inheritedMetas ); - } - - Iterator unionsubclassnodes = hmNode.elementIterator( "union-subclass" ); - while ( unionsubclassnodes.hasNext() ) { - Element subnode = (Element) unionsubclassnodes.next(); - PersistentClass superModel = getSuperclass( mappings, subnode ); - handleUnionSubclass( superModel, mappings, subnode, inheritedMetas ); - } - - nodes = hmNode.elementIterator( "query" ); - while ( nodes.hasNext() ) { - bindNamedQuery( (Element) nodes.next(), null, mappings ); - } - - nodes = hmNode.elementIterator( "sql-query" ); - while ( nodes.hasNext() ) { - bindNamedSQLQuery( (Element) nodes.next(), null, mappings ); - } - - nodes = hmNode.elementIterator( "resultset" ); - while ( nodes.hasNext() ) { - bindResultSetMappingDefinition( (Element) nodes.next(), null, mappings ); - } - - nodes = hmNode.elementIterator( "import" ); - while ( nodes.hasNext() ) { - Element n = (Element) nodes.next(); - String className = getClassName( n.attribute( "class" ), mappings ); - Attribute renameNode = n.attribute( "rename" ); - String rename = ( renameNode == null ) ? - StringHelper.unqualify( className ) : - renameNode.getValue(); - log.debug( "Import: " + rename + " -> " + className ); - mappings.addImport( className, rename ); - } - - nodes = hmNode.elementIterator( "database-object"); - while ( nodes.hasNext() ) { - Element auxDbObjectNode = ( Element ) nodes.next(); - AuxiliaryDatabaseObject auxDbObject = null; - Element definitionNode = auxDbObjectNode.element( "definition" ); - if ( definitionNode != null ) { - try { - auxDbObject = ( AuxiliaryDatabaseObject ) ReflectHelper - .classForName( definitionNode.attributeValue( "class" ) ) - .newInstance(); - } - catch( ClassNotFoundException e ) { - throw new MappingException( - "could not locate custom database object class [" + - definitionNode.attributeValue( "class" ) + "]" - ); - } - catch( Throwable t ) { - throw new MappingException( - "could not instantiate custom database object class [" + - definitionNode.attributeValue( "class" ) + "]" - ); - } + private static void bindAuxiliaryDatabaseObject(Element auxDbObjectNode, Mappings mappings) { + AuxiliaryDatabaseObject auxDbObject = null; + Element definitionNode = auxDbObjectNode.element( "definition" ); + if ( definitionNode != null ) { + try { + auxDbObject = ( AuxiliaryDatabaseObject ) ReflectHelper + .classForName( definitionNode.attributeValue( "class" ) ) + .newInstance(); } - else { - auxDbObject = new SimpleAuxiliaryDatabaseObject( - auxDbObjectNode.elementTextTrim( "create" ), - auxDbObjectNode.elementTextTrim( "drop" ) + catch( ClassNotFoundException e ) { + throw new MappingException( + "could not locate custom database object class [" + + definitionNode.attributeValue( "class" ) + "]" ); } - - Iterator dialectScopings = auxDbObjectNode.elementIterator( "dialect-scope" ); - while ( dialectScopings.hasNext() ) { - Element dialectScoping = ( Element ) dialectScopings.next(); - auxDbObject.addDialectScope( dialectScoping.attributeValue( "name" ) ); + catch( Throwable t ) { + throw new MappingException( + "could not instantiate custom database object class [" + + definitionNode.attributeValue( "class" ) + "]" + ); } + } + else { + auxDbObject = new SimpleAuxiliaryDatabaseObject( + auxDbObjectNode.elementTextTrim( "create" ), + auxDbObjectNode.elementTextTrim( "drop" ) + ); + } - mappings.addAuxiliaryDatabaseObject( auxDbObject ); + Iterator dialectScopings = auxDbObjectNode.elementIterator( "dialect-scope" ); + while ( dialectScopings.hasNext() ) { + Element dialectScoping = ( Element ) dialectScopings.next(); + auxDbObject.addDialectScope( dialectScoping.attributeValue( "name" ) ); } + + mappings.addAuxiliaryDatabaseObject( auxDbObject ); } private static void extractRootAttributes(Element hmNode, Mappings mappings) { |