1 /**
2 * Copyright Terracotta, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.config;
18
19 /**
20 * A class to represent the CacheManagerEventListener configuration.
21 *
22 * @param <T>
23 * the concrete factory type
24 *
25 * @author <a href="mailto:gluck@thoughtworks.com">Greg Luck</a>
26 * @version $Id: FactoryConfiguration.java 5631 2012-05-10 08:31:33Z teck $
27 */
28 public class FactoryConfiguration<T extends FactoryConfiguration> implements Cloneable {
29 /**
30 * class name.
31 */
32 protected String fullyQualifiedClassPath;
33
34 /**
35 * properties.
36 */
37 protected String properties;
38
39 /**
40 * A property separator. By default it is a comma, but other separators can be configured.
41 */
42 protected String propertySeparator;
43
44 /**
45 * Clones this object, following the usual contract.
46 *
47 * @return a copy, which independent other than configurations than cannot change.
48 */
49 @Override
50 public T clone() {
51 FactoryConfiguration config;
52 try {
53 config = (FactoryConfiguration) super.clone();
54 } catch (CloneNotSupportedException e) {
55 throw new RuntimeException(e);
56 }
57
58 return (T) config;
59 }
60
61 /**
62 * Sets the class name.
63 *
64 * @param fullyQualifiedClassPath
65 */
66 public final void setClass(String fullyQualifiedClassPath) {
67 this.fullyQualifiedClassPath = fullyQualifiedClassPath;
68 }
69
70 /**
71 * @return this configuration instance
72 * @see #setClass(String)
73 */
74 public T className(String fullyQualifiedClassPath) {
75 setClass(fullyQualifiedClassPath);
76 return (T) this;
77 }
78
79 /**
80 * Getter.
81 */
82 public final String getFullyQualifiedClassPath() {
83 return fullyQualifiedClassPath;
84 }
85
86 /**
87 * Sets the configuration properties.
88 *
89 * @param properties
90 */
91 public final void setProperties(String properties) {
92 this.properties = properties;
93 }
94
95 /**
96 * @return this configuration instance
97 * @see #setProperties(String)
98 */
99 public T properties(String properties) {
100 setProperties(properties);
101 return (T) this;
102 }
103
104 /**
105 * Getter.
106 */
107 public final String getProperties() {
108 return properties;
109 }
110
111 /**
112 * Setter
113 */
114 public void setPropertySeparator(String propertySeparator) {
115 this.propertySeparator = propertySeparator;
116 }
117
118 /**
119 * @return this configuration instance
120 * @see #setPropertySeparator(String)
121 */
122 public T propertySeparator(String propertySeparator) {
123 setPropertySeparator(propertySeparator);
124 return (T) this;
125 }
126
127 /**
128 * Getter
129 */
130 public String getPropertySeparator() {
131 return propertySeparator;
132 }
133
134 /**
135 * Overrided hashCode()
136 */
137 @Override
138 public int hashCode() {
139 final int prime = 31;
140 int result = 1;
141 result = prime * result + ((fullyQualifiedClassPath == null) ? 0 : fullyQualifiedClassPath.hashCode());
142 result = prime * result + ((properties == null) ? 0 : properties.hashCode());
143 result = prime * result + ((propertySeparator == null) ? 0 : propertySeparator.hashCode());
144 return result;
145 }
146
147 /**
148 * Overrided equals
149 */
150 @Override
151 public boolean equals(Object obj) {
152 if (this == obj) {
153 return true;
154 }
155 if (obj == null) {
156 return false;
157 }
158 if (getClass() != obj.getClass()) {
159 return false;
160 }
161 FactoryConfiguration other = (FactoryConfiguration) obj;
162 if (fullyQualifiedClassPath == null) {
163 if (other.fullyQualifiedClassPath != null) {
164 return false;
165 }
166 } else if (!fullyQualifiedClassPath.equals(other.fullyQualifiedClassPath)) {
167 return false;
168 }
169 if (properties == null) {
170 if (other.properties != null) {
171 return false;
172 }
173 } else if (!properties.equals(other.properties)) {
174 return false;
175 }
176 if (propertySeparator == null) {
177 if (other.propertySeparator != null) {
178 return false;
179 }
180 } else if (!propertySeparator.equals(other.propertySeparator)) {
181 return false;
182 }
183 return true;
184 }
185
186 }
187