| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package uk.co.badgersinfoil.asxsd; |
| 6 |
|
|
| 7 |
|
import java.util.HashMap; |
| 8 |
|
import java.util.Map; |
| 9 |
|
import org.eclipse.xsd.XSDComplexTypeDefinition; |
| 10 |
|
import org.eclipse.xsd.XSDElementDeclaration; |
| 11 |
|
import org.eclipse.xsd.XSDParticle; |
| 12 |
|
import org.eclipse.xsd.XSDSimpleTypeDefinition; |
| 13 |
|
import org.eclipse.xsd.XSDTypeDefinition; |
| 14 |
|
import uk.co.badgersinfoil.metaas.dom.ASClassType; |
| 15 |
|
import uk.co.badgersinfoil.metaas.dom.ASCompilationUnit; |
| 16 |
|
|
| 17 |
|
|
| 18 |
|
public class TypeBuilder { |
| 19 |
|
|
| 20 |
|
private static final String KEY_CURRENT_TYPE_COMPILATION_UNIT = "uk.co.badgersinfoil.asxsd.currentTypeCompilationUnit"; |
| 21 |
|
TypeNameGenerator nameGen; |
| 22 |
15 |
private Map representationClassesByQName = new HashMap(); |
| 23 |
|
|
| 24 |
|
private CodegenContext context; |
| 25 |
|
|
| 26 |
15 |
public TypeBuilder(CodegenContext context, TypeNameGenerator nameGen) { |
| 27 |
15 |
this.nameGen = nameGen; |
| 28 |
15 |
this.context = context; |
| 29 |
15 |
} |
| 30 |
|
|
| 31 |
|
public String typeNameFor(XSDTypeDefinition typeDef) { |
| 32 |
34 |
return nameGen.typeName(typeDef); |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
public static ASCompilationUnit getCurrentTypeCompilationUnit(CodegenContext context) { |
| 36 |
81 |
ASCompilationUnit result = (ASCompilationUnit)context.getAttribute(KEY_CURRENT_TYPE_COMPILATION_UNIT); |
| 37 |
81 |
if (result == null) { |
| 38 |
0 |
throw new IllegalStateException("No current compilation unit"); |
| 39 |
|
} |
| 40 |
81 |
return result; |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
public static ASClassType getCurrentType(CodegenContext context) { |
| 44 |
78 |
return (ASClassType)getCurrentTypeCompilationUnit(context).getType(); |
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
public static void setCurrentTypeCompilationUnit(CodegenContext context, ASCompilationUnit unit) { |
| 48 |
20 |
context.setAttribute(KEY_CURRENT_TYPE_COMPILATION_UNIT, unit); |
| 49 |
20 |
} |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
private void processComplexType(XSDComplexTypeDefinition typeDef) { |
| 56 |
0 |
context.setCurrentRole(CodegenRole.TYPE); |
| 57 |
0 |
context.generateCode(typeDef); |
| 58 |
0 |
} |
| 59 |
|
} |