001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-impl/api-impl/src/java/org/sakaiproject/metaobj/utils/xml/impl/ValidatedNodeImpl.java $
003: * $Id: ValidatedNodeImpl.java 14225 2006-09-05 17:39:44Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.metaobj.utils.xml.impl;
021:
022: import java.util.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import org.jdom.Element;
027: import org.sakaiproject.metaobj.utils.xml.SchemaNode;
028: import org.sakaiproject.metaobj.utils.xml.ValidatedNode;
029:
030: /**
031: * Created by IntelliJ IDEA.
032: * User: John Ellis
033: * Date: Apr 15, 2004
034: * Time: 12:10:37 PM
035: * To change this template use File | Settings | File Templates.
036: */
037: public class ValidatedNodeImpl implements ValidatedNode {
038:
039: private SchemaNode parentSchema;
040: private Element currentElement;
041: private List currentErrors = new ArrayList();
042: private List children = new ArrayList();
043: private Object normalizedValue;
044:
045: public ValidatedNodeImpl(SchemaNode parentSchema,
046: Element currentElement) {
047:
048: this .parentSchema = parentSchema;
049: this .currentElement = currentElement;
050: }
051:
052: /**
053: * Get the schema responsible for this node.
054: *
055: * @return
056: */
057: public SchemaNode getSchema() {
058: return parentSchema;
059: }
060:
061: /**
062: * Get the named child node as a validated node
063: *
064: * @param elementName
065: * @return
066: */
067: public ValidatedNode getChild(String elementName) {
068:
069: for (Iterator i = children.iterator(); i.hasNext();) {
070: ValidatedNode currentNode = (ValidatedNode) i.next();
071:
072: if (elementName.equals(currentNode.getElement().getName())) {
073: return currentNode;
074: }
075: }
076:
077: return null;
078: }
079:
080: /**
081: * Get all the direct children of this node as
082: * a list of ValidatedNode objects
083: *
084: * @return
085: */
086: public List getChildren() {
087: return children;
088: }
089:
090: /**
091: * Get all the named direct children of this node
092: * as a list of ValidatedNode objects.
093: *
094: * @param elementName
095: * @return
096: */
097: public List getChildren(String elementName) {
098:
099: List namedList = new ArrayList();
100:
101: for (Iterator i = children.iterator(); i.hasNext();) {
102: ValidatedNode currentNode = (ValidatedNode) i.next();
103:
104: if (elementName.equals(currentNode.getElement().getName())) {
105: namedList.add(currentNode);
106: }
107: }
108:
109: return namedList;
110: }
111:
112: /**
113: * Get the normalized value of this element as an object.
114: * Note: in the case of complex nodes, this could return
115: * a List of ValidatedNode objects (the children of this node)
116: *
117: * @return
118: */
119: public Object getNormalizedValue() {
120: return normalizedValue;
121: }
122:
123: public void setNormalizedValue(Object normalizedValue) {
124: this .normalizedValue = normalizedValue;
125: }
126:
127: /**
128: * The errors associated with this node if any or null if the
129: * node validated completely.
130: *
131: * @return
132: */
133: public List getErrors() {
134: return currentErrors;
135: }
136:
137: /**
138: * This returnes the element associated with this node.
139: *
140: * @return
141: */
142: public Element getElement() {
143: return currentElement;
144: }
145: }
|