01: /* $Id: PropertyOrderModifier.java 787 2007-01-03 16:19:50Z hengels $ */
02: package org.conform.modifier;
03:
04: import org.conform.*;
05: import org.apache.commons.logging.LogFactory;
06:
07: import java.net.URL;
08: import java.io.*;
09: import java.util.*;
10:
11: /**
12: * @version $Revision: 787 $
13: */
14: public class PropertyOrderModifier implements Modifier,
15: Comparator<PropertyMeta> {
16: private List<String> propertyNames;
17:
18: public PropertyOrderModifier(String... propertyNames) {
19: this .propertyNames = Arrays.asList(propertyNames);
20: }
21:
22: public void modify(BeanMeta beanMeta) {
23: Arrays.sort(beanMeta.getProperties(), this );
24: }
25:
26: public int compare(PropertyMeta m1, PropertyMeta m2) {
27: int i1 = propertyNames.indexOf(m1.getName());
28: int i2 = propertyNames.indexOf(m2.getName());
29: if (i1 == -1)
30: i1 = 1000;
31: if (i2 == -1)
32: i2 = 1000;
33: return i1 - i2;
34: }
35: }
|