| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
package org.trails.callback; |
| 15 |
|
|
| 16 |
|
import java.util.HashMap; |
| 17 |
|
|
| 18 |
|
import ognl.Ognl; |
| 19 |
|
import ognl.OgnlException; |
| 20 |
|
import org.trails.TrailsRuntimeException; |
| 21 |
|
import org.trails.descriptor.CollectionDescriptor; |
| 22 |
|
import org.trails.persistence.PersistenceService; |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
public class CollectionCallback extends EditCallback |
| 29 |
|
{ |
| 30 |
|
private CollectionDescriptor collectionDescriptor; |
| 31 |
|
|
| 32 |
|
private boolean childRelationship; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
public CollectionCallback(String pageName, Object model, CollectionDescriptor collectionDescriptor) |
| 39 |
|
{ |
| 40 |
10 |
super(pageName, model); |
| 41 |
10 |
this.collectionDescriptor = collectionDescriptor; |
| 42 |
10 |
} |
| 43 |
|
|
| 44 |
|
public void save(PersistenceService persistenceService, Object newObject) |
| 45 |
|
{ |
| 46 |
4 |
executeOgnlExpression(collectionDescriptor.findAddExpression(), newObject); |
| 47 |
4 |
persistenceService.save(getModel()); |
| 48 |
4 |
} |
| 49 |
|
|
| 50 |
|
public void remove(PersistenceService persistenceService, Object object) |
| 51 |
|
{ |
| 52 |
2 |
executeOgnlExpression(collectionDescriptor.findRemoveExpression(), object); |
| 53 |
2 |
persistenceService.save(getModel()); |
| 54 |
2 |
} |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
private void executeOgnlExpression(String ognlExpression, Object newObject) |
| 60 |
|
{ |
| 61 |
6 |
HashMap context = new HashMap(); |
| 62 |
6 |
context.put("member", newObject); |
| 63 |
|
|
| 64 |
|
try |
| 65 |
|
{ |
| 66 |
6 |
Ognl.getValue(ognlExpression + "(#member)", context, model); |
| 67 |
0 |
} catch (OgnlException e) |
| 68 |
|
{ |
| 69 |
0 |
throw new TrailsRuntimeException(e, model.getClass()); |
| 70 |
|
} |
| 71 |
6 |
} |
| 72 |
|
|
| 73 |
|
public boolean isChildRelationship() |
| 74 |
|
{ |
| 75 |
1 |
return childRelationship; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
public void setChildRelationship(boolean child) |
| 80 |
|
{ |
| 81 |
3 |
this.childRelationship = child; |
| 82 |
3 |
} |
| 83 |
|
|
| 84 |
|
} |