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