public ClassMapping(string classPackage, MappingElement parentElement, ClassName superClass, Element classElement, MultiMap inheritedMeta) : base(classElement, parentElement) { InitBlock(); InitWith(classPackage, superClass, classElement, false, inheritedMeta); }
public FieldProperty(Element element, MappingElement parent, string name, ClassName type, ClassName implementationClassName, bool nullable, ClassName foreignClass, SupportClass.SetSupport foreignKeys, MultiMap metaattribs) : base(element, parent) { InitWith(name, type, implementationClassName, nullable, id, false, foreignClass, foreignKeys, metaattribs); }
public ClassMapping(string classPackage, MappingElement parentElement, ClassName superClass, ClassMapping superClassMapping, Element classElement, MultiMap inheritedMeta) : this(classPackage, parentElement, superClass, classElement, inheritedMeta) { this.superClassMapping = superClassMapping; if (this.superClassMapping != null) { AddImport(superClassMapping.FullyQualifiedName); SupportClass.ListCollectionSupport l = this.superClassMapping.AllFieldsForFullConstructor; for (IEnumerator iter = l.GetEnumerator(); iter.MoveNext();) { FieldProperty element = (FieldProperty) iter.Current; ClassName ct = element.ClassType; if (ct != null) { // add imports for superclasses possible fields. //addImport(ct); } else { //addImport(element.FullyQualifiedTypeName); } } } }
public MappingElement(Element element, MappingElement parentElement) { this.element = element; this.parentElement = parentElement; // merge with parent meta map /* * MultiMap inherited = null; if (parentModel != null) { inherited = * parentModel.getMetaMap(); } */ }
public SubclassMapping(string classPackage, MappingElement mappingElement, string superClass, Element clazz, MultiMap multiMap) { this.classPackage = classPackage; this.mappingElement = mappingElement; this.superClass = superClass; this.clazz = clazz; this.multiMap = multiMap; this.orphaned = true; }
private static void HandleClass(string classPackage, MappingElement me, Hashtable classMappings, IEnumerator classElements, MultiMap mm, bool extendz) { while (classElements.MoveNext()) { Element clazz = (Element)classElements.Current; if (!extendz) { ClassMapping cmap = new ClassMapping(classPackage, clazz, me, mm); SupportClass.PutElement(classMappings, cmap.FullyQualifiedName, cmap); SupportClass.PutElement(allMaps, cmap.FullyQualifiedName, cmap); } else { string ex = clazz.Attributes["extends"] == null ? null : clazz.Attributes["extends"].Value; if ((object)ex == null) { throw new MappingException("Missing extends attribute on <" + clazz.LocalName + " name=" + clazz.Attributes["name"].Value + ">"); } int commaIndex = ex.IndexOf(','); if (commaIndex > -1) { //suppress the leading AssemblyName ex = ex.Substring(0, commaIndex).Trim(); } ClassMapping superclass = (ClassMapping)allMaps[ex]; if (superclass == null) { // Haven't seen the superclass yet, so record this and process at the end SubclassMapping orphan = new SubclassMapping(classPackage, me, ex, clazz, mm); children.Add(orphan); } else { ClassMapping subclassMapping = new ClassMapping(classPackage, me, superclass.ClassName, superclass, clazz, mm); superclass.AddSubClass(subclassMapping); SupportClass.PutElement(allMaps, subclassMapping.FullyQualifiedName, subclassMapping); } } } }
public static void Generate(String[] args,IFileCreationObserver fileCreationObserver) { //this has to change... dirty things during porting ClassMapping.ResetComponents(); nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("urn", "urn:nhibernate-mapping-2.2"); children = new ArrayList(); allMaps = new MultiMap(); ArrayList mappingFiles = new ArrayList(); string outputDir = null; SupportClass.ListCollectionSupport generators = new SupportClass.ListCollectionSupport(); MultiMap globalMetas = new MultiHashMap(); // parse command line parameters cmdLine = new Hbm2NetParameters(args); try { cmdLine.Parse(); if (0 == cmdLine.FileNames.Count()) { Console.Error.WriteLine("No input file(s) specified"); throw new NotEnougthParametersException(); } } catch (NotEnougthParametersException) { Console.Error.WriteLine(string.Format("Use:hbm2net {0} files.hbm.xml ( wildcards allowed )",cmdLine.GetShortHelp())); Console.Error.WriteLine(cmdLine.GetHelp()); Environment.Exit(-1); } if (!string.IsNullOrEmpty(cmdLine.ConfigFile)) { if (File.Exists(cmdLine.ConfigFile)) { try { FileInfo configFile = new FileInfo(cmdLine.ConfigFile); // parse config xml file Document document = new XmlDocument(); document.Load(configFile.FullName); var cfgValidator = new ConfigurationValidator(); cfgValidator.Validate(document); if (!string.IsNullOrEmpty(cfgValidator.WarningMessage)) { log.Warn("Configuration:" + cfgValidator.WarningMessage); } globalMetas = MetaAttributeHelper.LoadAndMergeMetaMap((document["codegen"]), null); IEnumerator generateElements = document["codegen"].SelectNodes("generate").GetEnumerator(); while (generateElements.MoveNext()) { generators.Add(new Generator(configFile.Directory, (Element)generateElements.Current)); } } catch (ConfigurationValidationException validationException) { Console.Error.WriteLine("Error validating configuration file:" + validationException.Message); Environment.Exit(-1); } catch (Exception genericException) { Console.Error.WriteLine("Error reading configuration file:" + genericException.Message); Environment.Exit(-1); } } else { log.Error("Configuration file:" + cmdLine.ConfigFile + " does not exist"); Environment.Exit(-1); } } if (generators.Count == 0) { log.Info("No configuration file specified: using T4 generator with default template."); T4Render t4 = new T4Render(); t4.Configure(new DirectoryInfo(Directory.GetCurrentDirectory()), new NameValueCollection()); generators.Add(new Generator(t4)); } if (!string.IsNullOrEmpty(cmdLine.OutputDir)) { outputDir = cmdLine.OutputDir; } foreach (string inFile in cmdLine.FileNames) { if (inFile.IndexOf("*") > -1) { mappingFiles.AddRange(GetFiles(inFile)); } else { mappingFiles.Add(inFile); } } Hashtable classMappings = new Hashtable(); for (IEnumerator iter = mappingFiles.GetEnumerator(); iter.MoveNext(); ) { log.Info(iter.Current.ToString()); string mappingFile = (string)iter.Current; if (!Path.IsPathRooted(mappingFile)) { mappingFile = Path.Combine(Environment.CurrentDirectory, mappingFile); } if (!File.Exists(mappingFile)) throw new FileNotFoundException("Mapping file does not exist.", mappingFile); // parse the mapping file NameTable nt = new NameTable(); nt.Add("urn:nhibernate-mapping-2.2"); Document document = new XmlDocument(nt); document.Load(mappingFile); FileInfo mappingFileInfo = new FileInfo(mappingFile); SourceFileInfoMap.Instance.Add(document, mappingFileInfo); Element rootElement = document["hibernate-mapping"]; if (rootElement == null) continue; XmlAttribute a = rootElement.Attributes["namespace"]; string pkg = null; if (a != null) { pkg = a.Value; } MappingElement me = new MappingElement(rootElement, null); IEnumerator classElements = rootElement.SelectNodes("urn:class", nsmgr).GetEnumerator(); MultiMap mm = MetaAttributeHelper.LoadAndMergeMetaMap(rootElement, globalMetas); HandleClass(pkg, me, classMappings, classElements, mm, false); classElements = rootElement.SelectNodes("urn:subclass", nsmgr).GetEnumerator(); HandleClass(pkg, me, classMappings, classElements, mm, true); classElements = rootElement.SelectNodes("urn:joined-subclass", nsmgr).GetEnumerator(); HandleClass(pkg, me, classMappings, classElements, mm, true); // Ok, pickup subclasses that we found before their superclasses ProcessChildren(classMappings); } // generate source files for (IEnumerator iterator = generators.GetEnumerator(); iterator.MoveNext(); ) { Generator g = (Generator)iterator.Current; g.BaseDirName = outputDir ?? ".\\"; g.Generate(classMappings,fileCreationObserver,cmdLine.CheckTime!=null); } }
private static void HandleClass(string classPackage, MappingElement me, Hashtable classMappings, IEnumerator classElements, MultiMap mm, bool extendz) { while (classElements.MoveNext()) { Element clazz = (Element) classElements.Current; if (!extendz) { ClassMapping cmap = new ClassMapping(classPackage, clazz, me, mm); SupportClass.PutElement(classMappings, cmap.FullyQualifiedName, cmap); SupportClass.PutElement(allMaps, cmap.FullyQualifiedName, cmap); } else { string ex = clazz.Attributes["extends"] == null ? null : clazz.Attributes["extends"].Value; if ((object) ex == null) { throw new MappingException("Missing extends attribute on <" + clazz.LocalName + " name=" + clazz.Attributes["name"].Value + ">"); } int commaIndex = ex.IndexOf(','); if (commaIndex > -1) { //suppress the leading AssemblyName ex = ex.Substring(0, commaIndex).Trim(); } ClassMapping superclass = (ClassMapping) allMaps[ex]; if (superclass == null) { // Haven't seen the superclass yet, so record this and process at the end SubclassMapping orphan = new SubclassMapping(classPackage, me, ex, clazz, mm); children.Add(orphan); } else { ClassMapping subclassMapping = new ClassMapping(classPackage, me, superclass.ClassName, superclass, clazz, mm); superclass.AddSubClass(subclassMapping); SupportClass.PutElement(allMaps, subclassMapping.FullyQualifiedName, subclassMapping); } } } }
public ClassMapping(string classPackage, Element classElement, MappingElement parentElement, bool component, MultiMap inheritedMeta) : base(classElement, parentElement) { InitBlock(); InitWith(classPackage, null, classElement, component, inheritedMeta); }
public FieldProperty(Element element, MappingElement parent, string name, ClassName type, bool nullable, bool id, bool generated, MultiMap metaattribs) : base(element, parent) { InitWith(name, type, type, nullable, id, generated, null, null, metaattribs); }
public static void Main(String[] args) { nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("urn", "urn:nhibernate-mapping-2.2"); children = new ArrayList(); allMaps = new MultiMap(); File.Delete("error-log.txt"); // DOMConfigurator is deprecated in the latest log4net, but we are using an earlier // version that comes with NVelocity. XmlConfigurator.Configure(new FileInfo("NHibernate.Tool.hbm2net.exe.config")); if (args.Length == 0) { Console.Error.WriteLine("No arguments provided. Nothing to do. Exit."); Environment.Exit(- 1); } ArrayList mappingFiles = new ArrayList(); string outputDir = null; SupportClass.ListCollectionSupport generators = new SupportClass.ListCollectionSupport(); MultiMap globalMetas = new MultiHashMap(); // parse command line parameters for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("--")) { if (args[i].StartsWith("--config=")) { FileInfo configFile = new FileInfo(args[i].Substring(9)); // parse config xml file Document document = new XmlDocument(); document.Load(configFile.FullName); globalMetas = MetaAttributeHelper.LoadAndMergeMetaMap((document["codegen"]), null); IEnumerator generateElements = document["codegen"].SelectNodes("generate").GetEnumerator(); while (generateElements.MoveNext()) { generators.Add(new Generator(configFile.Directory, (Element) generateElements.Current)); } } else if (args[i].StartsWith("--output=")) { outputDir = args[i].Substring(9); } } else if (args[i].IndexOf("*") > -1) { // Handle wildcards mappingFiles.AddRange(GetFiles(args[i])); } else { mappingFiles.Add(args[i]); } } // if no config xml file, add a default generator if (generators.Count == 0) { generators.Add(new Generator(new DirectoryInfo(Environment.CurrentDirectory))); } Hashtable classMappings = new Hashtable(); for (IEnumerator iter = mappingFiles.GetEnumerator(); iter.MoveNext(); ) { log.Info(iter.Current.ToString()); string mappingFile = (string)iter.Current; if (!Path.IsPathRooted(mappingFile)) { mappingFile = Path.Combine(Environment.CurrentDirectory, mappingFile); } if (!File.Exists(mappingFile)) throw new FileNotFoundException("Mapping file does not exist.", mappingFile); // parse the mapping file NameTable nt = new NameTable(); nt.Add("urn:nhibernate-mapping-2.2"); Document document = new XmlDocument(nt); document.Load(mappingFile); Element rootElement = document["hibernate-mapping"]; if (rootElement == null) continue; XmlAttribute a = rootElement.Attributes["namespace"]; string pkg = null; if (a != null) { pkg = a.Value; } MappingElement me = new MappingElement(rootElement, null); IEnumerator classElements = rootElement.SelectNodes("urn:class", nsmgr).GetEnumerator(); MultiMap mm = MetaAttributeHelper.LoadAndMergeMetaMap(rootElement, globalMetas); HandleClass(pkg, me, classMappings, classElements, mm, false); classElements = rootElement.SelectNodes("urn:subclass", nsmgr).GetEnumerator(); HandleClass(pkg, me, classMappings, classElements, mm, true); classElements = rootElement.SelectNodes("urn:joined-subclass", nsmgr).GetEnumerator(); HandleClass(pkg, me, classMappings, classElements, mm, true); // Ok, pickup subclasses that we found before their superclasses ProcessChildren(classMappings); // generate source files for (IEnumerator iterator = generators.GetEnumerator(); iterator.MoveNext(); ) { Generator g = (Generator)iterator.Current; g.BaseDirName = outputDir; g.Generate(classMappings); } } }
public static void Generate(String[] args, IFileCreationObserver fileCreationObserver) { //this has to change... dirty things during porting ClassMapping.ResetComponents(); nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("urn", "urn:nhibernate-mapping-2.2"); children = new ArrayList(); allMaps = new MultiMap(); ArrayList mappingFiles = new ArrayList(); string outputDir = null; SupportClass.ListCollectionSupport generators = new SupportClass.ListCollectionSupport(); MultiMap globalMetas = new MultiHashMap(); // parse command line parameters cmdLine = new Hbm2NetParameters(args); try { cmdLine.Parse(); if (0 == cmdLine.FileNames.Count()) { Console.Error.WriteLine("No input file(s) specified"); throw new NotEnougthParametersException(); } } catch (NotEnougthParametersException) { Console.Error.WriteLine(string.Format("Use:hbm2net {0} files.hbm.xml ( wildcards allowed )", cmdLine.GetShortHelp())); Console.Error.WriteLine(cmdLine.GetHelp()); Environment.Exit(-1); } if (!string.IsNullOrEmpty(cmdLine.ConfigFile)) { if (File.Exists(cmdLine.ConfigFile)) { try { FileInfo configFile = new FileInfo(cmdLine.ConfigFile); // parse config xml file Document document = new XmlDocument(); document.Load(configFile.FullName); var cfgValidator = new ConfigurationValidator(); cfgValidator.Validate(document); if (!string.IsNullOrEmpty(cfgValidator.WarningMessage)) { log.Warn("Configuration:" + cfgValidator.WarningMessage); } globalMetas = MetaAttributeHelper.LoadAndMergeMetaMap((document["codegen"]), null); IEnumerator generateElements = document["codegen"].SelectNodes("generate").GetEnumerator(); while (generateElements.MoveNext()) { generators.Add(new Generator(configFile.Directory, (Element)generateElements.Current)); } } catch (ConfigurationValidationException validationException) { Console.Error.WriteLine("Error validating configuration file:" + validationException.Message); Environment.Exit(-1); } catch (Exception genericException) { Console.Error.WriteLine("Error reading configuration file:" + genericException.Message); Environment.Exit(-1); } } else { log.Error("Configuration file:" + cmdLine.ConfigFile + " does not exist"); Environment.Exit(-1); } } if (generators.Count == 0) { log.Info("No configuration file specified: using T4 generator with default template."); T4Render t4 = new T4Render(); t4.Configure(new DirectoryInfo(Directory.GetCurrentDirectory()), new NameValueCollection()); generators.Add(new Generator(t4)); } if (!string.IsNullOrEmpty(cmdLine.OutputDir)) { outputDir = cmdLine.OutputDir; } foreach (string inFile in cmdLine.FileNames) { if (inFile.IndexOf("*") > -1) { mappingFiles.AddRange(GetFiles(inFile)); } else { mappingFiles.Add(inFile); } } Hashtable classMappings = new Hashtable(); for (IEnumerator iter = mappingFiles.GetEnumerator(); iter.MoveNext();) { log.Info(string.Concat("Handling:", iter.Current.ToString())); string mappingFile = (string)iter.Current; if (!Path.IsPathRooted(mappingFile)) { mappingFile = Path.Combine(Environment.CurrentDirectory, mappingFile); } if (!File.Exists(mappingFile)) { throw new FileNotFoundException("Mapping file does not exist.", mappingFile); } // parse the mapping file NameTable nt = new NameTable(); nt.Add("urn:nhibernate-mapping-2.2"); Document document = new XmlDocument(nt); document.Load(mappingFile); FileInfo mappingFileInfo = new FileInfo(mappingFile); SourceFileInfoMap.Instance.Add(document, mappingFileInfo); Element rootElement = document["hibernate-mapping"]; if (rootElement == null) { continue; } XmlAttribute a = rootElement.Attributes["namespace"]; string pkg = null; if (a != null) { pkg = a.Value; } MappingElement me = new MappingElement(rootElement, null); IEnumerator classElements = rootElement.SelectNodes("urn:class", nsmgr).GetEnumerator(); MultiMap mm = MetaAttributeHelper.LoadAndMergeMetaMap(rootElement, globalMetas); HandleClass(pkg, me, classMappings, classElements, mm, false); classElements = rootElement.SelectNodes("urn:subclass", nsmgr).GetEnumerator(); HandleClass(pkg, me, classMappings, classElements, mm, true); classElements = rootElement.SelectNodes("urn:joined-subclass", nsmgr).GetEnumerator(); HandleClass(pkg, me, classMappings, classElements, mm, true); // Ok, pickup subclasses that we found before their superclasses ProcessChildren(classMappings); } // generate source files for (IEnumerator iterator = generators.GetEnumerator(); iterator.MoveNext();) { Generator g = (Generator)iterator.Current; g.BaseDirName = outputDir ?? ".\\"; g.Generate(classMappings, fileCreationObserver, cmdLine.CheckTime != null); } }