| 1 |
|
package org.trails.io; |
| 2 |
|
|
| 3 |
|
import org.apache.commons.logging.Log; |
| 4 |
|
import org.apache.commons.logging.LogFactory; |
| 5 |
|
import org.apache.tapestry.services.DataSqueezer; |
| 6 |
|
import org.apache.tapestry.util.io.SqueezeAdaptor; |
| 7 |
|
import org.trails.descriptor.DescriptorService; |
| 8 |
|
import org.trails.descriptor.IPropertyDescriptor; |
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
5 |
public class PropertyDescriptorSqueezerStrategy implements SqueezeAdaptor |
| 14 |
|
{ |
| 15 |
|
|
| 16 |
1 |
private static final Log LOG = LogFactory.getLog(PropertyDescriptorSqueezerStrategy.class); |
| 17 |
|
|
| 18 |
|
public static final String PREFIX = "W"; |
| 19 |
|
private DescriptorService descriptorService; |
| 20 |
|
|
| 21 |
|
public Class getDataClass() |
| 22 |
|
{ |
| 23 |
0 |
return IPropertyDescriptor.class; |
| 24 |
|
} |
| 25 |
|
|
| 26 |
|
public String getPrefix() |
| 27 |
|
{ |
| 28 |
0 |
return PREFIX; |
| 29 |
|
} |
| 30 |
|
|
| 31 |
|
public DescriptorService getDescriptorService() |
| 32 |
|
{ |
| 33 |
1 |
return descriptorService; |
| 34 |
|
} |
| 35 |
|
|
| 36 |
|
public void setDescriptorService(DescriptorService descriptorService) |
| 37 |
|
{ |
| 38 |
2 |
this.descriptorService = descriptorService; |
| 39 |
2 |
} |
| 40 |
|
|
| 41 |
|
public String squeeze(DataSqueezer squeezer, Object object) |
| 42 |
|
{ |
| 43 |
1 |
final IPropertyDescriptor propertyDescriptor = (IPropertyDescriptor) object; |
| 44 |
|
|
| 45 |
1 |
if (LOG.isDebugEnabled()) |
| 46 |
|
{ |
| 47 |
0 |
LOG.debug("squeezing: " + propertyDescriptor.getBeanType().getName() + "." + propertyDescriptor.getName()); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
1 |
final String squeezed = squeezer.squeeze(propertyDescriptor.getBeanType()); |
| 51 |
1 |
return PREFIX + squeezed + "." + propertyDescriptor.getName(); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
public Object unsqueeze(DataSqueezer squeezer, String string) |
| 55 |
|
{ |
| 56 |
1 |
if (LOG.isDebugEnabled()) |
| 57 |
|
{ |
| 58 |
0 |
LOG.debug("unsqueezing: " + string); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
1 |
final int dotIndex = string.lastIndexOf("."); |
| 62 |
1 |
final String squeezed = string.substring(PREFIX.length(), dotIndex); |
| 63 |
1 |
final String propertyName = string.substring(dotIndex + 1); |
| 64 |
1 |
final Class clazz = (Class) squeezer.unsqueeze(squeezed); |
| 65 |
1 |
return getDescriptorService().getClassDescriptor(clazz).getPropertyDescriptor(propertyName); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
} |