001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-api/api/src/java/org/sakaiproject/metaobj/shared/model/StructuredArtifact.java $
003: * $Id: StructuredArtifact.java 21318 2007-02-10 23:53:53Z 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.model;
021:
022: import org.jdom.Element;
023: import org.sakaiproject.component.cover.ComponentManager;
024: import org.sakaiproject.metaobj.shared.mgt.IdManager;
025: import org.sakaiproject.metaobj.shared.mgt.ReadableObjectHome;
026: import org.sakaiproject.metaobj.shared.mgt.home.StructuredArtifactHomeInterface;
027: import org.sakaiproject.metaobj.utils.xml.SchemaNode;
028: import org.sakaiproject.content.api.ContentResource;
029:
030: /**
031: * Created by IntelliJ IDEA.
032: * User: John Ellis
033: * Date: Apr 19, 2004
034: * Time: 2:14:46 PM
035: * To change this template use File | Settings | File Templates.
036: */
037: public class StructuredArtifact extends ElementBean implements Artifact {
038: private Agent owner = null;
039: private Id id = null;
040: private StructuredArtifactHomeInterface home = null;
041: private IdManager idManager = null;
042: private String parentFolder = null;
043:
044: private static String ID_PARAMETER_NAME = "id";
045: private static String ARTIFACT_ID_PARAMETER_NAME = "artifactId";
046: private static String DISPLAY_NAME_PARAMETER_NAME = "displayName";
047: private String displayName;
048: private ContentResource baseResource;
049:
050: public StructuredArtifact(String elementName,
051: SchemaNode currentSchema) {
052: super (elementName, currentSchema);
053: }
054:
055: public StructuredArtifact() {
056: }
057:
058: public StructuredArtifact(Element baseElement,
059: SchemaNode currentSchema) {
060: super (baseElement, currentSchema, true);
061: }
062:
063: public Agent getOwner() {
064: return owner;
065: }
066:
067: public Id getId() {
068: return id;
069: }
070:
071: public void setId(Id id) {
072: this .id = id;
073: }
074:
075: public void setId(Object id) {
076: if (id instanceof Id) {
077: this .id = (Id) id;
078: } else if (id != null) {
079: this .id = getIdManager().getId(id.toString());
080: } else {
081: this .id = null;
082: }
083: }
084:
085: public Object get(Object key) {
086: if (key.equals(ID_PARAMETER_NAME)
087: || key.equals(ARTIFACT_ID_PARAMETER_NAME)) {
088: return getId();
089: } else if (key.equals(DISPLAY_NAME_PARAMETER_NAME)) {
090: return getDisplayName();
091: } else {
092: return super .get(key);
093: }
094: }
095:
096: public Object put(Object key, Object value) {
097: if (key.equals(ID_PARAMETER_NAME)
098: || key.equals(ARTIFACT_ID_PARAMETER_NAME)) {
099: setId(value);
100: return null;
101: } else if (key.equals(DISPLAY_NAME_PARAMETER_NAME)) {
102: setDisplayName((String) value);
103: return null;
104: } else {
105: return super .put(key, value);
106: }
107: }
108:
109: public boolean equals(Object other) {
110: if (other == null || !(other instanceof StructuredArtifact)) {
111: return false;
112: }
113: StructuredArtifact in = (StructuredArtifact) other;
114: return getId().equals(in.getId());
115: }
116:
117: public int hashCode() {
118: if (id == null) {
119: return 0;
120: }
121: return this .id.hashCode();
122: }
123:
124: public ReadableObjectHome getHome() {
125: return home;
126: }
127:
128: public void setHome(ReadableObjectHome homeObject) {
129: home = (StructuredArtifactHomeInterface) homeObject;
130: this .setCurrentSchema(home.getSchema().getChild(
131: home.getRootNode()));
132: }
133:
134: public String getDisplayName() {
135: return displayName;
136: }
137:
138: public void setDisplayName(String displayName) {
139: this .displayName = displayName;
140: }
141:
142: public Class getType(String key) {
143: if (key.equals(ID_PARAMETER_NAME)
144: || key.equals(ARTIFACT_ID_PARAMETER_NAME)) {
145: return Id.class;
146: } else if (key.equals(DISPLAY_NAME_PARAMETER_NAME)) {
147: return String.class;
148: } else {
149: return super .getType(key);
150: }
151: }
152:
153: public IdManager getIdManager() {
154: if (idManager == null) {
155: idManager = (IdManager) ComponentManager.getInstance().get(
156: "idManager");
157: }
158: return idManager;
159: }
160:
161: public void setIdManager(IdManager idManager) {
162: this .idManager = idManager;
163: }
164:
165: public String toString() {
166: return "Artifact: id=" + getId();
167: }
168:
169: public void setOwner(Agent owner) {
170: this .owner = owner;
171: }
172:
173: public String getParentFolder() {
174: return parentFolder;
175: }
176:
177: public void setParentFolder(String parentFolder) {
178: this .parentFolder = parentFolder;
179: }
180:
181: public ContentResource getBaseResource() {
182: return baseResource;
183: }
184:
185: public void setBaseResource(ContentResource baseResource) {
186: this.baseResource = baseResource;
187: }
188: }
|