001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/shared/control/SchemaBean.java $
003: * $Id: SchemaBean.java 14230 2006-09-05 18:02:51Z 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.shared.control;
021:
022: import java.util.ArrayList;
023: import java.util.Hashtable;
024: import java.util.Iterator;
025: import java.util.List;
026: import java.util.Map;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.sakaiproject.metaobj.utils.xml.SchemaNode;
031:
032: /**
033: * Created by IntelliJ IDEA.
034: * User: John Ellis
035: * Date: Apr 20, 2004
036: * Time: 5:43:43 PM
037: * To change this template use File | Settings | File Templates.
038: */
039: public class SchemaBean {
040:
041: private SchemaNode schema;
042: private String schemaName;
043: private String parentName = "";
044: private boolean rootNodeFlag = false;
045: private Map annotations = null;
046: private SchemaBean parent = null;
047: protected final Log logger = LogFactory.getLog(getClass());
048: private boolean documentRoot = false;
049: private String description;
050:
051: public SchemaBean(String rootNode, SchemaNode schema,
052: String schemaName, String schemaDescription) {
053: this .schema = schema.getChild(rootNode);
054: this .schemaName = schemaName;
055: this .description = schemaDescription;
056: rootNodeFlag = true;
057: this .parent = new SchemaBean(schema, schemaName, null,
058: schemaDescription);
059: documentRoot = true;
060: }
061:
062: public SchemaBean(SchemaNode schema, String schemaName,
063: String parentName, String schemaDescription) {
064: this .schema = schema;
065: this .schemaName = schemaName;
066: this .parentName = parentName;
067: this .description = schemaDescription;
068:
069: if (parentName == null) {
070: rootNodeFlag = true;
071: }
072: }
073:
074: public List getFields() {
075: logger.debug("schema name" + schema.getName());
076: List fieldList = schema.getChildren();
077: List returnedList = new ArrayList();
078:
079: for (Iterator i = fieldList.iterator(); i.hasNext();) {
080: returnedList.add(new SchemaBean((SchemaNode) i.next(),
081: schemaName, getFieldNamePath(), description));
082: }
083:
084: return returnedList;
085: }
086:
087: public String getFieldName() {
088: return schema.getName();
089: }
090:
091: public String getFieldNamePath() {
092: return getFieldNamePath(false);
093: }
094:
095: public String getFieldNamePathReadOnly() {
096: return getFieldNamePath(true);
097: }
098:
099: public String getFieldNamePath(boolean viewOnly) {
100: if (rootNodeFlag) {
101: return "";
102: }
103:
104: String returnedPath = parentName;
105:
106: if (returnedPath != null && returnedPath.length() > 0) {
107: if (viewOnly) {
108: returnedPath += "']['";
109: } else {
110: returnedPath += ".";
111: }
112: } else if (returnedPath == null) {
113: returnedPath = "";
114: }
115:
116: return returnedPath + getFieldName();
117: }
118:
119: public SchemaNode getSchema() {
120: return schema;
121: }
122:
123: public void setSchema(SchemaNode schema) {
124: this .schema = schema;
125: }
126:
127: public String getSchemaName() {
128: return schemaName;
129: }
130:
131: public void setSchemaName(String schemaName) {
132: this .schemaName = schemaName;
133: }
134:
135: public Map getAnnotations() {
136: if (annotations != null) {
137: return annotations;
138: }
139:
140: annotations = new Hashtable();
141:
142: for (Iterator i = schema.getDocumentAnnotations().entrySet()
143: .iterator(); i.hasNext();) {
144: Map.Entry entry = (Map.Entry) i.next();
145:
146: if (entry.getKey().toString().startsWith("ospi.")) {
147: annotations.put(entry.getKey().toString().substring(5),
148: entry.getValue());
149: } else if (entry.getKey().toString().startsWith("sakai.")) {
150: annotations.put(entry.getKey().toString().substring(6),
151: entry.getValue());
152: }
153: }
154:
155: return annotations;
156: }
157:
158: public SchemaBean getParent() {
159: return parent;
160: }
161:
162: public void setParent(SchemaBean parent) {
163: this .parent = parent;
164: }
165:
166: public boolean isDocumentRoot() {
167: return documentRoot;
168: }
169:
170: public String getDescription() {
171: return description;
172: }
173:
174: public void setDescription(String description) {
175: this.description = description;
176: }
177: }
|