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 java.util.List;
|
13
|
|
|
14
|
|
import org.jbind.xml.core.bridge.IRegEx;
|
15
|
|
import org.jbind.xml.core.constraint.ConstraintType;
|
16
|
|
import org.jbind.xml.core.constraint.IConstraints;
|
17
|
|
import org.jbind.xml.core.constraint.IPatternConstraint;
|
18
|
|
import org.jbind.xml.core.type.IAnyType;
|
19
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
20
|
|
import org.jbind.xml.msg.XmlMessages;
|
21
|
|
import org.jbind.xml.schema.instantiation.IElemValHelper;
|
22
|
|
|
23
|
|
public class PatternFacet extends Facet {
|
24
|
|
|
25
|
|
private IRegEx myRegEx = null;
|
26
|
|
|
27
|
30
|
public PatternFacet(CreationParams aCreationParams) {
|
28
|
30
|
super(aCreationParams, ConstraintType.PATTERN);
|
29
|
|
}
|
30
|
|
|
31
|
30
|
public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
|
32
|
30
|
super.validateElement(aHelper, aViolations);
|
33
|
30
|
try {
|
34
|
30
|
if (null != getValue()) {
|
35
|
30
|
myRegEx = aHelper.createRegEx(getValue());
|
36
|
|
}
|
37
|
|
} catch (Exception e) {
|
38
|
0
|
aViolations.add(XmlMessages.invalidPattern(getValue(), e, this));
|
39
|
|
}
|
40
|
|
}
|
41
|
|
|
42
|
28
|
public void doAddConstraint(IAnyType aType, IConstraints aConstraints, IConstraintViolations aViolations) {
|
43
|
28
|
List l = aConstraints.getConstraintList(ConstraintType.PATTERN);
|
44
|
28
|
IPatternConstraint c = null;
|
45
|
|
assert l.size() <= 1 : "internal error";
|
46
|
28
|
if (l.size() == 0) {
|
47
|
26
|
c = ConstraintType.PATTERN.createConstraint();
|
48
|
26
|
l.add(c);
|
49
|
|
} else {
|
50
|
2
|
c = (IPatternConstraint)l.get(0);
|
51
|
|
}
|
52
|
28
|
c.addPattern(myRegEx, aViolations, this);
|
53
|
|
}
|
54
|
|
|
55
|
|
}
|
56
|
|
|