KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > formmodel > UnionDefinition


1 /*
2  * Copyright 1999-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.cocoon.woody.formmodel;
17
18
19 /**
20  * The {@link WidgetDefinition} corresponding to a {@link Union} widget.
21  *
22  * @author Timothy Larson
23  * @version $Id: UnionDefinition.java 30932 2004-07-29 17:35:38Z vgritsenko $
24  */

25 public class UnionDefinition extends AbstractContainerDefinition {
26     private String JavaDoc caseWidgetId;
27
28     /*
29     public void setDatatype(Datatype datatype) {
30         if (!String.class.isAssignableFrom(datatype.getTypeClass()))
31             throw new RuntimeException("Only datatype string is allowed for this widget at " + getLocation() + ".");
32         super.setDatatype(datatype);
33     }
34
35     public void setDefault(Object value) throws Exception {
36         if (!(value == null || String.class.isAssignableFrom(value.getClass())))
37             throw new Exception("UnionDefinition: Default case must be supplied as a string (" + getLocation() + ")");
38         if (value == null || value.equals("")) {
39             if (isRequired())
40                 throw new Exception("UnionWidget: Union is marked required, but no default case was supplied (" + getLocation() + ")");
41             this.defaultValue = "";
42         } else {
43             if (!hasWidget((String)value))
44                 throw new Exception("UnionWidget: The default value \"" + value + "\" does not match a union case (" + getLocation() + ")");
45             this.defaultValue = (String)value;
46         }
47     }
48
49     public Object getDefaultValue() {
50         return defaultValue;
51     }
52     */

53
54     public void setCaseWidgetId(String JavaDoc id) {
55         caseWidgetId = id;
56     }
57
58     public String JavaDoc getCaseWidgetId() {
59         return caseWidgetId;
60     }
61
62     public Widget createInstance() {
63         Union unionWidget = new Union(this);
64         return unionWidget;
65     }
66 }
67
Popular Tags