final SInstance getAttributeInstanceInternal(String fullName) { for (SType<?> current = this; current != null; current = current.superType) { SInstance instance = current.attributesResolved.get(fullName); if (instance != null) { return instance; } } return null; }
/** * Lista todos os atributos com valor associado diretamente ao tipo atual. Não retorna os atributos consolidado do * tipo pai. * * @return Nunca null */ @Override public Collection<SInstance> getAttributes() { return attributesResolved.getAttributes(); }
public void set(String attributePath, Object value) { getCreating(attributePath).setValue(value); }
protected SType(String simpleName, Class<? extends I> instanceClass) { if (simpleName == null) { simpleName = getInfoType().name(); if (StringUtils.isEmpty(simpleName)) { simpleName = getClass().getSimpleName(); if (simpleName.startsWith("STYPE")) { simpleName = simpleName.substring(5); } } } SFormUtil.validateSimpleName(simpleName); this.nameSimple = simpleName; this.instanceClass = instanceClass; attributesResolved = new MapAttributeDefinitionResolver(this); }
@Override public <V> void setAttributeCalculation(String attributeFullName, String subPath, SimpleValueCalculation<V> valueCalculation) { SInstance instance = attributesResolved.getCreating(mapName(attributeFullName)); SInstance.setValueCalculation(instance, subPath, valueCalculation); }
/** * Retorna a instancia do atributo se houver uma associada diretamente ao objeto atual. */ @Override public Optional<SInstance> getAttribute(String fullName) { return Optional.ofNullable(attributesResolved.get(fullName)); }
@Override public void setAttributeValue(String attributeFullName, String subPath, Object value) { SInstance instance = attributesResolved.getCreating(mapName(attributeFullName)); if (subPath != null) { instance.setValue(new PathReader(subPath), value); } else { instance.setValue(value); } }
public SInstance getCreating(String attributePath) { SInstance entry = get(attributePath); if (entry != null) { return entry; } for (SType<?> current = owner; current != null; current = current.getSuperType()) { SType<?> attrType = current.getAttributeDefinedLocally(attributePath); if (attrType != null) { SInstance attrInstance = attrType.newAttributeInstanceFor(owner); if (attributes == null) { attributes = new LinkedHashMap<>(); } attributes.put(attributePath, attrInstance); return attrInstance; } } if(owner != null) { throw new SingularFormException( "Não existe o atributo '" + attributePath + "' definido em '" + owner.getName() + "' ou nos tipos extendidos"); } else { throw new SingularFormException("Não existe o atributo '" + attributePath + "'"); } }