[Snmap-developer] SNMAP/src/net/sf/snmap/cfg SnmapBinder.java,1.2,1.3 Environment.java,1.2,1.3
Status: Planning
Brought to you by:
arden
|
From: arden l. <ar...@us...> - 2006-01-19 04:31:31
|
Update of /cvsroot/snmap/SNMAP/src/net/sf/snmap/cfg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7595/src/net/sf/snmap/cfg Modified Files: SnmapBinder.java Environment.java Log Message: Index: SnmapBinder.java =================================================================== RCS file: /cvsroot/snmap/SNMAP/src/net/sf/snmap/cfg/SnmapBinder.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SnmapBinder.java 13 Jan 2006 03:23:44 -0000 1.2 --- SnmapBinder.java 19 Jan 2006 04:31:20 -0000 1.3 *************** *** 1,8 **** package net.sf.snmap.cfg; - import java.util.ArrayList; - import java.util.HashSet; import java.util.Iterator; ! import java.util.Properties; import net.sf.snmap.MappingException; --- 1,6 ---- package net.sf.snmap.cfg; import java.util.Iterator; ! import java.util.Map; import net.sf.snmap.MappingException; *************** *** 11,14 **** --- 9,13 ---- import net.sf.snmap.mapping.RootClass; import net.sf.snmap.mapping.Property; + import net.sf.snmap.mapping.Table; import net.sf.snmap.mapping.Value; import net.sf.snmap.mapping.SimpleValue; *************** *** 25,238 **** * metamodel (the classes in the <tt>mapping</tt> package) */ ! public final class SnmapBinder ! { ! private static final Log log = LogFactory.getLog( SnmapBinder.class ); ! /** ! * Private constructor to disallow instantiation. ! */ ! private SnmapBinder() ! {} ! /** ! * The main contract into the hbm.xml-based binder. Performs necessary ! * binding operations represented by the given DOM. ! * ! * @param doc ! * The DOM to be parsed and bound. ! * @param mappings ! * Current bind state. ! * @param inheritedMetas ! * Any inherited meta-tag information. ! * @throws MappingException ! */ ! public static void bindRoot( Document doc, Mappings mappings, java.util.Map inheritedMetas ) ! throws MappingException ! { ! // Get extend information (package) ! SnmapBinder.getExtendsNeeded( doc, mappings ); ! Element hmNode = doc.getRootElement(); ! 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 ); ! } ! } ! /** ! * Responsible for perfoming the bind operation related to an <class/> ! * mapping element. ! * ! * @param node ! * The DOM Element for the <class/> element. ! * @param rootClass ! * The mapping instance to which to bind the information. ! * @param mappings ! * The current bind state. ! * @param inheritedMetas ! * Any inherited meta-tag information. ! * @throws MappingException ! */ ! public static void bindRootClass( Element node, RootClass rootClass, Mappings mappings, ! java.util.Map inheritedMetas ) throws MappingException ! { ! bindClass( node, rootClass, mappings, inheritedMetas ); ! bindRootPersistentClassCommonValues( node, inheritedMetas, mappings, rootClass ); ! } ! private static void bindRootPersistentClassCommonValues( Element node, ! java.util.Map inheritedMetas, Mappings mappings, RootClass entity ) throws MappingException ! { ! Iterator subnodes = node.elementIterator(); ! while( subnodes.hasNext() ) ! { ! Element subnode = (Element) subnodes.next(); ! String name = subnode.getName(); ! // TODO : check Table? ! if ("table".equals(name)) { ! } ! } ! createClassProperties( node, entity, mappings, inheritedMetas ); ! } ! public static void getExtendsNeeded( Document doc, Mappings mappings ) ! { ! final Element hmNode = doc.getRootElement(); ! Attribute packNode = hmNode.attribute( "package" ); ! if( packNode != null ) ! mappings.setDefaultPackage( packNode.getValue() ); ! } ! public static void bindClass( Element node, PersistentClass persistentClass, Mappings mappings, ! java.util.Map inheritedMetas ) throws MappingException ! { ! bindPojoRepresentation( node, persistentClass, mappings, inheritedMetas ); ! } ! protected static void createClassProperties( Element node, PersistentClass persistentClass, ! Mappings mappings, java.util.Map inheritedMetas ) throws MappingException ! { ! createClassProperties( node, persistentClass, mappings, inheritedMetas, true, true ); ! } ! protected static void createClassProperties( Element node, PersistentClass persistentClass, ! Mappings mappings, java.util.Map inheritedMetas, boolean mutable, boolean nullable ) ! throws MappingException ! { ! Iterator iter = node.elementIterator(); ! while( iter.hasNext() ) ! { ! Element subnode = (Element) iter.next(); ! String name = subnode.getName(); ! String propertyName = subnode.attributeValue( "name" ); ! ! Value value = null; ! ! if( "property".equals( name ) ) ! { ! value = new SimpleValue(); ! bindSimpleValue( subnode, (SimpleValue) value, nullable, propertyName, mappings ); ! } ! if( value != null ) ! { ! Property property = createProperty( value, propertyName, persistentClass ! .getClassName(), subnode, mappings, inheritedMetas ); ! persistentClass.addProperty( property ); ! } ! } ! } ! private static void bindPojoRepresentation( Element node, PersistentClass entity, ! Mappings mappings, java.util.Map metaTags ) ! { ! String className = getClassName( node.attribute( "name" ), mappings ); ! entity.setClassName( className ); ! } ! private static String getClassName( Attribute att, Mappings model ) ! { ! if( att == null ) ! return null; ! return getClassName( att.getValue(), model ); ! } ! private static String getClassName( String unqualifiedName, Mappings model ) ! { ! if( unqualifiedName == null ) ! return null; ! if( unqualifiedName.indexOf( '.' ) < 0 && model.getDefaultPackage() != null ) ! { ! return model.getDefaultPackage() + '.' + unqualifiedName; ! } ! return unqualifiedName; ! } ! private static Property createProperty( final Value value, final String propertyName, ! final String className, final Element subnode, final Mappings mappings, ! java.util.Map inheritedMetas ) throws MappingException ! { ! value.setTypeUsingReflection( className, propertyName ); ! Property prop = new Property(); ! prop.setValue( value ); ! bindProperty( subnode, prop, mappings, inheritedMetas ); ! return prop; ! } ! ! // automatically makes a ?? with OID ! public static void bindSimpleValue(Element node, SimpleValue simpleValue, boolean isNullable, ! String path, Mappings mappings) throws MappingException { ! bindOid( node, simpleValue, isNullable, path, mappings ); ! } ! ! public static void bindProperty( Element node, Property property, Mappings mappings, ! java.util.Map inheritedMetas ) throws MappingException ! { ! String propName = node.attributeValue( "name" ); ! property.setName( propName ); ! } ! ! public static void bindOid(final Element node, final SimpleValue simpleValue, ! final boolean isNullable, final String propertyPath, ! final Mappings mappings) throws MappingException { ! // OID ! Attribute oidAttribute = node.attribute( "oid" ); ! if ( oidAttribute == null ) { ! throw new MappingException( ! "oid attribute should not be null." ); ! } ! else { ! ObjectType objectType = new ObjectType(); ! objectType.setValue( simpleValue ); ! bindObjectType( node, objectType, isNullable ); ! ! simpleValue.setObjectType(objectType); ! ! } ! ! } ! public static void bindObjectType(Element node, ObjectType objectType, boolean isNullable) { ! Attribute oidNode = node.attribute( "oid" ); ! if ( oidNode != null ) ! { ! OID oid = new OID(oidNode.getValue()); ! objectType.setOid(oid); ! } ! } } --- 24,297 ---- * metamodel (the classes in the <tt>mapping</tt> package) */ ! public final class SnmapBinder { ! private static final Log log = LogFactory.getLog(SnmapBinder.class); ! /** ! * Private constructor to disallow instantiation. ! */ ! private SnmapBinder() { ! } ! /** ! * The main contract into the hbm.xml-based binder. Performs necessary ! * binding operations represented by the given DOM. ! * ! * @param doc ! * The DOM to be parsed and bound. ! * @param mappings ! * Current bind state. ! * @param inheritedMetas ! * Any inherited meta-tag information. ! * @throws MappingException ! */ ! public static void bindRoot(Document doc, Mappings mappings, ! java.util.Map inheritedMetas) throws MappingException { ! // Get extend information (package) ! SnmapBinder.getExtendsNeeded(doc, mappings); ! Element hmNode = doc.getRootElement(); ! 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); ! } ! } ! /** ! * Responsible for perfoming the bind operation related to an <class/> ! * mapping element. ! * ! * @param node ! * The DOM Element for the <class/> element. ! * @param rootClass ! * The mapping instance to which to bind the information. ! * @param mappings ! * The current bind state. ! * @param inheritedMetas ! * Any inherited meta-tag information. ! * @throws MappingException ! */ ! public static void bindRootClass(Element node, RootClass rootClass, ! Mappings mappings, java.util.Map inheritedMetas) ! throws MappingException { ! bindClass(node, rootClass, mappings, inheritedMetas); ! bindRootPersistentClassCommonValues(node, inheritedMetas, mappings, ! rootClass); ! } ! private static void bindRootPersistentClassCommonValues(Element node, ! java.util.Map inheritedMetas, Mappings mappings, RootClass entity) ! throws MappingException { ! Iterator subnodes = node.elementIterator(); ! while (subnodes.hasNext()) { ! Element subnode = (Element) subnodes.next(); ! String name = subnode.getName(); ! // Check "table". ! if ("table".equals(name)) { ! // bind table information. ! bindTable(subnode, entity, mappings, inheritedMetas); ! } ! } ! createClassProperties(node, entity, mappings, inheritedMetas); ! } ! private static void bindTable(Element node, RootClass entity, ! Mappings mappings, Map inheritedMetas) { ! Iterator subnodes = node.elementIterator(); ! while (subnodes.hasNext()) { ! Element subnode = (Element) subnodes.next(); ! String name = subnode.getName(); ! if ("id".equals(name)) { ! // ID ! bindSimpleId(subnode, entity, mappings, inheritedMetas); ! } ! // TODO : I will support composite-id later. ! //else if ( "composite-id".equals( name ) ) { ! // // COMPOSITE-ID ! // bindCompositeId( subnode, entity, mappings, inheritedMetas ); ! //} ! ! // Table property. ! createTableProperties(node, entity, mappings, inheritedMetas); ! } ! } ! private static void createTableProperties(Element node, RootClass entity, ! net.sf.snmap.cfg.Mappings mappings, Map inheritedMetas) { ! Iterator iter = node.elementIterator(); ! while (iter.hasNext()) { ! Element subnode = (Element) iter.next(); ! String name = subnode.getName(); ! String propertyName = subnode.attributeValue("name"); ! Value value = null; ! if ("property".equals(name)) { ! value = new SimpleValue(); ! bindSimpleValue(subnode, (SimpleValue) value, false, ! propertyName, mappings); ! } ! if (value != null) { ! // TODO : ??? ! /* ! * Property property = createProperty( value, propertyName, ! * persistentClass .getClassName(), subnode, mappings, ! * inheritedMetas ); ! * ! * table.addProperty( property ); ! */ ! Property property = new Property(); ! entity.getTable().addProperty( property ); ! } ! } ! } ! private static void bindSimpleId(Element idNode, RootClass entity, ! Mappings mappings, Map inheritedMetas) { ! String propertyName = idNode.attributeValue("name"); ! SimpleValue id = new SimpleValue(); ! entity.getTable().setIdentifier(id); ! bindSimpleValue(idNode, id, false, propertyName, mappings); ! id.setTypeUsingReflection(entity.getClassName(), propertyName); ! } ! public static void getExtendsNeeded(Document doc, Mappings mappings) { ! final Element hmNode = doc.getRootElement(); ! Attribute packNode = hmNode.attribute("package"); ! if (packNode != null) ! mappings.setDefaultPackage(packNode.getValue()); ! } ! public static void bindClass(Element node, PersistentClass persistentClass, ! Mappings mappings, java.util.Map inheritedMetas) ! throws MappingException { ! bindPojoRepresentation(node, persistentClass, mappings, inheritedMetas); ! } ! protected static void createClassProperties(Element node, ! PersistentClass persistentClass, Mappings mappings, ! java.util.Map inheritedMetas) throws MappingException { ! createClassProperties(node, persistentClass, mappings, inheritedMetas, ! true, true); ! } ! ! protected static void createClassProperties(Element node, ! PersistentClass persistentClass, Mappings mappings, ! java.util.Map inheritedMetas, boolean mutable, boolean nullable) ! throws MappingException { ! ! Iterator iter = node.elementIterator(); ! while (iter.hasNext()) { ! Element subnode = (Element) iter.next(); ! String name = subnode.getName(); ! String propertyName = subnode.attributeValue("name"); ! ! Value value = null; ! ! if ("property".equals(name)) { ! value = new SimpleValue(); ! bindSimpleValue(subnode, (SimpleValue) value, nullable, ! propertyName, mappings); ! } ! ! if (value != null) { ! Property property = createProperty(value, propertyName, ! persistentClass.getClassName(), subnode, mappings, ! inheritedMetas); ! ! persistentClass.addProperty(property); ! } ! ! } ! } ! ! private static void bindPojoRepresentation(Element node, ! PersistentClass entity, Mappings mappings, java.util.Map metaTags) { ! ! String className = getClassName(node.attribute("name"), mappings); ! entity.setClassName(className); ! } ! ! private static String getClassName(Attribute att, Mappings model) { ! if (att == null) ! return null; ! return getClassName(att.getValue(), model); ! } ! ! private static String getClassName(String unqualifiedName, Mappings model) { ! if (unqualifiedName == null) ! return null; ! if (unqualifiedName.indexOf('.') < 0 ! && model.getDefaultPackage() != null) { ! return model.getDefaultPackage() + '.' + unqualifiedName; ! } ! return unqualifiedName; ! } ! ! private static Property createProperty(final Value value, ! final String propertyName, final String className, ! final Element subnode, final Mappings mappings, ! java.util.Map inheritedMetas) throws MappingException { ! value.setTypeUsingReflection(className, propertyName); ! ! Property prop = new Property(); ! prop.setValue(value); ! bindProperty(subnode, prop, mappings, inheritedMetas); ! return prop; ! } ! ! // automatically makes a ?? with OID ! public static void bindSimpleValue(Element node, SimpleValue simpleValue, ! boolean isNullable, String path, Mappings mappings) ! throws MappingException { ! bindOid(node, simpleValue, isNullable, path, mappings); ! } ! ! public static void bindProperty(Element node, Property property, ! Mappings mappings, java.util.Map inheritedMetas) ! throws MappingException { ! String propName = node.attributeValue("name"); ! property.setName(propName); ! } ! ! public static void bindOid(final Element node, ! final SimpleValue simpleValue, final boolean isNullable, ! final String propertyPath, final Mappings mappings) ! throws MappingException { ! // OID ! Attribute oidAttribute = node.attribute("oid"); ! if (oidAttribute == null) { ! throw new MappingException("oid attribute should not be null."); ! } else { ! ObjectType objectType = new ObjectType(); ! objectType.setValue(simpleValue); ! bindObjectType(node, objectType, isNullable); ! ! simpleValue.setObjectType(objectType); ! } ! } ! ! public static void bindObjectType(Element node, ObjectType objectType, ! boolean isNullable) { ! Attribute oidNode = node.attribute("oid"); ! if (oidNode != null) { ! OID oid = new OID(oidNode.getValue()); ! objectType.setOid(oid); ! } ! } } Index: Environment.java =================================================================== RCS file: /cvsroot/snmap/SNMAP/src/net/sf/snmap/cfg/Environment.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Environment.java 10 Dec 2005 23:05:58 -0000 1.2 --- Environment.java 19 Jan 2006 04:31:20 -0000 1.3 *************** *** 1,10 **** package net.sf.snmap.cfg; import java.util.Properties; public final class Environment { public static final String VERSION = "0.0.1"; ! /** * Return <tt>System</tt> properties, extended by any properties specified --- 1,33 ---- package net.sf.snmap.cfg; + import java.util.HashMap; + import java.util.Iterator; + import java.util.Map; import java.util.Properties; + import org.apache.commons.logging.Log; + import org.apache.commons.logging.LogFactory; + public final class Environment { public static final String VERSION = "0.0.1"; ! ! private static final Map OBSOLETE_PROPERTIES = new HashMap(); ! ! private static final Log log = LogFactory.getLog(Environment.class); ! ! /** ! * Issues warnings to the user when any obsolete property names are used. ! * (In current version, there is not any obsolete property.) ! */ ! public static void verifyProperties(Properties props) { ! Iterator iter = props.keySet().iterator(); ! while ( iter.hasNext() ) { ! Object oldProp = iter.next(); ! Object newProp = OBSOLETE_PROPERTIES.get(oldProp); ! if ( newProp!=null ) log.warn("Usage of obsolete property: " + oldProp + " no longer supported, use: " + newProp); ! } ! } ! /** * Return <tt>System</tt> properties, extended by any properties specified *************** *** 15,19 **** public static Properties getProperties() { Properties copy = new Properties(); - // copy.putAll(GLOBAL_PROPERTIES); return copy; } --- 38,41 ---- |