| 1 | |
package org.jscsi.target.settings.entry; |
| 2 | |
|
| 3 | |
|
| 4 | |
import org.jscsi.target.TargetServer; |
| 5 | |
import org.jscsi.target.settings.BooleanResultFunction; |
| 6 | |
import org.jscsi.target.settings.KeySet; |
| 7 | |
import org.jscsi.target.settings.NegotiationStatus; |
| 8 | |
import org.jscsi.target.settings.NegotiationType; |
| 9 | |
import org.jscsi.target.settings.TextParameter; |
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
public final class BooleanEntry extends Entry { |
| 24 | |
|
| 25 | |
private final boolean negotiationValue; |
| 26 | |
private final BooleanResultFunction resultFunction; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public BooleanEntry (final KeySet keySet, final Use use, final NegotiationStatus negotiationStatus, final boolean negotiationValue, final BooleanResultFunction resultFunction, final Boolean defaultValue) { |
| 40 | 0 | super(keySet, NegotiationType.NEGOTIATED, use, negotiationStatus, defaultValue); |
| 41 | 0 | this.negotiationValue = negotiationValue; |
| 42 | 0 | this.resultFunction = resultFunction; |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
@Override |
| 46 | |
protected Object parseOffer (TargetServer target, final String values) { |
| 47 | 0 | return TextParameter.parseBooleanValue(values); |
| 48 | |
} |
| 49 | |
|
| 50 | |
@Override |
| 51 | |
protected boolean inProtocolValueRange (final Object values) { |
| 52 | 0 | if (values instanceof Boolean) return true; |
| 53 | 0 | return false; |
| 54 | |
} |
| 55 | |
|
| 56 | |
@Override |
| 57 | |
protected void processDeclaration (final Object values) { |
| 58 | |
|
| 59 | 0 | } |
| 60 | |
|
| 61 | |
@Override |
| 62 | |
protected String processNegotiation (final Object values) { |
| 63 | 0 | final boolean request = (Boolean) values; |
| 64 | 0 | final boolean result = resultFunction.getResult(request, negotiationValue); |
| 65 | 0 | value = result; |
| 66 | 0 | return TextParameter.booleanToTextValue(result); |
| 67 | |
} |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
public Boolean getBooleanValue () { |
| 71 | 0 | return (Boolean) value; |
| 72 | |
} |
| 73 | |
|
| 74 | |
@Override |
| 75 | |
public Entry copy () { |
| 76 | 0 | final BooleanEntry e = new BooleanEntry(keySet, use, negotiationStatus, negotiationValue, resultFunction, (Boolean) value); |
| 77 | 0 | e.alreadyNegotiated = this.alreadyNegotiated; |
| 78 | 0 | return e; |
| 79 | |
} |
| 80 | |
|
| 81 | |
} |