f8e63b6e9d173f9113a9a9baebcacc7729638ddb
[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.data.std.primitive.UTF8StringPointable;
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 return getUriUTFLength(bytes, start) + 2;
63 }
64
65 public int getUriUTFLength() {
66 return getUriUTFLength(bytes, start);
67 }
68
69 public static int getUriUTFLength(byte[] bytes, int start) {
70 return UTF8StringPointable.getUTFLength(bytes, start);
71 }
72
73 public int getPrefixLength() {
74 return getPrefixLength(bytes, start);
75 }
76
77 public static int getPrefixLength(byte[] bytes, int start) {
78 return getPrefixUTFLength(bytes, start) + 2;
79 }
80
81 public int getPrefixUTFLength() {
82 return getPrefixUTFLength(bytes, start);
83 }
84
85 public static int getPrefixUTFLength(byte[] bytes, int start) {
86 return UTF8StringPointable.getUTFLength(bytes, start + getUriLength(bytes, start));
87 }
88
89 public int getLocalNameLength() {
90 return getLocalNameLength(bytes, start);
91 }
92
93 public static int getLocalNameLength(byte[] bytes, int start) {
94 return getLocalNameUTFLength(bytes, start) + 2;
95 }
96
97 public int getLocalNameUTFLength() {
98 return getLocalNameUTFLength(bytes, start);
99 }
100
101 public static int getLocalNameUTFLength(byte[] bytes, int start) {
102 return UTF8StringPointable.getUTFLength(bytes,
103 start + getUriLength(bytes, start) + getPrefixLength(bytes, start));
104 }
105
106 public void getUri(IPointable stringp) {
107 getUri(bytes, start, stringp);
108 }
109
110 public static void getUri(byte[] bytes, int start, IPointable stringp) {
111 stringp.set(bytes, start, getUriLength(bytes, start));
112 }
113
114 public void getPrefix(IPointable stringp) {
115 getPrefix(bytes, start, stringp);
116 }
117
118 public static void getPrefix(byte[] bytes, int start, IPointable stringp) {
119 stringp.set(bytes, start + getUriLength(bytes, start), getPrefixLength(bytes, start));
120 }
121
122 public void getLocalName(IPointable stringp) {
123 getLocalName(bytes, start, stringp);
124 }
125
126 public static void getLocalName(byte[] bytes, int start, IPointable stringp) {
127 stringp.set(bytes, start + getUriLength(bytes, start) + getPrefixLength(bytes, start),
128 getLocalNameLength(bytes, start));
129 }
130 }

Copyright 2016, The Apache Software Foundation.