01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-impl/api-impl/src/java/org/sakaiproject/metaobj/utils/xml/impl/BooleanElementType.java $
03: * $Id: BooleanElementType.java 27836 2007-03-26 23:46:10Z john.ellis@rsmart.com $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.metaobj.utils.xml.impl;
21:
22: import org.jdom.Element;
23: import org.jdom.Namespace;
24: import org.sakaiproject.metaobj.utils.xml.NormalizationException;
25: import org.sakaiproject.metaobj.utils.xml.SchemaNode;
26:
27: /**
28: * Created by IntelliJ IDEA.
29: * User: John Ellis
30: * Date: May 27, 2004
31: * Time: 6:31:58 AM
32: * To change this template use File | Settings | File Templates.
33: */
34: public class BooleanElementType extends BaseElementType {
35: private boolean required = false;
36:
37: public BooleanElementType(String typeName, Element schemaElement,
38: SchemaNode parentNode, Namespace xsdNamespace) {
39: super (typeName, schemaElement, parentNode, xsdNamespace);
40: required = parentNode.getMinOccurs() >= 1;
41: }
42:
43: public String getSchemaNormalizedValue(Object value)
44: throws NormalizationException {
45: if (required && (value == null || !(Boolean) value)) {
46: throw new NormalizationException("Required field",
47: NormalizationException.REQIRED_FIELD_ERROR_CODE,
48: new Object[0]);
49: }
50:
51: return value.toString();
52: }
53:
54: public String getSchemaNormalizedValue(String value)
55: throws NormalizationException {
56: return new Boolean(value).toString();
57: }
58:
59: public Class getObjectType() {
60: return Boolean.class;
61: }
62:
63: public Object getActualNormalizedValue(String value) {
64: return new Boolean(value);
65: }
66: }
|