ApplicationParameter.java revision 9439a7fe517b858bc5e5c654b459315e4722feb2
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
35public class ApplicationParameter {
36    private int max_length_ini = 1000;
37
38    private byte[] b_array;
39
40    private int length;
41
42    public static class TRIPLET_TAGID {
43        public static final byte ORDER_TAGID = 0x01;
44
45        public static final byte SEARCH_VALUE_TAGID = 0x02;
46
47        public static final byte SEARCH_ATTRIBUTE_TAGID = 0x03;
48
49        public static final byte MAXLISTCOUNT_TAGID = 0x04;//if equals to "0", PSE only reply number of contacts
50
51        public static final byte LISTSTARTOFFSET_TAGID = 0x05;
52
53        public static final byte FILTER_TAGID = 0x06;
54
55        public static final byte FORMAT_TAGID = 0x07;
56
57        public static final byte PHONEBOOKSIZE_TAGID = 0x08;//only used if max list count = 0
58
59        public static final byte NEWMISSEDCALLS_TAGID = 0x09;//only used in "mch" in response
60    }
61
62    public static class TRIPLET_VALUE {
63        public static class ORDER {
64            public static final byte ORDER_BY_INDEX = 0x00;
65
66            public static final byte ORDER_BY_ALPHANUMERIC = 0x01;
67
68            public static final byte ORDER_BY_PHONETIC = 0x02;
69        }
70
71        public static class SEARCHATTRIBUTE {
72            public static final byte SEARCH_BY_NAME = 0x00;
73
74            public static final byte SEARCH_BY_NUMBER = 0x01;
75
76            public static final byte SEARCH_BY_SOUND = 0x02;
77        }
78
79        public static class FORMAT {
80            public static final byte VCARD_VERSION_21 = 0x00;
81
82            public static final byte VCARD_VERSION_30 = 0x01;
83        }
84    }
85
86    public static class TRIPLET_LENGTH {
87        public static final byte ORDER_LENGTH = 1;
88
89        //public final byte SEARCH_VALUE_LENGTH = 0x02;
90        public static final byte SEARCH_ATTRIBUTE_LENGTH = 1;
91
92        public static final byte MAXLISTCOUNT_LENGTH = 2;
93
94        public static final byte LISTSTARTOFFSET_LENGTH = 2;
95
96        public static final byte FILTER_LENGTH = 8;
97
98        public static final byte FORMAT_LENGTH = 1;
99
100        public static final byte PHONEBOOKSIZE_LENGTH = 2;
101
102        public static final byte NEWMISSEDCALLS_LENGTH = 1;
103    }
104
105    /*
106    public class TRIPLET_STRUCTURE{
107        TRIPLET_TAGID id;
108        TRIPLET_LENGTH length;
109        byte[] value;
110    }
111    */
112    public ApplicationParameter() {
113        b_array = new byte[max_length_ini];
114        length = 0;
115    }
116
117    public void addAPPHeader(byte tag, byte len, byte[] value) {
118        if ((length + len + 2) > max_length_ini) {
119            byte[] array_tmp = new byte[length + 4 * len];
120            System.arraycopy(b_array, 0, array_tmp, 0, length);
121            b_array = array_tmp;
122            max_length_ini = length + 4 * len;
123        }
124        b_array[length++] = tag;
125        b_array[length++] = len;
126        System.arraycopy(value, 0, b_array, length, len);
127        length += len;
128    }
129
130    public byte[] getAPPparam() {
131        byte[] para = new byte[length];
132        System.arraycopy(b_array, 0, para, 0, length);
133        return para;
134    }
135}
136