KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > api > metadata > common > service > impl > hibernate > persistent > RepoResourceBase


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.persistent;
22
23 import java.util.Date JavaDoc;
24
25 import com.jaspersoft.jasperserver.api.JSException;
26 import com.jaspersoft.jasperserver.api.metadata.common.domain.Folder;
27 import com.jaspersoft.jasperserver.api.metadata.common.domain.Resource;
28 import com.jaspersoft.jasperserver.api.metadata.common.domain.impl.IdedObject;
29 import com.jaspersoft.jasperserver.api.metadata.common.service.ResourceFactory;
30 import com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.PersistentObjectResolver;
31
32
33 /**
34  * @author Lucian Chirita (lucianc@users.sourceforge.net)
35  * @version $Id: RepoResourceBase.java 4051 2006-07-22 06:43:27Z swood $
36  */

37 public abstract class RepoResourceBase implements IdedObject {
38     
39     private long id;
40     
41     private int version;
42     
43     private Date JavaDoc creationDate;
44
45     private String JavaDoc name = null;
46     private String JavaDoc label = null;
47     private String JavaDoc description = null;
48     
49     private RepoFolder parent;
50
51     protected RepoResourceBase() {
52         version = Resource.VERSION_NEW;
53     }
54     
55     /**
56      * @return
57      * @hibernate.id generator-class="identity"
58      */

59     public long getId() {
60         return id;
61     }
62
63     public void setId(long id) {
64         this.id = id;
65     }
66
67     /**
68      * @hibernate.version column="version" unsaved-value="negative"
69      */

70     public int getVersion() {
71         return version;
72     }
73
74     public void setVersion(int version) {
75         this.version = version;
76     }
77
78     /**
79      * @hibernate.property
80      * column="name" type="string" length="100" not-null="true"
81      */

82     public String JavaDoc getName()
83     {
84         return name;
85     }
86
87     /**
88      *
89      */

90     public void setName(String JavaDoc name)
91     {
92         this.name = name;
93     }
94
95     /**
96      * @hibernate.property
97      * column="label" type="string" length="100" not-null="true"
98      *
99      */

100     public String JavaDoc getLabel()
101     {
102         return label;
103     }
104
105     /**
106      *
107      */

108     public void setLabel(String JavaDoc label)
109     {
110         this.label = label;
111     }
112
113     /**
114      * @hibernate.property
115      * column="description" type="string" length="100"
116      *
117      */

118     public String JavaDoc getDescription()
119     {
120         return description;
121     }
122
123     /**
124      *
125      */

126     public void setDescription(String JavaDoc description)
127     {
128         this.description = description;
129     }
130     
131
132     /**
133      * @hibernate.many-to-one
134      * column="parent_folder"
135      */

136     public RepoFolder getParent() {
137         return parent;
138     }
139
140     public void setParent(RepoFolder parent) {
141         this.parent = parent;
142     }
143
144     protected abstract Class JavaDoc getClientItf();
145
146     public Object JavaDoc toClient(ResourceFactory resourceFactory) {
147         Class JavaDoc clientItf = getClientItf();
148         //TODO context?
149
Resource clientRes = resourceFactory.newResource(null, clientItf);
150         return clientRes;
151     }
152     
153     public void copyFromClient(Object JavaDoc objIdent, PersistentObjectResolver resolver){
154         copyFrom((Resource) objIdent);
155     }
156
157     protected void copyFrom(Resource clientRes)
158     {
159         if (!isNew() && getVersion() != clientRes.getVersion()) {
160             throw new JSException(getResourceURI() + ": the client version (" + clientRes.getVersion() + ") does not match the repository version (" + getVersion() + ").");
161         }
162
163         setName(clientRes.getName());
164         setLabel(clientRes.getLabel());
165         setDescription(clientRes.getDescription());
166     }
167
168     protected void copyTo(Resource clientRes)
169     {
170         clientRes.setVersion(getVersion());
171         clientRes.setCreationDate(getCreationDate());
172         clientRes.setName(getName());
173         clientRes.setLabel(getLabel());
174         clientRes.setDescription(getDescription());
175         
176         RepoFolder parentFolder = getParent();
177         if (parentFolder != null) {
178             clientRes.setParentFolder(parentFolder.getURI());
179         }
180     }
181
182     public final String JavaDoc getResourceURI() {
183         RepoFolder parentFolder = getParent();
184         String JavaDoc uri;
185         if (parentFolder == null || parentFolder.isRoot()) {
186             uri = Folder.SEPARATOR + getName();
187         } else {
188             uri = parentFolder.getURI() + Folder.SEPARATOR + getName();
189         }
190         return uri;
191     }
192     
193     public boolean isNew() {
194         return getVersion() == Resource.VERSION_NEW;
195     }
196
197     
198     /**
199      * @hibernate.property
200      * column="creation_date" type="timestamp" not-null="true"
201      */

202     public Date JavaDoc getCreationDate() {
203         return creationDate;
204     }
205
206     public void setCreationDate(Date JavaDoc creationDate) {
207         this.creationDate = creationDate;
208     }
209 }
210
Popular Tags