OptionalPropKey.java
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.util.callbacks.Option
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.PropertyType
* javax.jcr.RepositoryException
*/
package com.adobe.cq.dam.s7imaging.impl.jcr.props;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropExtractor;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropKey;
import com.scene7.is.util.callbacks.Option;
import java.util.Iterator;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
class OptionalPropKey<T>
extends PropKey<Option<T>> {
private final PropExtractor<T> extractor;
static <T> PropKey<Option<T>> optionalPropKey(String name, PropExtractor<T> extractor) {
return new OptionalPropKey<T>(name, extractor);
}
@Override
Option<T> extractValue(Option<Property> value) throws RepositoryException {
Iterator i$ = value.iterator();
if (i$.hasNext()) {
Property prop = (Property)i$.next();
int actualType = prop.getType();
for (int t : this.extractor.jcrTypes) {
if (t != actualType) continue;
return Option.some(this.extractor.extract(prop));
}
String expected = this.extractor.expectedTypes;
String actual = PropertyType.nameFromValue((int)prop.getType());
throw new IllegalArgumentException("Unexpected property type for '" + this.name + "'" + " in: '" + (Object)prop.getParent() + "'." + " Expected: " + expected + ',' + " Actual: " + actual);
}
return Option.none();
}
private OptionalPropKey(String name, PropExtractor extractor) {
super(name);
this.extractor = extractor;
}
}