| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.s9api; |
| 9 | |
| 10 | import net.sf.saxon.type.Type; |
| 11 | |
| 12 | /** |
| 13 | * Enumeration class defining the seven kinds of node defined in the XDM model |
| 14 | */ |
| 15 | public enum XdmNodeKind { |
| 16 | DOCUMENT(Type.DOCUMENT), |
| 17 | ELEMENT(Type.ELEMENT), |
| 18 | ATTRIBUTE(Type.ATTRIBUTE), |
| 19 | TEXT(Type.TEXT), |
| 20 | COMMENT(Type.COMMENT), |
| 21 | PROCESSING_INSTRUCTION(Type.PROCESSING_INSTRUCTION), |
| 22 | NAMESPACE(Type.NAMESPACE); |
| 23 | |
| 24 | private int number; |
| 25 | |
| 26 | private XdmNodeKind(int number) { |
| 27 | this.number = number; |
| 28 | } |
| 29 | |
| 30 | protected int getNumber() { |
| 31 | return number; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * Get the node kind corresponding to one of the integer constants in class |
| 37 | * {@link net.sf.saxon.type.Type}, for example {@link Type#ELEMENT}. These integer |
| 38 | * constants are chosen to be consistent with those used in DOM, though the semantics |
| 39 | * of the different node kinds are slightly different. |
| 40 | * |
| 41 | * @param type the integer type code, for example {@link Type#ELEMENT} or {@link Type#TEXT} |
| 42 | * @return the corresponding {@link XdmNodeKind}; |
| 43 | * @since 9.9.1.5 |
| 44 | */ |
| 45 | public static XdmNodeKind forType(int type) { |
| 46 | switch (type) { |
| 47 | case Type.DOCUMENT: |
| 48 | return DOCUMENT; |
| 49 | case Type.ELEMENT: |
| 50 | return ELEMENT; |
| 51 | case Type.ATTRIBUTE: |
| 52 | return ATTRIBUTE; |
| 53 | case Type.TEXT: |
| 54 | return TEXT; |
| 55 | case Type.COMMENT: |
| 56 | return COMMENT; |
| 57 | case Type.PROCESSING_INSTRUCTION: |
| 58 | return PROCESSING_INSTRUCTION; |
| 59 | case Type.NAMESPACE: |
| 60 | return NAMESPACE; |
| 61 | default: |
| 62 | throw new IllegalArgumentException(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | } |
| 67 |