001: /*--------------------------------------------------------------------------*
002: | Copyright (C) 2006 Christopher Kohlhaas |
003: | |
004: | This program is free software; you can redistribute it and/or modify |
005: | it under the terms of the GNU General Public License as published by the |
006: | Free Software Foundation. A copy of the license has been included with |
007: | these distribution in the COPYING file, if not go to www.fsf.org . |
008: | |
009: | As a special exception, you are granted the permissions to link this |
010: | program with every library, which license fulfills the Open Source |
011: | Definition as published by the Open Source Initiative (OSI). |
012: *--------------------------------------------------------------------------*/
013:
014: package org.rapla.storage.xml;
015:
016: import org.rapla.entities.Category;
017: import org.rapla.entities.User;
018: import org.rapla.entities.domain.Permission;
019: import org.rapla.entities.domain.internal.AllocatableImpl;
020: import org.rapla.entities.domain.internal.PermissionImpl;
021: import org.rapla.entities.storage.RefEntity;
022: import org.rapla.entities.storage.internal.SimpleEntity;
023: import org.rapla.framework.RaplaContext;
024: import org.rapla.framework.RaplaException;
025: import org.xml.sax.Attributes;
026: import org.xml.sax.SAXException;
027:
028: public class AllocatableReader extends RaplaXMLReader {
029: DynAttReader dynAttHandler;
030: AllocatableImpl allocatable;
031:
032: public AllocatableReader(RaplaContext context)
033: throws RaplaException {
034: super (context);
035: dynAttHandler = new DynAttReader(context);
036: addChildHandler(dynAttHandler);
037: }
038:
039: public void processElement(String namespaceURI, String localName,
040: String qName, Attributes atts) throws SAXException {
041: if (namespaceURI.equals(DYNATT_NS)) {
042: dynAttHandler.setClassifiable(allocatable);
043: delegateElement(dynAttHandler, namespaceURI, localName,
044: qName, atts);
045: return;
046: }
047:
048: if (!namespaceURI.equals(RAPLA_NS))
049: return;
050:
051: String holdBackString = getString(atts, "holdbackconflicts",
052: "false");
053: boolean holdBackConflicts = Boolean.valueOf(holdBackString)
054: .booleanValue();
055: if (localName.equals("resource")) {
056: allocatable = new AllocatableImpl();
057: allocatable.setHoldBackConflicts(holdBackConflicts);
058: setId((SimpleEntity) allocatable, atts);
059: setVersionIfThere(allocatable, atts);
060: }
061:
062: if (localName.equals("person")) {
063: allocatable = new AllocatableImpl();
064: allocatable.setPerson(true);
065: allocatable.setHoldBackConflicts(holdBackConflicts);
066: setId((SimpleEntity) allocatable, atts);
067: setVersionIfThere(allocatable, atts);
068: }
069:
070: if (localName.equals("permission")) {
071: PermissionImpl permission = new PermissionImpl();
072:
073: // process user
074: String userString = atts.getValue("user");
075: if (userString != null)
076: permission
077: .setUser((User) resolve(User.TYPE, userString));
078:
079: // process group
080: String groupId = atts.getValue("groupidref");
081: if (groupId != null) {
082: permission.setGroup((Category) resolve(Category.TYPE,
083: groupId));
084: } else {
085: String groupName = atts.getValue("group");
086: if (groupName != null) {
087: Category group = getGroup(groupName);
088: permission.setGroup(group);
089: }
090: }
091:
092: String startDate = getString(atts, "start-date", null);
093: if (startDate != null) {
094: permission.setStart(parseDate(startDate, false));
095: }
096:
097: String endDate = getString(atts, "end-date", null);
098: if (endDate != null) {
099: permission.setEnd(parseDate(endDate, false));
100: }
101:
102: String minAdvance = getString(atts, "min-advance", null);
103: if (minAdvance != null) {
104: permission.setMinAdvance(parseLong(minAdvance));
105: }
106:
107: String maxAdvance = getString(atts, "max-advance", null);
108: if (maxAdvance != null) {
109: permission.setMaxAdvance(parseLong(maxAdvance));
110: }
111:
112: String accessLevel = getString(atts, "access",
113: (String) Permission.ACCESS_LEVEL_NAMEMAP
114: .get(Permission.ALLOCATE_CONFLICTS));
115: int[] matchingLevel = Permission.ACCESS_LEVEL_NAMEMAP
116: .findMatchingKeys(accessLevel);
117: if (matchingLevel.length == 0) {
118: throw createSAXParseException("Unknown access level '"
119: + accessLevel + "'");
120: }
121: permission.setAccessLevel(matchingLevel[0]);
122: allocatable.addPermission(permission);
123: }
124: }
125:
126: public void processEnd(String namespaceURI, String localName,
127: String qName) throws SAXException {
128: if (!namespaceURI.equals(RAPLA_NS))
129: return;
130:
131: if (localName.equals("resource") || localName.equals("person")) {
132: if (allocatable.getPermissions().length == 0)
133: allocatable.addPermission(new PermissionImpl());
134: add((RefEntity) allocatable);
135: }
136: }
137: }
|