001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.cleverphl.session;
025:
026: import jacareto.cleverphl.CleverPHL;
027: import jacareto.record.RecordException;
028: import jacareto.starter.StarterList;
029: import jacareto.struct.RecordStructureCompound;
030: import jacareto.struct.StructureException;
031: import jacareto.system.Customization;
032: import jacareto.system.EnvironmentMember;
033: import jacareto.toolkit.io.PersistenceUtilities;
034:
035: import java.io.File;
036: import java.io.IOException;
037:
038: /**
039: * Class which allows to load sessions.
040: *
041: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
042: * @version 1.00
043: */
044: public class SessionLoader extends EnvironmentMember {
045: /** The CleverPHL instance. */
046: private CleverPHL cleverPHL;
047:
048: /**
049: * Creates a new session loader.
050: *
051: * @param cleverPHL the evironment
052: */
053: public SessionLoader(CleverPHL cleverPHL) {
054: super (cleverPHL.getEnvironment());
055: this .cleverPHL = cleverPHL;
056: }
057:
058: /**
059: * Loads a session with the given name. The new session is autmatically added to CleverPHL.
060: *
061: * @param name the name of the session
062: *
063: * @throws IOException when one of the session files cannot be loaded
064: * @throws RecordException when the session's record cannot be loaded
065: * @throws StructureException when the session's structure cannot be built
066: */
067: public void loadSession(String name) throws IOException,
068: RecordException, StructureException {
069: String sessionDirName = getFiles().getDir(
070: "CLEVERPHL_SESSIONS_DIR").getCanonicalPath()
071: + File.separator + name;
072: Customization sessionCustom = new Customization(sessionDirName
073: + File.separator + "session_custom.xml");
074: StarterList starterList = new StarterList(getEnvironment(),
075: sessionDirName + File.separator + "starters.xml");
076:
077: Session session = new Session(cleverPHL, name, sessionCustom);
078: session.setStarterList(starterList);
079:
080: cleverPHL.getSessionList().add(session);
081:
082: RecordStructureCompound compound = PersistenceUtilities
083: .loadCompoundFromFile(getEnvironment(), sessionDirName
084: + File.separator + "record.xml", session
085: .getSessionClassLoader());
086: session.setRecordStructureCompound(compound);
087:
088: session.setSessionUnsaved(false);
089:
090: session.initShutdownHook();
091: }
092:
093: /**
094: * Returns a stored session without adding it to the session list. This method can be used to
095: * access data of a stored session (for example, the structure) without adding it to the
096: * session list of CleverPHL
097: *
098: * @param name the name of the session
099: *
100: * @return DOCUMENT ME!
101: *
102: * @throws IOException when one of the session files cannot be loaded
103: * @throws RecordException when the session's record cannot be loaded
104: * @throws StructureException when the session's structure cannot be built
105: */
106: public Session getSession(String name) throws IOException,
107: RecordException, StructureException {
108: String sessionDirName = getFiles().getDir(
109: "CLEVERPHL_SESSIONS_DIR").getCanonicalPath()
110: + File.separator + name;
111: Customization sessionCustom = new Customization(sessionDirName
112: + File.separator + "session_custom.xml");
113: StarterList starterList = new StarterList(getEnvironment(),
114: sessionDirName + File.separator + "starters.xml");
115:
116: Session session = new Session(cleverPHL, name, sessionCustom);
117: session.setStarterList(starterList);
118:
119: RecordStructureCompound compound = PersistenceUtilities
120: .loadCompoundFromFile(getEnvironment(), sessionDirName
121: + File.separator + "record.xml", session
122: .getSessionClassLoader());
123: session.setRecordStructureCompound(compound);
124:
125: session.setSessionUnsaved(false);
126:
127: return session;
128: }
129: }
|