| 1 |
|
package org.trails.engine.encoders.abbreviator; |
| 2 |
|
|
| 3 |
|
import org.apache.commons.collections.BidiMap; |
| 4 |
|
import org.apache.commons.collections.bidimap.TreeBidiMap; |
| 5 |
|
import org.trails.util.Utils; |
| 6 |
|
import org.trails.descriptor.DescriptorService; |
| 7 |
|
import org.trails.descriptor.IClassDescriptor; |
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
0 |
public class DefaultAbbreviator implements EntityNameAbbreviator |
| 15 |
|
{ |
| 16 |
|
|
| 17 |
|
private BidiMap abbreviationMap; |
| 18 |
|
private DescriptorService descriptorService; |
| 19 |
|
|
| 20 |
|
public String abbreviate(Class entityName) |
| 21 |
|
{ |
| 22 |
0 |
return (String) abbreviationMap.get(entityName.getName()); |
| 23 |
|
} |
| 24 |
|
|
| 25 |
|
public Class unabbreviate(String abbreviation) |
| 26 |
|
{ |
| 27 |
0 |
return Utils.classForName((String) abbreviationMap.getKey(abbreviation)); |
| 28 |
|
} |
| 29 |
|
|
| 30 |
|
public void initializeService() |
| 31 |
|
{ |
| 32 |
0 |
abbreviationMap = new TreeBidiMap(); |
| 33 |
0 |
for (IClassDescriptor classDescriptor : descriptorService.getAllDescriptors()) |
| 34 |
|
{ |
| 35 |
0 |
abbreviationMap.put(classDescriptor.getType().getName(), classDescriptor.getType().getSimpleName()); |
| 36 |
|
} |
| 37 |
0 |
} |
| 38 |
|
|
| 39 |
|
public void setDescriptorService(DescriptorService descriptorService) |
| 40 |
|
{ |
| 41 |
0 |
this.descriptorService = descriptorService; |
| 42 |
0 |
} |
| 43 |
|
} |