KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > 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.forms.formmodel;
17
18
19 /**
20  * The {@link WidgetDefinition} corresponding to a {@link Union} widget.
21  *
22  * @version $Id: UnionDefinition.java 289538 2005-09-16 13:46:22Z sylvain $
23  */

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

52     
53     /**
54      * initialize this definition with the other, sort of like a copy constructor
55      */

56     public void initializeFrom(WidgetDefinition definition) throws Exception JavaDoc {
57         super.initializeFrom(definition);
58         
59         if(definition instanceof UnionDefinition) {
60             UnionDefinition other = (UnionDefinition)definition;
61             this.caseWidgetId = other.caseWidgetId;
62             
63         } else {
64             throw new Exception JavaDoc("Definition to inherit from is not of the right type! (at "+getLocation()+")");
65         }
66     }
67
68     public void setCaseWidgetId(String JavaDoc id) {
69         checkMutable();
70         caseWidgetId = id;
71     }
72
73     public String JavaDoc getCaseWidgetId() {
74         return caseWidgetId;
75     }
76
77     public Widget createInstance() {
78         Union unionWidget = new Union(this);
79         return unionWidget;
80     }
81 }
82
Popular Tags