1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.util;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import javax.faces.context.FacesContext;
26 import javax.faces.el.ValueBinding;
27 import java.util.Comparator;
28 import java.util.Map;
29
30
31
32
33 @Deprecated
34 public class ValueBindingComparator extends ComparatorBase {
35
36 private static final Logger LOG = LoggerFactory.getLogger(ValueBindingComparator.class);
37
38 private FacesContext facesContext;
39
40 private String var;
41
42 private ValueBinding valueBinding;
43
44 public ValueBindingComparator(FacesContext facesContext, String var, ValueBinding valueBinding) {
45 this.facesContext = facesContext;
46 this.var = var;
47 this.valueBinding = valueBinding;
48 }
49
50 public ValueBindingComparator(FacesContext facesContext, String var, ValueBinding valueBinding, boolean reverse) {
51 super(reverse);
52 this.facesContext = facesContext;
53 this.var = var;
54 this.valueBinding = valueBinding;
55 }
56
57 public ValueBindingComparator(FacesContext facesContext, String var,
58 ValueBinding valueBinding, Comparator comparator) {
59 super(comparator);
60 this.facesContext = facesContext;
61 this.var = var;
62 this.valueBinding = valueBinding;
63 }
64
65 public ValueBindingComparator(FacesContext facesContext, String var,
66 ValueBinding valueBinding, boolean reverse, Comparator comparator) {
67 super(reverse, comparator);
68 this.facesContext = facesContext;
69 this.var = var;
70 this.valueBinding = valueBinding;
71 }
72
73 public boolean equals(Object o) {
74 if (this == o) {
75 return true;
76 }
77 if (o == null || getClass() != o.getClass()) {
78 return false;
79 }
80
81 final ValueBindingComparator that = (ValueBindingComparator) o;
82
83 if (!super.equals(o)) {
84 return false;
85 }
86 if (facesContext != null ? !facesContext.equals(that.facesContext) : that.facesContext != null) {
87 return false;
88 }
89 if (valueBinding != null ? !valueBinding.equals(that.valueBinding) : that.valueBinding != null) {
90 return false;
91 }
92 if (var != null ? !var.equals(that.var) : that.var != null) {
93 return false;
94 }
95
96 return true;
97 }
98
99 public int hashCode() {
100 int result;
101 result = (facesContext != null ? facesContext.hashCode() : 0);
102 result = 29 * result + (var != null ? var.hashCode() : 0);
103 result = 29 * result + (valueBinding != null ? valueBinding.hashCode() : 0);
104 result = 29 * result + super.hashCode();
105 return result;
106 }
107
108
109
110
111
112
113
114
115 public int compare(Object param1, Object param2) {
116 Object obj1;
117 Object obj2;
118 try {
119 final Map requestMap = facesContext.getExternalContext().getRequestMap();
120 requestMap.put(var, param1);
121 obj1 = valueBinding.getValue(facesContext);
122 requestMap.put(var, param2);
123 obj2 = valueBinding.getValue(facesContext);
124
125 } catch (Exception e) {
126 LOG.error(e.getMessage(), e);
127 return 0;
128 }
129 return super.internalCompare(obj1, obj2);
130 }
131
132 }