001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/facade/authz/QualifierFacade.java $
003: * $Id: QualifierFacade.java 9273 2006-05-10 22:34:28Z daisyf@stanford.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.tool.assessment.facade.authz;
021:
022: import java.util.ArrayList;
023: import java.util.Set;
024:
025: import org.osid.shared.Id;
026: import org.osid.shared.Type;
027:
028: import org.sakaiproject.tool.assessment.data.dao.authz.QualifierData;
029: import org.sakaiproject.tool.assessment.data.ifc.authz.QualifierIfc;
030: import org.sakaiproject.tool.assessment.facade.TypeFacadeQueriesAPI;
031: import org.sakaiproject.tool.assessment.services.PersistenceService;
032:
033: public class QualifierFacade implements QualifierIfc {
034: /**
035: *
036: */
037: private static final long serialVersionUID = 3908822740713745290L;
038: private Id id;
039: private QualifierIteratorFacade childrenIter;
040: private QualifierIteratorFacade parentIter;
041: private String referenceName;
042: private String description;
043: private Type qualifierType;
044: private QualifierIfc data;
045:
046: // private String qualifierId;
047: private long qualifierId;
048: private String displayName;
049: private String qualifierTypeId;
050: private Set childSet;
051: private Set parentSet;
052:
053: public QualifierFacade() {
054: this .data = new QualifierData(); //should do a create method later
055: }
056:
057: public QualifierFacade(
058: // String qualifierId, String referenceName, String displayName, String description, String qualifierTypeId){
059: long qualifierId, String referenceName, String displayName,
060: String description, String qualifierTypeId) {
061: this .data = new QualifierData(); //should do a create method later
062: this .referenceName = referenceName;
063: setQualifierId(qualifierId);
064: setReferenceName(referenceName);
065: setDisplayName(displayName);
066: setDescription(description);
067: setQualifierTypeId(qualifierTypeId);
068: }
069:
070: public QualifierFacade(QualifierIfc data) {
071: this .data = data;
072: this .id = getId();
073: /* this.childrenIter = getChildren();
074: this.parentIter = getParents();*/
075: this .referenceName = getReferenceName();
076: this .description = getDescription();
077: this .qualifierType = getQualifierType();
078: this .qualifierId = getQualifierId();
079: this .qualifierTypeId = getQualifierTypeId();
080: this .displayName = getDisplayName();
081: }
082:
083: public Id getId() {
084: return id;
085: }
086:
087: public String getReferenceName() {
088: return referenceName;
089: }
090:
091: public void setReferenceName(String referenceName) {
092: this .referenceName = referenceName;
093: data.setReferenceName(referenceName);
094: }
095:
096: public String getDescription() {
097: return data.getDescription();
098: }
099:
100: public void setDescription(String description) {
101: this .description = description;
102: data.setDescription(description);
103: }
104:
105: public boolean isParent() {
106: boolean returnValue = false;
107: //ArrayList a = new ArrayList();
108: while (childrenIter.hasNextQualifier()) {
109: Id i = (Id) childrenIter.nextQualifier();
110: if (i.equals(this .id)) {
111: returnValue = true;
112: break;
113: }
114: }
115: return returnValue;
116: }
117:
118: public Type getQualifierType() {
119: TypeFacadeQueriesAPI typeFacadeQueries = PersistenceService
120: .getInstance().getTypeFacadeQueries();
121: return typeFacadeQueries.getTypeById(new Long(this .data
122: .getQualifierTypeId()));
123: }
124:
125: public void updateDescription(String description) {
126: this .description = description;
127: }
128:
129: public void addParent(Id parm1) {
130: ArrayList a = new ArrayList();
131: while (parentIter.hasNextQualifier()) {
132: Id i = (Id) parentIter.nextQualifier();
133: a.add(i);
134: }
135: a.add(parm1);
136: this .parentIter = new QualifierIteratorFacade(a);
137: }
138:
139: public void removeParent(Id parm1) {
140: ArrayList a = new ArrayList();
141: while (parentIter.hasNextQualifier()) {
142: Id i = (Id) parentIter.nextQualifier();
143: if (!parm1.equals(i))
144: a.add(i);
145: }
146: this .parentIter = new QualifierIteratorFacade(a);
147: }
148:
149: public void changeParent(Id oldParent, Id newParent) {
150: ArrayList a = new ArrayList();
151: while (parentIter.hasNextQualifier()) {
152: Id i = (Id) parentIter.nextQualifier();
153: if (!oldParent.equals(i))
154: a.add(i);
155: else
156: a.add(newParent); // replace oldParent with newParent
157: }
158: this .parentIter = new QualifierIteratorFacade(a);
159: }
160:
161: public boolean isChildOf(Id parent) {
162: boolean returnValue = false;
163: //ArrayList a = new ArrayList();
164: while (parentIter.hasNextQualifier()) {
165: Id i = (Id) parentIter.nextQualifier();
166: if (parent.equals(i)) {
167: returnValue = true;
168: break;
169: }
170: }
171: return returnValue;
172: }
173:
174: /* public QualifierIteratorFacade getChildren() {
175: return PersistenceService.getInstance().getAuthorizationFacadeQueries().getQualifierChildren(data.getQualifierId());
176: }
177: public QualifierIteratorFacade getParents() {
178: return PersistenceService.getInstance().getAuthorizationFacadeQueries().getQualifierParents(data.getQualifierId());
179: }*/
180:
181: public QualifierIfc getData() {
182: return this .data;
183: }
184:
185: // public String getQualifierId() {
186: public long getQualifierId() {
187: return data.getQualifierId();
188: }
189:
190: // public void setQualifierId(String id) {
191: public void setQualifierId(long id) {
192: this .qualifierId = id;
193: data.setQualifierId(id);
194: }
195:
196: public String getDisplayName() {
197: return data.getDisplayName();
198: }
199:
200: public void setDisplayName(String displayName) {
201: this .displayName = displayName;
202: data.setDisplayName(displayName);
203: }
204:
205: public String getQualifierTypeId() {
206: return data.getQualifierTypeId();
207: }
208:
209: public void setQualifierTypeId(String qualifierTypeId) {
210: this .qualifierTypeId = qualifierTypeId;
211: data.setQualifierTypeId(qualifierTypeId);
212: }
213:
214: /* public Set getChildSet() {
215: return data.getChildSet();
216: }
217:
218: public void setChildSet(Set childSet) {
219: this.childSet = childSet;
220: data.setChildSet(childSet);
221: }
222:
223: public Set getParentSet() {
224: return data.getParentSet();
225: }
226:
227: public void setParentSet(Set parentSet) {
228: this.parentSet = parentSet;
229: data.setParentSet(parentSet);
230: }
231: */
232: }
|