/** * Returns a named attribute that is either declared in this ObjEntity or is inherited. In any * case returned attribute 'getEntity' method will return this entity. Returns null if no matching * attribute is found. */ @Override public ObjAttribute getAttribute(String name) { ObjAttribute attribute = (ObjAttribute) super.getAttribute(name); if (attribute != null) { return attribute; } // check embedded attribute int dot = name.indexOf('.'); if (dot > 0 && dot < name.length() - 1) { ObjAttribute embedded = getAttribute(name.substring(0, dot)); if (embedded instanceof EmbeddedAttribute) { return ((EmbeddedAttribute) embedded).getAttribute(name.substring(dot + 1)); } } // check super attribute ObjEntity superEntity = getSuperEntity(); if (superEntity != null) { ObjAttribute superAttribute = superEntity.getAttribute(name); if (superAttribute == null) { return null; } // decorate returned attribute to make it appear as if it belongs to // this // entity ObjAttribute decoratedAttribute = new ObjAttribute(superAttribute); decoratedAttribute.setEntity(this); String pathOverride = attributeOverrides.get(name); if (pathOverride != null) { decoratedAttribute.setDbAttributePath(pathOverride); } return decoratedAttribute; } return null; }
/** Recursively appends all attributes in the entity inheritance hierarchy. */ final void appendAttributes(Map<String, ObjAttribute> map) { map.putAll((Map<String, ObjAttribute>) super.getAttributeMap()); ObjEntity superEntity = getSuperEntity(); if (superEntity != null) { SortedMap<String, ObjAttribute> attributeMap = new TreeMap<String, ObjAttribute>(); superEntity.appendAttributes(attributeMap); for (String attributeName : attributeMap.keySet()) { String overridedDbPath = attributeOverrides.get(attributeName); ObjAttribute attribute = new ObjAttribute(attributeMap.get(attributeName)); attribute.setEntity(this); if (overridedDbPath != null) { attribute.setDbAttributePath(overridedDbPath); } map.put(attributeName, attribute); } } }