LPP-10129 bug fixing
Frank Guo <fguo <at> laszlosystems.com>
2012-02-03 10:34:59 GMT
Summary: Fix lazyreplicator.insertNode(), classroot
New Features:
Bugs Fixed: LPP-10129
Documentation:
Release Notes:
Overview:
when compiling file include user type definition to lzo,
there are some generated code out side
the XML.
Details:
TypeCompiler.java
It is because the TypeCompiler generate the lzs code when it
resolve the type element.
The moment is too early, so the lzs code for user
type declaration will appear at the top of lzo file.
But the compile method of TypeCompiler is empty, so it will not
generate any code, when compile the type element.
Files:
M
WEB-INF/lps/server/src/org/openlaszlo/compiler/TypeCompiler.java
M
WEB-INF/lps/server/src/org/openlaszlo/compiler/ViewSchema.java
After tracing the OL code, I found the reason of LPP-10129, the
lzo problem.
It is because the TypeCompiler generate the lzs code when resolve
the the type element.
The moment is too early, so the lzs code for user
type declaration will appear at the top of lzo file.
But the compile method of TypeCompiler is empty, so it will not
generate any code, when compile the type element.
I read the code of ClassCompiler, use the idea of it. I added the
content of compile method of TypeCompiler, move the code that can
generate lzs code from resolve method to compile method.
After some basic test, I found it works well. Do you think we can
fix the bug like this.
I attach the file I had changed, I add a method to ViewSchema
class, to get Type Class model.
thanks
frank
Index: compiler/TypeCompiler.java
===================================================================
--- compiler/TypeCompiler.java (revision 19507)
+++ compiler/TypeCompiler.java (working copy)
@@ -47,10 +47,15 @@
@Override
public ClassModel resolve(CompilationEnvironment env)
- throws CompilationError
- {
+ throws CompilationError {
+
if (resolved) { return this; }
resolved = true;
+ return this;
+ }
+
+ protected void compile(CompilationEnvironment env, boolean force) {
+
String typename = XMLUtils.requireAttributeValue(definition, "name");
LinkedHashMap<String, Object> instanceAttributes = new LinkedHashMap<String, Object>();
LinkedHashMap<String, Object> classAttributes = new LinkedHashMap<String, Object>();
@@ -70,12 +75,11 @@
"The tag '" + childName + "' cannot be used as a child of <type>", definition);
}
}
- classAttributes.put("lzxtype", ScriptCompiler.quote(typename));
+ classAttributes.put("lzxtype", ScriptCompiler.quote(typename));
ScriptClass scriptClass = new ScriptClass(className, "$lz$class_PresentationType", null,
instanceAttributes, classAttributes, "", "class");
env.compileScript(scriptClass.toString(), definition);
env.compileScript("lz.Type.addType('" + typename + "', new " + className + "());");
- return this;
- }
+ }
}
/**
@@ -103,8 +107,18 @@
}
@Override
- public void compile(Element element)
- {
+ public void compile(Element element) {
+
+ String tagName = element.getAttributeValue("name");
+ if (tagName.equals("anonymous")) {
+ CompilationError cerr = new CompilationError(
+ "The type 'anonymous' is reserved for system use, please choose another class name"
+ , element);
+ throw(cerr);
+ }
+
+ ClassModel classModel = mEnv.getSchema().getInstanceTypeClassModel(element);
+ classModel.compile(mEnv, true);
}
}
Index: compiler/ViewSchema.java
===================================================================
--- compiler/ViewSchema.java (revision 19507)
+++ compiler/ViewSchema.java (working copy)
@@ -19,6 +19,7 @@
import org.jdom.Element;
import org.jdom.JDOMException;
import org.openlaszlo.xml.internal.Schema;
+import org.openlaszlo.xml.internal.XMLUtils;
import org.openlaszlo.utils.ChainedException;
import org.openlaszlo.server.*;
@@ -341,6 +342,16 @@
}
return model;
}
+
+ ClassModel getInstanceTypeClassModel(Element element) {
+ String kind = KIND_TYPE;
+ String typename = XMLUtils.requireAttributeValue(element, "name");
+ ClassModel model = getClassModel(kind, typename);
+ if (model == null ) {
+ throw new CompilationError("no type"+typename, element);
+ }
+ return model;
+ }
ClassModel getInstanceClassModel(Element element) {
return getInstanceClassModel(element, true);