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.main.OpenCms;
032
033/**
034 * Resource type descriptor for unknown folder types.<p>
035 *
036 * This will be used for folder corpses when the resource type is not configured.<p>
037 *
038 * The most common use case is when deleting a module with the resource type definition,
039 * but not the content that uses that resource type definition.<p>
040 *
041 * @since 7.0.0
042 */
043public class CmsResourceTypeUnknownFolder extends A_CmsResourceTypeFolderBase {
044
045    /** The type id of this resource type. */
046    public static final int RESOURCE_TYPE_ID = -2;
047
048    /** The name of this resource type. */
049    public static final String RESOURCE_TYPE_NAME = "unknown_folder";
050
051    /** Indicates that the static configuration of the resource type has been frozen. */
052    private static boolean m_staticFrozen;
053
054    /** The static type id of this resource type. */
055    private static int m_staticTypeId;
056
057    /** The serial version id. */
058    private static final long serialVersionUID = 1623371480810407019L;
059
060    /**
061     * Default constructor, used to initialize member variables.<p>
062     */
063    public CmsResourceTypeUnknownFolder() {
064
065        super();
066        m_typeId = RESOURCE_TYPE_ID;
067        m_typeName = RESOURCE_TYPE_NAME;
068    }
069
070    /**
071     * Returns the static type id of this (default) resource type.<p>
072     *
073     * @return the static type id of this (default) resource type
074     */
075    public static int getStaticTypeId() {
076
077        return m_staticTypeId;
078    }
079
080    /**
081     * Returns the static type name of this (default) resource type.<p>
082     *
083     * @return the static type name of this (default) resource type
084     */
085    public static String getStaticTypeName() {
086
087        return RESOURCE_TYPE_NAME;
088    }
089
090    /**
091     * @see org.opencms.file.types.A_CmsResourceType#initConfiguration(java.lang.String, java.lang.String, String)
092     */
093    @Override
094    public void initConfiguration(String name, String id, String className) throws CmsConfigurationException {
095
096        if ((OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) && m_staticFrozen) {
097            // configuration already frozen
098            throw new CmsConfigurationException(
099                Messages.get().container(
100                    Messages.ERR_CONFIG_FROZEN_3,
101                    this.getClass().getName(),
102                    getStaticTypeName(),
103                    new Integer(getStaticTypeId())));
104        }
105
106        if (!RESOURCE_TYPE_NAME.equals(name)) {
107            // default resource type MUST have default name
108            throw new CmsConfigurationException(
109                Messages.get().container(
110                    Messages.ERR_INVALID_RESTYPE_CONFIG_NAME_3,
111                    this.getClass().getName(),
112                    RESOURCE_TYPE_NAME,
113                    name));
114        }
115
116        // freeze the configuration
117        m_staticFrozen = true;
118
119        super.initConfiguration(RESOURCE_TYPE_NAME, id, className);
120        // set static members with values from the configuration
121        m_staticTypeId = m_typeId;
122    }
123}