01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.woody.formmodel;
18:
19: /**
20: * The {@link WidgetDefinition} corresponding to a {@link Union} widget.
21: *
22: * @author Timothy Larson
23: * @version $Id: UnionDefinition.java 433543 2006-08-22 06:22:54Z crossley $
24: */
25: public class UnionDefinition extends AbstractContainerDefinition {
26: private String 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 id) {
55: caseWidgetId = id;
56: }
57:
58: public String getCaseWidgetId() {
59: return caseWidgetId;
60: }
61:
62: public Widget createInstance() {
63: Union unionWidget = new Union(this);
64: return unionWidget;
65: }
66: }
|