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: /**
030: * Encapsulation of a single-value PIM field
031: *
032: */
033: class ScalarPIMField implements PIMField {
034: /** Current value of the field. */
035: private Object value;
036: /** Field attributes. */
037: private int attributes;
038:
039: /**
040: * Adds a value to a PIM field.
041: * @param attributes properties to update
042: * @param value entry to be updated
043: */
044: public void addValue(int attributes, Object value) {
045: this .value = value;
046: this .attributes = attributes;
047: }
048:
049: /**
050: * Gets the value of the field.
051: * @param index element index
052: * @return field value
053: */
054: public Object getValue(int index) {
055: return value;
056: }
057:
058: /**
059: * Sets the value of the field.
060: * @param attributes field attributes requested
061: * @param value new value for field
062: * @param index element identifier
063: */
064: public void setValue(int attributes, Object value, int index) {
065: this .value = value;
066: this .attributes = attributes;
067: }
068:
069: /**
070: * Gets the field attributes.
071: * @param index element identifier
072: * @return encoded attributes
073: */
074: public int getAttributes(int index) {
075: checkIndex(index);
076: return attributes;
077: }
078:
079: /**
080: * Checks if the field contains data.
081: * @return <code>true</code> if field contains data
082: */
083: public boolean containsData() {
084: return true;
085: }
086:
087: /**
088: * Gets the number of value elements.
089: * @return always returns 1
090: */
091: public int getValueCount() {
092: return 1;
093: }
094:
095: /**
096: * Removes a value element.
097: * @param index identifier for value to remove
098: */
099: public void removeValue(int index) {
100: }
101:
102: /**
103: * Checks if field has scalar value.
104: * @return always returns true
105: */
106: public boolean isScalar() {
107: return true;
108: }
109:
110: /**
111: * Ensures that index is value value offset.
112: * @param index offset for value
113: */
114: private void checkIndex(int index) {
115: if (index != 0) {
116: throw new IndexOutOfBoundsException(String.valueOf(index));
117: }
118: }
119:
120: }
|