1 package org.apache.commons.jcs.auxiliary;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.jcs.engine.behavior.IElementSerializer;
23 import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
24 import org.apache.commons.jcs.utils.config.OptionConverter;
25 import org.apache.commons.jcs.utils.config.PropertySetter;
26 import org.apache.commons.jcs.utils.serialization.StandardSerializer;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 import java.util.Properties;
31
32
33
34
35
36 public class AuxiliaryCacheConfigurator
37 {
38
39 private static final Log log = LogFactory.getLog( AuxiliaryCacheConfigurator.class );
40
41
42 public static final String ATTRIBUTE_PREFIX = ".attributes";
43
44
45
46
47
48
49 public static final String CACHE_EVENT_LOGGER_PREFIX = ".cacheeventlogger";
50
51
52
53
54
55
56 public static final String SERIALIZER_PREFIX = ".serializer";
57
58
59
60
61
62
63
64
65 public static ICacheEventLogger parseCacheEventLogger( Properties props, String auxPrefix )
66 {
67 ICacheEventLogger cacheEventLogger = null;
68
69
70 String eventLoggerClassName = auxPrefix + CACHE_EVENT_LOGGER_PREFIX;
71 cacheEventLogger = OptionConverter.instantiateByKey( props, eventLoggerClassName, null );
72 if ( cacheEventLogger != null )
73 {
74 String cacheEventLoggerAttributePrefix = auxPrefix + CACHE_EVENT_LOGGER_PREFIX + ATTRIBUTE_PREFIX;
75 PropertySetter.setProperties( cacheEventLogger, props, cacheEventLoggerAttributePrefix + "." );
76 if ( log.isInfoEnabled() )
77 {
78 log.info( "Using custom cache event logger [" + cacheEventLogger + "] for auxiliary [" + auxPrefix
79 + "]" );
80 }
81 }
82 else
83 {
84 if ( log.isInfoEnabled() )
85 {
86 log.info( "No cache event logger defined for auxiliary [" + auxPrefix + "]" );
87 }
88 }
89 return cacheEventLogger;
90 }
91
92
93
94
95
96
97
98
99 public static IElementSerializer parseElementSerializer( Properties props, String auxPrefix )
100 {
101
102 IElementSerializer elementSerializer = null;
103
104
105 String elementSerializerClassName = auxPrefix + SERIALIZER_PREFIX;
106 elementSerializer = OptionConverter.instantiateByKey( props, elementSerializerClassName, null );
107 if ( elementSerializer != null )
108 {
109 String attributePrefix = auxPrefix + SERIALIZER_PREFIX + ATTRIBUTE_PREFIX;
110 PropertySetter.setProperties( elementSerializer, props, attributePrefix + "." );
111 if ( log.isInfoEnabled() )
112 {
113 log.info( "Using custom element serializer [" + elementSerializer + "] for auxiliary [" + auxPrefix
114 + "]" );
115 }
116 }
117 else
118 {
119
120 elementSerializer = new StandardSerializer();
121 if ( log.isInfoEnabled() )
122 {
123 log.info( "Using standard serializer [" + elementSerializer + "] for auxiliary [" + auxPrefix + "]" );
124 }
125 }
126 return elementSerializer;
127 }
128 }