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

📄 metadataschema.java

📁 DSPACE的源码 dspace-1.4-source
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * MetadataSchema.java * * Version: $Revision: 1.2 $ * * Date: $Date: 2006/05/26 14:17:01 $ * * 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.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.HashMap;import java.util.ArrayList;import java.util.List;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;/** * Class representing a schema in DSpace. * <p> * The schema object exposes a name which can later be used to generate * namespace prefixes in RDF or XML, e.g. the core DSpace Dublin Core schema * would have a name of <code>'dc'</code>. * </p> * * @author Martin Hald * @version $Revision: 1.2 $ * @see org.dspace.content.MetadataValue, org.dspace.content.MetadataField */public class MetadataSchema{    /** log4j logger */    private static Logger log = Logger.getLogger(MetadataSchema.class);    /** Numeric Identifier of built-in Dublin Core schema. */    public static final int DC_SCHEMA_ID = 1;    /** Short Name of built-in Dublin Core schema. */    public static final String DC_SCHEMA = "dc";    /** The row in the table representing this type */    private TableRow row;    private int schemaID;    private String namespace;    private String name;    // cache of schema by ID (Integer)    private static HashMap id2schema = null;    // cache of schema by short name    private static HashMap name2schema = null;    /**     * Default constructor.     */    public MetadataSchema()    {    }    /**     * Object constructor.     *     * @param schemaID  database key ID number     * @param namespace  XML namespace URI     * @param name  short name of schema     */    public MetadataSchema(int schemaID, String namespace, String name)    {        this.schemaID = schemaID;        this.namespace = namespace;        this.name = name;    }    /**     * Immutable object constructor for creating a new schema.     *     * @param namespace  XML namespace URI     * @param name  short name of schema     */    public MetadataSchema(String namespace, String name)    {        this.namespace = namespace;        this.name = name;    }    /**     * Constructor for loading the metadata schema from the database.     *     * @param row table row object from which to populate this schema.     */    public MetadataSchema(TableRow row)    {        if (row != null)        {            this.schemaID = row.getIntColumn("metadata_schema_id");            this.namespace = row.getStringColumn("namespace");            this.name = row.getStringColumn("short_id");            this.row = row;        }    }    /**     * Get the schema namespace.     *     * @return namespace String     */    public String getNamespace()    {        return namespace;    }    /**     * Set the schema namespace.     *     * @param namespace  XML namespace URI     */    public void setNamespace(String namespace)    {        this.namespace = namespace;    }    /**     * Get the schema name.     *     * @return name String     */    public String getName()    {        return name;    }    /**     * Set the schema name.     *     * @param name  short name of schema     */    public void setName(String name)    {        this.name = name;    }    /**     * Get the schema record key number.     *     * @return schema record key     */    public int getSchemaID()    {        return schemaID;    }    /**     * Creates a new metadata schema in the database, out of this object.     *     * @param context     *            DSpace context object     * @throws SQLException     * @throws AuthorizeException     * @throws NonUniqueMetadataException     */    public void create(Context context) throws SQLException,            AuthorizeException, NonUniqueMetadataException    {        // Check authorisation: Only admins may create metadata schemas        if (!AuthorizeManager.isAdmin(context))        {            throw new AuthorizeException(                    "Only administrators may modify the metadata registry");        }        // Ensure the schema name is unique        if (!uniqueShortName(context, name))        {            throw new NonUniqueMetadataException("Please make the name " + name                    + " unique");        }                // Ensure the schema namespace is unique        if (!uniqueNamespace(context, namespace))        {            throw new NonUniqueMetadataException("Please make the namespace " + namespace                    + " unique");        }        // Create a table row and update it with the values        row = DatabaseManager.create(context, "MetadataSchemaRegistry");        row.setColumn("namespace", namespace);        row.setColumn("short_id", name);        DatabaseManager.update(context, row);        // invalidate our fast-find cache.        decache();        // Remember the new row number        this.schemaID = row.getIntColumn("metadata_schema_id");        log                .info(LogManager.getHeader(context, "create_metadata_schema",                        "metadata_schema_id="                                + row.getIntColumn("metadata_schema_id")));    }    /**     * Get the schema object corresponding to this namespace URI.     *     * @param context DSpace context     * @param namespace namespace URI to match     * @return metadata schema object or null if none found.     * @throws SQLException     */    public static MetadataSchema findByNamespace(Context context,            String namespace) throws SQLException    {        // Grab rows from DB        TableRowIterator tri = DatabaseManager.queryTable(context,"MetadataSchemaRegistry",                "SELECT * FROM MetadataSchemaRegistry WHERE namespace= ? ", 

⌨️ 快捷键说明

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