1 /** ------------------------------------
2 * SweetDEV RIA library
3 * Copyright [2006 - 2010] [Ideo Technologies]
4 * ------------------------------------
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 *
19 * For more information, please contact us at:
20 * Ideo Technologies S.A
21 * 124 rue de Verdun
22 * 92800 Puteaux - France
23 *
24 * France & Europe Phone : +33 1.46.25.09.60
25 *
26 *
27 * web : http://www.ideotechnologies.com
28 * email : SweetDEV-RIA@ideotechnologies.com
29 *
30 *
31 * @version ${pom.version}
32 * @author Ideo Technologies
33 */
34 package com.ideo.sweetdevria.util;
35
36 import java.io.Serializable;
37
38 import org.apache.commons.logging.Log;
39 import org.apache.commons.logging.LogFactory;
40
41 // Referenced classes of package org.apache.struts.util:
42 // RequestUtils, MessageResources
43
44 /**
45 */
46 public abstract class MessageResourcesFactory implements Serializable {
47
48 /**
49 * Serial version ID.
50 */
51 private static final long serialVersionUID = 7375636806793604758L;
52
53 protected boolean returnNull;
54
55 protected static transient Class clazz = null;
56
57 private static final Log LOG = LogFactory.getLog(MessageResourcesFactory.class);
58
59 protected static String factoryClass = "com.ideo.sweetdevria.util.PropertyMessageResourcesFactory";
60
61 public MessageResourcesFactory() {
62 returnNull = true;
63 }
64
65 /**
66 * Get the returnNull.
67 * @return Returns the returnNull.
68 */
69 public boolean getReturnNull() {
70 return returnNull;
71 }
72
73 /**
74 * Set the returnNull.
75 * @param returnNull The returnNull to set.
76 */
77 public void setReturnNull(boolean returnNull) {
78 this.returnNull = returnNull;
79 }
80
81 public abstract MessageResources createResources(String s);
82
83 /**
84 * Get the factoryClass.
85 * @return Returns the factoryClass.
86 */
87 public static String getFactoryClass() {
88 return factoryClass;
89 }
90
91 /**
92 * Set the factoryClass.
93 * @param factoryClass The factoryClass to set.
94 */
95 public static void setFactoryClass(String factoryClass) {
96 MessageResourcesFactory.factoryClass = factoryClass;
97 clazz = null;
98 }
99
100 public static MessageResourcesFactory createFactory() {
101 /* SWTRIA-1132 -> Out Of memory Exception
102 Catch a Throwable can cause some down time and an imminent restart of the JVM due to an OOME
103 */
104 MessageResourcesFactory factory = null;
105 try {
106 factory = (MessageResourcesFactory) ClassUtils.applicationInstance(factoryClass);
107 }
108 catch (ClassNotFoundException e) {
109 LOG.error("Class of Message Resources Factory not found :" + factoryClass, e);
110 }
111 catch (InstantiationException e) {
112 LOG.error("Errors occure during instantiation of Message Resources Factory [" + factoryClass + "].", e);
113 }
114 catch (IllegalAccessException e) {
115 LOG.error("Default constructor of Message Resources Factory [" + factoryClass + "] not visible.", e);
116 }
117 catch (ClassCastException e) {
118 LOG.error(factoryClass + " must implement " + MessageResourcesFactory.class.getName(), e);
119 }
120 return factory;
121 }
122
123 }