<html>
<head>
<style><!--
body {background-color:#ffffff;}
.file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
.pathname {font-family:monospace; float:right;}
.fileheader {margin-bottom:.5em;}
.diff {margin:0;}
.tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
.tasklist ul {margin-top:0;margin-bottom:0;}
tr.alt {background-color:#eeeeee}
#added {background-color:#ddffdd;}
#addedchars {background-color:#99ff99;font-weight:bolder;}
tr.alt #added {background-color:#ccf7cc;}
#removed {background-color:#ffdddd;}
#removedchars {background-color:#ff9999;font-weight:bolder;}
tr.alt #removed {background-color:#f7cccc;}
#copied {background-color:#ccccff;}
tr.alt #copied {background-color:#bbbbf7;}
#info {color:#888888;}
#context {background-color:#eeeeee;}
td {padding-left:.3em;padding-right:.3em;}
tr.head {border-bottom-width:1px;border-bottom-style:solid;}
tr.head td {padding:0;padding-top:.2em;}
.task {background-color:#ffff00;}
.comment {white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;padding:4px;border:1px dashed #000000;background-color:#ffffdd}
.error {color:red;}
hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="5">Commit in <b><tt>asxsd/trunk/src</tt></b></td></tr>
<tr><td><tt>main/java/uk/co/badgersinfoil/asxsd/<a href="#file1">BaseCodegenContext.java</a></tt> </td><td></td><td align="right" id="added">+12</td><td align="right" id="removed">-9</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt> /<a href="#file2">BasicMappingFunction.java</a></tt> </td><td></td><td align="right" id="added">+7</td><td align="right" id="removed">-14</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td><tt> /<a href="#file3">CodegenContext.java</a></tt> </td><td></td><td align="right" id="added">+3</td><td align="right" id="removed">-1</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt> /<a href="#file4">CodegenRole.java</a></tt> </td><td></td><td align="right" id="added">+2</td><td align="right" id="removed">-1</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td><tt> /<a href="#file5">MappingCodeGenerator.java</a></tt> </td><td></td><td align="right" id="added">+2</td><td align="right" id="removed">-2</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt> /<a href="#file6">MappingComponent.java</a></tt> </td><td></td><td align="right" id="added">+3</td><td align="right" id="removed">-1</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td><tt> /<a href="#file7">MappingFunction.java</a></tt> </td><td></td><td align="right" id="added">+1</td><td></td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt> /<a href="#file8">MarshalBuilder.java</a></tt> </td><td></td><td align="right" id="added">+7</td><td align="right" id="removed">-46</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td><tt> /<a href="#file9">UnmarshalBuilder.java</a></tt> </td><td></td><td align="right" id="added">+1</td><td align="right" id="removed">-58</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt>main/java/uk/co/badgersinfoil/asxsd/components/<a href="#file10">AbstractMappingComponent.java</a></tt> </td><td></td><td align="right" id="added">+9</td><td align="right" id="removed">-1</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td><tt> /<a href="#file11">AbstractParticleComponent.java</a></tt> </td><td></td><td align="right" id="added">+5</td><td align="right" id="removed">-1</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt> /<a href="#file12">AbstractSimpleTypeComponent.java</a></tt> </td><td></td><td align="right" id="added">+70</td><td align="right" id="removed">-3</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td><tt> /<a href="#file13">ArrayElementDeclarationComponent.java</a></tt> </td><td></td><td align="right" id="added">+47</td><td align="right" id="removed">-2</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt> /<a href="#file14">ArrayTypeDeclarationComponent.java</a></tt> </td><td></td><td align="right" id="added">+3</td><td align="right" id="removed">-3</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td><tt> /<a href="#file15">ChoiceMappingComponent.java</a></tt> </td><td></td><td align="right" id="added">+52</td><td align="right" id="removed">-35</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt> /<a href="#file16">ComplexTypeComponent.java</a></tt> </td><td></td><td align="right" id="added">+69</td><td align="right" id="removed">-5</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td><tt> /<a href="#file17">ElementDeclarationComponent.java</a></tt> </td><td></td><td align="right" id="added">+81</td><td align="right" id="removed">-23</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt> /<a href="#file18">ElementDeclarationReferenceComponent.java</a></tt> </td><td></td><td align="right" id="added">+12</td><td align="right" id="removed">-5</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td><tt> /<a href="#file19">IdentityMappingFunction.java</a></tt> </td><td></td><td align="right" id="added">+3</td><td></td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt> /<a href="#file20">MultiplyOccuringParticleComponent.java</a></tt> </td><td></td><td align="right" id="added">+18</td><td align="right" id="removed">-11</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td><tt> /<a href="#file21">OptionallyOccuringParticleComponent.java</a></tt> </td><td></td><td align="right" id="added">+44</td><td align="right" id="removed">-27</td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr class="alt"><td><tt>test/resources/xsd/<a href="#file22">OptionalChoiceInSequenceTest.xsd</a></tt> </td><td></td><td align="right" id="added">+4</td><td></td><td nowrap="nowrap" align="center">163 -> 164</td></tr>
<tr><td></td><td></td><td align="right" id="added">+455</td><td align="right" id="removed">-248</td><td></td></tr>
</table>
<small id="info">22 modified files</small><br />
<div class="tasklist"><ul>
<li><a href="#task1">TODO: don't strictly need to test that there are remaining elements if we know there should be mandatory elements following this optional one,</a></li>
</ul></div>
<pre class="comment">
sanitise the method-creation code, pushing most of it into the component framework in the process
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd</span><br />
<div class="fileheader"><big><b>BaseCodegenContext.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/BaseCodegenContext.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/BaseCodegenContext.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -11,6 +11,7 @@
</small></pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.ActionScriptFactory;
import uk.co.badgersinfoil.metaas.ActionScriptProject;
import uk.co.badgersinfoil.metaas.dom.ASExpression;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.ASMethod;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.StatementContainer;
public class BaseCodegenContext implements CodegenContext {
</pre><pre class="diff"><small id="info">@@ -84,18 +85,15 @@
</small></pre><pre class="diff" id="context">                 CodegenRole role = getCurrentRole();
                MappingFunction convert = functionStore.get(role, component);
                if (convert == null) {
</pre><pre class="diff" id="removed">-                        pushAttrScope();
-                        convert = createFunction(component);
-                        if (convert.getImplementation() == null) {
-                                throw new RuntimeException("null fn for "+component);
-                        }
</pre><pre class="diff" id="added">+//                        pushAttrScope();
+                        convert = createFunctionRef(component);
</pre><pre class="diff" id="context">                         functionStore.put(role, component, convert);
                        // now that we've got a ref to the method in the map,
                        // its safe to generate the method body without the
                        // potential for infinite recursion,
</pre><pre class="diff" id="removed">-                        setCurrentMethodCode(convert.getImplementation());
-                        generateCode(component);
-                        popAttrScope();
</pre><pre class="diff" id="added">+                        ASMethod impl = createFunction(component);
+                        convert.setImplementation(impl);
+//                        popAttrScope();
</pre><pre class="diff" id="context">                 }
                return convert;
        }
</pre><pre class="diff"><small id="info">@@ -126,8 +124,13 @@
</small></pre><pre class="diff" id="context">                 setAttribute(KEY_CODE, code);
        }
</pre><pre class="diff" id="removed">-        public MappingFunction createFunction(XSDConcreteComponent component) {
</pre><pre class="diff" id="added">+        public MappingFunction createFunction<span id="addedchars">Ref</span>(XSDConcreteComponent component) {
</pre><pre class="diff" id="context">                 MappingComponent mapComp = componentFor(component);
</pre><pre class="diff" id="added">+                return mapComp.createFunctionRef(this, component);
+        }
+
+        public ASMethod createFunction(XSDConcreteComponent component) {
+                MappingComponent mapComp = componentFor(component);
</pre><pre class="diff" id="context">                 return mapComp.createFunction(this, component);
        }
</pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd</span><br />
<div class="fileheader"><big><b>BasicMappingFunction.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/BasicMappingFunction.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/BasicMappingFunction.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -4,33 +4,26 @@
</small></pre><pre class="diff" id="context">
package uk.co.badgersinfoil.asxsd;
</pre><pre class="diff" id="removed">-import uk.co.badgersinfoil.metaas.dom.ASCompilationUnit;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.ASMethod;
public class BasicMappingFunction implements MappingFunction {
        
</pre><pre class="diff" id="removed">-        private ASCompilationUnit unit;
</pre><pre class="diff" id="added">+        private String qname;
</pre><pre class="diff" id="context">         private ASMethod impl;
</pre><pre class="diff" id="removed">-        public BasicMappingFunction(ASCompilationUnit unit, ASMethod impl) {
-                this.unit = unit;
-                this.impl = impl;
</pre><pre class="diff" id="added">+        public BasicMappingFunction(String qname) {
+                this.qname = qname;
</pre><pre class="diff" id="context">         }
        public String appliedTo(String accessExpr) {
</pre><pre class="diff" id="removed">-                return qualifiedMethodName() + "(" + accessExpr + ")";
</pre><pre class="diff" id="added">+                return qname + "(" + accessExpr + ")";
</pre><pre class="diff" id="context">         }
</pre><pre class="diff" id="added">+        public void setImplementation(ASMethod impl) {
+                this.impl = impl;
+        }
</pre><pre class="diff" id="context">         public ASMethod getImplementation() {
                return impl;
        }
</pre><pre class="diff" id="removed">-
-        private String qualifiedMethodName() {
-                String pkgName = unit.getPackageName();
-                if (pkgName == null) {
-                        return unit.getType().getName() + "." + impl.getName();
-                }
-                return pkgName + "." + unit.getType().getName() + "." + impl.getName();
-        }
</pre><pre class="diff" id="context"> }
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file3" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd</span><br />
<div class="fileheader"><big><b>CodegenContext.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/CodegenContext.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/CodegenContext.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -4,6 +4,7 @@
</small></pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.ActionScriptFactory;
import uk.co.badgersinfoil.metaas.ActionScriptProject;
import uk.co.badgersinfoil.metaas.dom.ASExpression;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.ASMethod;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.StatementContainer;
public interface CodegenContext {
</pre><pre class="diff"><small id="info">@@ -25,7 +26,8 @@
</small></pre><pre class="diff" id="context">
        public MappingFunction functionFor(XSDConcreteComponent component);
</pre><pre class="diff" id="removed">-        public MappingFunction createFunction(XSDConcreteComponent component);
</pre><pre class="diff" id="added">+        public MappingFunction createFunction<span id="addedchars">Ref</span>(XSDConcreteComponent component);
+        public ASMethod createFunction(XSDConcreteComponent component);
</pre><pre class="diff" id="context">
        public MappingFunction getOrCreateFunction(XSDConcreteComponent component);
</pre></div>
<hr /><a name="file4" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd</span><br />
<div class="fileheader"><big><b>CodegenRole.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/CodegenRole.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/CodegenRole.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -14,7 +14,8 @@
</small></pre><pre class="diff" id="context">         public static final CodegenRole UNMARSHAL = new CodegenRole("UNMARSHAL");
        public static final CodegenRole MARSHAL = new CodegenRole("MARSHAL");
        public static final CodegenRole TYPE = new CodegenRole("TYPE");
</pre><pre class="diff" id="removed">-        public static final CodegenRole DETECT = new CodegenRole("DETECT");
</pre><pre class="diff" id="added">+        public static final CodegenRole UNMARSHAL_DETECT = new CodegenRole("UNMARSHAL_DETECT");
+        public static final CodegenRole MARSHAL_DETECT = new CodegenRole("MARSHAL_DETECT");
</pre><pre class="diff" id="context">
        public String toString() { return name; }
}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file5" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd</span><br />
<div class="fileheader"><big><b>MappingCodeGenerator.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/MappingCodeGenerator.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/MappingCodeGenerator.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -30,10 +30,10 @@
</small></pre><pre class="diff" id="context">                 typeBuilder = new TypeBuilder(ctxt, nameGen);
                ctxt.setTypeBuilder(typeBuilder);
</pre><pre class="diff" id="removed">-                unmarshalerBuilder = new UnmarshalBuilder(project, <span id="removedchars">typeBuilder, </span>ctxt);
</pre><pre class="diff" id="added">+                unmarshalerBuilder = new UnmarshalBuilder(project, ctxt);
</pre><pre class="diff" id="context">                 ctxt.setUnmarshalBuilder(unmarshalerBuilder);
</pre><pre class="diff" id="removed">-                marshalerBuilder = new MarshalBuilder(project, <span id="removedchars">typeBuilder, </span>ctxt);
</pre><pre class="diff" id="added">+                marshalerBuilder = new MarshalBuilder(project, ctxt);
</pre><pre class="diff" id="context">                 ctxt.setMarshalBuilder(marshalerBuilder);
                context = ctxt;
        }
</pre></div>
<hr /><a name="file6" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd</span><br />
<div class="fileheader"><big><b>MappingComponent.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/MappingComponent.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/MappingComponent.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -6,6 +6,7 @@
</small></pre><pre class="diff" id="context">
import org.eclipse.xsd.XSDConcreteComponent;
import uk.co.badgersinfoil.metaas.dom.ASExpression;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.ASMethod;
</pre><pre class="diff" id="context">
public interface MappingComponent {
</pre><pre class="diff"><small id="info">@@ -14,7 +15,8 @@
</small></pre><pre class="diff" id="context">         public String createTypeNameFor(CodegenContext context, XSDConcreteComponent component);
        public void generateCode(CodegenContext context, XSDConcreteComponent component);
        public MappingFunction functionFor(CodegenContext context, XSDConcreteComponent component);
</pre><pre class="diff" id="removed">-        public MappingFunction createFunction(CodegenContext context, XSDConcreteComponent component);
</pre><pre class="diff" id="added">+        public MappingFunction createFunction<span id="addedchars">Ref</span>(CodegenContext context, XSDConcreteComponent component);
+        public ASMethod createFunction(CodegenContext context, XSDConcreteComponent component);
</pre><pre class="diff" id="context">         public ASExpression createExpression(CodegenContext context, XSDConcreteComponent component);
        public TypeDescriptor createType(CodegenContext context, XSDConcreteComponent component);
        public String variableNameFor(CodegenContext context, XSDConcreteComponent component);
</pre></div>
<hr /><a name="file7" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd</span><br />
<div class="fileheader"><big><b>MappingFunction.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/MappingFunction.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/MappingFunction.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -12,4 +12,5 @@
</small></pre><pre class="diff" id="context">         public String appliedTo(String accessExpr);
        public ASMethod getImplementation();
</pre><pre class="diff" id="added">+        public void setImplementation(ASMethod impl);
</pre><pre class="diff" id="context"> }
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file8" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd</span><br />
<div class="fileheader"><big><b>MarshalBuilder.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/MarshalBuilder.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/MarshalBuilder.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -16,7 +16,6 @@
</small></pre><pre class="diff" id="context"> import org.eclipse.xsd.XSDTypeDefinition;
import uk.co.badgersinfoil.metaas.ActionScriptProject;
import uk.co.badgersinfoil.metaas.ActionScriptFactory;
</pre><pre class="diff" id="removed">-import uk.co.badgersinfoil.metaas.dom.ASArg;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.ASClassType;
import uk.co.badgersinfoil.metaas.dom.ASCompilationUnit;
import uk.co.badgersinfoil.metaas.dom.ASConstants;
</pre><pre class="diff"><small id="info">@@ -33,13 +32,11 @@
</small></pre><pre class="diff" id="context">
        private Map converterClassesByNamespace = new HashMap();
        private ActionScriptProject project;
</pre><pre class="diff" id="removed">-        private TypeBuilder typeBuilder;
</pre><pre class="diff" id="context">
        private CodegenContext context;
</pre><pre class="diff" id="removed">-        public MarshalBuilder(ActionScriptProject project, <span id="removedchars">TypeBuilder typeBuilder, </span>CodegenContext context) {
</pre><pre class="diff" id="added">+        public MarshalBuilder(ActionScriptProject project, CodegenContext context) {
</pre><pre class="diff" id="context">                 this.project = project;
</pre><pre class="diff" id="removed">-                this.typeBuilder = typeBuilder;
</pre><pre class="diff" id="context">                 this.context = context;
        }
</pre><pre class="diff"><small id="info">@@ -63,29 +60,7 @@
</small></pre><pre class="diff" id="context">                 context.popAttrScope();
        }
</pre><pre class="diff" id="removed">-        private MappingFunction createMethodForType(XSDTypeDefinition typeDef) {
-                ASCompilationUnit unit = getClassForNamespace(typeDef.getTargetNamespace());
-                ASClassType clazz = (ASClassType)unit.getType();
-                String typeName = xmlReturnTypeFor(typeDef);
-                String methodName = methodNameFor(typeDef);
-                ASMethod meth = clazz.newMethod(methodName, Visibility.PUBLIC, typeName);
-                buildMethodParams(meth, typeDef);
-                meth.setStatic(true);
-                return new BasicMappingFunction(unit, meth);
-        }
-
-        private MappingFunction createMethodForElement(XSDElementDeclaration elementDecl) {
-                ASCompilationUnit unit = getClassForNamespace(elementDecl.getTargetNamespace());
-                ASClassType clazz = (ASClassType)unit.getType();
-                String typeName = "XML";
-                String methodName = methodNameFor(elementDecl);
-                ASMethod meth = clazz.newMethod(methodName, Visibility.PUBLIC, typeName);
-                buildMethodParams(meth, elementDecl);
-                meth.setStatic(true);
-                return new BasicMappingFunction(unit, meth);
-        }
-
-        private void buildMethodParams(ASMethod meth, XSDElementDeclaration elementDecl) {
</pre><pre class="diff" id="added">+        public void buildMethodParams(ASMethod meth, XSDElementDeclaration elementDecl) {
</pre><pre class="diff" id="context">                 TypeDescriptor typeDesc = context.getTypeDescriptor(elementDecl);
                if (elementDecl.getType() instanceof XSDComplexTypeDefinition) {
                        meth.addParam("thisObject", typeDesc.getTypeName());
</pre><pre class="diff"><small id="info">@@ -94,7 +69,7 @@
</small></pre><pre class="diff" id="context">                 }
        }
</pre><pre class="diff" id="removed">-        p<span id="removedchars">rivate</span> void buildMethodParams(ASMethod meth, XSDTypeDefinition typeDef) {
</pre><pre class="diff" id="added">+        p<span id="addedchars">ublic</span> void buildMethodParams(ASMethod meth, XSDTypeDefinition typeDef) {
</pre><pre class="diff" id="context">                 TypeDescriptor typeDesc = context.getTypeDescriptor(typeDef);
                if (typeDef instanceof XSDComplexTypeDefinition) {
                        meth.addParam("_result", "XML");
</pre><pre class="diff"><small id="info">@@ -104,20 +79,16 @@
</small></pre><pre class="diff" id="context">                 }
        }
</pre><pre class="diff" id="removed">-        p<span id="removedchars">rivate</span> String methodNameFor(XSDTypeDefinition typeDef) {
</pre><pre class="diff" id="added">+        p<span id="addedchars">ublic</span> String methodNameFor(XSDTypeDefinition typeDef) {
</pre><pre class="diff" id="context">                 return "marshal" + StringUtils.sanitize(typeDef.getName());
        }
</pre><pre class="diff" id="removed">-        private String methodNameFor(XSDElementDeclaration elementDecl) {
-                String name = typeBuilder.nameGen.getNameFor(elementDecl);
-                int pos = name.lastIndexOf('.');
-                if (pos > 0) {
-                        name = name.substring(pos+1);
-                }
</pre><pre class="diff" id="added">+        public String methodNameFor(XSDElementDeclaration elementDecl) {
+                String name = StringUtils.sanitize(elementDecl.getName());
</pre><pre class="diff" id="context">                 return "marshal" + name;
        }
</pre><pre class="diff" id="removed">-        p<span id="removedchars">rivate</span> static String xmlReturnTypeFor(XSDTypeDefinition typeDef) {
</pre><pre class="diff" id="added">+        p<span id="addedchars">ublic</span> static String xmlReturnTypeFor(XSDTypeDefinition typeDef) {
</pre><pre class="diff" id="context">                 if (typeDef instanceof XSDComplexTypeDefinition) {
                        return "XML";
                }
</pre><pre class="diff"><small id="info">@@ -165,16 +136,6 @@
</small></pre><pre class="diff" id="context">                 context.setAttribute(KEY_MARSHAL_CURRENT_TARGET_PARENTELEMENT_EXPR, expr);
        }
</pre><pre class="diff" id="removed">-        public MappingFunction createMethodFor(XSDConcreteComponent namedComponent) {
-                if (namedComponent instanceof XSDElementDeclaration) {
-                        return createMethodForElement((XSDElementDeclaration)namedComponent);
-                }
-                if (namedComponent instanceof XSDTypeDefinition) {
-                        return createMethodForType((XSDTypeDefinition)namedComponent);
-                }
-                throw new IllegalArgumentException(namedComponent.getClass().getName());
-        }
-
</pre><pre class="diff" id="context">         public static void warn(String msg) {
                System.err.println(msg);
        }
</pre></div>
<hr /><a name="file9" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd</span><br />
<div class="fileheader"><big><b>UnmarshalBuilder.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/UnmarshalBuilder.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/UnmarshalBuilder.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -12,15 +12,12 @@
</small></pre><pre class="diff" id="context"> import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDSchema;
</pre><pre class="diff" id="removed">-import org.eclipse.xsd.XSDSimpleTypeDefinition;
</pre><pre class="diff" id="context"> import org.eclipse.xsd.XSDTypeDefinition;
import uk.co.badgersinfoil.metaas.ActionScriptProject;
import uk.co.badgersinfoil.metaas.ActionScriptFactory;
</pre><pre class="diff" id="removed">-import uk.co.badgersinfoil.metaas.dom.ASArg;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.ASClassType;
import uk.co.badgersinfoil.metaas.dom.ASCompilationUnit;
import uk.co.badgersinfoil.metaas.dom.ASField;
</pre><pre class="diff" id="removed">-import uk.co.badgersinfoil.metaas.dom.ASMethod;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.Visibility;
</pre><pre class="diff"><small id="info">@@ -30,13 +27,11 @@
</small></pre><pre class="diff" id="context">         static final String KEY_UNMARSHAL_CURRENT_SOURCE_EXPR = "uk.co.badgersinfoil.asxsd.unmarshal.currentSource.expr";
        private Map converterClassesByNamespace = new HashMap();
        private ActionScriptProject project;
</pre><pre class="diff" id="removed">-        private TypeBuilder typeBuilder;
</pre><pre class="diff" id="context">
        private CodegenContext context;
</pre><pre class="diff" id="removed">-        public UnmarshalBuilder(ActionScriptProject project, <span id="removedchars">TypeBuilder typeBuilder, </span>CodegenContext context) {
</pre><pre class="diff" id="added">+        public UnmarshalBuilder(ActionScriptProject project, CodegenContext context) {
</pre><pre class="diff" id="context">                 this.project = project;
</pre><pre class="diff" id="removed">-                this.typeBuilder = typeBuilder;
</pre><pre class="diff" id="context">                 this.context = context;
        }
</pre><pre class="diff"><small id="info">@@ -59,48 +54,6 @@
</small></pre><pre class="diff" id="context">                 context.popAttrScope();
        }
</pre><pre class="diff" id="removed">-        private MappingFunction createMethodForType(XSDTypeDefinition typeDef) {
-                ASCompilationUnit unit = getClassForNamespace(typeDef.getTargetNamespace());
-                ASClassType clazz = (ASClassType)unit.getType();
-                TypeDescriptor typeDesc = context.getTypeDescriptor(typeDef);
-                String methodName = "unmarshal" + StringUtils.sanitize(typeDef.getName());
-                ASMethod meth = clazz.newMethod(methodName, Visibility.PUBLIC, typeDesc.getTypeName());
-                if (typeDef instanceof XSDSimpleTypeDefinition) {
-                        ASArg arg = meth.addParam("thisValue", "String");
-                        String doc = "a value of type "+typeDef.getURI();
-                        arg.setDescription(doc);
-                }
-                if (typeDef instanceof XSDComplexTypeDefinition) {
-                        ASArg arg = meth.addParam("thisElement", "XML");
-                        String doc = "an element of type "+typeDef.getURI();
-                        arg.setDescription(doc);
-                }
-                meth.setStatic(true);
-                return new BasicMappingFunction(unit, meth);
-        }
-
-        private MappingFunction createMethodForElement(XSDElementDeclaration elementDecl) {
-                ASCompilationUnit unit = getClassForNamespace(elementDecl.getTargetNamespace());
-                ASClassType clazz = (ASClassType)unit.getType();
-                TypeDescriptor typeDesc = context.getTypeDescriptor(elementDecl);
-                String name = typeBuilder.nameGen.getNameFor(elementDecl);
-                int pos = name.lastIndexOf('.');
-                if (pos > 0) {
-                        name = name.substring(pos+1);
-                }
-                String methodName = "unmarshal" + name;
-                ASMethod meth = clazz.newMethod(methodName, Visibility.PUBLIC, typeDesc.getTypeName());
-                ASArg arg = meth.addParam("thisElement", "XML");
-                setCurrentSourceExpr(context, arg.getName());
-                String doc = "a &lt;" + elementDecl.getName()+"/&gt; element";
-                arg.setDescription(doc);
-                if (!elementDecl.isGlobal()) {
-                        meth.setVisibility(Visibility.PRIVATE);
-                }
-                meth.setStatic(true);
-                return new BasicMappingFunction(unit, meth);
-        }
-
</pre><pre class="diff" id="context">         public ASCompilationUnit getClassForNamespace(String namespace) {
                ASCompilationUnit result = (ASCompilationUnit)converterClassesByNamespace.get(namespace);
                if (result == null) {
</pre><pre class="diff"><small id="info">@@ -132,16 +85,6 @@
</small></pre><pre class="diff" id="context">                 context.setAttribute(KEY_UNMARSHAL_CURRENT_SOURCE_EXPR, expr);
        }
</pre><pre class="diff" id="removed">-        public MappingFunction createMethodFor(XSDConcreteComponent namedComponent) {
-                if (namedComponent instanceof XSDElementDeclaration) {
-                        return createMethodForElement((XSDElementDeclaration)namedComponent);
-                }
-                if (namedComponent instanceof XSDTypeDefinition) {
-                        return createMethodForType((XSDTypeDefinition)namedComponent);
-                }
-                throw new IllegalArgumentException(namedComponent.getClass().getName());
-        }
-
</pre><pre class="diff" id="context">         public static void warn(String msg) {
                System.err.println(msg);
        }
</pre></div>
<hr /><a name="file10" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd/components</span><br />
<div class="fileheader"><big><b>AbstractMappingComponent.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/AbstractMappingComponent.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/AbstractMappingComponent.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -12,6 +12,7 @@
</small></pre><pre class="diff" id="context"> import uk.co.badgersinfoil.asxsd.TypeDescriptor;
import uk.co.badgersinfoil.asxsd.XSDUtils;
import uk.co.badgersinfoil.metaas.dom.ASExpression;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.ASMethod;
</pre><pre class="diff" id="context">
public abstract class AbstractMappingComponent implements MappingComponent {
</pre><pre class="diff"><small id="info">@@ -36,7 +37,14 @@
</small></pre><pre class="diff" id="context">                 throw new RuntimeException(getClass().getName()+" does not suppport operation createTypeNameFor(role="+role+") at "+XSDUtils.path(component));
        }
</pre><pre class="diff" id="removed">-        public MappingFunction createFunction(CodegenContext context,
</pre><pre class="diff" id="added">+        public MappingFunction createFunction<span id="addedchars">Ref</span>(CodegenContext context,
+         XSDConcreteComponent component)
+        {
+                CodegenRole role = context.getCurrentRole();
+                throw new RuntimeException(getClass().getName()+" does not suppport operation createFunctionRef(role="+role+") at "+XSDUtils.path(component));
+        }
+
+        public ASMethod createFunction(CodegenContext context,
</pre><pre class="diff" id="context">          XSDConcreteComponent component)
        {
                CodegenRole role = context.getCurrentRole();
</pre></div>
<hr /><a name="file11" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd/components</span><br />
<div class="fileheader"><big><b>AbstractParticleComponent.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/AbstractParticleComponent.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/AbstractParticleComponent.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -8,6 +8,7 @@
</small></pre><pre class="diff" id="context"> import org.eclipse.xsd.XSDParticle;
import uk.co.badgersinfoil.asxsd.CodegenContext;
import uk.co.badgersinfoil.asxsd.CodegenRole;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.asxsd.MarshalBuilder;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.asxsd.TypeDescriptor;
import uk.co.badgersinfoil.metaas.dom.ASExpression;
</pre><pre class="diff"><small id="info">@@ -48,9 +49,12 @@
</small></pre><pre class="diff" id="context">         {
                CodegenRole role = context.getCurrentRole();
                XSDParticle particle = (XSDParticle)component;
</pre><pre class="diff" id="removed">-                if (role == CodegenRole.DETECT) {
</pre><pre class="diff" id="added">+                if (role == CodegenRole.<span id="addedchars">UNMARSHAL_</span>DETECT) {
</pre><pre class="diff" id="context">                         return context.createExpression(particle.getContent());
                }
</pre><pre class="diff" id="added">+                if (role == CodegenRole.MARSHAL_DETECT) {
+                        return context.createExpression(particle.getContent());
+                }
</pre><pre class="diff" id="context">                 return super.createExpression(context, component);
        }
}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file12" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd/components</span><br />
<div class="fileheader"><big><b>AbstractSimpleTypeComponent.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/AbstractSimpleTypeComponent.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/AbstractSimpleTypeComponent.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -6,13 +6,20 @@
</small></pre><pre class="diff" id="context">
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.asxsd.BasicMappingFunction;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.asxsd.CodegenContext;
import uk.co.badgersinfoil.asxsd.CodegenRole;
import uk.co.badgersinfoil.asxsd.MappingFunction;
import uk.co.badgersinfoil.asxsd.MarshalBuilder;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.asxsd.StringUtils;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.asxsd.TypeDescriptor;
import uk.co.badgersinfoil.asxsd.UnmarshalBuilder;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.ASArg;
+import uk.co.badgersinfoil.metaas.dom.ASClassType;
+import uk.co.badgersinfoil.metaas.dom.ASCompilationUnit;
+import uk.co.badgersinfoil.metaas.dom.ASMethod;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.StatementContainer;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.Visibility;
</pre><pre class="diff" id="context">
public abstract class AbstractSimpleTypeComponent extends AbstractMappingComponent {
</pre><pre class="diff"><small id="info">@@ -44,21 +51,81 @@
</small></pre><pre class="diff" id="context">
        protected abstract TypeDescriptor getTypeDescriptorFor(CodegenContext context,
         XSDSimpleTypeDefinition simpleType);
</pre><pre class="diff" id="removed">-        public MappingFunction createFunction(CodegenContext context,
</pre><pre class="diff" id="added">+
+        public MappingFunction createFunctionRef(CodegenContext context,
</pre><pre class="diff" id="context">          XSDConcreteComponent component)
        {
</pre><pre class="diff" id="added">+                XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition)component;
</pre><pre class="diff" id="context">                 CodegenRole role = context.getCurrentRole();
                if (role == CodegenRole.UNMARSHAL) {
                        UnmarshalBuilder builder = context.getUnmarshalBuilder();
</pre><pre class="diff" id="removed">-                        return builder.createMethodFor(component);
</pre><pre class="diff" id="added">+                        ASCompilationUnit unit = builder.getClassForNamespace(simpleType.getTargetNamespace());
+                        ASClassType clazz = (ASClassType)unit.getType();
+                        String methodName = "unmarshal" + StringUtils.sanitize(simpleType.getName());
+                        String qname;
+                        if (unit.getPackageName() != null) {
+                                qname = unit.getPackageName()+"."+clazz.getName()+"."+methodName;
+                        } else {
+                                qname = clazz.getName()+"."+methodName;
+                        }
+                        return new BasicMappingFunction(qname);
</pre><pre class="diff" id="context">                 }
                if (role == CodegenRole.MARSHAL) {
                        MarshalBuilder builder = context.getMarshalBuilder();
</pre><pre class="diff" id="removed">-                        return builder.createMethodFor(component);
</pre><pre class="diff" id="added">+                        ASCompilationUnit unit = builder.getClassForNamespace(simpleType.getTargetNamespace());
+                        ASClassType clazz = (ASClassType)unit.getType();
+                        String methodName = builder.methodNameFor(simpleType);
+                        String qname;
+                        if (unit.getPackageName() != null) {
+                                qname = unit.getPackageName()+"."+clazz.getName()+"."+methodName;
+                        } else {
+                                qname = clazz.getName()+"."+methodName;
+                        }
+                        return new BasicMappingFunction(qname);
</pre><pre class="diff" id="context">                 }
                throw new IllegalArgumentException(getClass().getName() + " does not support role "+role);
        }
</pre><pre class="diff" id="added">+        public ASMethod createFunction(CodegenContext context,
+         XSDConcreteComponent component)
+        {
+                XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition)component;
+                CodegenRole role = context.getCurrentRole();
+                if (role == CodegenRole.UNMARSHAL) {
+                        UnmarshalBuilder builder = context.getUnmarshalBuilder();
+                        ASCompilationUnit unit = builder.getClassForNamespace(simpleType.getTargetNamespace());
+                        ASClassType clazz = (ASClassType)unit.getType();
+                        TypeDescriptor typeDesc = context.getTypeDescriptor(simpleType);
+                        String methodName = "unmarshal" + StringUtils.sanitize(simpleType.getName());
+                        ASMethod meth = clazz.newMethod(methodName, Visibility.PUBLIC, typeDesc.getTypeName());
+                        ASArg arg = meth.addParam("thisValue", "String");
+                        String doc = "a value of type "+simpleType.getURI();
+                        arg.setDescription(doc);
+                        meth.setStatic(true);
+                        context.pushAttrScope();
+                        context.setCurrentMethodCode(meth);
+                        context.generateCode(simpleType);
+                        context.popAttrScope();
+                        return meth;
+                }
+                if (role == CodegenRole.MARSHAL) {
+                        MarshalBuilder builder = context.getMarshalBuilder();
+                        ASCompilationUnit unit = builder.getClassForNamespace(simpleType.getTargetNamespace());
+                        ASClassType clazz = (ASClassType)unit.getType();
+                        String typeName = MarshalBuilder.xmlReturnTypeFor(simpleType);
+                        String methodName = builder.methodNameFor(simpleType);
+                        ASMethod meth = clazz.newMethod(methodName, Visibility.PUBLIC, typeName);
+                        builder.buildMethodParams(meth, simpleType);
+                        meth.setStatic(true);
+                        context.pushAttrScope();
+                        context.setCurrentMethodCode(meth);
+                        context.generateCode(simpleType);
+                        context.popAttrScope();
+                        return meth;
+                }
+                return super.createFunction(context, component);
+        }
+
</pre><pre class="diff" id="context">         public boolean willAccept(XSDConcreteComponent component) {
                return component instanceof XSDSimpleTypeDefinition
                 && willAcceptType((XSDSimpleTypeDefinition)component);
</pre></div>
<hr /><a name="file13" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd/components</span><br />
<div class="fileheader"><big><b>ArrayElementDeclarationComponent.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/ArrayElementDeclarationComponent.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/ArrayElementDeclarationComponent.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -6,18 +6,22 @@
</small></pre><pre class="diff" id="context">
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDElementDeclaration;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.asxsd.BasicMappingFunction;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.asxsd.CodegenContext;
import uk.co.badgersinfoil.asxsd.CodegenRole;
import uk.co.badgersinfoil.asxsd.MappingFunction;
import uk.co.badgersinfoil.asxsd.MarshalBuilder;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.asxsd.StringUtils;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.asxsd.TypeBuilder;
import uk.co.badgersinfoil.asxsd.TypeDescriptor;
import uk.co.badgersinfoil.asxsd.UnmarshalBuilder;
import uk.co.badgersinfoil.asxsd.XSDUtils;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.ASArg;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.ASClassType;
import uk.co.badgersinfoil.metaas.dom.ASCompilationUnit;
import uk.co.badgersinfoil.metaas.dom.ASConstants;
import uk.co.badgersinfoil.metaas.dom.ASField;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.ASMethod;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.StatementContainer;
import uk.co.badgersinfoil.metaas.dom.Visibility;
</pre><pre class="diff"><small id="info">@@ -76,17 +80,58 @@
</small></pre><pre class="diff" id="context">                 }
        }
</pre><pre class="diff" id="removed">-        public MappingFunction createFunction(CodegenContext context,
</pre><pre class="diff" id="added">+        public MappingFunction createFunction<span id="addedchars">Ref</span>(CodegenContext context,
</pre><pre class="diff" id="context">          XSDConcreteComponent component)
        {
</pre><pre class="diff" id="added">+                XSDElementDeclaration elementDecl = (XSDElementDeclaration)component;
</pre><pre class="diff" id="context">                 CodegenRole role = context.getCurrentRole();
                if (role == CodegenRole.UNMARSHAL) {
                        UnmarshalBuilder builder = context.getUnmarshalBuilder();
</pre><pre class="diff" id="removed">-                        return builder.createMethodFor(component);
</pre><pre class="diff" id="added">+                        ASCompilationUnit unit = builder.getClassForNamespace(elementDecl.getTargetNamespace());
+                        ASClassType clazz = (ASClassType)unit.getType();
+                        String name = StringUtils.sanitize(elementDecl.getName());
+                        String methodName = "unmarshal" + name;
+                        String qname;
+                        if (unit.getPackageName() != null) {
+                                qname = unit.getPackageName()+"."+clazz.getName()+"."+methodName;
+                        } else {
+                                qname = clazz.getName()+"."+methodName;
+                        }
+                        return new BasicMappingFunction(qname);
</pre><pre class="diff" id="context">                 }
                throw new IllegalArgumentException(getClass().getName() + " does not support role "+role);
        }
</pre><pre class="diff" id="added">+        public ASMethod createFunction(CodegenContext context,
+         XSDConcreteComponent component)
+        {
+                XSDElementDeclaration elementDecl = (XSDElementDeclaration)component;
+                CodegenRole role = context.getCurrentRole();
+                if (role == CodegenRole.UNMARSHAL) {
+                        UnmarshalBuilder builder = context.getUnmarshalBuilder();
+                        ASCompilationUnit unit = builder.getClassForNamespace(elementDecl.getTargetNamespace());
+                        ASClassType clazz = (ASClassType)unit.getType();
+                        String name = StringUtils.sanitize(elementDecl.getName());
+                        String methodName = "unmarshal" + name;
+                        TypeDescriptor typeDesc = context.getTypeDescriptor(elementDecl);
+                        ASMethod meth = clazz.newMethod(methodName, Visibility.PUBLIC, typeDesc.getTypeName());
+                        ASArg arg = meth.addParam("thisElement", "XML");
+                        String doc = "a &lt;" + elementDecl.getName()+"/&gt; element";
+                        arg.setDescription(doc);
+                        if (!elementDecl.isGlobal()) {
+                                meth.setVisibility(Visibility.PRIVATE);
+                        }
+                        meth.setStatic(true);
+                        context.pushAttrScope();
+                        context.setCurrentMethodCode(meth);
+                        UnmarshalBuilder.setCurrentSourceExpr(context, arg.getName());
+                        context.generateCode(elementDecl);
+                        context.popAttrScope();
+                        return meth;
+                }
+                return super.createFunction(context, component);
+        }
+
</pre><pre class="diff" id="context">         public String variableNameFor(CodegenContext context,
         XSDConcreteComponent component)
        {
</pre></div>
<hr /><a name="file14" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd/components</span><br />
<div class="fileheader"><big><b>ArrayTypeDeclarationComponent.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/ArrayTypeDeclarationComponent.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/ArrayTypeDeclarationComponent.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -81,13 +81,13 @@
</small></pre><pre class="diff" id="context">                 }
        }
</pre><pre class="diff" id="removed">-        public MappingFunction createFunction(CodegenContext context,
-         XSDConcreteComponent component)
</pre><pre class="diff" id="added">+        public MappingFunction createFunctionRef(CodegenContext context,
+         XSDConcreteComponent component)
</pre><pre class="diff" id="context">         {
                CodegenRole role = context.getCurrentRole();
                if (role == CodegenRole.UNMARSHAL) {
                        UnmarshalBuilder builder = context.getUnmarshalBuilder();
</pre><pre class="diff" id="removed">-                        return builder.createMethodFor(component);
</pre><pre class="diff" id="added">+        //                return builder.createMethodForType((XSDTypeDefinition)component);
</pre><pre class="diff" id="context">                 }
                throw new IllegalArgumentException(getClass().getName() + " does not support role "+role);
        }
</pre></div>
<hr /><a name="file15" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd/components</span><br />
<div class="fileheader"><big><b>ChoiceMappingComponent.java</b></big> <small id="info">163 -> 164</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/ChoiceMappingComponent.java        2007-10-07 22:25:33 UTC (rev 163)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/ChoiceMappingComponent.java        2007-10-12 00:11:29 UTC (rev 164)
@@ -41,13 +41,6 @@
</small></pre><pre class="diff" id="context">                         List particles = modelGroup.getParticles();
                        StatementContainer code = context.getCurrentMethodCode();
                        XSDParticle particle = (XSDParticle)modelGroup.getContainer();
</pre><pre class="diff" id="removed">-                        if (!(particle.getContainer() instanceof XSDNamedComponent)) {
-                                code.addStmt("default xml namespace = NAMESPACE");
-                                TypeDescriptor typeDesc = context.getTypeDescriptor(modelGroup);
-                                code.addStmt("var _result:"+typeDesc.getTypeName()+" = new "+typeDesc.getTypeName()+"()");
-                                UnmarshalBuilder.setCurrentSourceExpr(context, "thisElement");
-                                context.setAttribute("element-access-expression", "thisElement");
-                        }
</pre><pre class="diff" id="context">                         code.addComment(" process choice,");
                        // TODO: could this be expressed as a switch-case rather than a sequence of ifs?
                        for (Iterator i=particles.iterator(); i.hasNext(); ) {
</pre><pre class="diff"><small id="info">@@ -59,9 +52,6 @@
</small></pre><pre class="diff" id="context">                                 context.generateCode(part);
                                context.popAttrScope();
                        }
</pre><pre class="diff" id="removed">-                        if (!(particle.getContainer() instanceof XSDNamedComponent)) {
-                                code.newReturn("_result");
-                        }
</pre><pre class="diff" id="context">                 } else if (role == CodegenRole.MARSHAL) {
                        XSDModelGroup modelGroup = (XSDModelGroup)component;
                        List particles = modelGroup.getParticles();
</pre><pre class="diff"><small id="info">@@ -98,7 +88,7 @@
</small></pre><pre class="diff" id="context">
        private static StatementContainer detectElementContentUnmarshal(CodegenContext context, XSDParticleContent partContent, StatementContainer code) {
                context.pushAttrScope();
</pre><pre class="diff" id="removed">-                context.setCurrentRole(CodegenRole.DETECT);
</pre><pre class="diff" id="added">+                context.setCurrentRole(CodegenRole.<span id="addedchars">UNMARSHAL_</span>DETECT);
</pre><pre class="diff" id="context">                 ASExpression detect = context.createExpression(partContent);
                context.popAttrScope();
                return code.newIf(detect);
</pre><pre class="diff"><small id="info">@@ -122,25 +112,6 @@
</small></pre><pre class="diff" id="context">                         }
                }
        }
</pre><pre class="diff" id="removed">-/*
-        private XSDElementDeclaration findFirstElementDeclaration(XSDParticleContent particleContent) {
-                while (true) {
-                        if (particleContent instanceof XSDElementDeclaration) {
-                                return (XSDElementDeclaration)particleContent;
-                        }
-                        if (particleContent instanceof XSDModelGroup) {
-                                XSDModelGroup modelGroup = (XSDModelGroup)particleContent;
-                                List particles = modelGroup.getParticles();
-                                if (particles.size() > 0) {
-