⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metadatafield.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * MetadataField.java * * Version: $Revision: 1.1 $ * * Date: $Date: 2005/11/16 21:40:51 $ * * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts * Institute of Technology.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of the Hewlett-Packard Company nor the name of the * Massachusetts Institute of Technology nor the names of their * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */package org.dspace.content;import java.io.IOException;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import java.util.HashMap;import org.apache.log4j.Logger;import org.dspace.authorize.AuthorizeException;import org.dspace.authorize.AuthorizeManager;import org.dspace.core.Context;import org.dspace.core.LogManager;import org.dspace.storage.rdbms.DatabaseManager;import org.dspace.storage.rdbms.TableRow;import org.dspace.storage.rdbms.TableRowIterator;/** * DSpace object that represents a metadata field, which is * defined by a combination of schema, element, and qualifier.  Every * metadata element belongs in a field. * * @author Martin Hald * @version $Revision: 1.1 $ * @see org.dspace.content.MetadataValue, org.dspace.content.MetadataSchema */public class MetadataField{    private int fieldID = 0;    private int schemaID = 0;    private String element;    private String qualifier;    private String scopeNote;    /** log4j logger */    private static Logger log = Logger.getLogger(MetadataField.class);    /** The row in the table representing this type */    private TableRow row;    // cache of field by ID (Integer)    private static HashMap id2field = null;    /**     * Default constructor.     */    public MetadataField()    {    }    /**     * Constructor creating a field within a schema.     *     * @param schema schema to which the field belongs     */    public MetadataField(MetadataSchema schema)    {        this.schemaID = schema.getSchemaID();    }    /**     * Full contructor for new metadata field elements.     *     * @param schema schema to which the field belongs     * @param element element of the field     * @param qualifier qualifier of the field     * @param scopeNote scope note of the field     */    public MetadataField(MetadataSchema schema, String element,            String qualifier, String scopeNote)    {        this.schemaID = schema.getSchemaID();        this.element = element;        this.qualifier = qualifier;        this.scopeNote = scopeNote;    }    /**     * Full construtor for existing metadata field elements.     *     * @param schemaID schema to which the field belongs     * @param fieldID dataabse ID of field.     * @param element element of the field     * @param qualifier qualifier of the field     * @param scopeNote scope note of the field     */    public MetadataField(int schemaID, int fieldID, String element,            String qualifier, String scopeNote)    {        this.schemaID = schemaID;        this.fieldID = fieldID;        this.element = element;        this.qualifier = qualifier;        this.scopeNote = scopeNote;    }    /**     * Constructor to load the object from the database.     *     * @param row database row from which to populate object.     */    public MetadataField(TableRow row)    {        if (row != null)        {            this.fieldID = row.getIntColumn("metadata_field_id");            this.schemaID = row.getIntColumn("metadata_schema_id");            this.element = row.getStringColumn("element");            this.qualifier = row.getStringColumn("qualifier");            this.scopeNote = row.getStringColumn("scope_note");            this.row = row;        }    }    /**     * Get the element name.     *     * @return element name     */    public String getElement()    {        return element;    }    /**     * Set the element name.     *     * @param element new value for element     */    public void setElement(String element)    {        this.element = element;    }    /**     * Get the metadata field id.     *     * @return metadata field id     */    public int getFieldID()    {        return fieldID;    }    /**     * Get the qualifier.     *     * @return qualifier     */    public String getQualifier()    {        return qualifier;    }    /**     * Set the qualifier.     *     * @param qualifier new value for qualifier     */    public void setQualifier(String qualifier)    {        this.qualifier = qualifier;    }    /**     * Get the schema record key.     *     * @return schema record key     */    public int getSchemaID()    {        return schemaID;    }    /**     * Set the schema record key.     *     * @param schemaID new value for key     */    public void setSchemaID(int schemaID)    {        this.schemaID = schemaID;    }    /**     * Get the scope note.     *     * @return scope note     */    public String getScopeNote()    {        return scopeNote;    }    /**     * Set the scope note.     *     * @param scopeNote new value for scope note     */    public void setScopeNote(String scopeNote)    {        this.scopeNote = scopeNote;    }    /**     * Creates a new metadata field.     *     * @param context     *            DSpace context object     * @throws IOException     * @throws AuthorizeException     * @throws SQLException     * @throws NonUniqueMetadataException     */    public void create(Context context) throws IOException, AuthorizeException,            SQLException, NonUniqueMetadataException    {        // Check authorisation: Only admins may create DC types        if (!AuthorizeManager.isAdmin(context))        {            throw new AuthorizeException(                    "Only administrators may modify the metadata registry");        }        // Ensure the element and qualifier are unique within a given schema.        if (!unique(context, schemaID, element, qualifier))        {            throw new NonUniqueMetadataException("Please make " + element + "."                    + qualifier + " unique within schema #" + schemaID);        }        // Create a table row and update it with the values        row = DatabaseManager.row("MetadataFieldRegistry");        row.setColumn("metadata_schema_id", schemaID);        row.setColumn("element", element);        row.setColumn("qualifier", qualifier);        row.setColumn("scope_note", scopeNote);        DatabaseManager.insert(context, row);        decache();        // Remember the new row number        this.fieldID = row.getIntColumn("metadata_field_id");        log.info(LogManager.getHeader(context, "create_metadata_field",                "metadata_field_id=" + row.getIntColumn("metadata_field_id")));    }    /**     * Retrieves the metadata field from the database.     *     * @param context dspace context     * @param schemaID schema by ID     * @param element element name     * @param qualifier qualifier (may be ANY or null)     * @return recalled metadata field     * @throws SQLException

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -