1 package org.jellyfish.implementation;
2
3 import javax.naming.NamingException;
4 import javax.naming.directory.DirContext;
5
6 import org.apache.avalon.framework.logger.LogEnabled;
7 import org.apache.avalon.framework.logger.Logger;
8 import org.apache.avalon.framework.service.ServiceException;
9 import org.apache.avalon.framework.service.ServiceManager;
10 import org.apache.avalon.framework.service.Serviceable;
11 import org.apache.commons.beanutils.Converter;
12 import org.jellyfish.ConnectionManager;
13 import org.jellyfish.MappingManager;
14
15 public class ConverterDefault implements Converter, Serviceable, LogEnabled {
16 private static ConverterDefault instance;
17 private ServiceManager serviceManager;
18 private Logger logger;
19 private ConnectionManager connectionManager;
20 private MappingManager mappingManager;
21
22 public ConverterDefault() {
23 }
24
25 public Object convert(Class type, Object value) {
26 try {
27 DirContext context = connectionManager.getContext();
28 if (context != null) {
29 return mappingManager.mapFromAttributes(
30 context.getAttributes((String) value));
31 }
32 } catch (NamingException e) {
33 logger.fatalError(
34 "Exception converting [" + value + "]" + e.toString());
35 }
36 return null;
37 }
38
39 public void service(ServiceManager serviceManager)
40 throws ServiceException {
41 this.serviceManager = serviceManager;
42 try {
43 mappingManager =
44 (MappingManager) serviceManager.lookup(MappingManager.ROLE);
45 connectionManager =
46 (ConnectionManager) serviceManager.lookup(
47 ConnectionManager.ROLE);
48 } catch (ServiceException e) {
49 logger.fatalError(e.getMessage(), e);
50 throw new RuntimeException(e);
51 }
52 }
53
54 public void enableLogging(Logger logger) {
55 this.logger = logger;
56 }
57 }
This page was automatically generated by Maven