KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > configuration > CmsDigesterResourceTypeCreationFactory


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/configuration/CmsDigesterResourceTypeCreationFactory.java,v $
3  * Date : $Date: 2006/03/27 14:52:46 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2002 - 2005 Alkacon Software (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.configuration;
33
34 import org.opencms.file.types.CmsResourceTypeUnknown;
35 import org.opencms.file.types.I_CmsResourceType;
36 import org.opencms.main.CmsLog;
37
38 import org.apache.commons.digester.AbstractObjectCreationFactory;
39 import org.apache.commons.digester.ObjectCreationFactory;
40 import org.apache.commons.logging.Log;
41
42 import org.xml.sax.Attributes JavaDoc;
43
44 /**
45  * Factory to create resource type instances from the XML configuration.<p>
46  *
47  * This is required because the default digester implementation will cause an exception in case
48  * a resource type class is missing. However, a missing class is common if a module with a new resource type
49  * class is imported. In this case, the resource type class is changes to <code>{@link org.opencms.file.types.CmsResourceTypeUnknown}</code>,
50  * so that the import of the resources can proceed.<p>
51  *
52  * @author Alexander Kandzior
53  *
54  * @version $Revision: 1.2 $
55  *
56  * @since 6.0.2
57  */

58 public class CmsDigesterResourceTypeCreationFactory extends AbstractObjectCreationFactory
59 implements ObjectCreationFactory {
60
61     /** The log object of this class. */
62     private static final Log LOG = CmsLog.getLog(CmsDigesterResourceTypeCreationFactory.class);
63
64     /**
65      * Default constructor for the resource type configuration factory.<p>
66      */

67     public CmsDigesterResourceTypeCreationFactory() {
68
69         super();
70     }
71
72     /**
73      * @see org.apache.commons.digester.ObjectCreationFactory#createObject(org.xml.sax.Attributes)
74      */

75     public Object JavaDoc createObject(Attributes JavaDoc attributes) throws Exception JavaDoc {
76
77         // get the class name attribute
78
String JavaDoc className = attributes.getValue(I_CmsXmlConfiguration.A_CLASS);
79         // create the class instance
80
I_CmsResourceType type;
81         try {
82             if (className != null) {
83                 className = className.trim();
84             }
85             type = (I_CmsResourceType)Class.forName(className).newInstance();
86         } catch (Exception JavaDoc e) {
87             // resource type is unknown, use dummy class to import the module resources
88
type = new CmsResourceTypeUnknown();
89             // write an error to the log
90
LOG.error(Messages.get().getBundle().key(
91                 Messages.ERR_UNKNOWN_RESTYPE_CLASS_2,
92                 className,
93                 type.getClass().getName()), e);
94         }
95         return type;
96     }
97 }
Popular Tags