@Override protected void applyUpdate(final DomainModel element) throws UpdateFailedException { // Validate empty ProfileElement pe = element.getProfile(profileName); if (pe != null && (pe.getIncludedProfiles().size() > 0 || pe.getSubsystems().size() > 0)) { throw new UpdateFailedException("Profile '" + profileName + "' is not empty and cannot be removed"); } // Validate unused StringBuilder illegal = null; for (String serverGroupName : element.getServerGroupNames()) { ServerGroupElement sge = element.getServerGroup(serverGroupName); if (profileName.equals(sge.getName())) { if (illegal == null) { illegal = new StringBuilder(sge.getName()); } else { illegal.append(", "); illegal.append(sge.getName()); } } } if (illegal != null) { throw new UpdateFailedException(String.format("Profile %s cannot be removed as it is still used by server groups %s", profileName, illegal.toString())); } element.removeProfile(profileName); }
private static void processProfile(DomainModel domainModel, ProfileElement profile, List<AbstractServerModelUpdate<?>> list, Set<String> processedProfiles, Set<String> processedSubsystems) { if (! processedProfiles.add(profile.getName())) { // we already hit this one via another path return; } // Parent profile subsystems first for (String included : profile.getIncludedProfiles()) { processProfile(domainModel, domainModel.getProfile(included), list, processedProfiles, processedSubsystems); } for (AbstractSubsystemElement<? extends AbstractSubsystemElement<?>> subsystemElement : profile.getSubsystems()) { String namespaceURI = subsystemElement.getElementName().getNamespaceURI(); if (processedSubsystems.contains(namespaceURI)) { // FIXME catch this problem in domain model parsing throw findDuplicateProfile(namespaceURI, profile.getName(), processedProfiles, domainModel); } // todo: find a better way around this generics issue processSubsystem((AbstractSubsystemElement) subsystemElement, list); processedSubsystems.add(namespaceURI); } }