| 1 | |
package org.jscsi.target.settings.entry; |
| 2 | |
|
| 3 | |
|
| 4 | |
import org.jscsi.target.TargetServer; |
| 5 | |
import org.jscsi.target.settings.KeySet; |
| 6 | |
import org.jscsi.target.settings.NegotiationStatus; |
| 7 | |
import org.jscsi.target.settings.NegotiationType; |
| 8 | |
import org.jscsi.target.settings.TextParameter; |
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
public final class StringEntry extends Entry { |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
private final String[] supportedValues; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public StringEntry (final KeySet keySet, final NegotiationType negotiationType, final Use use, final NegotiationStatus negotiationStatus, final String[] supportedValues, final Object defaultValue) { |
| 38 | 0 | super(keySet, negotiationType, use, negotiationStatus, defaultValue); |
| 39 | 0 | this.supportedValues = supportedValues; |
| 40 | 0 | } |
| 41 | |
|
| 42 | |
@Override |
| 43 | |
protected boolean inProtocolValueRange (Object values) { |
| 44 | |
|
| 45 | |
|
| 46 | 0 | final String[] vals = (String[]) values; |
| 47 | |
|
| 48 | 0 | for (String s : vals) |
| 49 | 0 | if (!TextParameter.checkTextValueFormat(s)) return false; |
| 50 | 0 | return true; |
| 51 | |
} |
| 52 | |
|
| 53 | |
@Override |
| 54 | |
protected Object parseOffer (TargetServer target, String values) { |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | 0 | final String[] split = TextParameter.splitValues(values); |
| 59 | 0 | if (negotiationType == NegotiationType.DECLARED && split.length > 1) return null; |
| 60 | 0 | return split; |
| 61 | |
} |
| 62 | |
|
| 63 | |
@Override |
| 64 | |
protected void processDeclaration (Object values) { |
| 65 | |
|
| 66 | 0 | value = ((String[]) values)[0]; |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
protected String processNegotiation (Object values) { |
| 71 | |
|
| 72 | 0 | final String[] requestedValues = (String[]) values; |
| 73 | 0 | final String[] commonValues = TextParameter.intersect(supportedValues, requestedValues); |
| 74 | |
|
| 75 | 0 | if (commonValues.length == 0) return null; |
| 76 | |
|
| 77 | 0 | value = commonValues[0]; |
| 78 | 0 | return commonValues[0]; |
| 79 | |
} |
| 80 | |
|
| 81 | |
@Override |
| 82 | |
public String getStringValue () { |
| 83 | 0 | return (String) value; |
| 84 | |
} |
| 85 | |
|
| 86 | |
@Override |
| 87 | |
public Entry copy () { |
| 88 | 0 | final StringEntry e = new StringEntry(keySet, negotiationType, use, negotiationStatus, supportedValues, (String) value); |
| 89 | 0 | e.alreadyNegotiated = this.alreadyNegotiated; |
| 90 | 0 | return e; |
| 91 | |
} |
| 92 | |
} |