1 |
26600
|
sandro.lab
|
package eu.dnetlib.data.collective.transformation.core.schema.visitor;
|
2 |
|
|
|
3 |
|
|
import java.util.Collection;
|
4 |
|
|
import java.util.Iterator;
|
5 |
|
|
|
6 |
52285
|
jochen.sch
|
import org.apache.commons.lang3.NotImplementedException;
|
7 |
26600
|
sandro.lab
|
|
8 |
|
|
import com.sun.xml.xsom.XSAttributeUse;
|
9 |
|
|
import com.sun.xml.xsom.XSContentType;
|
10 |
|
|
import com.sun.xml.xsom.XSElementDecl;
|
11 |
|
|
import com.sun.xml.xsom.XSParticle;
|
12 |
|
|
import com.sun.xml.xsom.XSSimpleType;
|
13 |
|
|
import com.sun.xml.xsom.XSType;
|
14 |
|
|
import com.sun.xml.xsom.visitor.XSContentTypeVisitor;
|
15 |
|
|
|
16 |
|
|
import eu.dnetlib.data.collective.transformation.core.schema.SchemaAttribute;
|
17 |
|
|
import eu.dnetlib.data.collective.transformation.core.schema.SchemaElement;
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* @author jochen
|
21 |
|
|
*
|
22 |
|
|
*/
|
23 |
|
|
public class XSContentTypeVisitorImpl implements XSContentTypeVisitor {
|
24 |
|
|
|
25 |
|
|
private Visitor visitor;
|
26 |
|
|
|
27 |
|
|
@Override
|
28 |
|
|
public void empty(XSContentType arg0) {
|
29 |
52285
|
jochen.sch
|
throw new NotImplementedException("TODO empty");
|
30 |
26600
|
sandro.lab
|
}
|
31 |
|
|
|
32 |
|
|
@Override
|
33 |
|
|
public void particle(XSParticle aParticle) {
|
34 |
|
|
XSTermVisitorImpl termVisitor = new XSTermVisitorImpl();
|
35 |
|
|
termVisitor.setVisitor(this.visitor);
|
36 |
|
|
aParticle.getTerm().visit(termVisitor);
|
37 |
|
|
if (aParticle.getTerm().isElementDecl()){
|
38 |
|
|
XSElementDecl elem = aParticle.getTerm().asElementDecl();
|
39 |
|
|
SchemaElement element = new SchemaElement();
|
40 |
|
|
|
41 |
|
|
XSType type = elem.getType();
|
42 |
|
|
if (type.isComplexType()){
|
43 |
|
|
Collection<? extends XSAttributeUse> attrColls =
|
44 |
|
|
type.asComplexType().getDeclaredAttributeUses();
|
45 |
|
|
Iterator<? extends XSAttributeUse> attrIter = attrColls.iterator();
|
46 |
|
|
while (attrIter.hasNext()){
|
47 |
|
|
XSAttributeUse attrUse = attrIter.next();
|
48 |
|
|
SchemaAttribute attribute = new SchemaAttribute();
|
49 |
|
|
attribute.setName(attrUse.getDecl().getName());
|
50 |
|
|
attribute.setRequired(attrUse.isRequired());
|
51 |
28752
|
jochen.sch
|
element.addAttribute(attribute);
|
52 |
26600
|
sandro.lab
|
}
|
53 |
|
|
}
|
54 |
|
|
element.setName(elem.getName());
|
55 |
|
|
element.setTargetNamespace(elem.getTargetNamespace());
|
56 |
|
|
element.setMinOccurs(aParticle.getMinOccurs().intValue());
|
57 |
|
|
element.setMaxOccurs(aParticle.getMaxOccurs().intValue());
|
58 |
|
|
element.setRepeatable(aParticle.isRepeated());
|
59 |
|
|
|
60 |
|
|
if (elem.getType().isComplexType()){
|
61 |
|
|
if (elem.getType().asComplexType().getContentType().asSimpleType() != null){
|
62 |
|
|
element.setContainsSimpleType(true);
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
this.visitor.getCurrentElement().getChildList().add(element);
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
@Override
|
70 |
|
|
public void simpleType(XSSimpleType arg0) {
|
71 |
52285
|
jochen.sch
|
throw new NotImplementedException("TODO simpleType");
|
72 |
26600
|
sandro.lab
|
}
|
73 |
|
|
|
74 |
|
|
public void setVisitor(Visitor visitor) {
|
75 |
|
|
this.visitor = visitor;
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
public Visitor getVisitor() {
|
79 |
|
|
return visitor;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
28752
|
jochen.sch
|
}
|