2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with any library licensed under the Apache Software License,
\r
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
\r
23 * (or with modified versions of the above that use the same license as the above),
\r
24 * and distribute linked combinations including the two. You must obey the
\r
25 * GNU General Public License in all respects for all of the code used other than
\r
26 * the above mentioned libraries. If you modify this file, you may extend this
\r
27 * exception to your version of the file, but you are not obligated to do so.
\r
28 * If you do not wish to do so, delete this exception statement from your version.
\r
31 package mircoders.global;
\r
35 import mir.config.MirPropertiesConfiguration;
\r
36 import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
\r
37 import mir.misc.ConfigException;
\r
38 import mircoders.localizer.MirCachingLocalizerDecorator;
\r
39 import mircoders.localizer.*;
\r
40 import mircoders.accesscontrol.*;
\r
41 import mircoders.entity.*;
\r
42 import mir.entity.adapter.*;
\r
44 public class MirGlobal {
\r
45 static private MirPropertiesConfiguration configuration;
\r
46 static private MirLocalizer localizer;
\r
47 static private ProducerEngine producerEngine;
\r
48 static private Abuse abuse;
\r
49 static private MRUCache mruCache;
\r
50 static private AccessControl accessControl;
\r
51 static private Map articleOperations;
\r
52 static private Map commentOperations;
\r
54 public synchronized static MirLocalizer localizer() {
\r
55 String localizerClassName;
\r
56 Class localizerClass;
\r
58 if (localizer == null ) {
\r
59 localizerClassName = config().getString("Mir.Localizer", "mirlocal.localizer.basic.MirBasicLocalizer");
\r
62 localizerClass = Class.forName(localizerClassName);
\r
64 catch (Throwable t) {
\r
65 throw new ConfigException("localizer class '" + localizerClassName + "' not found: " + t.toString());
\r
68 if (!(MirLocalizer.class.isAssignableFrom(localizerClass)))
\r
69 throw new ConfigException("localizer class '" + localizerClassName + "' is not assignable from MirLocalizer");
\r
72 localizer = new MirCachingLocalizerDecorator((MirLocalizer) localizerClass.newInstance());
\r
74 catch (Throwable t) {
\r
75 throw new ConfigException("localizer class '" + localizerClassName + "' cannot be instantiated: " + t.toString());
\r
82 public static Abuse abuse() {
\r
84 synchronized(MirGlobal.class) {
\r
86 abuse = new Abuse();
\r
93 public static MirPropertiesConfiguration config() {
\r
95 return MirPropertiesConfiguration.instance();
\r
97 catch (PropertiesConfigExc e) {
\r
98 throw new RuntimeException(e.getMessage());
\r
102 public static ProducerEngine producerEngine() {
\r
103 if (producerEngine == null) {
\r
104 producerEngine = new ProducerEngine();
\r
107 return producerEngine;
\r
110 public static MRUCache mruCache() {
\r
111 synchronized(MirGlobal.class) {
\r
112 if (mruCache == null) {
\r
113 mruCache = new MRUCache();
\r
119 public static synchronized AccessControl accessControl() {
\r
120 if (accessControl == null) {
\r
121 accessControl=new AccessControl();
\r
124 return accessControl;
\r
127 public static void performArticleOperation(EntityUsers aUser, EntityContent anArticle, String anOperation) {
\r
128 MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getArticleOperationForName(anOperation);
\r
131 if (operation!=null)
\r
133 localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser),
\r
134 localizer().dataModel().adapterModel().makeEntityAdapter("content", anArticle));
\r
136 catch (Throwable t) {
\r
137 throw new RuntimeException(t.toString());
\r
141 public static void performCommentOperation(EntityUsers aUser, EntityComment aComment, String anOperation) {
\r
142 MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getCommentOperationForName(anOperation);
\r
145 if (operation!=null)
\r
147 localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser),
\r
148 localizer().dataModel().adapterModel().makeEntityAdapter("comment", aComment));
\r
150 catch (Throwable t) {
\r
151 throw new RuntimeException(t.toString());
\r
155 private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation getArticleOperationForName(String aName) {
\r
157 if (articleOperations == null) {
\r
158 articleOperations = new HashMap();
\r
159 Iterator i = localizer().adminInterface().simpleArticleOperations().iterator();
\r
160 while (i.hasNext()) {
\r
161 MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();
\r
162 articleOperations.put(operation.getName(), operation);
\r
166 return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) articleOperations.get(aName);
\r
168 catch (Throwable t) {
\r
169 throw new RuntimeException(t.toString());
\r
173 private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation getCommentOperationForName(String aName) {
\r
175 if (commentOperations == null) {
\r
176 commentOperations = new HashMap();
\r
177 Iterator i = localizer().adminInterface().simpleCommentOperations().iterator();
\r
178 while (i.hasNext()) {
\r
179 MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();
\r
180 commentOperations.put(operation.getName(), operation);
\r
184 return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) commentOperations.get(aName);
\r
186 catch (Throwable t) {
\r
187 throw new RuntimeException(t.toString());
\r