Author: max.andersen(a)jboss.com
Date: 2008-01-28 06:33:12 -0500 (Mon, 28 Jan 2008)
New Revision: 14293
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateProducer.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java
Log:
Put info about what root element is being processed in the exceptions.
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java 2008-01-26
22:24:52 UTC (rev 14292)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java 2008-01-28
11:33:12 UTC (rev 14293)
@@ -10,6 +10,7 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.Component;
+import org.hibernate.mapping.PersistentClass;
import org.hibernate.tool.hbm2x.pojo.ComponentPOJOClass;
import org.hibernate.tool.hbm2x.pojo.POJOClass;
import org.hibernate.util.StringHelper;
@@ -27,7 +28,8 @@
void process(GenericExporter ge) {
TemplateProducer producer = new
TemplateProducer(ge.getTemplateHelper(),ge.getArtifactCollector());
- producer.produce(new HashMap(), ge.getTemplateName(), new
File(ge.getOutputDirectory(),ge.filePattern), ge.templateName);
+ producer.produce(new HashMap(), ge.getTemplateName(), new
File(ge.getOutputDirectory(),ge.filePattern), ge.templateName,
"Configuration");
+
}
});
@@ -37,8 +39,8 @@
Iterator iterator =
ge.getCfg2JavaTool().getPOJOIterator(ge.getConfiguration().getClassMappings());
Map additionalContext = new HashMap();
while ( iterator.hasNext() ) {
- POJOClass element = (POJOClass) iterator.next();
- ge.exportPersistentClass( additionalContext, element );
+ POJOClass element = (POJOClass) iterator.next();
+ ge.exportPersistentClass( additionalContext, element );
}
}
});
@@ -58,7 +60,7 @@
while ( iterator.hasNext() ) {
Component component = (Component) iterator.next();
ComponentPOJOClass element = new
ComponentPOJOClass(component,ge.getCfg2JavaTool());
- ge.exportComponent( additionalContext, element );
+ ge.exportComponent( additionalContext, element );
}
}
});
@@ -143,7 +145,7 @@
if(filename.endsWith(".java") && filename.indexOf('$')>=0)
{
log.warn("Filename for " + getClassNameForFile( element ) + " contains
a $. Innerclass generation is not supported.");
}
- producer.produce(additionalContext, getTemplateName(), new
File(getOutputDirectory(),filename), templateName);
+ producer.produce(additionalContext, getTemplateName(), new
File(getOutputDirectory(),filename), templateName, element.toString());
}
protected String resolveFilename(POJOClass element) {
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java 2008-01-26
22:24:52 UTC (rev 14292)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java 2008-01-28
11:33:12 UTC (rev 14293)
@@ -39,7 +39,7 @@
Configuration cfg = getConfiguration();
if(c2h.isImportData(cfg) && (c2h.isNamedQueries(cfg)) &&
(c2h.isNamedSQLQueries(cfg)) && (c2h.isFilterDefinitions(cfg))) {
TemplateProducer producer = new
TemplateProducer(getTemplateHelper(),getArtifactCollector());
- producer.produce(new HashMap(), "hbm/generalhbm.hbm.ftl", new
File(getOutputDirectory(),"GeneralHbmSettings.hbm.xml"), getTemplateName());
+ producer.produce(new HashMap(), "hbm/generalhbm.hbm.ftl", new
File(getOutputDirectory(),"GeneralHbmSettings.hbm.xml"), getTemplateName(),
"General Settings");
}
}
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java 2008-01-26
22:24:52 UTC (rev 14292)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java 2008-01-28
11:33:12 UTC (rev 14293)
@@ -245,19 +245,23 @@
}
/** look up the template named templateName via the paths and print the content to
the output */
- public void processTemplate(String templateName, Writer output) {
+ public void processTemplate(String templateName, Writer output, String rootContext)
{
+ if(rootContext == null) {
+ rootContext = "Unknown context";
+ }
+
try {
Template template = freeMarkerEngine.getTemplate(templateName);
template.process(getContext(), output);
}
catch (IOException e) {
- throw new ExporterException("Error while processing template " +
templateName, e);
+ throw new ExporterException("Error while processing " + rootContext
+ " with template " + templateName, e);
}
- catch (TemplateException te) {
- throw new ExporterException("Error while processing template " +
templateName, te);
+ catch (TemplateException te) {
+ throw new ExporterException("Error while processing " + rootContext +
" with template " + templateName, te);
}
catch (Exception e) {
- throw new ExporterException("Error while processing template " +
templateName, e);
+ throw new ExporterException("Error while processing " + rootContext +
" with template " + templateName, e);
}
}
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateProducer.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateProducer.java 2008-01-26
22:24:52 UTC (rev 14292)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateProducer.java 2008-01-28
11:33:12 UTC (rev 14293)
@@ -23,9 +23,9 @@
this.ac = ac;
}
- void produce(Map additionalContext, String templateName, File destination, String
identifier, String fileType) {
+ public void produce(Map additionalContext, String templateName, File destination, String
identifier, String fileType, String rootContext) {
- String tempResult = produceToString( additionalContext, templateName );
+ String tempResult = produceToString( additionalContext, templateName, rootContext );
if(tempResult.trim().length()==0) {
log.warn("Generated output is empty. Skipped creation for file " +
destination);
@@ -58,13 +58,13 @@
}
- private String produceToString(Map additionalContext, String templateName) {
+ private String produceToString(Map additionalContext, String templateName, String
rootContext) {
Map contextForFirstPass = additionalContext;
putInContext( th, contextForFirstPass );
StringWriter tempWriter = new StringWriter();
BufferedWriter bw = new BufferedWriter(tempWriter);
// First run - writes to in-memory string
- th.processTemplate(templateName, bw);
+ th.processTemplate(templateName, bw, rootContext);
removeFromContext( th, contextForFirstPass );
try {
bw.flush();
@@ -94,6 +94,12 @@
public void produce(Map additionalContext, String templateName, File outputFile, String
identifier) {
String fileType = outputFile.getName();
fileType = fileType.substring(fileType.indexOf('.')+1);
- produce(additionalContext, templateName, outputFile, identifier, fileType);
+ produce(additionalContext, templateName, outputFile, identifier, fileType, null);
}
+
+ public void produce(Map additionalContext, String templateName, File outputFile, String
identifier, String rootContext) {
+ String fileType = outputFile.getName();
+ fileType = fileType.substring(fileType.indexOf('.')+1);
+ produce(additionalContext, templateName, outputFile, identifier, fileType,
rootContext);
+ }
}
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java 2008-01-26
22:24:52 UTC (rev 14292)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java 2008-01-28
11:33:12 UTC (rev 14293)
@@ -153,7 +153,7 @@
}
public String toString() {
- return getClass().getName() + "(" +
(clazz==null?"<none>":clazz.getComponentClassName()) + ")";
+ return "Component: " +
(clazz==null?"<none>":clazz.getComponentClassName());
}
public Property getIdentifierProperty(){
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2008-01-26
22:24:52 UTC (rev 14292)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2008-01-28
11:33:12 UTC (rev 14293)
@@ -815,7 +815,7 @@
public String toString() {
- return getClass().getName() + "(" +
(clazz==null?"<none>":clazz.getEntityName()) + ")";
+ return "Entity: " +
(clazz==null?"<none>":clazz.getEntityName());
}
public boolean hasVersionProperty() {
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java 2008-01-26
22:24:52 UTC (rev 14292)
+++
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java 2008-01-28
11:33:12 UTC (rev 14293)
@@ -135,7 +135,43 @@
e.printStackTrace();
}
}
-
+
+ public void testForEachWithExceptionGeneration() {
+
+ GenericExporter ge = new GenericExporter();
+ ge.setConfiguration(getCfg());
+ ge.setOutputDirectory(getOutputDir());
+ ge.setTemplateName("generictemplates/generic-exception.ftl");
+ ge.setFilePattern("{package-name}/generic{class-name}.txt");
+
+ try {
+ ge.setForEach("entity");
+ ge.start();
+ fail();
+ } catch(ExporterException e) {
+ assertTrue(e.getMessage().startsWith("Error while processing Entity:
HelloWorld"));
+ }
+
+
+ try {
+ ge.setForEach("component");
+ ge.start();
+ fail();
+ } catch(ExporterException e) {
+ assertTrue(e.getMessage().startsWith("Error while processing Component:
UniversalAddress"));
+ }
+
+ try {
+ ge.setForEach("configuration");
+ ge.start();
+ fail();
+ } catch(ExporterException e) {
+ assertTrue(e.getMessage().startsWith("Error while processing
Configuration"));
+ }
+
+
+ }
+
public void testPropertySet() throws FileNotFoundException, IOException {
GenericExporter ge = new GenericExporter();
ge.setConfiguration(getCfg());