| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package uk.co.badgersinfoil.asxsd.components; |
| 6 |
|
|
| 7 |
|
import org.eclipse.xsd.XSDConcreteComponent; |
| 8 |
|
import org.eclipse.xsd.XSDParticle; |
| 9 |
|
import uk.co.badgersinfoil.asxsd.CodegenContext; |
| 10 |
|
import uk.co.badgersinfoil.asxsd.CodegenRole; |
| 11 |
|
import uk.co.badgersinfoil.asxsd.TypeDescriptor; |
| 12 |
|
import uk.co.badgersinfoil.asxsd.XSDUtils; |
| 13 |
|
import uk.co.badgersinfoil.metaas.dom.ASExpression; |
| 14 |
|
|
| 15 |
47 |
public abstract class AbstractParticleComponent extends AbstractMappingComponent { |
| 16 |
|
|
| 17 |
|
public TypeDescriptor typeDescriptorFor(CodegenContext context, |
| 18 |
|
XSDConcreteComponent component) |
| 19 |
|
{ |
| 20 |
3 |
XSDParticle particle = (XSDParticle)component; |
| 21 |
3 |
return typeDescriptorFor(context, particle); |
| 22 |
|
} |
| 23 |
|
|
| 24 |
|
protected TypeDescriptor typeDescriptorFor(CodegenContext context, |
| 25 |
|
XSDParticle particle) |
| 26 |
|
{ |
| 27 |
2 |
return super.typeDescriptorFor(context, particle); |
| 28 |
|
} |
| 29 |
|
|
| 30 |
|
public TypeDescriptor createTypeDescriptor(CodegenContext context, |
| 31 |
|
XSDConcreteComponent component) |
| 32 |
|
{ |
| 33 |
2 |
XSDParticle particle = (XSDParticle)component; |
| 34 |
2 |
return createTypeDescriptor(context, particle); |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
protected TypeDescriptor createTypeDescriptor(CodegenContext context, |
| 38 |
|
XSDParticle particle) |
| 39 |
|
{ |
| 40 |
0 |
CodegenRole role = context.getCurrentRole(); |
| 41 |
0 |
throw new RuntimeException(getClass().getName()+" does not suppport operation createTypeDescriptor(role="+role+", particle="+particle+") at "+XSDUtils.path(particle)); |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
public String createTypeNameFor(CodegenContext context, |
| 45 |
|
XSDConcreteComponent component) |
| 46 |
|
{ |
| 47 |
2 |
return context.createTypeNameFor(component.getContainer()); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
public boolean willAccept(XSDConcreteComponent component) { |
| 51 |
7653 |
return component instanceof XSDParticle |
| 52 |
|
&& willAcceptParticle((XSDParticle)component); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
protected abstract boolean willAcceptParticle(XSDParticle particle); |
| 56 |
|
|
| 57 |
|
public void generateCode(CodegenContext context, XSDConcreteComponent component) { |
| 58 |
219 |
XSDParticle particle = (XSDParticle)component; |
| 59 |
219 |
generateCodeFor(context, particle); |
| 60 |
219 |
} |
| 61 |
|
|
| 62 |
|
protected abstract void generateCodeFor(CodegenContext context, XSDParticle particle); |
| 63 |
|
|
| 64 |
|
public ASExpression createExpression(CodegenContext context, |
| 65 |
|
XSDConcreteComponent component) |
| 66 |
|
{ |
| 67 |
10 |
CodegenRole role = context.getCurrentRole(); |
| 68 |
10 |
XSDParticle particle = (XSDParticle)component; |
| 69 |
10 |
if (role == CodegenRole.UNMARSHAL_DETECT) { |
| 70 |
6 |
return context.createExpression(particle.getContent()); |
| 71 |
|
} |
| 72 |
4 |
if (role == CodegenRole.MARSHAL_DETECT) { |
| 73 |
4 |
return context.createExpression(particle.getContent()); |
| 74 |
|
} |
| 75 |
0 |
return super.createExpression(context, component); |
| 76 |
|
} |
| 77 |
|
} |