fd4cfc6b21124a73b53739244246b67639da451d
[vxquery.git] / vxquery-core / src / main / java / org / apache / vxquery / datamodel / accessors / nodes / AttributeNodePointable.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.atomic.CodedQNamePointable;
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 * Attribute {
28 * NamePtr namePtr;
29 * NamePtr typePtr?;
30 * NodeId nodeId?;
31 * TaggedValue value;
32 * }
33 *
34 * NamePtr {
35 * Integer PrefixCode;
36 * Integer NamespaceCode;
37 * Integer LocalCode;
38 * }
39 */
40 public class AttributeNodePointable extends AbstractNodePointable {
41 private static final int LOCAL_NODE_ID_SIZE = 4;
42 public static final IPointableFactory FACTORY = new IPointableFactory() {
43 private static final long serialVersionUID = 1L;
44
45 @Override
46 public ITypeTraits getTypeTraits() {
47 return VoidPointable.TYPE_TRAITS;
48 }
49
50 @Override
51 public IPointable createPointable() {
52 return new AttributeNodePointable();
53 }
54 };
55
56 public void getName(CodedQNamePointable name) {
57 name.set(bytes, getNameOffset(), getNameSize());
58 }
59
60 public void getTypeName(NodeTreePointable nodeTree, CodedQNamePointable typeName) {
61 if (nodeTree.typeExists()) {
62 typeName.set(bytes, getTypeOffset(), getTypeSize(nodeTree));
63 } else {
64 typeName.set(null, -1, -1);
65 }
66 }
67
68 public void getValue(NodeTreePointable nodeTree, IPointable value) {
69 value.set(bytes, getValueOffset(nodeTree), getValueSize(nodeTree));
70 }
71
72 private int getNameOffset() {
73 return start;
74 }
75
76 private int getNameSize() {
77 return CodedQNamePointable.SIZE;
78 }
79
80 private int getTypeOffset() {
81 return getNameOffset() + getNameSize();
82 }
83
84 private int getTypeSize(NodeTreePointable nodeTree) {
85 return nodeTree.typeExists() ? CodedQNamePointable.SIZE : 0;
86 }
87
88 protected int getLocalNodeIdOffset(NodeTreePointable nodeTree) {
89 return getTypeOffset() + getTypeSize(nodeTree);
90 }
91
92 private int getLocalNodeIdSize(NodeTreePointable nodeTree) {
93 return nodeTree.nodeIdExists() ? LOCAL_NODE_ID_SIZE : 0;
94 }
95
96 private int getValueOffset(NodeTreePointable nodeTree) {
97 return getLocalNodeIdOffset(nodeTree) + getLocalNodeIdSize(nodeTree);
98 }
99
100 private int getValueSize(NodeTreePointable nodeTree) {
101 return length - (getValueOffset(nodeTree) - start);
102 }
103 }