public interface AttrSettable
PropMapHelper.setField(Object, String, String)
Modifier and Type | Field and Description |
---|---|
static int |
ILLEGAL_TYPE
Return value for
setAttribute() . |
static int |
ILLEGAL_VALUE
Return value for
setAttribute() . |
static int |
NO_ATTRIBUTE
Return value for
setAttribute() . |
static int |
NO_KNOWN_ATTRIBUTE
Return value for
setAttribute() . |
static int |
NO_VALUE
Return value for
setAttribute() . |
static int |
OK
Return value for
setAttribute() . |
static String[] |
retVtext
Mapping return values to text.
|
Modifier and Type | Method and Description |
---|---|
static String |
retVtext(int ret)
Mapping return values to text.
|
int |
setAttribute(String name,
Object value)
Set a named attribute or property.
|
static final int OK
static final int NO_ATTRIBUTE
static final int NO_VALUE
setAttribute()
. ILLEGAL_TYPE
or by
ILLEGAL_VALUE
.static final int ILLEGAL_TYPE
setAttribute()
. setAttribute(String, Object)
) if the
value parameter is a character sequence.static final int ILLEGAL_VALUE
setAttribute()
. setAttribute(String, Object)
delegates
to throws an exception.static final int NO_KNOWN_ATTRIBUTE
setAttribute()
. static final String[] retVtext
static String retVtext(int ret)
int setAttribute(String name, Object value)
CharSequence
or derived. It is
most strongly recommended that the type String
is always accepted
for any settable attribute / property.NO_KNOWN_ATTRIBUTE
is returned, if name and
value are given (non null / empty), but this method just knows nothing
about a property name
. This (plus perhaps NO_VALUE
if
other setters might accept null) is the only return value where
further delegation to other setters makes any sense. @Override public int setAttribute(final String name, final Object value){
if (name == null || name.isEmpty()) return NO_ATTRIBUTE;
final boolean isNull = value == null;
final Class<? extends Object> cl = isNull ? null : value.getClass();
final boolean isStringVal = !isNull && cl == java.lang.String.class;
// do own job; return 0 (OK) on set attribute
// return failure on implemented attributes, but wrong value or type
return NO_KNOWN_ATTRIBUTE; // not implemented here (try other setters)
} // setAttribute(String, Object)
Hint 2 for implementation (with prior delegation to like above):
@SuppressWarnings("null")
@Override public int setAttribute(final String name, final Object value) {
final int ret = super.setAttribute(name, value); // (1)
if (ret != NO_KNOWN_ATTRIBUTE) return ret; // all done by (1)
final boolean isNull = value == null;
final Class<? extends Object> cl = isNull ? null : value.getClass();
final boolean isStringVal = !isNull && cl == java.lang.String.class;
/// rest as above
name
- the name of the property to be set; null, empty and start with
< 'a' will be rejected with
NO_ATTRIBUTE
value
- the new value for the named propertyOK
) or rejected (with
NO_VALUE
,
ILLEGAL_TYPE
or
ILLEGAL_VALUE
)OK
, NO_ATTRIBUTE
,
NO_KNOWN_ATTRIBUTE
,
NO_VALUE
,
ILLEGAL_TYPE
or
ILLEGAL_VALUE