001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.kvem.midp.pim;
028:
029: import com.sun.midp.main.Configuration;
030:
031: /**
032: * Specification of a PIM field.
033: *
034: */
035: public class PIMFieldDescriptor {
036:
037: /** PIM: field. */
038: private int field;
039: /** PIM: type. */
040: private int dataType;
041: /** PIM: is the default value present? */
042: private boolean hasDefaultValue;
043: /** PIM: default value. */
044: private Object defaultValue;
045: /** PIM: label. */
046: private String label;
047: /** PIM: label resources. */
048: String[] labelResources;
049: /** PIM: attributes. */
050: private long attributes;
051: /** PIM: maximum number of values or -1 for unlimited data. */
052: private int maxValues;
053:
054: /**
055: * Constructor: field initialization.
056: *
057: * @param field ID
058: * @param dataType type
059: * @param hasDefaultValue is the default value present?
060: * @param defaultValue default value of the field
061: * @param labelResource label
062: * @param labelResources array of label resources
063: * @param attributes field attributes
064: * @param maxValues maximum number of values or -1
065: */
066: public PIMFieldDescriptor(int field, int dataType,
067: boolean hasDefaultValue, Object defaultValue,
068: String labelResource, String[] labelResources,
069: long attributes, int maxValues) {
070:
071: this .field = field;
072: this .dataType = dataType;
073: this .hasDefaultValue = hasDefaultValue;
074: this .defaultValue = defaultValue;
075: this .label = Configuration.getPropertyDefault(labelResource,
076: "Label_" + labelResource);
077: this .labelResources = labelResources;
078: this .attributes = attributes;
079: this .maxValues = maxValues;
080: }
081:
082: /**
083: * Constructor: field initialization.
084: *
085: * @param field ID
086: * @param dataType type
087: * @param hasDefaultValue is the default value present?
088: * @param defaultValue default value of the field
089: * @param labelResource label (labelResources = null)
090: * @param attributes field attributes
091: * @param maxValues maximum number of values or -1
092: */
093: public PIMFieldDescriptor(int field, int dataType,
094: boolean hasDefaultValue, Object defaultValue,
095: String labelResource, long attributes, int maxValues) {
096:
097: this (field, dataType, hasDefaultValue, defaultValue,
098: labelResource, null, attributes, maxValues);
099: }
100:
101: /**
102: * Gets field ID.
103: *
104: * @return the field ID
105: */
106: public int getField() {
107: return field;
108: }
109:
110: /**
111: * Gets field type.
112: *
113: * @return the field type
114: */
115: public int getDataType() {
116: return dataType;
117: }
118:
119: /**
120: * Gets field label.
121: *
122: * @return the field label
123: */
124: public String getLabel() {
125: return label;
126: }
127:
128: /**
129: * Checks if the field has a default value?
130: *
131: * @return true if the field has a default value?
132: */
133: public boolean hasDefaultValue() {
134: return hasDefaultValue;
135: }
136:
137: /**
138: * Gets the default value.
139: *
140: * @return the default value
141: */
142: public Object getDefaultValue() {
143: return defaultValue;
144: }
145:
146: /**
147: * Gets the length of array (type STRING_ARRAY).
148: *
149: * @return the length of array
150: */
151: public int getStringArraySize() {
152: return labelResources.length;
153: }
154:
155: /**
156: * Gets the label.
157: *
158: * @param arrayElement index of label in labelResources array
159: * @return the label
160: */
161: public String getElementlabel(int arrayElement) {
162: return Configuration.getPropertyDefault(
163: labelResources[arrayElement], "Label_"
164: + labelResources[arrayElement]);
165: }
166:
167: /**
168: * Gets the supported attributes.
169: *
170: * @return the set of supported attributes
171: */
172: public long getSupportedAttributes() {
173: return attributes;
174: }
175:
176: /**
177: * Gets the maximum values.
178: *
179: * @return the maximum values
180: */
181: public int getMaximumValues() {
182: return maxValues;
183: }
184: }
|