1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.schema.cmp;
|
11
|
|
|
12
|
|
import java.util.HashMap;
|
13
|
|
import java.util.Iterator;
|
14
|
|
import java.util.Map;
|
15
|
|
import java.util.Set;
|
16
|
|
|
17
|
|
import org.jbind.base.UnexpectedException;
|
18
|
|
import org.jbind.util.collection.FilterIterator;
|
19
|
|
import org.jbind.util.collection.TransformingIterator;
|
20
|
|
import org.jbind.xml.base.AttributeOccurence;
|
21
|
|
import org.jbind.xml.base.IRef;
|
22
|
|
import org.jbind.xml.core.bridge.IAttributeImpl;
|
23
|
|
import org.jbind.xml.core.bridge.IElementImpl;
|
24
|
|
import org.jbind.xml.core.bridge.IXPathMethod;
|
25
|
|
import org.jbind.xml.core.cmp.IAttributesModel;
|
26
|
|
import org.jbind.xml.core.cmp.IComponentVisitor;
|
27
|
|
import org.jbind.xml.core.cmp.ISourceInfo;
|
28
|
|
import org.jbind.xml.core.constraint.ICheckContext;
|
29
|
|
import org.jbind.xml.core.content.IAttrRefOrDecl;
|
30
|
|
import org.jbind.xml.core.data.IAnyTypeData;
|
31
|
|
import org.jbind.xml.core.type.IAnyType;
|
32
|
|
import org.jbind.xml.core.type.IComplexType;
|
33
|
|
import org.jbind.xml.msg.XmlException;
|
34
|
|
|
35
|
|
public abstract class ComplexType extends AbstractType implements IComplexType {
|
36
|
|
|
37
|
|
private boolean myIsExtension;
|
38
|
|
private Map myXPathMethods = new HashMap(17);
|
39
|
|
|
40
|
485
|
public ComplexType(ISourceInfo aSourceInfo, String aNamespace, String aName, String aRole, Set aFinalTypes, Set aBlockTypes, boolean anIsAbstract, boolean anIsExtension) {
|
41
|
485
|
super(aSourceInfo, aNamespace, aName, aRole, aFinalTypes, aBlockTypes, anIsAbstract);
|
42
|
485
|
myIsExtension = anIsExtension;
|
43
|
|
}
|
44
|
|
|
45
|
493
|
public boolean isExtension() {
|
46
|
493
|
return myIsExtension;
|
47
|
|
}
|
48
|
|
|
49
|
1065
|
public void accept(IComponentVisitor aVisitor) throws XmlException {
|
50
|
1065
|
aVisitor.visitComplexTypeStart(this);
|
51
|
1065
|
visitSubComponents(aVisitor);
|
52
|
1065
|
aVisitor.visitComplexTypeEnd(this);
|
53
|
|
}
|
54
|
|
|
55
|
10428
|
public void checkEnclosedConstraints(ICheckContext aContext) {
|
56
|
10428
|
getBaseType().checkEnclosedConstraints(aContext);
|
57
|
|
}
|
58
|
|
|
59
|
1932
|
protected boolean isUnion() {
|
60
|
1932
|
return false;
|
61
|
|
}
|
62
|
|
|
63
|
3335
|
public final Class getSimpleStorageType() {
|
64
|
3335
|
return null;
|
65
|
|
}
|
66
|
|
|
67
|
|
//
|
68
|
|
// Implementation of DefaultAttrCreator
|
69
|
|
//
|
70
|
|
|
71
|
8027
|
public IAttributeImpl createDefaultAttr(IElementImpl anElement, IRef aRef) {
|
72
|
8027
|
IAttributeImpl res = null;
|
73
|
8027
|
IAttributesModel am = getAttributesModel();
|
74
|
8027
|
IAttrRefOrDecl decl = am.getDefaultAttr(aRef);
|
75
|
8027
|
if (null != decl) {
|
76
|
154
|
res = anElement.addAttribute(aRef.getNamespace(), aRef.getLocalPart(), decl.getDefault().getTextContent_(), true, null);
|
77
|
154
|
try {
|
78
|
154
|
IAnyTypeData data = decl.createData(res, null);
|
79
|
154
|
res.setData(data);
|
80
|
|
} catch (XmlException e) {
|
81
|
0
|
throw new UnexpectedException(e);
|
82
|
|
}
|
83
|
|
}
|
84
|
8027
|
return res;
|
85
|
|
}
|
86
|
|
|
87
|
372
|
public Iterator iterDefaultAttrRefs() {
|
88
|
372
|
return new TransformingIterator(new FilterIterator(getAttributesModel().iterAttributes(), new FilterIterator.ICondition() {
|
89
|
1269
|
public boolean evaluate(Object anObject) {
|
90
|
1269
|
IAttrRefOrDecl attr = (IAttrRefOrDecl)anObject;
|
91
|
1269
|
return (null != attr.getDefault()) && !AttributeOccurence.PROHIBITED.equals(attr.getOccurence());
|
92
|
|
}
|
93
|
|
}), new TransformingIterator.ITransformation() {
|
94
|
174
|
public Object transform(Object anObject) {
|
95
|
174
|
return ((IAttrRefOrDecl)anObject).getGlobalRef();
|
96
|
|
}
|
97
|
|
});
|
98
|
|
}
|
99
|
|
|
100
|
1265
|
public IAnyType getInstanceType() {
|
101
|
1265
|
return this;
|
102
|
|
}
|
103
|
|
|
104
|
777
|
public Map getXPathMethods() {
|
105
|
777
|
return myXPathMethods;
|
106
|
|
}
|
107
|
|
|
108
|
451
|
public void addXPathMethods(Map aMap) {
|
109
|
451
|
myXPathMethods.putAll(aMap);
|
110
|
|
}
|
111
|
|
|
112
|
12
|
public IXPathMethod addXPathMethod(IXPathMethod anXPathMethod) {
|
113
|
12
|
return (IXPathMethod)myXPathMethods.put(anXPathMethod.getName(), anXPathMethod);
|
114
|
|
}
|
115
|
|
}
|
116
|
|
|