95dc404dba74dd5856f6b4a27c034091adbc285e
[vxquery.git] / vxquery-core / src / main / java / org / apache / vxquery / datamodel / accessors / nodes / DocumentNodePointable.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.vxquery.datamodel.accessors.SequencePointable;
20
21 import org.apache.hyracks.api.dataflow.value.ITypeTraits;
22 import org.apache.hyracks.data.std.api.IPointable;
23 import org.apache.hyracks.data.std.api.IPointableFactory;
24 import org.apache.hyracks.data.std.primitive.VoidPointable;
25
26 /*
27 * Document {
28 * NodeId nodeId?;
29 * Sequence content;
30 * }
31 */
32 public class DocumentNodePointable extends AbstractNodePointable {
33 private static final int LOCAL_NODE_ID_SIZE = 4;
34 public static final IPointableFactory FACTORY = new IPointableFactory() {
35 private static final long serialVersionUID = 1L;
36
37 @Override
38 public ITypeTraits getTypeTraits() {
39 return VoidPointable.TYPE_TRAITS;
40 }
41
42 @Override
43 public IPointable createPointable() {
44 return new DocumentNodePointable();
45 }
46 };
47
48 public void getContent(NodeTreePointable nodeTree, SequencePointable content) {
49 content.set(bytes, getContentOffset(nodeTree), getContentSize(nodeTree));
50 }
51
52 protected int getLocalNodeIdOffset(NodeTreePointable nodeTree) {
53 return start;
54 }
55
56 private int getLocalNodeIdSize(NodeTreePointable nodeTree) {
57 return nodeTree.nodeIdExists() ? LOCAL_NODE_ID_SIZE : 0;
58 }
59
60 private int getContentOffset(NodeTreePointable nodeTree) {
61 return getLocalNodeIdOffset(nodeTree) + getLocalNodeIdSize(nodeTree);
62 }
63
64 private int getContentSize(NodeTreePointable nodeTree) {
65 return length - (getContentOffset(nodeTree) - start);
66 }
67 }