001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.commons.dsi.dml.functions;
020:
021: import org.openharmonise.commons.dsi.*;
022: import org.openharmonise.commons.dsi.dml.*;
023:
024: /**
025: * This class represents a SQL 'substring' function, storing the pertinent data so that
026: * the data store interface implementation can then create the correct function call.
027: *
028: * @author Michael Bell
029: * @version $Revision: 1.1 $
030: *
031: */
032: public class Substring implements Function {
033:
034: /**
035: * The start index
036: */
037: private Object m_objStart = null;
038:
039: /**
040: * The finish index
041: */
042: private Object m_objFinish = null;
043:
044: /**
045: * The string to be substringed
046: */
047: private String m_sString = null;
048:
049: /**
050: * Constructs a representation of the substring function which start the
051: * substring at <code>nStart</code> and finish the substring at <code>nFinish</code>.
052: *
053: * @param sString the string
054: * @param nStart the start index
055: * @param nFinish the finish index
056: */
057: public Substring(String sString, int nStart, int nFinish) {
058: m_objStart = new Integer(nStart);
059: m_objFinish = new Integer(nFinish);
060: m_sString = sString;
061: }
062:
063: /**
064: * Constructs a representation of the substring function which start the
065: * substring at the result of processing <code>objStart</code> and finish
066: * the substring at the result of processing <code>objFinish</code>. The
067: * start and finish parameters may be <code>Integer</code>, <code>Function</code>,
068: * or <code>String</code> values.
069: *
070: * @param sString the string
071: * @param objStart the object which defines the start index
072: * @param objFinish the object which defines the finish index
073: * @throws DataStoreException if either the start or finish values are invalid
074: */
075: public Substring(String sString, Object objStart, Object objFinish)
076: throws DataStoreException {
077:
078: if ((objStart instanceof Integer) == false
079: && (objStart instanceof Function) == false
080: && (objStart instanceof String) == false) {
081: throw new DataStoreException("Start value invalid");
082: }
083:
084: if ((objFinish instanceof Integer) == false
085: && (objFinish instanceof Function) == false
086: && (objFinish instanceof String) == false) {
087: throw new DataStoreException("Finish value invalid");
088: }
089:
090: m_objStart = objStart;
091: m_objFinish = objFinish;
092: m_sString = sString;
093: }
094:
095: /**
096: * Returns the index of where the substring should start as an <code>Integer</code>
097: * or a <code>Function</code>.
098: *
099: * @return the index of where the substring should start
100: */
101: public Object getStart() {
102: return m_objStart;
103: }
104:
105: /**
106: * Returns the index of where the substring should end as an <code>Integer</code>
107: * or a <code>Function</code>.
108: *
109: * @return the index of where the substring should end
110: */
111: public Object getFinish() {
112: return m_objFinish;
113: }
114:
115: /**
116: * Returns the <code>String</code> to be used in substring function.
117: *
118: * @return the <code>String</code> to be used in substring function
119: */
120: public String getString() {
121: return m_sString;
122: }
123: }
|