01: /**
02: * Copyright (C) 2001-2005 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.speedo.mapper.lib;
18:
19: import org.objectweb.speedo.api.SpeedoProperties;
20: import org.objectweb.speedo.mapper.api.ClassPropertyManager;
21: import org.objectweb.speedo.mim.api.HomeItf;
22: import org.objectweb.util.monolog.api.BasicLevel;
23: import org.objectweb.util.monolog.api.Logger;
24:
25: import java.util.Properties;
26:
27: /**
28: *
29: *
30: * @author S.Chassande-Barrioz
31: */
32: public class CPMCacheClassPolicy implements ClassPropertyManager,
33: SpeedoProperties {
34:
35: public String getName() {
36: return CACHE_CLASS_POLICY;
37: }
38:
39: public void applyDefault(HomeItf home, Properties props, Logger l) {
40: String str = props.getProperty(CACHE_CLASS_POLICY);
41: if (str != null) {
42: applyProp(home, str, l);
43: }
44: }
45:
46: public void applyDefault(HomeItf gcHome, HomeItf refHome,
47: Properties props, Logger l) {
48: String str = props.getProperty(CACHE_CLASS_POLICY);
49: if (str != null) {
50: applyProp(gcHome, str, l);
51: }
52: }
53:
54: public void applyProperty(String name, String value, HomeItf home,
55: Properties props, Logger logger) {
56: if (logger != null && logger.isLoggable(BasicLevel.INFO)) {
57: logger.log(BasicLevel.INFO, "Use the caching policy '"
58: + value + "' for the class '" + home.getPath());
59: }
60: applyProp(home, value, logger);
61: }
62:
63: private void applyProp(HomeItf home, String value, Logger logger) {
64: if (CACHE_CLASS_POLICY_NOCACHE.equalsIgnoreCase(value)) {
65: home.setCachePolicy(HomeItf.NO_CACHE);
66: } else if (CACHE_CLASS_POLICY_CACHED.equalsIgnoreCase(value)) {
67: home.setCachePolicy(HomeItf.CACHED);
68: } else if (CACHE_CLASS_POLICY_FIXED.equalsIgnoreCase(value)) {
69: home.setCachePolicy(HomeItf.FIXED);
70: //TODO: fix all loaded instances
71: } else if (CACHE_CLASS_POLICY_ALL.equalsIgnoreCase(value)) {
72: home.setCachePolicy(HomeItf.ALL);
73: //TODO: preload all instances and fix them
74: } else if (logger != null) {
75: logger.log(BasicLevel.WARN, "Policy '" + value
76: + "' specified for the class '" + home.getPath()
77: + "' is not managed.");
78: }
79: }
80:
81: public void applyProperty(String name, String value,
82: HomeItf gcHome, HomeItf refHome, Properties props,
83: Logger logger) {
84: }
85: }
|