001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.file.types;
029
030import org.opencms.configuration.CmsConfigurationException;
031import org.opencms.loader.CmsDumpLoader;
032import org.opencms.main.OpenCms;
033
034/**
035 * Resource type descriptor for the type "binary".<p>
036 *
037 * @since 6.0.0
038 */
039public class CmsResourceTypeBinary extends A_CmsResourceType {
040
041    /** Indicates that the static configuration of the resource type has been frozen. */
042    private static boolean m_staticFrozen;
043
044    /** The static type id of this resource type. */
045    private static int m_staticTypeId;
046
047    /** The type id of this resource type. */
048    private static final int RESOURCE_TYPE_ID = 2;
049
050    /** The name of this resource type. */
051    private static final String RESOURCE_TYPE_NAME = "binary";
052
053    /** The serial version id. */
054    private static final long serialVersionUID = -9136655668997852278L;
055
056    /**
057     * Default constructor, used to initialize member variables.<p>
058     */
059    public CmsResourceTypeBinary() {
060
061        super();
062        m_typeId = RESOURCE_TYPE_ID;
063        m_typeName = RESOURCE_TYPE_NAME;
064    }
065
066    /**
067     * Returns the static type id of this (default) resource type.<p>
068     *
069     * @return the static type id of this (default) resource type
070     */
071    public static int getStaticTypeId() {
072
073        return m_staticTypeId;
074    }
075
076    /**
077     * Returns the static type name of this (default) resource type.<p>
078     *
079     * @return the static type name of this (default) resource type
080     */
081    public static String getStaticTypeName() {
082
083        return RESOURCE_TYPE_NAME;
084    }
085
086    /**
087     * @see org.opencms.file.types.I_CmsResourceType#getLoaderId()
088     */
089    @Override
090    public int getLoaderId() {
091
092        return CmsDumpLoader.RESOURCE_LOADER_ID;
093    }
094
095    /**
096     * @see org.opencms.file.types.A_CmsResourceType#initConfiguration(java.lang.String, java.lang.String, String)
097     */
098    @Override
099    public void initConfiguration(String name, String id, String className) throws CmsConfigurationException {
100
101        if ((OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) && m_staticFrozen) {
102            // configuration already frozen
103            throw new CmsConfigurationException(
104                Messages.get().container(
105                    Messages.ERR_CONFIG_FROZEN_3,
106                    this.getClass().getName(),
107                    getStaticTypeName(),
108                    Integer.valueOf(getStaticTypeId())));
109        }
110
111        if (!RESOURCE_TYPE_NAME.equals(name)) {
112            // default resource type MUST have default name
113            throw new CmsConfigurationException(
114                Messages.get().container(
115                    Messages.ERR_INVALID_RESTYPE_CONFIG_NAME_3,
116                    this.getClass().getName(),
117                    RESOURCE_TYPE_NAME,
118                    name));
119        }
120
121        // freeze the configuration
122        m_staticFrozen = true;
123
124        super.initConfiguration(RESOURCE_TYPE_NAME, id, className);
125        // set static members with values from the configuration
126        m_staticTypeId = m_typeId;
127    }
128}