@Override public Builder<?> moveDown(String aName) { for (Builder<?> _b : nested) { if ((aName.equals(_b.getName().getName())) || (_b.getName().equals(Name.MISSING) && nested.size()==1)) { return _b; } } return null; }
public boolean prepare(Class<?> aClass, Name aName, Class<?> aValueType) { Method _m = cache.get(aName.getAlias()); if (_m == null) { synchronized(lock) { _m = cache.get(aName.getAlias()); // doesn't actually matter that DCL is broken, as worst case // we replace the cached method with the same method if (_m == null) { _m = getMutatorMethod(aClass, aName); // TODO: use the value for disambiguation? if (_m != null) { Map<String,Method> _newCache = new HashMap<String,Method>(cache); _newCache.put(aName.getAlias(), _m); cache = _newCache; } } } } return _m != null; }
private void buildAndSet(Builder aParentBuilder, Builder<?> aCurrentBuilder, String aTypeName) { String _name = ""; try { Object _o = aCurrentBuilder.build(this); if (!aParentBuilder.isArray()) _name = names.pop(); if (_o != null) aParentBuilder.setValue(this, _name, _o); } catch (ClassCastException anExc) { throw new ParsingException( "Problem converting " + aTypeName + " '" + _name + "' in '" + aParentBuilder.getName().getName() + "' ... does your document definition use 'property' where it should use '" + aTypeName + "'?", anExc); } }
private static <T> Method getMutatorMethod(Class<T> aContextClass, Name... aMaybeNames) { Set<String> _names = new LinkedHashSet<String>(); for (Name _s : aMaybeNames) { String _name = (_s.getAlias() == null) ? _s.getName() : _s.getAlias(); String _aliasSuffix = removeHyphensAndUpperCaseFirstLetters(_name); for (String _prefix : MUTATOR_PREFIXES) { _names.add(_prefix + _aliasSuffix); } } for (String _s : MUTATOR_PREFIXES) { _names.add(_s); } _names.add(MAGIC_SET); // always look for the magic set method for dynamic proxies return getMethod(aContextClass, _names, true); }
private static <T> Method getAccessorMethod(Class<T> aClass, Name... aMaybeNames) { Set<String> _names = new LinkedHashSet<String>(); for (Name _s : aMaybeNames) { String _name = (_s.getAlias() == null) ? _s.getName() : _s.getAlias(); String _suffix = removeHyphensAndUpperCaseFirstLetters(_name); for (String _prefix : ACCESSOR_PREFIXES) { _names.add(_prefix + _suffix); } } for (String _s : ACCESSOR_PREFIXES) { _names.add(_s); } return getMethod(aClass, _names, true); }
public ReflectiveBuilder( Name aName, Class<T> aTarget, Class<?> anIntermediate, Converter<Object,T> aConverter, Reflector aReflector, List<Builder<?>> aNested, boolean anIsArray) { if (aName == null) throw new IllegalArgumentException("Must supply a name"); if (aTarget == null) throw new IllegalArgumentException("Must supply a target type"); if (aReflector == null) throw new IllegalArgumentException("Must supply a reflector"); name = aName; target = aTarget; intermediate = (anIntermediate == null) ? aTarget : anIntermediate; converter = aConverter; reflector = aReflector; nested = aNested; array = anIsArray; if (nested != null) { aliases = new HashMap<String,String>(); for (Builder<?> _b : nested) aliases.put(_b.getName().getName(), _b.getName().getAlias()); } }