From: Robert Varga Date: Fri, 20 Jan 2017 10:45:18 +0000 (+0100) Subject: BUG-7608: restructure exception throws X-Git-Tag: release/carbon~319 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=d62041440e4f29ee119e5deeb2c1c2972adf5007 BUG-7608: restructure exception throws This cleans up the try-catch block so that we do not have to re-throw exceptions. Change-Id: I8c876f12b7a9e9108eb8dcca7a602927a78bec2c Signed-off-by: Robert Varga --- diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/RpcServiceMetadata.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/RpcServiceMetadata.java index 030a6840a8..90ebeb253c 100644 --- a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/RpcServiceMetadata.java +++ b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/RpcServiceMetadata.java @@ -43,30 +43,30 @@ class RpcServiceMetadata extends AbstractDependentComponentFactoryMetadata { private volatile ListenerRegistration rpcListenerReg; private volatile Class rpcInterface; - RpcServiceMetadata(String id, String interfaceName) { + RpcServiceMetadata(final String id, final String interfaceName) { super(id); this.interfaceName = interfaceName; } @SuppressWarnings({ "checkstyle:IllegalCatch", "unchecked" }) @Override - public void init(ExtendedBlueprintContainer container) { + public void init(final ExtendedBlueprintContainer container) { super.init(container); + final Class interfaceClass; try { - Class interfaceClass = container().getBundleContext().getBundle().loadClass(interfaceName); - if (!RpcService.class.isAssignableFrom(interfaceClass)) { - throw new ComponentDefinitionException(String.format( - "%s: The specified interface %s is not an RpcService", logName(), interfaceName)); - } - - rpcInterface = (Class)interfaceClass; - } catch (ComponentDefinitionException e) { - throw e; + interfaceClass = container().getBundleContext().getBundle().loadClass(interfaceName); } catch (Exception e) { throw new ComponentDefinitionException(String.format("%s: Error obtaining interface class %s", logName(), interfaceName), e); } + + if (!RpcService.class.isAssignableFrom(interfaceClass)) { + throw new ComponentDefinitionException(String.format( + "%s: The specified interface %s is not an RpcService", logName(), interfaceName)); + } + + rpcInterface = (Class)interfaceClass; } @Override @@ -77,7 +77,7 @@ class RpcServiceMetadata extends AbstractDependentComponentFactoryMetadata { service -> retrievedSchemaContext(((SchemaService)service).getGlobalContext())); } - private void retrievedSchemaContext(SchemaContext schemaContext) { + private void retrievedSchemaContext(final SchemaContext schemaContext) { LOG.debug("{}: retrievedSchemaContext", logName()); QNameModule moduleName = BindingReflections.getQNameModule(rpcInterface); @@ -100,23 +100,23 @@ class RpcServiceMetadata extends AbstractDependentComponentFactoryMetadata { service -> retrievedDOMRpcService((DOMRpcService)service)); } - private void retrievedDOMRpcService(DOMRpcService domRpcService) { + private void retrievedDOMRpcService(final DOMRpcService domRpcService) { LOG.debug("{}: retrievedDOMRpcService", logName()); setDependendencyDesc("Available DOM RPC for binding RPC: " + rpcInterface); rpcListenerReg = domRpcService.registerRpcListener(new DOMRpcAvailabilityListener() { @Override - public void onRpcAvailable(Collection rpcs) { + public void onRpcAvailable(final Collection rpcs) { onRpcsAvailable(rpcs); } @Override - public void onRpcUnavailable(Collection rpcs) { + public void onRpcUnavailable(final Collection rpcs) { } }); } - protected void onRpcsAvailable(Collection rpcs) { + protected void onRpcsAvailable(final Collection rpcs) { for (DOMRpcIdentifier identifier : rpcs) { if (rpcSchemaPaths.contains(identifier.getType())) { LOG.debug("{}: onRpcsAvailable - found SchemaPath {}", logName(), identifier.getType()); @@ -163,7 +163,7 @@ class RpcServiceMetadata extends AbstractDependentComponentFactoryMetadata { } @Override - public void destroy(Object instance) { + public void destroy(final Object instance) { super.destroy(instance); closeRpcListenerReg(); }