0N/A/*
3909N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.xml.internal.bind.v2.runtime.unmarshaller;
0N/A
0N/Aimport java.io.IOException;
0N/A
0N/Aimport com.sun.xml.internal.bind.v2.runtime.output.Pcdata;
0N/Aimport com.sun.xml.internal.bind.v2.runtime.output.UTF8XmlOutput;
0N/A
0N/A/**
0N/A * Typed {@link CharSequence} for int[].
0N/A *
0N/A * <p>
0N/A * Fed to unmarshaller when the 'text' data is actually
0N/A * a virtual image of int array.
0N/A *
0N/A * <p>
0N/A * This class holds int[] as a triplet of (data,start,len)
0N/A * where 'start' and 'len' represents the start position of the
2712N/A * data and the length.
2712N/A *
2712N/A * @author Kohsuke Kawaguchi
2712N/A */
2712N/Apublic final class IntArrayData extends Pcdata {
0N/A
0N/A private int[] data;
0N/A private int start;
2712N/A private int len;
0N/A
0N/A /**
2712N/A * String representation of the data. Lazily computed.
2712N/A */
2712N/A private StringBuilder literal;
2712N/A
2712N/A
2712N/A public IntArrayData(int[] data, int start, int len) {
3966N/A set(data, start, len);
2712N/A }
2712N/A
0N/A public IntArrayData() {
0N/A }
0N/A
0N/A /**
0N/A * Sets the int[] data to this object.
0N/A *
0N/A * <p>
0N/A * This method doesn't make a copy for a performance reason.
2712N/A * The caller is still free to modify the array it passed to this method,
2712N/A * but he should do so with a care. The unmarshalling code isn't expecting
0N/A * the value to be changed while it's being routed.
0N/A */
2712N/A public void set(int[] data, int start, int len) {
2712N/A this.data = data;
2712N/A this.start = start;
2712N/A this.len = len;
2712N/A this.literal = null;
2712N/A }
2712N/A
2712N/A public int length() {
2712N/A return getLiteral().length();
2712N/A }
2712N/A
2712N/A public char charAt(int index) {
2712N/A return getLiteral().charAt(index);
2712N/A }
2712N/A
2712N/A public CharSequence subSequence(int start, int end) {
2712N/A return getLiteral().subSequence(start,end);
2712N/A }
2712N/A
2712N/A /**
2712N/A * Computes the literal form from the data.
2712N/A */
2712N/A private StringBuilder getLiteral() {
2712N/A if(literal!=null) return literal;
2712N/A
2712N/A literal = new StringBuilder();
2712N/A int p = start;
2712N/A for( int i=len; i>0; i-- ) {
2712N/A if(literal.length()>0) literal.append(' ');
2712N/A literal.append(data[p++]);
2712N/A }
2712N/A
2712N/A return literal;
2712N/A }
2712N/A
2712N/A public String toString() {
2712N/A return literal.toString();
2712N/A }
2712N/A
2712N/A public void writeTo(UTF8XmlOutput output) throws IOException {
2712N/A int p = start;
2712N/A for( int i=len; i>0; i-- ) {
2712N/A if(i!=len)
2712N/A output.write(' ');
2712N/A output.text(data[p++]);
2712N/A }
2712N/A }
2712N/A}
2712N/A