|
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.element;
|
|
11
|
|
|
|
12
|
|
import org.jbind.xml.base.IAttribute;
|
|
13
|
|
import org.jbind.xml.base.IBindingAttributes;
|
|
14
|
|
import org.jbind.xml.base.ISymbolspaces;
|
|
15
|
|
import org.jbind.xml.core.bridge.IXPath;
|
|
16
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
|
17
|
|
import org.jbind.xml.msg.XmlException;
|
|
18
|
|
import org.jbind.xml.msg.XmlMessages;
|
|
19
|
|
import org.jbind.xml.schema.cmp.XPathMethod;
|
|
20
|
|
import org.jbind.xml.schema.instantiation.IElemValHelper;
|
|
21
|
|
|
|
22
|
|
public class XPathMethodElement extends Annotated {
|
|
23
|
|
|
|
24
|
|
private String myName = null;
|
|
25
|
|
private String myStringXPath = null;
|
|
26
|
|
private IXPath myXPath = null;
|
|
27
|
|
private XPathMethod.MethodType myMethodType = XPathMethod.SELECT;
|
|
28
|
|
|
|
29
|
12
|
public XPathMethodElement(CreationParams aCreationParams) {
|
|
30
|
12
|
super(aCreationParams);
|
|
31
|
|
}
|
|
32
|
|
|
|
33
|
36
|
protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
|
|
34
|
36
|
IAttribute res = null;
|
|
35
|
36
|
String an = NameUtil.getSchemaAttributeName(anACParams);
|
|
36
|
36
|
String ban = NameUtil.getBindingAttributeName(anACParams);
|
|
37
|
36
|
if (IBindingAttributes.REFERENCED_TYPE.equals(ban)) {
|
|
38
|
0
|
res = new RefAttribute(anACParams, ISymbolspaces.TYPE);
|
|
39
|
36
|
} else if ("name".equals(an)) {
|
|
40
|
12
|
res = new Attribute(anACParams);
|
|
41
|
12
|
myName = res.getStringValue();
|
|
42
|
24
|
} else if ("xpath".equals(an)) {
|
|
43
|
12
|
res = new Attribute(anACParams);
|
|
44
|
12
|
myStringXPath = res.getStringValue();
|
|
45
|
12
|
} else if ("type".equals(an)) {
|
|
46
|
12
|
res = new Attribute(anACParams);
|
|
47
|
12
|
String s = res.getStringValue();
|
|
48
|
12
|
if ("select".equals(s)) {
|
|
49
|
4
|
myMethodType = XPathMethod.SELECT;
|
|
50
|
8
|
} else if ("fetch".equals(s)) {
|
|
51
|
2
|
myMethodType = XPathMethod.FETCH;
|
|
52
|
6
|
} else if ("test".equals(s)) {
|
|
53
|
2
|
myMethodType = XPathMethod.TEST;
|
|
54
|
4
|
} else if ("number".equals(s)) {
|
|
55
|
2
|
myMethodType = XPathMethod.NUMBER;
|
|
56
|
2
|
} else if ("string".equals(s)) {
|
|
57
|
2
|
myMethodType = XPathMethod.STRING;
|
|
58
|
|
} else {
|
|
59
|
0
|
throw new XmlException(XmlMessages.unknownXPathMethodType(s, anACParams.location));
|
|
60
|
|
}
|
|
61
|
|
} else {
|
|
62
|
0
|
res = super.doCreateAttribute(anACParams);
|
|
63
|
|
}
|
|
64
|
36
|
return res;
|
|
65
|
|
}
|
|
66
|
|
|
|
67
|
12
|
public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
|
|
68
|
12
|
super.validateElement(aHelper, aViolations);
|
|
69
|
12
|
if (null == myStringXPath) {
|
|
70
|
0
|
aViolations.add(XmlMessages.missingAttribute("xpath", this));
|
|
71
|
|
} else {
|
|
72
|
12
|
try {
|
|
73
|
12
|
myXPath = aHelper.createXPath(myStringXPath, getPrefixToNamespaceMapping(), false);
|
|
74
|
|
} catch (Exception e) {
|
|
75
|
0
|
aViolations.add(XmlMessages.invalidXPath(myStringXPath, e, this));
|
|
76
|
|
}
|
|
77
|
|
}
|
|
78
|
12
|
if (null == myName) {
|
|
79
|
0
|
aViolations.add(XmlMessages.missingAttribute("name", this));
|
|
80
|
|
}
|
|
81
|
|
}
|
|
82
|
|
|
|
83
|
12
|
public String getName() {
|
|
84
|
12
|
return myName;
|
|
85
|
|
}
|
|
86
|
12
|
public IXPath getXPath() {
|
|
87
|
12
|
return myXPath;
|
|
88
|
|
}
|
|
89
|
12
|
public XPathMethod.MethodType getMethodType() {
|
|
90
|
12
|
return myMethodType;
|
|
91
|
|
}
|
|
92
|
|
}
|
|
93
|
|
|