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(final FacesContext facesContext, final String var, final ValueBinding valueBinding) {
45 this.facesContext = facesContext;
46 this.var = var;
47 this.valueBinding = valueBinding;
48 }
49
50 public ValueBindingComparator(
51 final FacesContext facesContext, final String var, final ValueBinding valueBinding, final boolean reverse) {
52 super(reverse);
53 this.facesContext = facesContext;
54 this.var = var;
55 this.valueBinding = valueBinding;
56 }
57
58 public ValueBindingComparator(
59 final FacesContext facesContext, final String var,
60 final ValueBinding valueBinding, final Comparator comparator) {
61 super(comparator);
62 this.facesContext = facesContext;
63 this.var = var;
64 this.valueBinding = valueBinding;
65 }
66
67 public ValueBindingComparator(
68 final FacesContext facesContext, final String var,
69 final ValueBinding valueBinding, final boolean reverse, final Comparator comparator) {
70 super(reverse, comparator);
71 this.facesContext = facesContext;
72 this.var = var;
73 this.valueBinding = valueBinding;
74 }
75
76 public boolean equals(final Object o) {
77 if (this == o) {
78 return true;
79 }
80 if (o == null || getClass() != o.getClass()) {
81 return false;
82 }
83
84 final ValueBindingComparator that = (ValueBindingComparator) o;
85
86 if (!super.equals(o)) {
87 return false;
88 }
89 if (facesContext != null ? !facesContext.equals(that.facesContext) : that.facesContext != null) {
90 return false;
91 }
92 if (valueBinding != null ? !valueBinding.equals(that.valueBinding) : that.valueBinding != null) {
93 return false;
94 }
95 if (var != null ? !var.equals(that.var) : that.var != null) {
96 return false;
97 }
98
99 return true;
100 }
101
102 public int hashCode() {
103 int result;
104 result = facesContext != null ? facesContext.hashCode() : 0;
105 result = 29 * result + (var != null ? var.hashCode() : 0);
106 result = 29 * result + (valueBinding != null ? valueBinding.hashCode() : 0);
107 result = 29 * result + super.hashCode();
108 return result;
109 }
110
111
112
113 @Override
114 public int compare(final Object param1, final Object param2) {
115 final Object obj1;
116 final Object obj2;
117 try {
118 final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
119 requestMap.put(var, param1);
120 obj1 = valueBinding.getValue(facesContext);
121 requestMap.put(var, param2);
122 obj2 = valueBinding.getValue(facesContext);
123
124 } catch (final Exception e) {
125 LOG.error(e.getMessage(), e);
126 return 0;
127 }
128 return super.internalCompare(obj1, obj2);
129 }
130
131 }