@Override public void check(String value) throws T2DBException { if (value == null || value.length() == 0 || value.length() > MAX_NAME_LENGTH) throw T2DBMsg.exception(D.D10105, value, 0, MAX_NAME_LENGTH); validNameMatcher.reset(value); if (!validNameMatcher.matches()) throw T2DBMsg.exception(D.D10104, value, NAME_PATTERN); }
private ValueScanner<T> findStandardScanner(String scannerClassOrKeyword) throws T2DBException { StandardValueType type = null; ValueScanner<T> scanner = null; try { type = StandardValueType.valueOf(scannerClassOrKeyword); } catch (IllegalArgumentException e) { } if (type == null) { keyword = null; try { @SuppressWarnings("unchecked") Class<ValueScanner<T>> scannerClass = (Class<ValueScanner<T>>) Class.forName(scannerClassOrKeyword); try { Constructor<ValueScanner<T>> constructor = scannerClass.getConstructor(ValueType.class); scanner = constructor.newInstance(this); } catch (NoSuchMethodException e) { scanner = scannerClass.newInstance(); } } catch (Exception e) { throw T2DBMsg.exception(e, D.D10110, name, scannerClassOrKeyword); } } else scanner = findStandardScanner(type); return scanner; }
@Override public ValueType<?> scan(String value) throws T2DBException { try { return database.getValueType(value); } catch (Exception e) { throw T2DBMsg.exception(e, D.D10107, value, ValueType.class.getName()); } }
@Override public DateTime scan(String value) throws T2DBException { try { return new DateTime(value); } catch (Exception e) { throw T2DBMsg.exception(e, D.D10107, value, ValueType.class.getName()); } }
@Override public TimeDomain scan(String value) throws T2DBException { try { return factory.get(value); } catch (Exception e) { throw T2DBMsg.exception(e, D.D10107, value, ValueType.class.getName()); } }
@Override public Double scan(String value) throws T2DBException { try { return new Double(value); } catch (NumberFormatException e) { if (value != null && value.equals("-")) return Double.NaN; throw T2DBMsg.exception(D.D10103, value); } }
@SuppressWarnings("unchecked") @Override public <S> ValueType<S> typeCheck(Class<S> type) throws T2DBException { try { if (type.isAssignableFrom(getScanner().getType())) return (ValueType<S>) this; } catch (Exception e) { } throw T2DBMsg.exception(D.D10101, getName(), type.getName(), getScanner().getType().getName()); }
@SuppressWarnings("unchecked") @Override public String toString(Object value) throws T2DBException { String result = null; try { if (!isRestricted() || values.containsKey(value)) result = scanner.toString((T) value); } catch (Exception e) { throw T2DBMsg.exception(e, D.D10114, value, getName()); } return result; }
@Override public T scan(String value) throws T2DBException { T result = null; if (value != null && value.length() == 0 && !isRestricted()) value = null; if (value != null) { result = scanner.scan(value); if (result == null) { // interpret value "" as null, except for String if (value.length() != 0) throw T2DBMsg.exception(D.D10114, value, getName()); } else check(result); } return result; }
@SuppressWarnings("unchecked") private void setValues(Map<String, String> valuesAndDescriptions) throws T2DBException { if (valuesAndDescriptions == null || valuesAndDescriptions.size() == 0) this.values = new HashMap<T, String>(); else { if (!isRestricted()) throw T2DBMsg.exception(D.D10108, getName()); if (getType().equals(String.class)) this.values = new LinkedHashMap<T, String>((Map<T, String>) valuesAndDescriptions); else { this.values = new LinkedHashMap<T, String>(); for (Map.Entry<String, String> e : valuesAndDescriptions.entrySet()) { /* * Don't use this.scan at this point, check will fail * because the value is not yet in the list of valid values. * On the other hand, the value must be valid, so catch scan * failures. Such failures can occur with bad bootstrap data * for example. */ T value = this.scanner.scan(e.getKey()); this.values.put(value, e.getValue()); } } } }
@Override public void check(T value) throws T2DBException { if (isRestricted() && !values.containsKey(value)) throw T2DBMsg.exception(D.D10115, value, getName()); }
/** * Return the value access methods object for this type. The value type object plays the role of a * cache for the value access method object, which is expensive to construct. * * @return a value access methods object */ public <S> ValueAccessMethods<T> getAccessMethods() throws T2DBException { if (am == null) throw T2DBMsg.exception(D.D10102, toString()); return am; }