001//
002// Name
003//      $RCSfile: KeyFieldValueList.java,v $
004// 
005// Copyright
006//      Confidential Property of Kabira Technologies, Inc.
007//      Copyright 2009, 2010 by Kabira Technologies, Inc.
008//      All rights reserved.
009//
010// History
011//      $Revision: 1.1.2.4 $ $Date: 2011/06/17 21:31:30 $
012//
013package com.kabira.platform;
014
015import java.util.ArrayList;
016
017/**
018 * Class used to manage field values.
019 */
020public class KeyFieldValueList
021{
022        /**
023         * Creates a KeyFieldValueList instance.
024         */
025        public KeyFieldValueList()
026        {
027                m_entries = new ArrayList<FieldEntry>();
028        }
029
030        /**
031         * Adds a field value pair.
032         *
033         * @param fieldName The field name.
034         * @param value The value to use.
035         *
036         * @exception KeyNullValueError
037         *      The given value is null.
038         * <p>
039         * When executed, this defines the value used for the given
040         * field. These field/value pairs are used when forming the key
041         * for a query, or for setting additional fields when a
042         * <code>getOrCreateSingleResult()</code> call results in an
043         * instance being created by the runtime.
044         *<p>
045         * Adding the same field more than once will result in
046         * a KeyMalformedQueryError exception if this instance
047         * is passed to KeyQuery.defineQuery() for a non-ordered key.
048         */
049        public void add(String fieldName, Object value)
050                throws KeyNullValueError
051        {
052                if (value == null)
053                {
054                        throw new KeyNullValueError(
055                                "Null value for field " + fieldName +
056                                ", keys cannot have null values");
057                }
058                FieldEntry f = new FieldEntry(); 
059
060                f.m_name = fieldName;
061                f.m_value = value;
062                f.m_op = KeyComparisonOperator.EQ;
063
064                m_entries.add(f);
065        }
066
067        /**
068         * Removes all fields from the list.
069         */
070        public void clear()
071        {
072                m_entries.clear();
073        }
074
075        ArrayList<FieldEntry> getEntries()
076        {
077                return new ArrayList<FieldEntry>(m_entries);
078        }
079
080        ArrayList<FieldEntry>     m_entries; 
081}