KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > commons > dsi > dml > functions > Substring


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.commons.dsi.dml.functions;
20
21 import org.openharmonise.commons.dsi.*;
22 import org.openharmonise.commons.dsi.dml.*;
23
24
25 /**
26  * This class represents a SQL 'substring' function, storing the pertinent data so that
27  * the data store interface implementation can then create the correct function call.
28  *
29  * @author Michael Bell
30  * @version $Revision: 1.1 $
31  *
32  */

33 public class Substring implements Function {
34
35     /**
36      * The start index
37      */

38     private Object JavaDoc m_objStart = null;
39     
40     /**
41      * The finish index
42      */

43     private Object JavaDoc m_objFinish = null;
44     
45     /**
46      * The string to be substringed
47      */

48     private String JavaDoc m_sString = null;
49
50     /**
51      * Constructs a representation of the substring function which start the
52      * substring at <code>nStart</code> and finish the substring at <code>nFinish</code>.
53      *
54      * @param sString the string
55      * @param nStart the start index
56      * @param nFinish the finish index
57      */

58     public Substring(String JavaDoc sString, int nStart, int nFinish) {
59         m_objStart = new Integer JavaDoc(nStart);
60         m_objFinish = new Integer JavaDoc(nFinish);
61         m_sString = sString;
62     }
63
64     /**
65      * Constructs a representation of the substring function which start the
66      * substring at the result of processing <code>objStart</code> and finish
67      * the substring at the result of processing <code>objFinish</code>. The
68      * start and finish parameters may be <code>Integer</code>, <code>Function</code>,
69      * or <code>String</code> values.
70      *
71      * @param sString the string
72      * @param objStart the object which defines the start index
73      * @param objFinish the object which defines the finish index
74      * @throws DataStoreException if either the start or finish values are invalid
75      */

76     public Substring(String JavaDoc sString, Object JavaDoc objStart, Object JavaDoc objFinish)
77         throws DataStoreException {
78
79         if ((objStart instanceof Integer JavaDoc) == false
80             && (objStart instanceof Function) == false
81             && (objStart instanceof String JavaDoc) == false) {
82             throw new DataStoreException("Start value invalid");
83         }
84
85         if ((objFinish instanceof Integer JavaDoc) == false
86             && (objFinish instanceof Function) == false
87             && (objFinish instanceof String JavaDoc) == false) {
88             throw new DataStoreException("Finish value invalid");
89         }
90
91         m_objStart = objStart;
92         m_objFinish = objFinish;
93         m_sString = sString;
94     }
95
96     /**
97      * Returns the index of where the substring should start as an <code>Integer</code>
98      * or a <code>Function</code>.
99      *
100      * @return the index of where the substring should start
101      */

102     public Object JavaDoc getStart() {
103         return m_objStart;
104     }
105
106     /**
107      * Returns the index of where the substring should end as an <code>Integer</code>
108      * or a <code>Function</code>.
109      *
110      * @return the index of where the substring should end
111      */

112     public Object JavaDoc getFinish() {
113         return m_objFinish;
114     }
115
116     /**
117      * Returns the <code>String</code> to be used in substring function.
118      *
119      * @return the <code>String</code> to be used in substring function
120      */

121     public String JavaDoc getString() {
122         return m_sString;
123     }
124 }
125
Popular Tags