/** * Removes an attribute from this resource class. * * @param attr an attribute. * @throws EntityDoesNotExistException if the class does not declare the attribute. */ public void deleteAttribute(Attribute attr) throws EntityDoesNotExistException { if (!attributes.containsKey(attr.getName())) { throw new EntityDoesNotExistException( "class " + getName() + " does not declare attribute " + "named " + attr.getName()); } attributes.remove(attr.getName()); attr.setDeclaringClass(null); }
/** * Adds an attribute to this resource class. * * @param attr an attribute. * @throws EntityExistsException if the class already delcares an attribute by that name. */ public void addAttribute(Attribute attr) throws EntityExistsException { if (attributes.containsKey(attr.getName())) { throw new EntityExistsException( "class " + getName() + " already declares attribute named " + attr.getName()); } if (getAllAttributes().contains(attr)) { throw new EntityExistsException( "class " + getName() + " already inherits attribute named " + attr.getName()); } attributes.put(attr.getName(), attr); attr.setDeclaringClass(this); }