1 // Copyright 2008 Thiago H. de Paula Figueiredo
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package br.com.arsmachina.tapestrycrud.services.impl;
16
17 import java.io.Serializable;
18 import java.util.Map;
19
20 import org.apache.tapestry5.ioc.util.StrategyRegistry;
21
22 import br.com.arsmachina.tapestrycrud.encoder.Encoder;
23 import br.com.arsmachina.tapestrycrud.services.EncoderSource;
24
25 /**
26 * {@link EncoderSource} implementation.
27 *
28 * @author Thiago H. de Paula Figueiredo
29 */
30 public class EncoderSourceImpl implements EncoderSource {
31
32 @SuppressWarnings("unchecked")
33 final private StrategyRegistry<Encoder> registry;
34
35 /**
36 * Single constructor.
37 *
38 * @param registrations
39 */
40 @SuppressWarnings("unchecked")
41 public EncoderSourceImpl(Map<Class, Encoder> registrations) {
42 registry = StrategyRegistry.newInstance(Encoder.class, registrations, true);
43 }
44
45 /**
46 * @see br.com.arsmachina.tapestrycrud.services.EncoderSource#get(java.lang.Class)
47 */
48 @SuppressWarnings("unchecked")
49 public <T, K extends Serializable> Encoder<T, K> get(Class<T> clasz) {
50 return registry.get(clasz);
51 }
52
53 }