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/EditedArtifactStorage.java $
003: * $Id: EditedArtifactStorage.java 23024 2007-03-20 00:48:00Z john.ellis@rsmart.com $
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.Stack;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.jdom.Element;
027: import org.sakaiproject.metaobj.shared.mgt.ReadableObjectHome;
028: import org.sakaiproject.metaobj.shared.model.ElementBean;
029: import org.sakaiproject.metaobj.shared.model.StructuredArtifact;
030: import org.sakaiproject.metaobj.utils.xml.SchemaNode;
031:
032: public class EditedArtifactStorage {
033: protected final Log logger = LogFactory.getLog(getClass());
034:
035: public static final String STORED_ARTIFACT_FLAG = "org_theospi_storedArtifactCall";
036: public static final String EDITED_ARTIFACT_STORAGE_SESSION_KEY = "org_theospi_editedArtifact";
037:
038: private SchemaNode rootSchemaNode = null;
039: private SchemaNode currentSchemaNode = null;
040: private StructuredArtifact rootArtifact = null;
041: private ElementBean currentElement = null;
042: private String currentPath = null;
043: private ReadableObjectHome home;
044: private Stack elementBeanStack = new Stack();
045: private Stack pathStack = new Stack();
046: private Element oldParentElement = null;
047:
048: public EditedArtifactStorage(SchemaNode rootSchemaNode,
049: StructuredArtifact rootArtifact) {
050: this .rootSchemaNode = rootSchemaNode;
051: this .currentSchemaNode = rootSchemaNode;
052: this .rootArtifact = rootArtifact;
053: this .currentElement = rootArtifact;
054: elementBeanStack.push(rootArtifact);
055: pathStack.push("");
056: setHome(rootArtifact.getHome());
057: }
058:
059: public SchemaNode getRootSchemaNode() {
060: return rootSchemaNode;
061: }
062:
063: protected void setRootSchemaNode(SchemaNode rootSchemaNode) {
064: this .rootSchemaNode = rootSchemaNode;
065: }
066:
067: public SchemaNode getCurrentSchemaNode() {
068: return currentSchemaNode;
069: }
070:
071: protected void setCurrentSchemaNode(SchemaNode currentSchemaNode) {
072: this .currentSchemaNode = currentSchemaNode;
073: }
074:
075: public StructuredArtifact getRootArtifact() {
076: return rootArtifact;
077: }
078:
079: protected void setRootArtifact(StructuredArtifact rootArtifact) {
080: this .rootArtifact = rootArtifact;
081: }
082:
083: public ElementBean getCurrentElement() {
084: return currentElement;
085: }
086:
087: protected void setCurrentElement(ElementBean currentElement) {
088: this .currentElement = currentElement;
089: }
090:
091: public String getCurrentPath() {
092: return currentPath;
093: }
094:
095: protected void setCurrentPath(String currentPath) {
096: this .currentPath = currentPath;
097: }
098:
099: public void pushCurrentElement(ElementBean newBean) {
100: oldParentElement = (Element) rootArtifact.getBaseElement()
101: .clone();
102: setCurrentElement(newBean);
103: elementBeanStack.push(newBean);
104: setCurrentSchemaNode(newBean.getCurrentSchema());
105: }
106:
107: public void pushCurrentPath(String s) {
108: if (getCurrentPath() != null && getCurrentPath().length() > 0) {
109: s = getCurrentPath() + "/" + s;
110: }
111: setCurrentPath(s);
112: pathStack.push(s);
113: }
114:
115: public ReadableObjectHome getHome() {
116: return home;
117: }
118:
119: protected void setHome(ReadableObjectHome home) {
120: this .home = home;
121: }
122:
123: public void popCurrentElement() {
124: popCurrentElement(false);
125: }
126:
127: public void popCurrentElement(boolean cancel) {
128: if (cancel) {
129: rootArtifact.setBaseElement(oldParentElement);
130: }
131: elementBeanStack.pop();
132: setCurrentElement((ElementBean) elementBeanStack.peek());
133: setCurrentSchemaNode(getCurrentElement().getCurrentSchema());
134: }
135:
136: public void popCurrentPath() {
137: pathStack.pop();
138: setCurrentPath((String) pathStack.peek());
139: }
140: }
|