01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/presentation/api/src/java/org/theospi/portfolio/presentation/model/PresentationItem.java $
03: * $Id:PresentationItem.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.presentation.model;
21:
22: import org.sakaiproject.component.cover.ComponentManager;
23: import org.sakaiproject.metaobj.shared.mgt.HomeFactory;
24: import org.sakaiproject.metaobj.shared.mgt.ReadableObjectHome;
25: import org.sakaiproject.metaobj.shared.model.Artifact;
26: import org.sakaiproject.metaobj.shared.model.Id;
27: import org.sakaiproject.metaobj.shared.model.IdentifiableObject;
28: import org.sakaiproject.metaobj.shared.model.PersistenceException;
29:
30: public class PresentationItem extends IdentifiableObject {
31: private PresentationItemDefinition definition;
32: private Id artifactId;
33:
34: public Artifact getArtifact() throws PersistenceException {
35: ReadableObjectHome home = getHomeFactory().getHome(
36: definition.getType());
37: return (Artifact) home.load(artifactId);
38: }
39:
40: public void setArtifact(Artifact artifact) {
41: artifactId = artifact.getId();
42: }
43:
44: public void setDefinition(PresentationItemDefinition definition) {
45: this .definition = definition;
46: }
47:
48: public PresentationItemDefinition getDefinition() {
49: return definition;
50: }
51:
52: public Id getArtifactId() {
53: return artifactId;
54: }
55:
56: public int hashCode() {
57: if (getId() != null) {
58: return getId().hashCode();
59: }
60: return (artifactId != null) ? (artifactId.getValue() + getHashDefId())
61: .hashCode()
62: : 0;
63: }
64:
65: protected String getHashDefId() {
66: if (definition == null) {
67: return "";
68: } else if (definition.getId() == null) {
69: return "";
70: } else {
71: return definition.getId().getValue();
72: }
73: }
74:
75: public void setArtifactId(Id artifactId) {
76: this .artifactId = artifactId;
77: }
78:
79: public HomeFactory getHomeFactory() {
80: return (HomeFactory) ComponentManager.getInstance().get(
81: "homeFactory");
82: }
83:
84: }
|