01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.util.crypt;
18:
19: /**
20: * {@link ICryptFactory} decorator that caches the call to
21: * {@link ICryptFactory#newCrypt()}
22: *
23: * @author Igor Vaynberg (ivaynberg)
24: */
25: public class CryptFactoryCachingDecorator implements ICryptFactory {
26: private final ICryptFactory delegate;
27: private ICrypt cache;
28:
29: /**
30: * Construct.
31: *
32: * @param delegate
33: * the crypt factory whose {@link ICryptFactory#newCrypt()} call
34: * will be cached
35: */
36: public CryptFactoryCachingDecorator(ICryptFactory delegate) {
37: if (delegate == null) {
38: throw new IllegalArgumentException(
39: "delegate cannot be null");
40: }
41: this .delegate = delegate;
42: }
43:
44: /**
45: * @see org.apache.wicket.util.crypt.ICryptFactory#newCrypt()
46: */
47: public final ICrypt newCrypt() {
48: if (cache == null) {
49: cache = delegate.newCrypt();
50: }
51: return cache;
52: }
53: }
|