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: * $Header:$
18: */
19: package org.apache.beehive.netui.compiler.model.validation;
20:
21: import org.apache.beehive.netui.compiler.model.XmlElementSupport;
22: import org.apache.beehive.netui.compiler.model.XmlModelWriter;
23: import org.w3c.dom.Element;
24:
25: import java.util.LinkedHashMap;
26: import java.util.Map;
27: import java.util.Iterator;
28:
29: class ValidatableEntity extends XmlElementSupport {
30: private String _entityName;
31: private Map _fields = new LinkedHashMap();
32:
33: public ValidatableEntity(String entityName) {
34: _entityName = entityName;
35: }
36:
37: protected String getEntityName() {
38: return _entityName;
39: }
40:
41: public void addField(ValidatableField field) {
42: _fields.put(field.getPropertyName(), field);
43: }
44:
45: public ValidatableField getField(String fieldName) {
46: return (ValidatableField) _fields.get(fieldName);
47: }
48:
49: public void writeToElement(XmlModelWriter xw, Element element) {
50: assert _entityName.equals(getElementAttribute(element, "name")) : _entityName
51: + ", " + getElementAttribute(element, "name");
52:
53: for (Iterator i = _fields.values().iterator(); i.hasNext();) {
54: ValidatableField field = (ValidatableField) i.next();
55: String fieldPropertyName = field.getPropertyName();
56: Element fieldElementToUse = findChildElement(xw, element,
57: "field", "property", fieldPropertyName, true, null);
58: field.writeXML(xw, fieldElementToUse);
59: }
60: }
61: }
|