1
2
3
4
5
6
7 package org.mule.api.registry;
8
9 import org.mule.util.ClassUtils;
10 import org.mule.util.StringUtils;
11
12 import java.util.Map;
13 import java.util.Properties;
14
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17
18 public abstract class AbstractServiceDescriptor implements ServiceDescriptor
19 {
20
21
22
23
24 protected final Log logger = LogFactory.getLog(getClass());
25
26 protected String service;
27
28 public AbstractServiceDescriptor(String service)
29 {
30 this.service = service;
31 }
32
33 public String getService()
34 {
35 return service;
36 }
37
38 protected String removeProperty(String name, Properties properties)
39 {
40 String temp = (String)properties.remove(name);
41 if (StringUtils.isEmpty(StringUtils.trim(temp)))
42 {
43 return null;
44 }
45 else
46 {
47 return temp;
48 }
49 }
50
51 protected Class<?> removeClassProperty(String name, Properties properties) throws ClassNotFoundException
52 {
53 String clazz = removeProperty(name, properties);
54 if (clazz == null)
55 {
56 return null;
57 }
58 else
59 {
60 return ClassUtils.loadClass(clazz, getClass());
61 }
62 }
63
64
65
66
67
68
69
70
71 public static class Key
72 {
73
74 private final Map<?, ?> overrides;
75 private final String service;
76
77 public Key(String service, Map<?, ?> overrides)
78 {
79 this.overrides = overrides;
80 this.service = service;
81 }
82
83 @Override
84 public boolean equals(Object o)
85 {
86 if (this == o)
87 {
88 return true;
89 }
90 if (!(o instanceof Key))
91 {
92 return false;
93 }
94
95 final Key key = (Key)o;
96
97 if (overrides != null ? !overrides.equals(key.overrides) : key.overrides != null)
98 {
99 return false;
100 }
101 if (!service.equals(key.service))
102 {
103 return false;
104 }
105
106 return true;
107 }
108
109 @Override
110 public int hashCode()
111 {
112 return 29 * (overrides != null ? overrides.hashCode() : 0) + (service != null ? service.hashCode(): 0);
113 }
114
115 public String getKey()
116 {
117 return service + ":" + Integer.toString(hashCode());
118 }
119
120 }
121
122 }
123
124