| 1 |
644 |
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
package org.trails.descriptor; |
| 15 |
|
|
| 16 |
|
import java.io.Serializable; |
| 17 |
|
import java.lang.reflect.InvocationTargetException; |
| 18 |
|
import java.util.Hashtable; |
| 19 |
|
import java.util.Map; |
| 20 |
|
|
| 21 |
|
import org.apache.commons.beanutils.BeanUtils; |
| 22 |
|
import org.apache.commons.logging.Log; |
| 23 |
|
import org.apache.commons.logging.LogFactory; |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
4 |
public class TrailsDescriptor implements IDescriptor, Serializable |
| 32 |
|
{ |
| 33 |
4 |
protected static final Log LOG = LogFactory.getLog(TrailsDescriptor.class); |
| 34 |
|
|
| 35 |
|
private String displayName; |
| 36 |
|
|
| 37 |
|
private String shortDescription; |
| 38 |
|
|
| 39 |
|
protected Class type; |
| 40 |
|
|
| 41 |
|
private boolean hidden; |
| 42 |
|
|
| 43 |
5472 |
Map<String, IDescriptorExtension> extensions = new Hashtable<String, IDescriptorExtension>(); |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
112 |
public TrailsDescriptor(TrailsDescriptor dto) |
| 49 |
|
{ |
| 50 |
|
try |
| 51 |
|
{ |
| 52 |
112 |
BeanUtils.copyProperties(this, dto); |
| 53 |
0 |
} catch (IllegalAccessException e) |
| 54 |
|
{ |
| 55 |
0 |
LOG.error(e.getMessage()); |
| 56 |
0 |
e.printStackTrace(); |
| 57 |
0 |
} catch (InvocationTargetException e) |
| 58 |
|
{ |
| 59 |
0 |
LOG.error(e.getMessage()); |
| 60 |
0 |
e.printStackTrace(); |
| 61 |
0 |
} catch (Exception e) |
| 62 |
|
{ |
| 63 |
0 |
LOG.error(e.toString()); |
| 64 |
0 |
e.printStackTrace(); |
| 65 |
|
} |
| 66 |
112 |
} |
| 67 |
|
|
| 68 |
20 |
public TrailsDescriptor(IDescriptor descriptor) |
| 69 |
|
{ |
| 70 |
|
try |
| 71 |
|
{ |
| 72 |
20 |
BeanUtils.copyProperties(this, descriptor); |
| 73 |
20 |
copyExtensionsFrom(descriptor); |
| 74 |
0 |
} catch (IllegalAccessException e) |
| 75 |
|
{ |
| 76 |
0 |
LOG.error(e.getMessage()); |
| 77 |
0 |
e.printStackTrace(); |
| 78 |
0 |
} catch (InvocationTargetException e) |
| 79 |
|
{ |
| 80 |
0 |
LOG.error(e.getMessage()); |
| 81 |
0 |
e.printStackTrace(); |
| 82 |
0 |
} catch (Exception e) |
| 83 |
|
{ |
| 84 |
0 |
LOG.error(e.toString()); |
| 85 |
0 |
e.printStackTrace(); |
| 86 |
|
} |
| 87 |
20 |
} |
| 88 |
|
|
| 89 |
5340 |
public TrailsDescriptor(Class type) |
| 90 |
|
{ |
| 91 |
5340 |
this.type = type; |
| 92 |
5340 |
} |
| 93 |
|
|
| 94 |
|
public String getDisplayName() |
| 95 |
|
{ |
| 96 |
644 |
return displayName; |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
public void setDisplayName(String displayName) |
| 100 |
|
{ |
| 101 |
5400 |
this.displayName = displayName; |
| 102 |
5400 |
} |
| 103 |
|
|
| 104 |
|
public String getShortDescription() |
| 105 |
|
{ |
| 106 |
328 |
return shortDescription; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
public void setShortDescription(String shortDescription) |
| 110 |
|
{ |
| 111 |
1460 |
this.shortDescription = shortDescription; |
| 112 |
1460 |
} |
| 113 |
|
|
| 114 |
|
@Override |
| 115 |
|
public Object clone() |
| 116 |
|
{ |
| 117 |
0 |
return new TrailsDescriptor(this); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
public void copyFrom(IDescriptor descriptor) |
| 121 |
|
{ |
| 122 |
|
try |
| 123 |
|
{ |
| 124 |
40 |
BeanUtils.copyProperties(this, descriptor); |
| 125 |
40 |
copyExtensionsFrom(descriptor); |
| 126 |
0 |
} catch (IllegalAccessException e) |
| 127 |
280 |
{ |
| 128 |
560 |
LOG.error(e.getMessage()); |
| 129 |
24 |
e.printStackTrace(); |
| 130 |
256 |
} catch (InvocationTargetException e) |
| 131 |
|
{ |
| 132 |
0 |
LOG.error(e.getMessage()); |
| 133 |
0 |
e.printStackTrace(); |
| 134 |
0 |
} catch (Exception e) |
| 135 |
|
{ |
| 136 |
0 |
LOG.error(e.toString()); |
| 137 |
0 |
e.printStackTrace(); |
| 138 |
|
} |
| 139 |
40 |
} |
| 140 |
|
|
| 141 |
|
public void copyExtensionsFrom(IDescriptor descriptor) |
| 142 |
|
{ |
| 143 |
60 |
Map<String, IDescriptorExtension> exts = descriptor.getExtensions(); |
| 144 |
|
|
| 145 |
120 |
for (Map.Entry<String, IDescriptorExtension> entry : exts.entrySet()) |
| 146 |
|
{ |
| 147 |
0 |
String keye = entry.getKey(); |
| 148 |
0 |
IDescriptorExtension value = entry.getValue(); |
| 149 |
|
try |
| 150 |
|
{ |
| 151 |
0 |
this.addExtension(keye, (IDescriptorExtension) BeanUtils.cloneBean(value)); |
| 152 |
0 |
} catch (Exception e) |
| 153 |
|
{ |
| 154 |
|
|
| 155 |
|
} |
| 156 |
|
} |
| 157 |
60 |
} |
| 158 |
|
|
| 159 |
|
public boolean isHidden() |
| 160 |
|
{ |
| 161 |
540 |
return hidden; |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
public void setHidden(boolean hidden) |
| 165 |
|
{ |
| 166 |
4868 |
this.hidden = hidden; |
| 167 |
4868 |
} |
| 168 |
|
|
| 169 |
|
public Class getType() |
| 170 |
|
{ |
| 171 |
732 |
return type; |
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
public void setType(Class type) |
| 175 |
|
{ |
| 176 |
340 |
this.type = type; |
| 177 |
340 |
} |
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
public boolean supportsExtension(String keye) |
| 183 |
|
{ |
| 184 |
8 |
return getExtension(keye) != null; |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
public boolean supportsExtension(Class extensionType) |
| 188 |
|
{ |
| 189 |
0 |
return supportsExtension(extensionType.getName()); |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
public IDescriptorExtension getExtension(String keye) |
| 196 |
|
{ |
| 197 |
16 |
return extensions.get(keye); |
| 198 |
|
} |
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
|
|
| 203 |
|
public void addExtension(String keye, IDescriptorExtension extension) |
| 204 |
|
{ |
| 205 |
12 |
extensions.put(keye, extension); |
| 206 |
12 |
} |
| 207 |
|
|
| 208 |
|
public void addExtension(Class extensionType, IDescriptorExtension extension) |
| 209 |
|
{ |
| 210 |
0 |
addExtension(extensionType.getName(), extension); |
| 211 |
0 |
} |
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
| 216 |
|
public void removeExtension(String keye) |
| 217 |
|
{ |
| 218 |
0 |
extensions.remove(keye); |
| 219 |
0 |
} |
| 220 |
|
|
| 221 |
|
public void removeExtension(Class extensionType) |
| 222 |
|
{ |
| 223 |
0 |
removeExtension(extensionType.getName()); |
| 224 |
0 |
} |
| 225 |
|
|
| 226 |
|
public <E extends IDescriptorExtension> E getExtension(Class<E> extensionType) |
| 227 |
|
{ |
| 228 |
12 |
return (E) extensions.get(extensionType.getName()); |
| 229 |
|
} |
| 230 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
|
| 234 |
|
|
| 235 |
|
public Map<String, IDescriptorExtension> getExtensions() |
| 236 |
|
{ |
| 237 |
384 |
return extensions; |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
|
| 241 |
|
|
| 242 |
|
|
| 243 |
|
|
| 244 |
|
public void setExtensions(Map<String, IDescriptorExtension> extensions) |
| 245 |
|
{ |
| 246 |
324 |
this.extensions = extensions; |
| 247 |
324 |
} |
| 248 |
|
} |