Mostly renaming enum constants.
Change-Id: I24a3afe1281a070550ef3c8424b35ed58d3691f6
Signed-off-by: Dana Kutenicsova <dana.kutenics@gmail.com>
}
} catch (InstanceNotFoundException e) {
throw new DocumentedException(String.format("Unable to edit ref name " + refNameToServiceEntry.getKey() + " for instance " + on, e),
- ErrorType.application,
- ErrorTag.operation_failed,
- ErrorSeverity.error);
+ ErrorType.APPLICATION,
+ ErrorTag.OPERATION_FAILED,
+ ErrorSeverity.ERROR);
}
}
}
return parseObject(type, value);
} catch (Exception e) {
throw new DocumentedException("Unable to resolve attribute " + attrName + " from " + value,
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
LOG.trace("Error parsing object ",e);
throw new DocumentedException("Error parsing object.",
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
}
} catch (ParseException e) {
LOG.trace("Unable parse value {} due to ",value, e);
throw new DocumentedException("Unable to parse value "+value+" as date.",
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
}
if (!foundWithoutNamespaceNodes.isEmpty()){
throw new DocumentedException(String.format("Element %s present multiple times with different namespaces: %s, %s", name, foundConfigNodes,
foundWithoutNamespaceNodes),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.invalid_value,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.INVALID_VALUE,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
String module, String instance, ServiceRegistryWrapper services) throws
ConfigHandlingException {
throw new ConfigHandlingException(String.format("Unable to delete %s : %s , ServiceInstance not found", module, instance),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
@Override
} catch (InstanceNotFoundException e) {
throw new ConfigHandlingException(
String.format("Unable to delete %s because of exception %s" + on, e.getMessage()),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
}
throw new OperationNotPermittedException(String.format("With "
+ defaultStrategy
+ " as default-operation operations on module elements are not permitted since the default option is restrictive"),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
String.format("Unable to handle missing instance, no missing instances should appear at this point, missing: %s : %s ",
module,
instance),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
@Override
on,
configAttributeEntry.getKey(),
configAttributeEntry.getValue()),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
}
LOG.trace("New instance for {} {} created under name {}", module, instance, on);
} catch (InstanceAlreadyExistsException e1) {
throw new ConfigHandlingException(String.format("Unable to create instance for %s : %s.", module, instance),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
String module, String instance, ServiceRegistryWrapper services) throws ConfigHandlingException {
throw new ConfigHandlingException(
String.format("Unable to recreate %s : %s, Existing module instance not found", module, instance),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
@Override
ta.reCreateModule(objectName);
} catch(InstanceNotFoundException e) {
throw new ConfigHandlingException(String.format("Unable to recreate instance for %s", objectName),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
}
String.format("Unable to handle missing instance, no missing instances should appear at this point, missing: %s : %s ",
module,
instance),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
@Override
public class CloseableUtil {
+ private CloseableUtil() {
+ }
+
public static void closeAll(Iterable<? extends AutoCloseable> autoCloseables) throws Exception {
Exception lastException = null;
for (AutoCloseable autoCloseable : autoCloseables) {
if (lastException != null) {
throw lastException;
}
-
}
}
this.configMBeanServer = configMBeanServer;
this.configRegistryON = configRegistryON;
Set<ObjectInstance> searchResult = configMBeanServer.queryMBeans(configRegistryON, null);
- if (!(searchResult.size() == 1)) {
+ if (searchResult.size() != 1) {
throw new IllegalStateException("Config registry not found");
}
configRegistryMXBeanProxy = JMX.newMXBeanProxy(configMBeanServer, configRegistryON, ConfigRegistryMXBean.class,
static ObjectName translateServiceRefIfPossible(ObjectName on, Class<?> clazz, MBeanServer configMBeanServer) {
ObjectName onObj = on;
- if (ObjectNameUtil.isServiceReference(onObj) && clazz.equals(ServiceReferenceMXBean.class) == false) {
+ if (ObjectNameUtil.isServiceReference(onObj) && !clazz.equals(ServiceReferenceMXBean.class)) {
ServiceReferenceMXBean proxy = JMX.newMXBeanProxy(configMBeanServer, onObj, ServiceReferenceMXBean.class);
onObj = proxy.getCurrentImplementation();
}
import static org.opendaylight.controller.config.util.xml.XmlMappingConstants.RPC_REPLY_KEY;
import static org.opendaylight.controller.config.util.xml.XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
-
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
private static final long serialVersionUID = 1L;
- private final static Logger LOG = LoggerFactory.getLogger( DocumentedException.class );
+ private static final Logger LOG = LoggerFactory.getLogger(DocumentedException.class);
private static final DocumentBuilderFactory BUILDER_FACTORY;
}
public enum ErrorType {
- transport, rpc, protocol, application;
+ TRANSPORT, RPC, PROTOCOL, APPLICATION;
public String getTagValue() {
return name();
return valueOf( text );
}
catch( Exception e ) {
- return application;
+ return APPLICATION;
}
}
}
public enum ErrorTag {
- access_denied("access-denied"),
- bad_attribute("bad-attribute"),
- bad_element("bad-element"),
- data_exists("data-exists"),
- data_missing("data-missing"),
- in_use("in-use"),
- invalid_value("invalid-value"),
- lock_denied("lock-denied"),
- malformed_message("malformed-message"),
- missing_attribute("missing-attribute"),
- missing_element("missing-element"),
- operation_failed("operation-failed"),
- operation_not_supported("operation-not-supported"),
- resource_denied("resource-denied"),
- rollback_failed("rollback-failed"),
- too_big("too-big"),
- unknown_attribute("unknown-attribute"),
- unknown_element("unknown-element"),
- unknown_namespace("unknown-namespace");
+ ACCESS_DENIED("access-denied"),
+ BAD_ATTRIBUTE("bad-attribute"),
+ BAD_ELEMENT("bad-element"),
+ DATA_EXISTS("data-exists"),
+ DATA_MISSING("data-missing"),
+ IN_USE("in-use"),
+ INVALID_VALUE("invalid-value"),
+ LOCK_DENIED("lock-denied"),
+ MALFORMED_MESSAGE("malformed-message"),
+ MISSING_ATTRIBUTE("missing-attribute"),
+ MISSING_ELEMENT("missing-element"),
+ OPERATION_FAILED("operation-failed"),
+ OPERATION_NOT_SUPPORTED("operation-not-supported"),
+ RESOURCE_DENIED("resource-denied"),
+ ROLLBCK_FAILED("rollback-failed"),
+ TOO_BIG("too-big"),
+ UNKNOWN_ATTRIBUTE("unknown-attribute"),
+ UNKNOWN_ELEMENT("unknown-element"),
+ UNKNOWN_NAMESPACE("unknown-namespace");
private final String tagValue;
}
}
- return operation_failed;
+ return OPERATION_FAILED;
}
}
public enum ErrorSeverity {
- error, warning;
+ ERROR, WARNING;
public String getTagValue() {
return name();
return valueOf( text );
}
catch( Exception e ) {
- return error;
+ return ERROR;
}
}
}
public DocumentedException(String message) {
this(message,
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.invalid_value,
- DocumentedException.ErrorSeverity.error
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.INVALID_VALUE,
+ DocumentedException.ErrorSeverity.ERROR
);
}
public static <E extends Exception> DocumentedException wrap(E exception) throws DocumentedException {
final Map<String, String> errorInfo = new HashMap<>();
- errorInfo.put(ErrorTag.operation_failed.name(), "Exception thrown");
- throw new DocumentedException(exception.getMessage(), exception, ErrorType.application, ErrorTag.operation_failed,
- ErrorSeverity.error, errorInfo);
+ errorInfo.put(ErrorTag.OPERATION_FAILED.name(), "Exception thrown");
+ throw new DocumentedException(exception.getMessage(), exception, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED,
+ ErrorSeverity.ERROR, errorInfo);
}
public static DocumentedException wrap(ValidationException e) throws DocumentedException {
final Map<String, String> errorInfo = new HashMap<>();
- errorInfo.put(ErrorTag.operation_failed.name(), "Validation failed");
- throw new DocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
- ErrorSeverity.error, errorInfo);
+ errorInfo.put(ErrorTag.OPERATION_FAILED.name(), "Validation failed");
+ throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED,
+ ErrorSeverity.ERROR, errorInfo);
}
public static DocumentedException wrap(ConflictingVersionException e) throws DocumentedException {
final Map<String, String> errorInfo = new HashMap<>();
- errorInfo.put(ErrorTag.operation_failed.name(), "Optimistic lock failed");
- throw new DocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
- ErrorSeverity.error, errorInfo);
+ errorInfo.put(ErrorTag.OPERATION_FAILED.name(), "Optimistic lock failed");
+ throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED,
+ ErrorSeverity.ERROR, errorInfo);
}
public static DocumentedException fromXMLDocument( Document fromDoc ) {
- ErrorType errorType = ErrorType.application;
- ErrorTag errorTag = ErrorTag.operation_failed;
- ErrorSeverity errorSeverity = ErrorSeverity.error;
+ ErrorType errorType = ErrorType.APPLICATION;
+ ErrorTag errorTag = ErrorTag.OPERATION_FAILED;
+ ErrorSeverity errorSeverity = ErrorSeverity.ERROR;
Map<String, String> errorInfo = null;
String errorMessage = "";
}
}
catch( ParserConfigurationException e ) {
- LOG.error( "Error outputting to XML document", e ); // this shouldn't happen
+ // this shouldn't happen
+ LOG.error("Error outputting to XML document", e);
}
return doc;
} else {
if (!attribKey.startsWith(XmlUtil.XMLNS_ATTRIBUTE_KEY + ":")){
throw new DocumentedException("Attribute doesn't start with :",
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.invalid_value,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.INVALID_VALUE,
+ DocumentedException.ErrorSeverity.ERROR);
}
prefix = attribKey.substring(XmlUtil.XMLNS_ATTRIBUTE_KEY.length() + 1);
}
if (!getName().equals(expectedName)){
throw new UnexpectedElementException(String.format("Expected %s xml element but was %s", expectedName,
getName()),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s should be %s",
getNamespaceAttribute(),
expectedNamespace),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s should be %s",
getNamespace(),
expectedNamespace),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
List<XmlElement> nameElements = getChildElements(childName);
if (nameElements.size() != 1){
throw new DocumentedException("One element " + childName + " expected in " + toString(),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.invalid_value,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.INVALID_VALUE,
+ DocumentedException.ErrorSeverity.ERROR);
}
return nameElements.get(0);
}
if (children.size() != 1){
throw new DocumentedException(String.format("One element %s:%s expected in %s but was %s", namespace,
childName, toString(), children.size()),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.invalid_value,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.INVALID_VALUE,
+ DocumentedException.ErrorSeverity.ERROR);
}
return children.get(0);
if (children.size() != 1){
throw new DocumentedException(String.format( "One element expected in %s but was %s", toString(),
children.size()),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.invalid_value,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.INVALID_VALUE,
+ DocumentedException.ErrorSeverity.ERROR);
}
return children.get(0);
}
}
}
throw new DocumentedException(getName() + " should contain text.",
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.invalid_value,
- DocumentedException.ErrorSeverity.error
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.INVALID_VALUE,
+ DocumentedException.ErrorSeverity.ERROR
);
}
if (attribute == null || attribute.equals(DEFAULT_NAMESPACE_PREFIX)){
throw new MissingNameSpaceException(String.format("Element %s must specify namespace",
toString()),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
return attribute;
}
Optional<String> namespaceURI = getNamespaceOptionally();
if (!namespaceURI.isPresent()){
throw new MissingNameSpaceException(String.format("No namespace defined for %s", this),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.operation_failed,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.OPERATION_FAILED,
+ DocumentedException.ErrorSeverity.ERROR);
}
return namespaceURI.get();
}
}
if (!childElements.isEmpty()){
throw new DocumentedException(String.format("Unrecognised elements %s in %s", childElements, this),
- DocumentedException.ErrorType.application,
- DocumentedException.ErrorTag.invalid_value,
- DocumentedException.ErrorSeverity.error);
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.INVALID_VALUE,
+ DocumentedException.ErrorSeverity.ERROR);
}
}
}
public boolean hasNamespace() {
- if (!getNamespaceAttributeOptionally().isPresent()) {
- if (!getNamespaceOptionally().isPresent()) {
- return false;
- }
- }
- return true;
+ return getNamespaceAttributeOptionally().isPresent() || getNamespaceOptionally().isPresent();
}
private interface ElementFilteringStrategy {
public final class XmlMappingConstants {
-
- private XmlMappingConstants() {}
-
public static final String RPC_REPLY_KEY = "rpc-reply";
public static final String TYPE_KEY = "type";
public static final String MODULE_KEY = "module";
public static final String URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0 = "urn:ietf:params:xml:ns:netconf:base:1.0";
public static final String URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG = "urn:opendaylight:params:xml:ns:yang:controller:config";
+
+ private XmlMappingConstants() {
+ }
}