ApplicationParameter.java revision 2e0da96e757a977154063f980d3f4e1abd41cf09
1/* 2 * Copyright (c) 2008-2009, Motorola, Inc. 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * - Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * - Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * - Neither the name of the Motorola, Inc. nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33package javax.obex; 34 35/** 36 * @hide 37 */ 38public final class ApplicationParameter { 39 40 private byte[] b_array; 41 private int length; 42 private int max_length = 1000; 43 44 public static class TRIPLET_TAGID { 45 public static final byte ORDER_TAGID = 0x01; 46 47 public static final byte SEARCH_VALUE_TAGID = 0x02; 48 49 public static final byte SEARCH_ATTRIBUTE_TAGID = 0x03; 50 51 // if equals to "0", PSE only reply number of contacts 52 public static final byte MAXLISTCOUNT_TAGID = 0x04; 53 54 public static final byte LISTSTARTOFFSET_TAGID = 0x05; 55 56 public static final byte FILTER_TAGID = 0x06; 57 58 public static final byte FORMAT_TAGID = 0x07; 59 60 // only used if max list count = 0 61 public static final byte PHONEBOOKSIZE_TAGID = 0x08; 62 63 // only used in "mch" in response 64 public static final byte NEWMISSEDCALLS_TAGID = 0x09; 65 } 66 67 public static class TRIPLET_VALUE { 68 public static class ORDER { 69 public static final byte ORDER_BY_INDEX = 0x00; 70 71 public static final byte ORDER_BY_ALPHANUMERIC = 0x01; 72 73 public static final byte ORDER_BY_PHONETIC = 0x02; 74 } 75 76 public static class SEARCHATTRIBUTE { 77 public static final byte SEARCH_BY_NAME = 0x00; 78 79 public static final byte SEARCH_BY_NUMBER = 0x01; 80 81 public static final byte SEARCH_BY_SOUND = 0x02; 82 } 83 84 public static class FORMAT { 85 public static final byte VCARD_VERSION_21 = 0x00; 86 87 public static final byte VCARD_VERSION_30 = 0x01; 88 } 89 } 90 91 public static class TRIPLET_LENGTH { 92 public static final byte ORDER_LENGTH = 1; 93 94 //public final byte SEARCH_VALUE_LENGTH = 0x02; 95 public static final byte SEARCH_ATTRIBUTE_LENGTH = 1; 96 97 public static final byte MAXLISTCOUNT_LENGTH = 2; 98 99 public static final byte LISTSTARTOFFSET_LENGTH = 2; 100 101 public static final byte FILTER_LENGTH = 8; 102 103 public static final byte FORMAT_LENGTH = 1; 104 105 public static final byte PHONEBOOKSIZE_LENGTH = 2; 106 107 public static final byte NEWMISSEDCALLS_LENGTH = 1; 108 } 109 110 /* 111 public class TRIPLET_STRUCTURE{ 112 TRIPLET_TAGID id; 113 TRIPLET_LENGTH length; 114 byte[] value; 115 } 116 */ 117 public ApplicationParameter() { 118 b_array = new byte[max_length]; 119 length = 0; 120 } 121 122 public void addAPPHeader(byte tag, byte len, byte[] value) { 123 if ((length + len + 2) > max_length) { 124 byte[] array_tmp = new byte[length + 4 * len]; 125 System.arraycopy(b_array, 0, array_tmp, 0, length); 126 b_array = array_tmp; 127 max_length = length + 4 * len; 128 } 129 b_array[length++] = tag; 130 b_array[length++] = len; 131 System.arraycopy(value, 0, b_array, length, len); 132 length += len; 133 } 134 135 public byte[] getAPPparam() { 136 byte[] para = new byte[length]; 137 System.arraycopy(b_array, 0, para, 0, length); 138 return para; 139 } 140} 141