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/SimpleSchemaNodeImpl.java $
003: * $Id: SimpleSchemaNodeImpl.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.List;
023:
024: import org.jdom.Attribute;
025: import org.jdom.Element;
026: import org.sakaiproject.metaobj.utils.xml.ElementType;
027: import org.sakaiproject.metaobj.utils.xml.NormalizationException;
028: import org.sakaiproject.metaobj.utils.xml.SchemaInvalidException;
029: import org.sakaiproject.metaobj.utils.xml.ValidatedNode;
030: import org.sakaiproject.metaobj.utils.xml.ValidationError;
031:
032: /**
033: * Created by IntelliJ IDEA.
034: * User: John Ellis
035: * Date: Apr 15, 2004
036: * Time: 3:47:58 PM
037: * To change this template use File | Settings | File Templates.
038: */
039: public class SimpleSchemaNodeImpl extends SchemaNodeImpl {
040:
041: private BaseElementType type;
042: private boolean isAttribute = false;
043:
044: /*
045: public SimpleSchemaNodeImpl(Element schemaElement, GlobalMaps globalMaps)
046: throws SchemaInvalidException {
047:
048: super(schemaElement, globalMaps);
049: }
050: */
051:
052: public SimpleSchemaNodeImpl(Element schemaElement,
053: GlobalMaps globalMaps, boolean isAttribute)
054: throws SchemaInvalidException {
055:
056: super (schemaElement, globalMaps);
057: this .isAttribute = isAttribute;
058: }
059:
060: protected void initSchemaElement() {
061: super .initSchemaElement();
062: type = ElementTypeFactory.getInstance().createElementType(
063: getSchemaElement(), this , xsdNamespace);
064: }
065:
066: /**
067: * Validates the passed in node and all children.
068: * Will also normalize any values.
069: *
070: * @param node a jdom element to validate
071: * @return the validated Element wrapped
072: * in a ValidatedNode class
073: */
074: public ValidatedNode validateAndNormalize(Element node) {
075: return type.validateAndNormalize(node);
076: }
077:
078: public ValidatedNode validateAndNormalize(Attribute node) {
079: ValidatedNodeImpl validatedNode = new ValidatedNodeImpl(this ,
080: null);
081:
082: if (!isAttribute()) {
083: validatedNode.getErrors().add(
084: new ValidationError(validatedNode,
085: "not an attribute", new Object[] {}));
086: }
087: return type.validateAndNormalize(node);
088: }
089:
090: public String getSchemaNormalizedValue(Object value)
091: throws NormalizationException {
092: if (value instanceof String) {
093: return type.getSchemaNormalizedValue((String) value);
094: } else {
095: return type.getSchemaNormalizedValue(value);
096: }
097: }
098:
099: public Object getActualNormalizedValue(String value)
100: throws NormalizationException {
101: return type.getActualNormalizedValue(value);
102: }
103:
104: public Class getObjectType() {
105: return type.getObjectType();
106: }
107:
108: public int getMaxLength() {
109: return type.maxLength;
110: }
111:
112: public ElementType getType() {
113: return type;
114: }
115:
116: public List getEnumeration() {
117: return type.getEnumeration();
118: }
119:
120: public boolean isAttribute() {
121: return isAttribute;
122: }
123:
124: public boolean isDataNode() {
125: return true;
126: }
127:
128: }
|