cea7c02fe3730af667ddbfe6a1f24010a6dfa0d6
[vxquery.git] / vxquery-core / src / main / java / org / apache / vxquery / datamodel / accessors / nodes / TextOrCommentNodePointable.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.vxquery.datamodel.accessors.nodes;
18
19 import org.apache.hyracks.api.dataflow.value.ITypeTraits;
20 import org.apache.hyracks.data.std.api.IPointable;
21 import org.apache.hyracks.data.std.api.IPointableFactory;
22 import org.apache.hyracks.data.std.primitive.VoidPointable;
23
24 /*
25 * Text | Comment {
26 * NodeId nodeId?;
27 * UTF8String value;
28 * }
29 */
30 public class TextOrCommentNodePointable extends AbstractNodePointable {
31 private static final int LOCAL_NODE_ID_SIZE = 4;
32 public static final IPointableFactory FACTORY = new IPointableFactory() {
33 private static final long serialVersionUID = 1L;
34
35 @Override
36 public ITypeTraits getTypeTraits() {
37 return VoidPointable.TYPE_TRAITS;
38 }
39
40 @Override
41 public IPointable createPointable() {
42 return new TextOrCommentNodePointable();
43 }
44 };
45
46 public void getValue(NodeTreePointable nodeTree, IPointable value) {
47 value.set(bytes, getValueOffset(nodeTree), getValueSize(nodeTree));
48 }
49
50 protected int getLocalNodeIdOffset(NodeTreePointable nodeTree) {
51 return start;
52 }
53
54 private int getLocalNodeIdSize(NodeTreePointable nodeTree) {
55 return nodeTree.nodeIdExists() ? LOCAL_NODE_ID_SIZE : 0;
56 }
57
58 private int getValueOffset(NodeTreePointable nodeTree) {
59 return getLocalNodeIdOffset(nodeTree) + getLocalNodeIdSize(nodeTree);
60 }
61
62 private int getValueSize(NodeTreePointable nodeTree) {
63 return length - (getValueOffset(nodeTree) - start);
64 }
65
66 }