| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package uk.co.badgersinfoil.asxsd.components; |
| 6 |
|
|
| 7 |
|
import org.eclipse.xsd.XSDConcreteComponent; |
| 8 |
|
import org.eclipse.xsd.XSDSimpleTypeDefinition; |
| 9 |
|
import org.eclipse.xsd.XSDVariety; |
| 10 |
|
import uk.co.badgersinfoil.asxsd.CodegenContext; |
| 11 |
|
import uk.co.badgersinfoil.asxsd.CodegenRole; |
| 12 |
|
import uk.co.badgersinfoil.asxsd.MappingFunction; |
| 13 |
|
import uk.co.badgersinfoil.asxsd.TypeDescriptor; |
| 14 |
|
import uk.co.badgersinfoil.metaas.dom.StatementContainer; |
| 15 |
|
|
| 16 |
|
|
| 17 |
|
public class StringSimpleTypeComponent extends AbstractSimpleTypeComponent { |
| 18 |
|
|
| 19 |
|
private String localName; |
| 20 |
|
private String namespace; |
| 21 |
|
|
| 22 |
106 |
public StringSimpleTypeComponent(String localName, String namespace) { |
| 23 |
106 |
this.localName = localName; |
| 24 |
106 |
this.namespace = namespace; |
| 25 |
106 |
} |
| 26 |
|
|
| 27 |
|
protected TypeDescriptor createTypeDescriptor(CodegenContext context, |
| 28 |
|
XSDSimpleTypeDefinition simpleType) |
| 29 |
|
{ |
| 30 |
20 |
return new TypeDescriptor("String", false, null, simpleType); |
| 31 |
|
} |
| 32 |
|
|
| 33 |
|
public MappingFunction functionFor(CodegenContext context, XSDConcreteComponent component) { |
| 34 |
81 |
return IdentityMappingFunction.INSTANCE; |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
protected boolean willAcceptType(XSDSimpleTypeDefinition simpleType) { |
| 38 |
5464 |
return simpleType.getVariety() == XSDVariety.ATOMIC_LITERAL |
| 39 |
|
&& localName.equals(simpleType.getName()) |
| 40 |
|
&& namespace.equals(simpleType.getTargetNamespace()); |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
public void generateCode(CodegenContext context, XSDConcreteComponent component) { |
| 44 |
31 |
CodegenRole role = context.getCurrentRole(); |
| 45 |
31 |
if (role == CodegenRole.UNMARSHAL) { |
| 46 |
16 |
StatementContainer code = context.getCurrentMethodCode(); |
| 47 |
16 |
String expr = "thisValue"; |
| 48 |
16 |
code.addStmt("return " + expr); |
| 49 |
16 |
} else if (role == CodegenRole.MARSHAL) { |
| 50 |
15 |
StatementContainer code = context.getCurrentMethodCode(); |
| 51 |
15 |
String expr = "thisValue"; |
| 52 |
15 |
code.addStmt("return " + expr); |
| 53 |
15 |
} else { |
| 54 |
0 |
super.generateCode(context, component); |
| 55 |
|
} |
| 56 |
31 |
} |
| 57 |
|
} |