KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > sqls > impl > CaseImpl


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.ws.jaxme.sqls.impl;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.ws.jaxme.sqls.Case;
22 import org.apache.ws.jaxme.sqls.Column;
23 import org.apache.ws.jaxme.sqls.Column.Type;
24
25
26 /** Implementation of a
27  * {@link org.apache.ws.jaxme.sqls.Case} clause.
28  */

29 public class CaseImpl implements Case {
30     /** Implementation of a
31      * {@link org.apache.ws.jaxme.sqls.Case.When} clause.
32      */

33     public static class WhenImpl implements When {
34         private final Object JavaDoc condition, value;
35         /** Creates a new instance with the given condition
36          * and value.
37          */

38         public WhenImpl(Object JavaDoc pCondition, Object JavaDoc pValue) {
39             condition = ValueImpl.asValue(pCondition);
40             value = ValueImpl.asValue(pValue);
41         }
42         public Object JavaDoc getCondition() { return condition; }
43         public Object JavaDoc getValue() { return value; }
44     }
45
46     private final Column.Type type;
47     private Object JavaDoc checkedValue, elseValue;
48     private List JavaDoc whens = new ArrayList JavaDoc();
49
50     /** Creates a new instance with the given type.
51      */

52     protected CaseImpl(Column.Type pType) {
53         type = pType;
54     }
55
56     public void setCheckedValue(Object JavaDoc pValue) {
57         checkedValue = ValueImpl.asValue(pValue);
58     }
59     public Object JavaDoc getCheckedValue() {
60         return checkedValue;
61     }
62     public void addWhen(Object JavaDoc pCondition, Object JavaDoc pValue) {
63         addWhen(new WhenImpl(pCondition, pValue));
64     }
65     public void addWhen(When pWhen) { whens.add(pWhen); }
66     public void setElseValue(Object JavaDoc pValue) {
67         elseValue = ValueImpl.asValue(pValue);
68     }
69     public Object JavaDoc getElseValue() { return elseValue; }
70     public Type getType() { return type; }
71     public When[] getWhens() {
72         return (When[]) whens.toArray(new When[whens.size()]);
73     }
74 }
75
Popular Tags