From: <one...@us...> - 2003-01-16 20:54:58
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/tool/hbm2java In directory sc8-pr-cvs1:/tmp/cvs-serv8993a/net/sf/hibernate/tool/hbm2java Added Files: MetaAttributeHelper.java Log Message: applied Max Andersen's patch for <meta>attributes in hbm2java --- NEW FILE: MetaAttributeHelper.java --- package net.sf.hibernate.tool.hbm2java; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.commons.collections.MultiHashMap; import org.apache.commons.collections.MultiMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdom.Element; /** * Helper for loading, merging and accessing <meta> tags. * * @author max * * */ public class MetaAttributeHelper { static private Log log = LogFactory.getLog(MetaAttributeHelper.class); /** * Load meta attributes from jdom element into a MultiMap. * * @param element * @return MultiMap */ static protected MultiMap loadMetaMap(Element element) { MultiMap result = new MultiHashMap(); List metaAttributeList = new ArrayList(); metaAttributeList.addAll(element.getChildren("meta")); for (Iterator iter = metaAttributeList.iterator(); iter.hasNext();) { Element metaAttrib = (Element) iter.next(); // does not use getTextNormalize() or getTextTrim() as that would remove the formatting in new lines in items like description for javadocs. result.put(metaAttrib.getAttribute("attribute").getValue(), metaAttrib.getText()); } return result; } /** * Merges a Multimap with inherited maps. * Values specified always overrules/replaces the inherited values. * * @param local * @param inherited * @return a MultiMap with all values from local and extra values * from inherited */ static public MultiMap mergeMetaMaps(MultiMap local, MultiMap inherited) { MultiHashMap result = new MultiHashMap(); if (inherited != null) { result.putAll(local); for (Iterator iter = inherited.keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); if (!local.containsKey(key)) { // inheriting a meta attribute result.put(key, inherited.get(key)); } } } return result; } /** * Method loadAndMergeMetaMap. * @param classElement * @param inheritedMeta * @return MultiMap */ public static MultiMap loadAndMergeMetaMap(Element classElement, MultiMap inheritedMeta) { return mergeMetaMaps(loadMetaMap(classElement), inheritedMeta); } } |