OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 73
Line 24... Line 24...
24
import org.jdom.Element;
24
import org.jdom.Element;
25
import org.jdom.Namespace;
25
import org.jdom.Namespace;
26
 
26
 
27
/**
27
/**
28
 * A step in {@link SimpleXMLPath}. There's only 2 types of step, those which go to {@link Element}
28
 * A step in {@link SimpleXMLPath}. There's only 2 types of step, those which go to {@link Element}
29
 * and those which go to {@link Attribute}.
29
 * and those which go to {@link Attribute}. Thread-safe if its {@link #getPredicate() predicate} is.
30
 * 
30
 * 
31
 * @author Sylvain CUAZ
31
 * @author Sylvain CUAZ
32
 * 
32
 * 
33
 * @param <T> type of items after the step.
33
 * @param <T> type of items after the step.
34
 */
34
 */
Line 36... Line 36...
36
 
36
 
37
    public enum Axis {
37
    public enum Axis {
38
        attribute, child, ancestor, descendantOrSelf
38
        attribute, child, ancestor, descendantOrSelf
39
    }
39
    }
40
 
40
 
-
 
41
    private static final Step<Attribute> ANY_ATTRIBUTE = createAttributeStep(null, null);
-
 
42
    private static final Step<Element> ANY_CHILD_ELEMENT = createElementStep(Axis.child, null, null);
-
 
43
 
-
 
44
    /**
-
 
45
     * Return a step that match any attribute.
-
 
46
     * 
-
 
47
     * @return the equivalent of <code>@*</code>.
-
 
48
     */
-
 
49
    public static Step<Attribute> getAnyAttributeStep() {
-
 
50
        return ANY_ATTRIBUTE;
-
 
51
    }
-
 
52
 
41
    public static Step<Attribute> createAttributeStep(final String name, final String ns) {
53
    public static Step<Attribute> createAttributeStep(final String name, final String ns) {
42
        return createAttributeStep(name, ns, null);
54
        return createAttributeStep(name, ns, null);
43
    }
55
    }
44
 
56
 
45
    public static Step<Attribute> createAttributeStep(final String name, final String ns, final IPredicate<Attribute> pred) {
57
    public static Step<Attribute> createAttributeStep(final String name, final String ns, final IPredicate<Attribute> pred) {
46
        return new Step<Attribute>(Axis.attribute, name, ns, Attribute.class, pred);
58
        return new Step<Attribute>(Axis.attribute, name, ns, Attribute.class, pred);
47
    }
59
    }
48
 
60
 
-
 
61
    /**
-
 
62
     * Return a step that match any child element.
-
 
63
     * 
-
 
64
     * @return the equivalent of <code>*</code>.
-
 
65
     */
-
 
66
    public static Step<Element> getAnyChildElementStep() {
-
 
67
        return ANY_CHILD_ELEMENT;
-
 
68
    }
-
 
69
 
49
    public static Step<Element> createElementStep(final String name, final String ns) {
70
    public static Step<Element> createElementStep(final String name, final String ns) {
50
        return createElementStep(name, ns, null);
71
        return createElementStep(name, ns, null);
51
    }
72
    }
52
 
73
 
53
    public static Step<Element> createElementStep(final String name, final String ns, final IPredicate<Element> pred) {
74
    public static Step<Element> createElementStep(final String name, final String ns, final IPredicate<Element> pred) {
Line 89... Line 110...
89
 
110
 
90
    public final String getName() {
111
    public final String getName() {
91
        return this.name;
112
        return this.name;
92
    }
113
    }
93
 
114
 
-
 
115
    public final IPredicate<T> getPredicate() {
-
 
116
        return this.pred;
-
 
117
    }
-
 
118
 
94
    protected final Namespace getNS(final Element elem) {
119
    protected final Namespace getNS(final Element elem) {
95
        return this.ns == null ? Namespace.NO_NAMESPACE : elem.getNamespace(this.ns);
120
        return this.ns == null ? Namespace.NO_NAMESPACE : elem.getNamespace(this.ns);
96
    }
121
    }
97
 
122
 
98
    protected final T evaluate(final Object node) {
123
    protected final T evaluate(final Object node) {