return new CClassInfo(owner.model,owner.getTargetPackage(),className,locator,null,tagName,null,null/*TODO*/);
}
void bind() {
CClassInfo ci = getClassInfo();
assert ci!=null || attributes.isEmpty();
for( CPropertyInfo p : attributes )
ci.addProperty(p);
switch(contentModelType) {
case DTDEventListener.CONTENT_MODEL_ANY:
CReferencePropertyInfo rp = new CReferencePropertyInfo("Content",true,false,true,null,null/*TODO*/,locator, false, false, false);
rp.setWildcard(WildcardMode.SKIP);
ci.addProperty(rp);
return;
case DTDEventListener.CONTENT_MODEL_CHILDREN:
break; // handling follows
case DTDEventListener.CONTENT_MODEL_MIXED:
if(contentModel!=Term.EMPTY)
throw new UnsupportedOperationException("mixed content model unsupported yet");
if(ci!=null) {
// if this element is mapped to a class, just put one property
CValuePropertyInfo p = new CValuePropertyInfo("value", null,null/*TODO*/,locator,getConversion(),null);
ci.addProperty(p);
}
return;
case DTDEventListener.CONTENT_MODEL_EMPTY:
// no content model
assert ci!=null;
return;
}
// normalize
List<Block> n = new ArrayList<Block>();
contentModel.normalize(n,false);
{// check collision among Blocks
Set<String> names = new HashSet<String>();
boolean collision = false;
OUTER:
for( Block b : n )
for( Element e : b.elements )
if(!names.add(e.name)) {
collision = true;
break OUTER;
}
if(collision) {
// collapse all blocks into one
Block all = new Block(true,true);
for( Block b : n )
all.elements.addAll(b.elements);
n.clear();
n.add(all);
}
}
for( Block b : n ) {
CElementPropertyInfo p;
if(b.isRepeated || b.elements.size()>1) {
// collection
StringBuilder name = new StringBuilder();
for( Element e : b.elements ) {
if(name.length()>0)
name.append("Or");
name.append(owner.model.getNameConverter().toPropertyName(e.name));
}
p = new CElementPropertyInfo(name.toString(), REPEATED_ELEMENT, ID.NONE, null, null,null/*TODO*/, locator, !b.isOptional );
for( Element e : b.elements ) {
CClassInfo child = owner.getOrCreateElement(e.name).getClassInfo();
assert child!=null; // we are requiring them to be classes.
p.getTypes().add(new CTypeRef(child,new QName("",e.name),null,false,null));
}
} else {
// single property