001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/osid/authz/impl/QualifierImpl.java $
003: * $Id: QualifierImpl.java 9276 2006-05-10 23:04:20Z daisyf@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 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.tool.assessment.osid.authz.impl;
021:
022: import org.osid.authorization.Qualifier;
023: import org.osid.shared.Id;
024: import org.osid.authorization.AuthorizationException;
025: import org.osid.shared.Type;
026: import org.osid.authorization.QualifierIterator;
027: import java.util.ArrayList;
028:
029: public class QualifierImpl implements Qualifier {
030: private Id id;
031: private QualifierIterator childrenIter;
032: private QualifierIterator parentIter;
033: private String referenceName;
034: private String description;
035: private Type qualifierType;
036:
037: public QualifierImpl() {
038: }
039:
040: public Id getId()
041: throws org.osid.authorization.AuthorizationException {
042: return id;
043: }
044:
045: public String getReferenceName()
046: throws org.osid.authorization.AuthorizationException {
047: return referenceName;
048: }
049:
050: public String getDescription()
051: throws org.osid.authorization.AuthorizationException {
052: return description;
053: }
054:
055: public boolean isParent()
056: throws org.osid.authorization.AuthorizationException {
057: boolean returnValue = false;
058: //ArrayList a = new ArrayList();
059: while (childrenIter.hasNextQualifier()) {
060: Id i = (Id) childrenIter.nextQualifier();
061: if (i.equals(this .id)) {
062: returnValue = true;
063: break;
064: }
065: }
066: return returnValue;
067: }
068:
069: public Type getQualifierType()
070: throws org.osid.authorization.AuthorizationException {
071: return qualifierType;
072: }
073:
074: public void updateDescription(String parm1)
075: throws org.osid.authorization.AuthorizationException {
076: this .description = parm1;
077: }
078:
079: public void addParent(Id parm1)
080: throws org.osid.authorization.AuthorizationException {
081: ArrayList a = new ArrayList();
082: while (parentIter.hasNextQualifier()) {
083: Id i = (Id) parentIter.nextQualifier();
084: a.add(i);
085: }
086: a.add(parm1);
087: this .parentIter = new QualifierIteratorImpl(a);
088: }
089:
090: public void removeParent(Id parm1)
091: throws org.osid.authorization.AuthorizationException {
092: ArrayList a = new ArrayList();
093: while (parentIter.hasNextQualifier()) {
094: Id i = (Id) parentIter.nextQualifier();
095: if (!parm1.equals(i))
096: a.add(i);
097: }
098: this .parentIter = new QualifierIteratorImpl(a);
099: }
100:
101: public void changeParent(Id oldParent, Id newParent)
102: throws org.osid.authorization.AuthorizationException {
103: ArrayList a = new ArrayList();
104: while (parentIter.hasNextQualifier()) {
105: Id i = (Id) parentIter.nextQualifier();
106: if (!oldParent.equals(i))
107: a.add(i);
108: else
109: a.add(newParent); // replace oldParent with newParent
110: }
111: this .parentIter = new QualifierIteratorImpl(a);
112: }
113:
114: public boolean isChildOf(Id parent)
115: throws org.osid.authorization.AuthorizationException {
116: boolean returnValue = false;
117: //ArrayList a = new ArrayList();
118: while (parentIter.hasNextQualifier()) {
119: Id i = (Id) parentIter.nextQualifier();
120: if (parent.equals(i)) {
121: returnValue = true;
122: break;
123: }
124: }
125: return returnValue;
126: }
127:
128: public boolean isDescendantOf(Id parent)
129: throws org.osid.authorization.AuthorizationException {
130: throw new AuthorizationException(
131: AuthorizationException.UNIMPLEMENTED);
132: }
133:
134: public QualifierIterator getChildren()
135: throws org.osid.authorization.AuthorizationException {
136: return childrenIter;
137: }
138:
139: public QualifierIterator getParents()
140: throws org.osid.authorization.AuthorizationException {
141: return parentIter;
142: }
143:
144: }
|