977101b2a4a9126306947dc44207a1ae9cab9aeb
[vxquery.git] / vxquery-core / src / main / java / org / apache / vxquery / datamodel / accessors / atomic / XSQNamePointable.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.atomic;
18
19 import org.apache.hyracks.api.dataflow.value.ITypeTraits;
20 import org.apache.hyracks.data.std.api.AbstractPointable;
21 import org.apache.hyracks.data.std.api.IPointable;
22 import org.apache.hyracks.data.std.api.IPointableFactory;
23 import org.apache.hyracks.util.string.UTF8StringUtil;
24
25 /**
26 * The XSQNamePointable holds three strings: URI, Prefix and Local Name.
27 */
28 public class XSQNamePointable extends AbstractPointable {
29 public static final ITypeTraits TYPE_TRAITS = new ITypeTraits() {
30 private static final long serialVersionUID = 1L;
31
32 @Override
33 public boolean isFixedLength() {
34 return false;
35 }
36
37 @Override
38 public int getFixedLength() {
39 return 0;
40 }
41 };
42
43 public static final IPointableFactory FACTORY = new IPointableFactory() {
44 private static final long serialVersionUID = 1L;
45
46 @Override
47 public IPointable createPointable() {
48 return new XSQNamePointable();
49 }
50
51 @Override
52 public ITypeTraits getTypeTraits() {
53 return TYPE_TRAITS;
54 }
55 };
56
57 public int getUriLength() {
58 return getUriLength(bytes, start);
59 }
60
61 public static int getUriLength(byte[] bytes, int start) {
62 int utfLength = getUriUTFLength(bytes, start);
63 return utfLength + UTF8StringUtil.getNumBytesToStoreLength(utfLength);
64 }
65
66 public int getUriUTFLength() {
67 return getUriUTFLength(bytes, start);
68 }
69
70 public static int getUriUTFLength(byte[] bytes, int start) {
71 return UTF8StringUtil.getUTFLength(bytes, start);
72 }
73
74 public int getPrefixLength() {
75 return getPrefixLength(bytes, start);
76 }
77
78 public static int getPrefixLength(byte[] bytes, int start) {
79 int utfLength = getPrefixUTFLength(bytes, start);
80 return utfLength + UTF8StringUtil.getNumBytesToStoreLength(utfLength);
81 }
82
83 public int getPrefixUTFLength() {
84 return getPrefixUTFLength(bytes, start);
85 }
86
87 public static int getPrefixUTFLength(byte[] bytes, int start) {
88 return UTF8StringUtil.getUTFLength(bytes, start + getUriLength(bytes, start));
89 }
90
91 public int getLocalNameLength() {
92 return getLocalNameLength(bytes, start);
93 }
94
95 public static int getLocalNameLength(byte[] bytes, int start) {
96 int utfLength = getLocalNameUTFLength(bytes, start);
97 return utfLength + UTF8StringUtil.getNumBytesToStoreLength(utfLength);
98 }
99
100 public int getLocalNameUTFLength() {
101 return getLocalNameUTFLength(bytes, start);
102 }
103
104 public static int getLocalNameUTFLength(byte[] bytes, int start) {
105 return UTF8StringUtil.getUTFLength(bytes,
106 start + getUriLength(bytes, start) + getPrefixLength(bytes, start));
107 }
108
109 public void getUri(IPointable stringp) {
110 getUri(bytes, start, stringp);
111 }
112
113 public static void getUri(byte[] bytes, int start, IPointable stringp) {
114 stringp.set(bytes, start, getUriLength(bytes, start));
115 }
116
117 public void getPrefix(IPointable stringp) {
118 getPrefix(bytes, start, stringp);
119 }
120
121 public static void getPrefix(byte[] bytes, int start, IPointable stringp) {
122 stringp.set(bytes, start + getUriLength(bytes, start), getPrefixLength(bytes, start));
123 }
124
125 public void getLocalName(IPointable stringp) {
126 getLocalName(bytes, start, stringp);
127 }
128
129 public static void getLocalName(byte[] bytes, int start, IPointable stringp) {
130 stringp.set(bytes, start + getUriLength(bytes, start) + getPrefixLength(bytes, start),
131 getLocalNameLength(bytes, start));
132 }
133 }