KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > administer > DCType


1 /*
2  * DCType.java
3  *
4  * Version: $Revision: 1.18 $
5  *
6  * Date: $Date: 2005/11/16 21:40:50 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40 package org.dspace.administer;
41
42 import java.io.IOException JavaDoc;
43 import java.sql.SQLException JavaDoc;
44
45 import org.apache.log4j.Logger;
46 import org.dspace.authorize.AuthorizeException;
47 import org.dspace.content.MetadataField;
48 import org.dspace.content.MetadataSchema;
49 import org.dspace.content.NonUniqueMetadataException;
50 import org.dspace.core.Context;
51
52 /**
53  * Class representing a particular Dublin Core metadata type, with various
54  * utility methods. In general, only used for manipulating the registry of
55  * Dublin Core types in the system, so most users will not need this.
56  *
57  * <p>
58  * The DCType implementation has been deprecated, please use MetadataManager,
59  * MetadataSchema and MetadataField instead. For backward compatibility the this
60  * implementation has been updated to transparently call the new classes.
61  * </p>
62  *
63  * @author Robert Tansley
64  * @author Martin Hald
65  * @version $Revision: 1.18 $
66  * @deprecated
67  */

68 public class DCType
69 {
70     /** log4j logger */
71     private static Logger log = Logger.getLogger(DCType.class);
72
73     /** Our context */
74     private Context ourContext;
75
76     /** The matching metadata field */
77     private MetadataField field = new MetadataField();
78
79     /**
80      * Create a DCType from an existing metadata field.
81      *
82      * @param context
83      * @param field
84      * @deprecated
85      */

86     public DCType(Context context, MetadataField field)
87     {
88         this.ourContext = context;
89         this.field = field;
90     }
91
92     /**
93      * Default constructor.
94      *
95      * @param context
96      * @deprecated
97      */

98     public DCType(Context context)
99     {
100         this.ourContext = context;
101     }
102
103     /**
104      * Utility method for quick access to an element and qualifier given the
105      * type ID.
106      *
107      * @param context
108      * context, in case DC types need to be read in from DB
109      * @param id
110      * the DC type ID
111      * @return a two-String array, string 0 is the element, string 1 is the
112      * qualifier
113      * @deprecated
114      */

115     public static String JavaDoc[] quickFind(Context context, int id)
116             throws SQLException JavaDoc
117     {
118         MetadataField field = MetadataField.find(context, id);
119
120         String JavaDoc[] result = new String JavaDoc[2];
121
122         if (field == null)
123         {
124         return result;
125     }
126         else
127         {
128             result[0] = field.getElement();
129             result[1] = field.getQualifier();
130             return result;
131         }
132     }
133
134     /**
135      * Get a metadata field from the database.
136      *
137      * @param context
138      * DSpace context object
139      * @param id
140      * ID of the dublin core type
141      *
142      * @return the metadata field, or null if the ID is invalid.
143      * @deprecated
144      */

145     public static DCType find(Context context, int id) throws SQLException JavaDoc
146     {
147         MetadataField field = MetadataField.find(context, id);
148         return new DCType(context, field);
149     }
150
151     /**
152      * Find a given Dublin Core type. Returns <code>null</code> if the Dublin
153      * Core type doesn't exist.
154      *
155      * @param context
156      * the DSpace context to use
157      * @param element
158      * the element to find
159      * @param qualifier
160      * the qualifier, or <code>null</code> to find an unqualified
161      * type
162      *
163      * @return the Dublin Core type, or <code>null</code> if there isn't a
164      * corresponding type in the registry
165      * @throws AuthorizeException
166      * @deprecated
167      */

168     public static DCType findByElement(Context context, String JavaDoc element,
169             String JavaDoc qualifier) throws SQLException JavaDoc, AuthorizeException
170     {
171         MetadataField field = MetadataField.findByElement(context,
172                 MetadataSchema.DC_SCHEMA_ID, element, qualifier);
173
174         if (field == null)
175         {
176             return null;
177         }
178         else
179         {
180             return new DCType(context, field);
181         }
182     }
183
184     /**
185      * Retrieve all Dublin Core types from the registry
186      *
187      * @return an array of all the Dublin Core types
188      * @deprecated
189      */

190     public static DCType[] findAll(Context context) throws SQLException JavaDoc
191     {
192
193         MetadataField field[] = MetadataField.findAll(context);
194         DCType[] typeArray = new DCType[field.length];
195
196         for (int ii = 0; ii < field.length; ii++)
197         {
198             typeArray[ii] = new DCType(context, field[ii]);
199         }
200
201         // Return the array
202
return typeArray;
203     }
204
205     /**
206      * Create a new Dublin Core type
207      *
208      * @param context
209      * DSpace context object
210      * @return the newly created DCType
211      * @throws NonUniqueMetadataException
212      * @throws IOException
213      * @deprecated
214      */

215     public static DCType create(Context context) throws SQLException JavaDoc,
216             AuthorizeException, IOException JavaDoc, NonUniqueMetadataException
217         {
218         MetadataField field = new MetadataField();
219         field.setSchemaID(MetadataSchema.DC_SCHEMA_ID);
220         field.create(context);
221         return new DCType(context, field);
222     }
223
224     /**
225      * Delete this DC type. This won't work if there are any DC values in the
226      * database of this type - they need to be updated first. An
227      * <code>SQLException</code> (referential integrity violation) will be
228      * thrown in this case.
229      * @deprecated
230      */

231     public void delete() throws SQLException JavaDoc, AuthorizeException
232     {
233         field.delete(ourContext);
234     }
235
236     /**
237      * Get the internal identifier of this metadata field
238      *
239      * @return the internal identifier
240      */

241     public int getID()
242     {
243         return field.getFieldID();
244     }
245
246     /**
247      * Get the DC element
248      *
249      * @return the element
250      */

251     public String JavaDoc getElement()
252     {
253         return field.getElement();
254     }
255
256     /**
257      * Set the DC element
258      *
259      * @param s
260      * the new element
261      */

262     public void setElement(String JavaDoc s)
263     {
264         field.setElement(s);
265     }
266
267     /**
268      * Get the DC qualifier, if any.
269      *
270      * @return the DC qualifier, or <code>null</code> if this is an
271      * unqualified element
272      */

273     public String JavaDoc getQualifier()
274     {
275         return field.getQualifier();
276     }
277
278     /**
279      * Set the DC qualifier
280      *
281      * @param s
282      * the DC qualifier, or <code>null</code> if this is an
283      * unqualified element
284      */

285     public void setQualifier(String JavaDoc s)
286     {
287         field.setQualifier(s);
288     }
289
290     /**
291      * Get the scope note - information about the DC type and its use
292      *
293      * @return the scope note
294      */

295     public String JavaDoc getScopeNote()
296     {
297         return field.getScopeNote();
298     }
299
300     /**
301      * Set the scope note
302      *
303      * @param s
304      * the new scope note
305      */

306     public void setScopeNote(String JavaDoc s)
307     {
308         field.setScopeNote(s);
309     }
310
311     /**
312      * Update the dublin core registry
313      *
314      * @throws IOException
315      * @throws NonUniqueMetadataException
316      * @deprecated
317      */

318     public void update() throws SQLException JavaDoc, AuthorizeException,
319             NonUniqueMetadataException, IOException JavaDoc
320         {
321         field.update(ourContext);
322     }
323 }
324
Popular Tags