You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2015/11/01 01:44:58 UTC
[08/12] oodt git commit: OODT-911 make code clearer
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/Configuration.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/Configuration.java b/commons/src/main/java/org/apache/oodt/commons/Configuration.java
index eb44cbd..d57265c 100644
--- a/commons/src/main/java/org/apache/oodt/commons/Configuration.java
+++ b/commons/src/main/java/org/apache/oodt/commons/Configuration.java
@@ -73,7 +73,9 @@ public class Configuration {
*/
public static Configuration getConfiguration() throws IOException, SAXException {
// Got one? Use it.
- if (configuration != null) return configuration;
+ if (configuration != null) {
+ return configuration;
+ }
URL url;
@@ -88,7 +90,9 @@ public class Configuration {
String filename = System.getProperty("org.apache.oodt.commons.Configuration.file");
if (filename != null) {
file = new File(filename);
- if (!file.exists()) throw new IOException("File " + file + " not found");
+ if (!file.exists()) {
+ throw new IOException("File " + file + " not found");
+ }
} else {
List candidates = new ArrayList();
@@ -124,9 +128,10 @@ public class Configuration {
break;
}
}
- if (found && file == alt)
- System.err.println("WARNING: Using older config file " + alt + "; rename to "
- + homedirfile + " as soon as possible.");
+ if (found && file == alt) {
+ System.err.println("WARNING: Using older config file " + alt + "; rename to "
+ + homedirfile + " as soon as possible.");
+ }
if (!found) {
return getEmptyConfiguration();
}
@@ -149,16 +154,18 @@ public class Configuration {
*/
public static Configuration getConfiguration(URL configFileUrl) throws SAXException, IOException {
synchronized (Configuration.class) {
- if (configuration == null)
- configuration = new Configuration(configFileUrl);
+ if (configuration == null) {
+ configuration = new Configuration(configFileUrl);
+ }
}
return configuration;
}
private static Configuration getEmptyConfiguration() {
synchronized (Configuration.class) {
- if (configuration == null)
- configuration = new Configuration();
+ if (configuration == null) {
+ configuration = new Configuration();
+ }
}
return configuration;
}
@@ -173,7 +180,9 @@ public class Configuration {
*/
public static Configuration getConfigurationWithoutException() {
// Got one? Use it. Do this out of a try block for performance.
- if (configuration != null) return configuration;
+ if (configuration != null) {
+ return configuration;
+ }
// Try to get it.
try {
@@ -215,7 +224,9 @@ public class Configuration {
Configuration(InputSource inputSource) throws IOException, SAXException {
String systemID = inputSource.getSystemId();
- if (systemID == null) inputSource.setSystemId("file:/unknown");
+ if (systemID == null) {
+ inputSource.setSystemId("file:/unknown");
+ }
// Get the document
DOMParser parser = XML.createDOMParser();
@@ -238,8 +249,9 @@ public class Configuration {
document.normalize();
// See if this really is a <configuration> document.
- if (!document.getDocumentElement().getNodeName().equals("configuration"))
- throw new SAXException("Configuration " + inputSource.getSystemId() + " is not a <configuration> document");
+ if (!document.getDocumentElement().getNodeName().equals("configuration")) {
+ throw new SAXException("Configuration " + inputSource.getSystemId() + " is not a <configuration> document");
+ }
NodeList list = document.getDocumentElement().getChildNodes();
for (int eachChild = 0; eachChild < list.getLength(); ++eachChild) {
@@ -248,27 +260,31 @@ public class Configuration {
NodeList children = childNode.getChildNodes();
for (int i = 0; i < children.getLength(); ++i) {
Node node = children.item(i);
- if ("host".equals(node.getNodeName()))
- webHost = XML.unwrappedText(node);
- else if ("port".equals(node.getNodeName()))
- webPort = XML.unwrappedText(node);
- else if ("dir".equals(node.getNodeName()))
- webServerDocumentDirectory = new File(XML.unwrappedText(node));
+ if ("host".equals(node.getNodeName())) {
+ webHost = XML.unwrappedText(node);
+ } else if ("port".equals(node.getNodeName())) {
+ webPort = XML.unwrappedText(node);
+ } else if ("dir".equals(node.getNodeName())) {
+ webServerDocumentDirectory = new File(XML.unwrappedText(node));
+ }
}
properties.setProperty("org.apache.oodt.commons.Configuration.webServer.baseURL", getWebServerBaseURL());
- if (webServerDocumentDirectory == null)
- webServerDocumentDirectory = new File(System.getProperty("user.home", "/")
- + "/dev/htdocs");
+ if (webServerDocumentDirectory == null) {
+ webServerDocumentDirectory = new File(System.getProperty("user.home", "/")
+ + "/dev/htdocs");
+ }
} else if (childNode.getNodeName().equals("nameServer")) {
Element nameServerNode = (Element) childNode;
String nameServerStateFrequencyString = nameServerNode.getAttribute("stateFrequency");
- if (nameServerStateFrequencyString == null || nameServerStateFrequencyString.length() == 0)
- nameServerStateFrequency = 0;
- else try {
+ if (nameServerStateFrequencyString == null || nameServerStateFrequencyString.length() == 0) {
+ nameServerStateFrequency = 0;
+ } else {
+ try {
nameServerStateFrequency = Integer.parseInt(nameServerStateFrequencyString);
- } catch (NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
throw new SAXException("Illegal nun-numeric value \"" + nameServerStateFrequencyString
- + "\" for stateFrequency attribute");
+ + "\" for stateFrequency attribute");
+ }
}
if (childNode.getFirstChild().getNodeName().equals("rir")) {
nameServerUsingRIRProtocol = true;
@@ -283,14 +299,15 @@ public class Configuration {
NodeList children = childNode.getFirstChild().getChildNodes();
for (int i = 0; i < children.getLength(); ++i) {
Node node = children.item(i);
- if (node.getNodeName().equals("version"))
- nameServerVersion = XML.unwrappedText(node);
- else if (node.getNodeName().equals("host"))
- nameServerHost = XML.unwrappedText(node);
- else if (node.getNodeName().equals("port"))
- nameServerPort = XML.unwrappedText(node);
- else if (node.getNodeName().equals("objectKey"))
- nameServerObjectKey = XML.unwrappedText(node);
+ if (node.getNodeName().equals("version")) {
+ nameServerVersion = XML.unwrappedText(node);
+ } else if (node.getNodeName().equals("host")) {
+ nameServerHost = XML.unwrappedText(node);
+ } else if (node.getNodeName().equals("port")) {
+ nameServerPort = XML.unwrappedText(node);
+ } else if (node.getNodeName().equals("objectKey")) {
+ nameServerObjectKey = XML.unwrappedText(node);
+ }
}
}
} else if (childNode.getNodeName().equals("xml")) {
@@ -300,11 +317,13 @@ public class Configuration {
if ("entityRef".equals(xmlNode.getNodeName())) {
NodeList dirNodes = xmlNode.getChildNodes();
StringBuilder refDirs = new StringBuilder(System.getProperty(ENTITY_DIRS_PROP, ""));
- for (int j = 0; j < dirNodes.getLength(); ++j)
- refDirs.append(',').append(XML.unwrappedText(dirNodes.item(j)));
- if (refDirs.length() > 0)
- System.setProperty(ENTITY_DIRS_PROP, refDirs.charAt(0) == ','?
- refDirs.substring(1) : refDirs.toString());
+ for (int j = 0; j < dirNodes.getLength(); ++j) {
+ refDirs.append(',').append(XML.unwrappedText(dirNodes.item(j)));
+ }
+ if (refDirs.length() > 0) {
+ System.setProperty(ENTITY_DIRS_PROP, refDirs.charAt(0) == ',' ?
+ refDirs.substring(1) : refDirs.toString());
+ }
}
}
} else if ("serverMgr".equals(childNode.getNodeName())) {
@@ -377,18 +396,22 @@ public class Configuration {
if (nameServerUsingRIRProtocol) {
Element rirNode = document.createElement("rir");
nameServerNode.appendChild(rirNode);
- if (nameServerObjectKey != null)
- XML.add(rirNode, "objectKey", nameServerObjectKey);
+ if (nameServerObjectKey != null) {
+ XML.add(rirNode, "objectKey", nameServerObjectKey);
+ }
} else {
Element iiopNode = document.createElement("iiop");
nameServerNode.appendChild(iiopNode);
- if (nameServerVersion != null)
- XML.add(iiopNode, "version", nameServerVersion);
+ if (nameServerVersion != null) {
+ XML.add(iiopNode, "version", nameServerVersion);
+ }
XML.add(iiopNode, "host", nameServerHost);
- if (nameServerPort != null)
- XML.add(iiopNode, "port", nameServerPort);
- if (nameServerObjectKey != null)
- XML.add(iiopNode, "objectKey", nameServerObjectKey);
+ if (nameServerPort != null) {
+ XML.add(iiopNode, "port", nameServerPort);
+ }
+ if (nameServerObjectKey != null) {
+ XML.add(iiopNode, "objectKey", nameServerObjectKey);
+ }
}
// <xml><entityRef><dir>...
@@ -408,8 +431,9 @@ public class Configuration {
}
// Global <properties>...</properties>
- if (properties.size() > 0)
- dumpProperties(properties, configurationNode);
+ if (properties.size() > 0) {
+ dumpProperties(properties, configurationNode);
+ }
// <programs>...
if (execServers.size() > 0) {
@@ -482,8 +506,9 @@ public class Configuration {
ExecServerConfig execServerConfig = null;
for (Iterator i = execServers.iterator(); i.hasNext() && execServerConfig == null;) {
ExecServerConfig exec = (ExecServerConfig) i.next();
- if (objectKey.equals(exec.getObjectKey()))
- execServerConfig = exec;
+ if (objectKey.equals(exec.getObjectKey())) {
+ execServerConfig = exec;
+ }
}
return execServerConfig;
}
@@ -495,8 +520,11 @@ public class Configuration {
public String getWebServerBaseURL() {
String proto = System.getProperty(WEB_PROTOCOL_PROPERTY);
if (proto == null) {
- if ("443".equals(webPort)) proto = "https";
- else proto = "http";
+ if ("443".equals(webPort)) {
+ proto = "https";
+ } else {
+ proto = "http";
+ }
}
return proto + "://" + webHost + ":" + webPort;
}
@@ -541,9 +569,10 @@ public class Configuration {
public Context getObjectContext() throws NamingException {
Context c;
final String className = (String) contextEnvironment.get(javax.naming.Context.INITIAL_CONTEXT_FACTORY);
- if (className == null)
- c = new InitialContext(contextEnvironment);
- else try {
+ if (className == null) {
+ c = new InitialContext(contextEnvironment);
+ } else {
+ try {
// Work around iPlanet bug. JNDI uses the thread's context class
// loader to load the initial context factory class. For some
// reason, that loader fails to find things in iPlanet's
@@ -557,15 +586,17 @@ public class Configuration {
InitialContextThread thread = new InitialContextThread(loader);
thread.start();
try {
- thread.join();
+ thread.join();
} catch (InterruptedException ex) {
- throw new NoInitialContextException("Initial context thread interrupted: " + ex.getMessage());
+ throw new NoInitialContextException("Initial context thread interrupted: " + ex.getMessage());
}
c = thread.getContext();
- if (c == null)
- throw thread.getException();
- } catch (ClassNotFoundException ex) {
+ if (c == null) {
+ throw thread.getException();
+ }
+ } catch (ClassNotFoundException ex) {
throw new NoInitialContextException("Class " + className + " not found");
+ }
}
return c;
}
@@ -576,8 +607,9 @@ public class Configuration {
*/
public List getEntityRefDirs() {
List dirs = new ArrayList();
- for (StringTokenizer t = new StringTokenizer(System.getProperty(ENTITY_DIRS_PROP, ""), ",;|"); t.hasMoreTokens();)
- dirs.add(t.nextToken());
+ for (StringTokenizer t = new StringTokenizer(System.getProperty(ENTITY_DIRS_PROP, ""), ",;|"); t.hasMoreTokens();) {
+ dirs.add(t.nextToken());
+ }
return dirs;
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/ConfigurationEntityResolver.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/ConfigurationEntityResolver.java b/commons/src/main/java/org/apache/oodt/commons/ConfigurationEntityResolver.java
index cc784dc..f5c35c1 100644
--- a/commons/src/main/java/org/apache/oodt/commons/ConfigurationEntityResolver.java
+++ b/commons/src/main/java/org/apache/oodt/commons/ConfigurationEntityResolver.java
@@ -34,8 +34,9 @@ import org.xml.sax.SAXException;
*/
class ConfigurationEntityResolver implements EntityResolver {
public InputSource resolveEntity(String publicID, String systemID) throws SAXException, IOException {
- if (Configuration.DTD_FPI.equals(publicID) || Configuration.DTD_OLD_FPI.equals(publicID))
- return new InputSource(Configuration.class.getResourceAsStream("Configuration.dtd"));
+ if (Configuration.DTD_FPI.equals(publicID) || Configuration.DTD_OLD_FPI.equals(publicID)) {
+ return new InputSource(Configuration.class.getResourceAsStream("Configuration.dtd"));
+ }
return null;
}
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/ExecServer.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/ExecServer.java b/commons/src/main/java/org/apache/oodt/commons/ExecServer.java
index 3a03290..3a84c30 100644
--- a/commons/src/main/java/org/apache/oodt/commons/ExecServer.java
+++ b/commons/src/main/java/org/apache/oodt/commons/ExecServer.java
@@ -134,9 +134,12 @@ public class ExecServer {
});
// We're done here.
- for (;;) try {
+ for (;;) {
+ try {
Thread.currentThread().join();
- } catch (InterruptedException ignore) {}
+ } catch (InterruptedException ignore) {
+ }
+ }
} catch (IOException ex) {
System.err.println("I/O error during initialization: " + ex.getMessage());
ex.printStackTrace();
@@ -283,8 +286,9 @@ public class ExecServer {
// Remove all the log messages from the document.
NodeList children = logElement.getChildNodes();
- for (int i = 0; i < children.getLength(); ++i)
- logElement.removeChild(children.item(i));
+ for (int i = 0; i < children.getLength(); ++i) {
+ logElement.removeChild(children.item(i));
+ }
// Return the serialized form, which included the log messages.
System.err.println(rc);
@@ -352,12 +356,15 @@ public class ExecServer {
private void shutdown0() {
// Unbind.
- if (!Boolean.getBoolean(DISABLE_BINDING)) try {
+ if (!Boolean.getBoolean(DISABLE_BINDING)) {
+ try {
binder.stopBinding();
Context objectContext = configuration.getObjectContext();
objectContext.unbind(getName());
objectContext.close();
- } catch (NamingException ignore) {}
+ } catch (NamingException ignore) {
+ }
+ }
// Kill the ORB. YEAH! KILL IT, KILL IT, KIIIIIIIIIIIIIIL IIIIIIIIT!!!!!!!1
try {
@@ -381,17 +388,20 @@ public class ExecServer {
keepBinding = true;
}
public void run() {
- while (shouldKeepBinding()) try {
+ while (shouldKeepBinding()) {
+ try {
Context objectContext = configuration.getObjectContext();
objectContext.rebind(name, server.getServant());
objectContext.close();
- } catch (Throwable ex) {
+ } catch (Throwable ex) {
System.err.println("Exception binding at " + new Date() + "; will keep trying...");
ex.printStackTrace();
- } finally {
+ } finally {
try {
- Thread.sleep(REBIND_PERIOD);
- } catch (InterruptedException ignore) {}
+ Thread.sleep(REBIND_PERIOD);
+ } catch (InterruptedException ignore) {
+ }
+ }
}
}
public synchronized void stopBinding() {
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/ExecServerConfig.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/ExecServerConfig.java b/commons/src/main/java/org/apache/oodt/commons/ExecServerConfig.java
index 53085c8..ae0dc94 100644
--- a/commons/src/main/java/org/apache/oodt/commons/ExecServerConfig.java
+++ b/commons/src/main/java/org/apache/oodt/commons/ExecServerConfig.java
@@ -62,11 +62,13 @@ public class ExecServerConfig extends Executable implements Documentable {
for (int i = 2; i < children.getLength(); ++i) {
Node child = children.item(i);
String name = child.getNodeName();
- if ("host".equals(name))
- preferredHost = InetAddress.getByName(XML.unwrappedText(children.item(2)));
- else if ("properties".equals(name))
- Configuration.loadProperties(child, properties);
- else throw new SAXException("Unknown node " + name + " in exec server XML");
+ if ("host".equals(name)) {
+ preferredHost = InetAddress.getByName(XML.unwrappedText(children.item(2)));
+ } else if ("properties".equals(name)) {
+ Configuration.loadProperties(child, properties);
+ } else {
+ throw new SAXException("Unknown node " + name + " in exec server XML");
+ }
}
}
@@ -133,8 +135,12 @@ public class ExecServerConfig extends Executable implements Documentable {
}
public boolean equals(Object rhs) {
- if (rhs == this) return true;
- if (rhs == null || !(rhs instanceof ExecServerConfig)) return false;
+ if (rhs == this) {
+ return true;
+ }
+ if (rhs == null || !(rhs instanceof ExecServerConfig)) {
+ return false;
+ }
ExecServerConfig obj = (ExecServerConfig) rhs;
return className.equals(obj.className) && objectKey.equals(obj.objectKey) && properties.equals(obj.properties);
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/Executable.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/Executable.java b/commons/src/main/java/org/apache/oodt/commons/Executable.java
index 44f1287..6af49f8 100644
--- a/commons/src/main/java/org/apache/oodt/commons/Executable.java
+++ b/commons/src/main/java/org/apache/oodt/commons/Executable.java
@@ -90,8 +90,9 @@ public abstract class Executable {
}.start();
// Spin until the process field is set.
- while (process == null)
- Thread.yield();
+ while (process == null) {
+ Thread.yield();
+ }
}
/** Wait for the process to terminate.
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/MultiServer.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/MultiServer.java b/commons/src/main/java/org/apache/oodt/commons/MultiServer.java
index f320bd4..d47accd 100644
--- a/commons/src/main/java/org/apache/oodt/commons/MultiServer.java
+++ b/commons/src/main/java/org/apache/oodt/commons/MultiServer.java
@@ -140,10 +140,12 @@ public class MultiServer {
String config = System.getProperty("org.apache.oodt.commons.MultiServer.config", System.getProperty("MultiServer.config",
System.getProperty("multiserver.config", System.getProperty("config"))));
if (config == null) {
- if (argv.length != 1)
- throw new IllegalStateException("No org.apache.oodt.commons.MultiServer.config property or config URL argument");
- else
- config = argv[0];
+ if (argv.length != 1) {
+ throw new IllegalStateException(
+ "No org.apache.oodt.commons.MultiServer.config property or config URL argument");
+ } else {
+ config = argv[0];
+ }
}
StringReader reader = new StringReader(CONFIG);
@@ -164,7 +166,9 @@ public class MultiServer {
ExecServer.runInitializers();
try {
LogInit.init(System.getProperties(), getAppName());
- if (servers.isEmpty()) throw new IllegalStateException("No servers defined in config");
+ if (servers.isEmpty()) {
+ throw new IllegalStateException("No servers defined in config");
+ }
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
@@ -179,9 +183,12 @@ public class MultiServer {
} catch (Throwable ignore) {}
System.exit(1);
}
- for (;;) try {
+ for (;;) {
+ try {
Thread.currentThread().join();
- } catch (InterruptedException ignore) {}
+ } catch (InterruptedException ignore) {
+ }
+ }
}
/**
@@ -209,7 +216,9 @@ public class MultiServer {
Document doc = builder.parse(is);
Element root = doc.getDocumentElement();
appName = root.getAttribute("id");
- if (appName == null) throw new SAXException("id attribute missing from multiserver element");
+ if (appName == null) {
+ throw new SAXException("id attribute missing from multiserver element");
+ }
// Set properties
NodeList children = root.getChildNodes();
@@ -234,24 +243,32 @@ public class MultiServer {
for (int i = 0; i < serverNodes.getLength(); ++i) {
Element serverElem = (Element) serverNodes.item(i);
String name = serverElem.getAttribute("id");
- if (name == null) throw new SAXException("id attribute missing from server element");
+ if (name == null) {
+ throw new SAXException("id attribute missing from server element");
+ }
String className = serverElem.getAttribute("class");
- if (className == null) throw new SAXException("class attribute missing from server element");
+ if (className == null) {
+ throw new SAXException("class attribute missing from server element");
+ }
String bindKind = serverElem.getAttribute("bind");
- if (bindKind == null) throw new SAXException("bind attribute missing from server element");
+ if (bindKind == null) {
+ throw new SAXException("bind attribute missing from server element");
+ }
Server server;
- if ("true".equals(bindKind))
- server = new BindingServer(name, className);
- else if ("false".equals(bindKind))
- server = new NonbindingServer(name, className);
- else if ("rebind".equals(bindKind))
- server = new RebindingServer(name, className);
- else try {
+ if ("true".equals(bindKind)) {
+ server = new BindingServer(name, className);
+ } else if ("false".equals(bindKind)) {
+ server = new NonbindingServer(name, className);
+ } else if ("rebind".equals(bindKind)) {
+ server = new RebindingServer(name, className);
+ } else {
+ try {
long period = Long.parseLong(bindKind);
server = new AutobindingServer(name, className, period);
- } catch (NumberFormatException ex) {
+ } catch (NumberFormatException ex) {
throw new SAXException("Expected true, false, rebind, or auto for bind attribute but got `"
- + bindKind + "'");
+ + bindKind + "'");
+ }
}
servers.put(name, server);
}
@@ -545,7 +562,9 @@ public class MultiServer {
* @throws NamingException if an error occurs.
*/
public void stop() throws NamingException {
- if (binder != null) binder.cancel();
+ if (binder != null) {
+ binder.cancel();
+ }
context.unbind(name);
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/activity/Activity.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/activity/Activity.java b/commons/src/main/java/org/apache/oodt/commons/activity/Activity.java
index 2a36a0f..39610f2 100644
--- a/commons/src/main/java/org/apache/oodt/commons/activity/Activity.java
+++ b/commons/src/main/java/org/apache/oodt/commons/activity/Activity.java
@@ -47,7 +47,9 @@ public abstract class Activity {
* @param id New ID.
*/
public void setID(String id) {
- if (id == null) throw new IllegalArgumentException("ID required");
+ if (id == null) {
+ throw new IllegalArgumentException("ID required");
+ }
this.id = id;
}
@@ -65,7 +67,9 @@ public abstract class Activity {
* further incidents may be logged after calling this method.
*/
public synchronized void stop() {
- if (!started) return;
+ if (!started) {
+ return;
+ }
this.started = false;
log(new ActivityStopped());
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/activity/ActivityTracker.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/activity/ActivityTracker.java b/commons/src/main/java/org/apache/oodt/commons/activity/ActivityTracker.java
index 4af6812..ad14341 100644
--- a/commons/src/main/java/org/apache/oodt/commons/activity/ActivityTracker.java
+++ b/commons/src/main/java/org/apache/oodt/commons/activity/ActivityTracker.java
@@ -67,12 +67,13 @@ public class ActivityTracker {
Class factoryClass = Class.forName(factoryName);
factories.add(factoryClass.newInstance());
}
- if (factories.isEmpty())
- factory = new NullActivityFactory();
- else if (factories.size() == 1)
- factory = (ActivityFactory) factories.get(0);
- else
- factory = new CompositeActivityFactory(factories);
+ if (factories.isEmpty()) {
+ factory = new NullActivityFactory();
+ } else if (factories.size() == 1) {
+ factory = (ActivityFactory) factories.get(0);
+ } else {
+ factory = new CompositeActivityFactory(factories);
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/activity/CompositeActivity.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/activity/CompositeActivity.java b/commons/src/main/java/org/apache/oodt/commons/activity/CompositeActivity.java
index c0c3c8b..494202e 100644
--- a/commons/src/main/java/org/apache/oodt/commons/activity/CompositeActivity.java
+++ b/commons/src/main/java/org/apache/oodt/commons/activity/CompositeActivity.java
@@ -32,8 +32,9 @@ public class CompositeActivity extends Activity {
* @param activities a {@link Collection} of {@link Activity} instances.
*/
public CompositeActivity(Collection activities) {
- if (activities == null)
- throw new IllegalArgumentException("Activities collection required");
+ if (activities == null) {
+ throw new IllegalArgumentException("Activities collection required");
+ }
for (Object activity : activities) {
if (!(activity instanceof Activity)) {
throw new IllegalArgumentException("Non-Activity in activities collection");
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/activity/DatagramLoggingActivityFactory.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/activity/DatagramLoggingActivityFactory.java b/commons/src/main/java/org/apache/oodt/commons/activity/DatagramLoggingActivityFactory.java
index 7903797..dd95806 100644
--- a/commons/src/main/java/org/apache/oodt/commons/activity/DatagramLoggingActivityFactory.java
+++ b/commons/src/main/java/org/apache/oodt/commons/activity/DatagramLoggingActivityFactory.java
@@ -53,9 +53,11 @@ public class DatagramLoggingActivityFactory implements ActivityFactory {
System.getProperty("activity.host", ""));
port = Integer.getInteger("org.apache.oodt.commons.activity.DatagramLoggingActivityFactory.port",
Integer.getInteger("activity.port", 4556));
- if (hostname.length() == 0)
- throw new IllegalStateException("System property `org.apache.oodt.commons.activity.DatagramLoggingActivityFactory.host'"
- + " (or simply `activity.host') not defined or is empty");
+ if (hostname.length() == 0) {
+ throw new IllegalStateException(
+ "System property `org.apache.oodt.commons.activity.DatagramLoggingActivityFactory.host'"
+ + " (or simply `activity.host') not defined or is empty");
+ }
try {
host = InetAddress.getByName(hostname);
socket = new DatagramSocket();
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/activity/History.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/activity/History.java b/commons/src/main/java/org/apache/oodt/commons/activity/History.java
index 7267338..0042d3b 100644
--- a/commons/src/main/java/org/apache/oodt/commons/activity/History.java
+++ b/commons/src/main/java/org/apache/oodt/commons/activity/History.java
@@ -68,24 +68,31 @@ final class History {
* @param incident an {@link Incident} value.
*/
synchronized void addIncident(Incident incident) {
- if (!incident.getActivityID().equals(id))
- throw new IllegalArgumentException("Incident's activity ID " + incident.getActivityID()
- + " doesn't match History's ID " + id);
- if (incidents == null) return;
+ if (!incident.getActivityID().equals(id)) {
+ throw new IllegalArgumentException("Incident's activity ID " + incident.getActivityID()
+ + " doesn't match History's ID " + id);
+ }
+ if (incidents == null) {
+ return;
+ }
incidents.add(incident);
- if (expireHistoryTask != null)
- expireHistoryTask.cancel();
- if (incident instanceof ActivityStopped)
- commit();
- else if (closeHistoryTask == null)
- scheduleExpiration();
+ if (expireHistoryTask != null) {
+ expireHistoryTask.cancel();
+ }
+ if (incident instanceof ActivityStopped) {
+ commit();
+ } else if (closeHistoryTask == null) {
+ scheduleExpiration();
+ }
}
/**
* Commit this history by starting the commit-to-close timer.
*/
private void commit() {
- if (closeHistoryTask != null) return;
+ if (closeHistoryTask != null) {
+ return;
+ }
TIMER.schedule(closeHistoryTask = new CloseHistoryTask(), closeTime);
}
@@ -132,7 +139,9 @@ final class History {
// current expiration task is this task, then we're clear
// to commit the history, and any incidents that arrive
// won't reset it.
- if (expireHistoryTask == this) commit();
+ if (expireHistoryTask == this) {
+ commit();
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/activity/Incident.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/activity/Incident.java b/commons/src/main/java/org/apache/oodt/commons/activity/Incident.java
index ff1d062..e6da1c8 100644
--- a/commons/src/main/java/org/apache/oodt/commons/activity/Incident.java
+++ b/commons/src/main/java/org/apache/oodt/commons/activity/Incident.java
@@ -69,8 +69,12 @@ public class Incident implements Serializable, Comparable {
* @return True if incidents are equal.
*/
public boolean equals(Object obj) {
- if (obj == this) return true;
- if (!(obj instanceof Incident)) return false;
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof Incident)) {
+ return false;
+ }
Incident rhs = (Incident) obj;
return ((id == null && rhs.id == null) || id.equals(rhs.id)) && time.equals(rhs.time);
}
@@ -86,10 +90,11 @@ public class Incident implements Serializable, Comparable {
Incident rhs = (Incident) obj;
int idComp = id == null && rhs.id != null ? -1 : id == null ? 0 : rhs.id == null ? 1
: id.compareTo(rhs.id);
- if (idComp == 0)
- return time.compareTo(rhs.time);
- else
- return idComp;
+ if (idComp == 0) {
+ return time.compareTo(rhs.time);
+ } else {
+ return idComp;
+ }
}
public String toString() {
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/activity/SQLDatabaseRetrieval.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/activity/SQLDatabaseRetrieval.java b/commons/src/main/java/org/apache/oodt/commons/activity/SQLDatabaseRetrieval.java
index 3d1197f..e9a414b 100644
--- a/commons/src/main/java/org/apache/oodt/commons/activity/SQLDatabaseRetrieval.java
+++ b/commons/src/main/java/org/apache/oodt/commons/activity/SQLDatabaseRetrieval.java
@@ -158,8 +158,12 @@ public class SQLDatabaseRetrieval implements Retrieval {
}
finally {
try {
- if (stmt != null) stmt.close();
- if (conn != null) conn.close();
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
}
catch (SQLException ignored) {}
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/database/SqlScript.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/database/SqlScript.java b/commons/src/main/java/org/apache/oodt/commons/database/SqlScript.java
index ee3f9bf..8a5ea8e 100644
--- a/commons/src/main/java/org/apache/oodt/commons/database/SqlScript.java
+++ b/commons/src/main/java/org/apache/oodt/commons/database/SqlScript.java
@@ -114,8 +114,9 @@ public class SqlScript {
boolean queryEnds;
while ((line = reader.readLine()) != null) {
- if (isComment(line))
+ if (isComment(line)) {
continue;
+ }
queryEnds = checkStatementEnds(line);
query.append(line);
if (queryEnds) {
@@ -161,8 +162,9 @@ public class SqlScript {
}
private boolean isComment(String line) {
- if ((line != null) && (line.length() > 0))
+ if ((line != null) && (line.length() > 0)) {
return (line.charAt(0) == '#');
+ }
return false;
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/date/DateUtils.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/date/DateUtils.java b/commons/src/main/java/org/apache/oodt/commons/date/DateUtils.java
index ad854ed..ed2e9cc 100644
--- a/commons/src/main/java/org/apache/oodt/commons/date/DateUtils.java
+++ b/commons/src/main/java/org/apache/oodt/commons/date/DateUtils.java
@@ -101,8 +101,9 @@ public class DateUtils {
public static int getLeapSecsForDate(Calendar utcCal) throws CommonsException {
long timeInMillis = utcCal.getTimeInMillis();
for (int i = dateAndLeapSecs.length - 1; i >= 0; i--) {
- if (dateAndLeapSecs[i][IndexType.DATE.index] < timeInMillis)
+ if (dateAndLeapSecs[i][IndexType.DATE.index] < timeInMillis) {
return (int) dateAndLeapSecs[i][IndexType.LEAP_SECS.index];
+ }
}
throw new CommonsException("No Leap Second found for given date!");
}
@@ -218,8 +219,9 @@ public class DateUtils {
}else {
epochDiffInMilli = epoch.getTimeInMillis() - julianEpoch.getTimeInMillis() ;
}
- if (cal.getTimeZone().getID().equals("TAI"))
+ if (cal.getTimeZone().getID().equals("TAI")) {
epochDiffInMilli += getLeapSecsForDate(epoch) * 1000;
+ }
long milliseconds = cal.getTimeInMillis();
return milliseconds - epochDiffInMilli;
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/exec/EnvUtilities.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/exec/EnvUtilities.java b/commons/src/main/java/org/apache/oodt/commons/exec/EnvUtilities.java
index 3979f32..a8a6d35 100644
--- a/commons/src/main/java/org/apache/oodt/commons/exec/EnvUtilities.java
+++ b/commons/src/main/java/org/apache/oodt/commons/exec/EnvUtilities.java
@@ -67,8 +67,9 @@ public final class EnvUtilities {
*/
public static Properties getEnv() {
Properties envProps = new Properties();
- for (Map.Entry<String, String> entry : System.getenv().entrySet())
+ for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
envProps.setProperty(entry.getKey(), entry.getValue());
+ }
return envProps;
}
@@ -103,18 +104,21 @@ public final class EnvUtilities {
+ e.getMessage());
} finally {
try {
- if (p.getErrorStream() != null)
+ if (p.getErrorStream() != null) {
p.getErrorStream().close();
+ }
} catch (Exception ignored) {
}
try {
- if (p.getInputStream() != null)
+ if (p.getInputStream() != null) {
p.getInputStream().close();
+ }
} catch (Exception ignored) {
}
try {
- if (p.getOutputStream() != null)
+ if (p.getOutputStream() != null) {
p.getOutputStream().close();
+ }
} catch (Exception ignored) {
}
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/exec/ExecHelper.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/exec/ExecHelper.java b/commons/src/main/java/org/apache/oodt/commons/exec/ExecHelper.java
index 6429cfe..5da1f94 100644
--- a/commons/src/main/java/org/apache/oodt/commons/exec/ExecHelper.java
+++ b/commons/src/main/java/org/apache/oodt/commons/exec/ExecHelper.java
@@ -294,8 +294,9 @@ public final class ExecHelper {
*/
public static ExecHelper execUsingShell(String command, String charset)
throws IOException {
- if (command == null)
- throw new NullPointerException();
+ if (command == null) {
+ throw new NullPointerException();
+ }
String[] cmdarray;
String os = System.getProperty("os.name");
if (os.equals("Windows 95") || os.equals("Windows 98")
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/exec/StreamGobbler.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/exec/StreamGobbler.java b/commons/src/main/java/org/apache/oodt/commons/exec/StreamGobbler.java
index 8ddf691..6c7d286 100644
--- a/commons/src/main/java/org/apache/oodt/commons/exec/StreamGobbler.java
+++ b/commons/src/main/java/org/apache/oodt/commons/exec/StreamGobbler.java
@@ -63,18 +63,21 @@ public class StreamGobbler extends Thread {
public void run() {
try {
PrintWriter pw = null;
- if (os != null)
+ if (os != null) {
pw = new PrintWriter(os);
+ }
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null && this.running) {
- if (pw != null)
+ if (pw != null) {
pw.println(this.type + ": " + line);
+ }
}
- if (pw != null)
+ if (pw != null) {
pw.flush();
+ }
} catch (IOException ioe) {
LOG.log(Level.FINEST, "StreamGobbler failed while gobbling : " + ioe.getMessage(), ioe);
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/filter/ObjectTimeEvent.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/filter/ObjectTimeEvent.java b/commons/src/main/java/org/apache/oodt/commons/filter/ObjectTimeEvent.java
index a2a9822..ec6413f 100644
--- a/commons/src/main/java/org/apache/oodt/commons/filter/ObjectTimeEvent.java
+++ b/commons/src/main/java/org/apache/oodt/commons/filter/ObjectTimeEvent.java
@@ -49,8 +49,9 @@ public class ObjectTimeEvent<objType> extends TimeEvent {
if (obj instanceof ObjectTimeEvent) {
ObjectTimeEvent<?> ote = (ObjectTimeEvent<?>) obj;
return super.equals(obj) && this.timeObj.equals(ote.timeObj);
- } else
+ } else {
return false;
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/filter/TimeEvent.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/filter/TimeEvent.java b/commons/src/main/java/org/apache/oodt/commons/filter/TimeEvent.java
index 3d5f372..d4a73d0 100644
--- a/commons/src/main/java/org/apache/oodt/commons/filter/TimeEvent.java
+++ b/commons/src/main/java/org/apache/oodt/commons/filter/TimeEvent.java
@@ -74,8 +74,9 @@ public class TimeEvent implements Comparable<TimeEvent> {
if (obj instanceof TimeEvent) {
TimeEvent te = (TimeEvent) obj;
return te.startTime == this.startTime && te.endTime == this.endTime;
- } else
+ } else {
return false;
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/filter/TimeEventWeightedHash.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/filter/TimeEventWeightedHash.java b/commons/src/main/java/org/apache/oodt/commons/filter/TimeEventWeightedHash.java
index 9321741..c0d33a9 100644
--- a/commons/src/main/java/org/apache/oodt/commons/filter/TimeEventWeightedHash.java
+++ b/commons/src/main/java/org/apache/oodt/commons/filter/TimeEventWeightedHash.java
@@ -63,8 +63,9 @@ public class TimeEventWeightedHash {
TimeEventWeightedHash hash = new TimeEventWeightedHash();
hash.epsilon = epsilon;
events = TimeEvent.getTimeOrderedEvents(events);
- for (TimeEvent event : events)
- hash.addEvent(event);
+ for (TimeEvent event : events) {
+ hash.addEvent(event);
+ }
return hash;
}
@@ -84,8 +85,9 @@ public class TimeEventWeightedHash {
MyLinkedHashSet<TimeEventNode> parentNodes = this.findParents(newEvent);
MyLinkedHashSet<TimeEventNode> childrenNodes = this.findChildren(newEvent, parentNodes);
- if (childrenNodes.size() == 0)
+ if (childrenNodes.size() == 0) {
leafNodes.add(newEventNode);
+ }
newEventNode.addParents(parentNodes);
newEventNode.addChildren(childrenNodes);
@@ -111,8 +113,9 @@ public class TimeEventWeightedHash {
}
}
//if all children where not possible parents, then curPPN must be parent
- if (!ppnListChanged)
+ if (!ppnListChanged) {
parentNodes.add(curPPN);
+ }
//get next curPPN
possibleParentNodes.remove(curPPN);
@@ -155,8 +158,9 @@ public class TimeEventWeightedHash {
for (TimeEventNode ten : this.leafNodes) {
if (ten.getPathWeight() > max.getPathWeight()
|| (ten.getPathWeight() == max.getPathWeight()
- && ten.getPathPriorityWeight() > max.getPathPriorityWeight()))
+ && ten.getPathPriorityWeight() > max.getPathPriorityWeight())) {
max = ten;
+ }
}
WeightedNode root = new WeightedNode(max.getTimeEvent());
TimeEventNode curTEN = max.greatestWieghtedParent;
@@ -182,8 +186,9 @@ public class TimeEventWeightedHash {
@Override
public boolean add(E ten) {
boolean wasAdded;
- if (wasAdded = super.add(ten))
+ if (wasAdded = super.add(ten)) {
listSet.add(ten);
+ }
return wasAdded;
}
@@ -191,8 +196,9 @@ public class TimeEventWeightedHash {
public boolean addAll(Collection<? extends E> collection) {
boolean setChanged = false;
for (E ten : collection) {
- if (this.add(ten))
+ if (this.add(ten)) {
setChanged = true;
+ }
}
return setChanged;
}
@@ -202,25 +208,28 @@ public class TimeEventWeightedHash {
if (super.remove(ten)) {
this.listSet.remove(ten);
return true;
- }else
+ }else {
return false;
+ }
}
@Override
public boolean removeAll(Collection<?> collection) {
boolean setChanged = false;
for (Object obj : collection) {
- if (this.remove(obj))
+ if (this.remove(obj)) {
setChanged = true;
+ }
}
return setChanged;
}
public E get(int index) {
- if (this.listSet.size() > index)
+ if (this.listSet.size() > index) {
return this.listSet.get(index);
- else
+ } else {
return null;
+ }
}
public List<E> getList() {
@@ -246,19 +255,21 @@ public class TimeEventWeightedHash {
}
public long getPathWeight() {
- if (this.greatestWieghtedParent != null)
+ if (this.greatestWieghtedParent != null) {
return te.getDuration()
- + this.greatestWieghtedParent.getPathWeight();
- else
+ + this.greatestWieghtedParent.getPathWeight();
+ } else {
return te.getDuration();
+ }
}
public double getPathPriorityWeight() {
- if (this.greatestWieghtedParent != null)
+ if (this.greatestWieghtedParent != null) {
return te.getPriority()
- + this.greatestWieghtedParent.getPathPriorityWeight();
- else
+ + this.greatestWieghtedParent.getPathPriorityWeight();
+ } else {
return te.getPriority();
+ }
}
public TimeEvent getTimeEvent() {
@@ -288,8 +299,9 @@ public class TimeEventWeightedHash {
long pPaW = parent.getPathWeight();
double gwpPiW = child.greatestWieghtedParent.getPathPriorityWeight();
double pPiW = parent.getPathPriorityWeight();
- if (pPaW > gwpPaW || (pPaW == gwpPaW && pPiW > gwpPiW))
+ if (pPaW > gwpPaW || (pPaW == gwpPaW && pPiW > gwpPiW)) {
child.greatestWieghtedParent = parent;
+ }
}
}
@@ -298,13 +310,15 @@ public class TimeEventWeightedHash {
}
public void addChildren(Collection<TimeEventNode> children) {
- for (TimeEventNode child : children)
+ for (TimeEventNode child : children) {
this.addChild(child);
+ }
}
public void addParents(Collection<TimeEventNode> parents) {
- for (TimeEventNode parent : parents)
+ for (TimeEventNode parent : parents) {
this.addParent(parent);
+ }
}
public MyLinkedHashSet<TimeEventNode> getChildren() {
@@ -319,8 +333,9 @@ public class TimeEventWeightedHash {
if (obj instanceof TimeEventNode) {
TimeEventNode ten = (TimeEventNode) obj;
return this.te.equals(ten.te);
- } else
+ } else {
return false;
+ }
}
public String toString() {
@@ -344,8 +359,9 @@ public class TimeEventWeightedHash {
private void setChild(WeightedNode child) {
this.child = child;
- if (child != null)
+ if (child != null) {
this.pathWeight = this.te.getDuration() + child.getPathWeight();
+ }
}
public TimeEvent getTimeEvent() {
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/io/Base64DecodingInputStream.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/io/Base64DecodingInputStream.java b/commons/src/main/java/org/apache/oodt/commons/io/Base64DecodingInputStream.java
index 4cd3c3d..a6c951c 100644
--- a/commons/src/main/java/org/apache/oodt/commons/io/Base64DecodingInputStream.java
+++ b/commons/src/main/java/org/apache/oodt/commons/io/Base64DecodingInputStream.java
@@ -44,7 +44,9 @@ public class Base64DecodingInputStream extends FilterInputStream {
* @throws IOException If an I/O error occurs.
*/
public int read() throws IOException {
- if (in == null) throw new IOException("Can't read from a closed stream");
+ if (in == null) {
+ throw new IOException("Can't read from a closed stream");
+ }
// If we've used up the decoded data buffer, read 4 more bytes and decode 'em.
if (buffer == null || index == buffer.length) {
@@ -56,8 +58,11 @@ public class Base64DecodingInputStream extends FilterInputStream {
while (toRead > 0) {
actuallyGot = in.read(streamBuf, atIndex, toRead);
if (actuallyGot == -1) {
- if (firstRead) return -1;
- else break;
+ if (firstRead) {
+ return -1;
+ } else {
+ break;
+ }
}
firstRead = false;
atIndex += actuallyGot;
@@ -85,23 +90,35 @@ public class Base64DecodingInputStream extends FilterInputStream {
* @throws IOException If an I/O error occurs.
*/
public int read(byte[] b, int offset, int length) throws IOException {
- if (b == null) throw new IllegalArgumentException("Can't read data into a null array");
- if (offset < 0 || offset >= b.length)
- throw new IndexOutOfBoundsException("Can't read data into an array with indexes 0.." + (b.length-1)
- + " at index " + offset);
- if (length < 0) throw new IllegalArgumentException("Can't read a negative amount of data");
- if (offset + length > b.length)
- throw new IndexOutOfBoundsException("Can't read data past the right edge of an array");
- if (in == null) throw new IOException("Can't read from a closed stream");
+ if (b == null) {
+ throw new IllegalArgumentException("Can't read data into a null array");
+ }
+ if (offset < 0 || offset >= b.length) {
+ throw new IndexOutOfBoundsException("Can't read data into an array with indexes 0.." + (b.length - 1)
+ + " at index " + offset);
+ }
+ if (length < 0) {
+ throw new IllegalArgumentException("Can't read a negative amount of data");
+ }
+ if (offset + length > b.length) {
+ throw new IndexOutOfBoundsException("Can't read data past the right edge of an array");
+ }
+ if (in == null) {
+ throw new IOException("Can't read from a closed stream");
+ }
int c = read();
- if (c == -1) return -1;
+ if (c == -1) {
+ return -1;
+ }
b[offset] = (byte) c;
int i = 1;
try {
for (; i < length; ++i) {
c = read();
- if (c == -1) break;
+ if (c == -1) {
+ break;
+ }
b[offset + i] = (byte) c;
}
} catch (IOException ignore) {}
@@ -117,10 +134,14 @@ public class Base64DecodingInputStream extends FilterInputStream {
* @throws IOException If an I/O error occurs.
*/
public long skip(long n) throws IOException {
- if (in == null) throw new IOException("Can't skip past data on a closed stream");
+ if (in == null) {
+ throw new IOException("Can't skip past data on a closed stream");
+ }
int actuallySkipped = 0;
while (n > 0) {
- if (read() == -1) return actuallySkipped;
+ if (read() == -1) {
+ return actuallySkipped;
+ }
--n;
++actuallySkipped;
}
@@ -134,9 +155,12 @@ public class Base64DecodingInputStream extends FilterInputStream {
* @throws IOException If an I/O error occurs.
*/
public int available() throws IOException {
- if (in == null) throw new IOException("Can't see how many bytes are available on a closed stream");
- if (buffer != null && index < buffer.length)
- return buffer.length - index;
+ if (in == null) {
+ throw new IOException("Can't see how many bytes are available on a closed stream");
+ }
+ if (buffer != null && index < buffer.length) {
+ return buffer.length - index;
+ }
return in.available() >= 4? 1 : 0;
}
@@ -145,7 +169,9 @@ public class Base64DecodingInputStream extends FilterInputStream {
* @throws IOException If an I/O error occurs.
*/
public void close() throws IOException {
- if (in == null) throw new IOException("Can't close a closed stream");
+ if (in == null) {
+ throw new IOException("Can't close a closed stream");
+ }
in.close();
in = null;
buffer = null;
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/io/Base64EncodingOutputStream.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/io/Base64EncodingOutputStream.java b/commons/src/main/java/org/apache/oodt/commons/io/Base64EncodingOutputStream.java
index 0841313..6b062fc 100644
--- a/commons/src/main/java/org/apache/oodt/commons/io/Base64EncodingOutputStream.java
+++ b/commons/src/main/java/org/apache/oodt/commons/io/Base64EncodingOutputStream.java
@@ -44,10 +44,13 @@ public class Base64EncodingOutputStream extends FilterOutputStream {
* @throws IOException If an I/O error occurs.
*/
public void write(int b) throws IOException {
- if (buffer == null)
- throw new IOException("Can't write onto a closed stream");
+ if (buffer == null) {
+ throw new IOException("Can't write onto a closed stream");
+ }
buffer[index++] = (byte) b;
- if (index == buffer.length) shipout();
+ if (index == buffer.length) {
+ shipout();
+ }
}
/** Write a bunch of bytes.
@@ -60,15 +63,22 @@ public class Base64EncodingOutputStream extends FilterOutputStream {
* @throws IOException If an I/O error occurs.
*/
public void write(byte[] b, int offset, int length) throws IOException {
- if (b == null) throw new IllegalArgumentException("Can't write a null array");
- if (offset < 0 || offset >= b.length)
- throw new IndexOutOfBoundsException("Can't get bytes at " + offset + " in array with indexes 0.."
- + (b.length - 1));
- if (length < 0) throw new IllegalArgumentException("Can't write a negative amount of bytes");
- if (offset + length > b.length)
- throw new IndexOutOfBoundsException("Can't get bytes beyond edge of array");
- if (buffer == null)
- throw new IOException("Can't write onto a closed stream");
+ if (b == null) {
+ throw new IllegalArgumentException("Can't write a null array");
+ }
+ if (offset < 0 || offset >= b.length) {
+ throw new IndexOutOfBoundsException("Can't get bytes at " + offset + " in array with indexes 0.."
+ + (b.length - 1));
+ }
+ if (length < 0) {
+ throw new IllegalArgumentException("Can't write a negative amount of bytes");
+ }
+ if (offset + length > b.length) {
+ throw new IndexOutOfBoundsException("Can't get bytes beyond edge of array");
+ }
+ if (buffer == null) {
+ throw new IOException("Can't write onto a closed stream");
+ }
while (length > 0) {
int avail = buffer.length - index;
int amount = avail < length? avail : length;
@@ -76,7 +86,9 @@ public class Base64EncodingOutputStream extends FilterOutputStream {
index += amount;
offset += amount;
length -= amount;
- if (index == buffer.length) shipout();
+ if (index == buffer.length) {
+ shipout();
+ }
}
}
@@ -88,8 +100,9 @@ public class Base64EncodingOutputStream extends FilterOutputStream {
* @throws IOException If an I/O error occurs.
*/
public void flush() throws IOException {
- if (buffer == null)
- throw new IOException("Can't flush a closed stream");
+ if (buffer == null) {
+ throw new IOException("Can't flush a closed stream");
+ }
shipout();
out.flush();
}
@@ -102,8 +115,9 @@ public class Base64EncodingOutputStream extends FilterOutputStream {
* @throws IOException If an I/O error occurs.
*/
public void close() throws IOException {
- if (buffer == null)
- throw new IOException("Can't close an already closed stream");
+ if (buffer == null) {
+ throw new IOException("Can't close an already closed stream");
+ }
flush();
out.close();
out = null;
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/io/FixedBufferOutputStream.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/io/FixedBufferOutputStream.java b/commons/src/main/java/org/apache/oodt/commons/io/FixedBufferOutputStream.java
index 4c6217e..ba311e2 100644
--- a/commons/src/main/java/org/apache/oodt/commons/io/FixedBufferOutputStream.java
+++ b/commons/src/main/java/org/apache/oodt/commons/io/FixedBufferOutputStream.java
@@ -31,7 +31,9 @@ public class FixedBufferOutputStream extends OutputStream {
* @param n Size of the buffer.
*/
public FixedBufferOutputStream(int n) {
- if (n < 0) throw new IllegalArgumentException("Buffer size must be nonnegative");
+ if (n < 0) {
+ throw new IllegalArgumentException("Buffer size must be nonnegative");
+ }
buffer = new byte[n];
length = n;
size = 0;
@@ -40,10 +42,12 @@ public class FixedBufferOutputStream extends OutputStream {
public void write(int b) throws IOException {
checkIfClosed();
- if (length == 0) return;
- if (size < length)
- buffer[size++] = (byte) b;
- else {
+ if (length == 0) {
+ return;
+ }
+ if (size < length) {
+ buffer[size++] = (byte) b;
+ } else {
buffer[start] = (byte) b;
start = (start + 1) % length;
}
@@ -51,8 +55,9 @@ public class FixedBufferOutputStream extends OutputStream {
public void write(byte[] a, int off, int len) throws IOException {
checkIfClosed();
- if (a == null) throw new NullPointerException("Can't write from a null array");
- else if ((off < 0) || (off > a.length) || (len < 0) || ((off + len) > a.length) || ((off + len) < 0)) {
+ if (a == null) {
+ throw new NullPointerException("Can't write from a null array");
+ } else if ((off < 0) || (off > a.length) || (len < 0) || ((off + len) > a.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException("Offset " + off + " and length " + len + " not within array bounds");
} else if (len == 0) {
return;
@@ -69,8 +74,9 @@ public class FixedBufferOutputStream extends OutputStream {
if (remaining > 0) {
System.arraycopy(a, off + insertionLength, buffer, 0, remaining);
start = remaining;
- } else if (capacity == 0)
- start = insertionIndex + insertionLength;
+ } else if (capacity == 0) {
+ start = insertionIndex + insertionLength;
+ }
size = Math.min(length, size + len);
}
@@ -102,7 +108,9 @@ public class FixedBufferOutputStream extends OutputStream {
* @throws IOException If this stream has been closed.
*/
private void checkIfClosed() throws IOException {
- if (start == -1) throw new IOException("Can't write to closed stream");
+ if (start == -1) {
+ throw new IOException("Can't write to closed stream");
+ }
}
/** Length of the buffer. */
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/io/Log.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/io/Log.java b/commons/src/main/java/org/apache/oodt/commons/io/Log.java
index cb4ee3b..2aa711c 100644
--- a/commons/src/main/java/org/apache/oodt/commons/io/Log.java
+++ b/commons/src/main/java/org/apache/oodt/commons/io/Log.java
@@ -108,10 +108,11 @@ public class Log {
* @return A writer with which you can log messages.
*/
public static LogWriter get() {
- if (lastWriter != null && !lastWriter.isFlushed())
- return lastWriter;
- else
- return get(new Date(), getDefaultSource(), getDefaultCategory());
+ if (lastWriter != null && !lastWriter.isFlushed()) {
+ return lastWriter;
+ } else {
+ return get(new Date(), getDefaultSource(), getDefaultCategory());
+ }
}
/** Get a writer to log messages.
@@ -154,8 +155,9 @@ public class Log {
LogEvent event = null;
for (Enumeration e = listeners.elements(); e.hasMoreElements();) {
// Lazily create the event.
- if (event == null)
- event = new LogEvent(stream, timestamp, source);
+ if (event == null) {
+ event = new LogEvent(stream, timestamp, source);
+ }
((LogListener) e.nextElement()).streamStarted(event);
}
}
@@ -170,8 +172,9 @@ public class Log {
LogEvent event = null;
for (Enumeration e = listeners.elements(); e.hasMoreElements();) {
// Lazily create the event.
- if (event == null)
- event = new LogEvent(stream);
+ if (event == null) {
+ event = new LogEvent(stream);
+ }
((LogListener) e.nextElement()).streamStopped(event);
}
}
@@ -190,8 +193,9 @@ public class Log {
LogEvent event = null;
for (Enumeration e = listeners.elements(); e.hasMoreElements();) {
// Lazily create the event.
- if (event == null)
- event = new LogEvent(timestamp, source, category, message);
+ if (event == null) {
+ event = new LogEvent(timestamp, source, category, message);
+ }
((LogListener) e.nextElement()).messageLogged(event);
}
}
@@ -203,8 +207,9 @@ public class Log {
* @param source The new default source label.
*/
public static void setDefaultSource(String source) {
- if (source == null)
- throw new IllegalArgumentException("Can't set a null default source");
+ if (source == null) {
+ throw new IllegalArgumentException("Can't set a null default source");
+ }
defaultSource = source;
}
@@ -223,8 +228,9 @@ public class Log {
* @param category The new default category object.
*/
public static void setDefaultCategory(Object category) {
- if (category == null)
- throw new IllegalArgumentException("Can't set a null default category");
+ if (category == null) {
+ throw new IllegalArgumentException("Can't set a null default category");
+ }
defaultCategory = category;
}
@@ -244,8 +250,9 @@ public class Log {
* @param listener The listener to add.
*/
public static void addLogListener(LogListener listener) {
- if (listener == null)
- throw new IllegalArgumentException("Can't add a null log listener");
+ if (listener == null) {
+ throw new IllegalArgumentException("Can't add a null log listener");
+ }
listeners.addElement(listener);
}
@@ -256,8 +263,9 @@ public class Log {
* @param listener The listener to remove.
*/
public static void removeLogListener(LogListener listener) {
- if (listener == null)
- throw new IllegalArgumentException("Can't remove a null log listener");
+ if (listener == null) {
+ throw new IllegalArgumentException("Can't remove a null log listener");
+ }
listeners.removeElement(listener);
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/io/LogFilter.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/io/LogFilter.java b/commons/src/main/java/org/apache/oodt/commons/io/LogFilter.java
index 9e5d085..0eb17e7 100644
--- a/commons/src/main/java/org/apache/oodt/commons/io/LogFilter.java
+++ b/commons/src/main/java/org/apache/oodt/commons/io/LogFilter.java
@@ -50,11 +50,14 @@ public class LogFilter implements LogListener {
* is false).
*/
public LogFilter(LogListener listener, boolean passThrough, Object[] categories) {
- if (listener == null)
- throw new IllegalArgumentException("Can't filter messages to a null listener");
+ if (listener == null) {
+ throw new IllegalArgumentException("Can't filter messages to a null listener");
+ }
this.listener = listener;
this.passThrough = passThrough;
- if (categories == null) return;
+ if (categories == null) {
+ return;
+ }
for (Object category : categories) {
this.categories.put(category, DUMMY);
}
@@ -116,8 +119,9 @@ public class LogFilter implements LogListener {
*/
public void messageLogged(LogEvent event) {
boolean found = categories.containsKey(event.getCategory());
- if ((passThrough && !found) || (!passThrough && found))
- listener.messageLogged(event);
+ if ((passThrough && !found) || (!passThrough && found)) {
+ listener.messageLogged(event);
+ }
}
/** Ignore this event.
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/io/LogWriter.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/io/LogWriter.java b/commons/src/main/java/org/apache/oodt/commons/io/LogWriter.java
index 6dc1439..d6d89ee 100644
--- a/commons/src/main/java/org/apache/oodt/commons/io/LogWriter.java
+++ b/commons/src/main/java/org/apache/oodt/commons/io/LogWriter.java
@@ -58,7 +58,9 @@ public class LogWriter extends java.io.Writer {
* @param c The character to write.
*/
public void write(int c) {
- if (buf == null) return;
+ if (buf == null) {
+ return;
+ }
buf.append((char) c);
}
@@ -71,10 +73,13 @@ public class LogWriter extends java.io.Writer {
* @param length How many characters to write.
*/
public void write(char[] array, int offset, int length) {
- if (buf == null || length == 0) return;
- if (offset < 0 || offset > array.length || length < 0 || (offset+length) > array.length || (offset+length) < 0)
- throw new IndexOutOfBoundsException("Can't write " + length + " characters at " + offset
- + " from array whose length is " + array.length);
+ if (buf == null || length == 0) {
+ return;
+ }
+ if (offset < 0 || offset > array.length || length < 0 || (offset+length) > array.length || (offset+length) < 0) {
+ throw new IndexOutOfBoundsException("Can't write " + length + " characters at " + offset
+ + " from array whose length is " + array.length);
+ }
buf.append(array, offset, length);
}
@@ -98,7 +103,9 @@ public class LogWriter extends java.io.Writer {
* @param length How many characters to write.
*/
public void write(String string, int offset, int length) {
- if (buf == null || length == 0) return;
+ if (buf == null || length == 0) {
+ return;
+ }
buf.append(string.substring(offset, offset + length));
}
@@ -117,7 +124,9 @@ public class LogWriter extends java.io.Writer {
* This sends any text sent to the writer on its way to the logging facility, and beyond.
*/
public void flush() {
- if (buf == null) return;
+ if (buf == null) {
+ return;
+ }
Log.logMessage(timestamp, source, category, buf.toString());
buf.setLength(0);
flushed = true;
@@ -203,7 +212,9 @@ public class LogWriter extends java.io.Writer {
* @param s The <code>String</code> to print.
*/
public void print(String s) {
- if (s == null) s = "null";
+ if (s == null) {
+ s = "null";
+ }
write(s);
}
@@ -312,9 +323,9 @@ public class LogWriter extends java.io.Writer {
}
public void println(Throwable t) {
- if (t == null)
- println("Null throwable");
- else {
+ if (t == null) {
+ println("Null throwable");
+ } else {
StackTraceElement[] frames = t.getStackTrace();
println(t.getClass().getName() + ":");
for (StackTraceElement frame : frames) {
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/io/NullInputStream.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/io/NullInputStream.java b/commons/src/main/java/org/apache/oodt/commons/io/NullInputStream.java
index dae6dab..9cd61a9 100644
--- a/commons/src/main/java/org/apache/oodt/commons/io/NullInputStream.java
+++ b/commons/src/main/java/org/apache/oodt/commons/io/NullInputStream.java
@@ -54,7 +54,9 @@ public final class NullInputStream extends InputStream {
* @throws IOException If we're not open.
*/
private void checkOpen() throws IOException {
- if (!open) throw new IOException("Stream closed");
+ if (!open) {
+ throw new IOException("Stream closed");
+ }
}
/** Is the stream open? */
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/io/NullOutputStream.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/io/NullOutputStream.java b/commons/src/main/java/org/apache/oodt/commons/io/NullOutputStream.java
index d7a332d..0ae65ec 100644
--- a/commons/src/main/java/org/apache/oodt/commons/io/NullOutputStream.java
+++ b/commons/src/main/java/org/apache/oodt/commons/io/NullOutputStream.java
@@ -47,12 +47,13 @@ public class NullOutputStream extends OutputStream {
* @throws IOException If the stream is closed.
*/
public void write(byte[] a, int offset, int length) throws IOException {
- if (a == null)
- throw new NullPointerException("Can't write a null array");
- else if ((offset < 0) || (offset > a.length) || (length < 0) || ((offset + length) > a.length)
- || ((offset + length) < 0))
- throw new IndexOutOfBoundsException("Offset " + offset + " and length " + length
- + " not in array of length " + a.length);
+ if (a == null) {
+ throw new NullPointerException("Can't write a null array");
+ } else if ((offset < 0) || (offset > a.length) || (length < 0) || ((offset + length) > a.length)
+ || ((offset + length) < 0)) {
+ throw new IndexOutOfBoundsException("Offset " + offset + " and length " + length
+ + " not in array of length " + a.length);
+ }
checkOpen();
}
@@ -78,7 +79,9 @@ public class NullOutputStream extends OutputStream {
* @throws IOException If we're not open.
*/
private void checkOpen() throws IOException {
- if (!open) throw new IOException("Stream closed");
+ if (!open) {
+ throw new IOException("Stream closed");
+ }
}
/** Is the output stream open? */
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/io/WriterLogger.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/io/WriterLogger.java b/commons/src/main/java/org/apache/oodt/commons/io/WriterLogger.java
index 1ce6f6f..4ce802c 100644
--- a/commons/src/main/java/org/apache/oodt/commons/io/WriterLogger.java
+++ b/commons/src/main/java/org/apache/oodt/commons/io/WriterLogger.java
@@ -68,8 +68,9 @@ public class WriterLogger implements LogListener {
* logged. If false, don't call flush.
*/
public WriterLogger(Writer writer, boolean autoFlush) {
- if (writer == null)
- throw new IllegalArgumentException("Can't write to a null writer");
+ if (writer == null) {
+ throw new IllegalArgumentException("Can't write to a null writer");
+ }
this.writer = writer;
this.autoFlush = autoFlush;
this.lineSep = System.getProperty("line.separator", "\n");
@@ -81,7 +82,9 @@ public class WriterLogger implements LogListener {
* are ignored and not written.
*/
public final void close() {
- if (writer == null) return;
+ if (writer == null) {
+ return;
+ }
try {
writer.close();
} catch (IOException ignore) {}
@@ -96,11 +99,15 @@ public class WriterLogger implements LogListener {
* @param event The event describing the message that was logged.
*/
public final void messageLogged(LogEvent event) {
- if (writer == null) return;
+ if (writer == null) {
+ return;
+ }
try {
writer.write(formatMessage(event.getTimestamp(), (String) event.getSource(), event.getCategory(),
event.getMessage()) + lineSep);
- if (autoFlush) writer.flush();
+ if (autoFlush) {
+ writer.flush();
+ }
} catch (IOException ignore) {}
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/object/jndi/HTTPContext.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/object/jndi/HTTPContext.java b/commons/src/main/java/org/apache/oodt/commons/object/jndi/HTTPContext.java
index d164f99..b4a5cad 100644
--- a/commons/src/main/java/org/apache/oodt/commons/object/jndi/HTTPContext.java
+++ b/commons/src/main/java/org/apache/oodt/commons/object/jndi/HTTPContext.java
@@ -42,8 +42,9 @@ public class HTTPContext implements Context {
* @param environment Its environment, currently unused.
*/
public HTTPContext(Hashtable environment) {
- if (environment == null)
- throw new IllegalArgumentException("Nonnull environment required; don't know why, but it is");
+ if (environment == null) {
+ throw new IllegalArgumentException("Nonnull environment required; don't know why, but it is");
+ }
this.environment = (Hashtable) environment.clone();
}
@@ -97,8 +98,9 @@ public class HTTPContext implements Context {
}
public NamingEnumeration list(String name) throws NamingException {
- if (name.length() > 0)
- throw new NotContextException("Subcontexts not supported");
+ if (name.length() > 0) {
+ throw new NotContextException("Subcontexts not supported");
+ }
return new NamingEnumeration() {
public void close() {}
@@ -122,8 +124,9 @@ public class HTTPContext implements Context {
}
public NamingEnumeration listBindings(String name) throws NamingException {
- if (name.length() > 0)
- throw new NotContextException("Subcontexts not supported");
+ if (name.length() > 0) {
+ throw new NotContextException("Subcontexts not supported");
+ }
return new NamingEnumeration() {
public void close() {}
public boolean hasMore() {
@@ -189,17 +192,23 @@ public class HTTPContext implements Context {
}
public Object addToEnvironment(String propName, Object propVal) throws NamingException {
- if (environment == null) environment = new Hashtable();
+ if (environment == null) {
+ environment = new Hashtable();
+ }
return environment.put(propName, propVal);
}
public Object removeFromEnvironment(String propName) throws NamingException {
- if (environment == null) return null;
+ if (environment == null) {
+ return null;
+ }
return environment.remove(propName);
}
public Hashtable getEnvironment() throws NamingException {
- if (environment == null) return new Hashtable();
+ if (environment == null) {
+ return new Hashtable();
+ }
return (Hashtable) environment.clone();
}
@@ -218,12 +227,15 @@ public class HTTPContext implements Context {
* @throws InvalidNameException If <var>name</var>'s not an RMI object context name.
*/
protected void checkName(String name) throws InvalidNameException {
- if (name == null)
- throw new IllegalArgumentException("Can't check a null name");
- if (name.length() == 0)
- throw new InvalidNameException("Name's length is zero");
- if (name.startsWith("http:") || name.startsWith("https:"))
- return;
+ if (name == null) {
+ throw new IllegalArgumentException("Can't check a null name");
+ }
+ if (name.length() == 0) {
+ throw new InvalidNameException("Name's length is zero");
+ }
+ if (name.startsWith("http:") || name.startsWith("https:")) {
+ return;
+ }
throw new InvalidNameException("Not an HTTP name; try http://some.host/some-context/...");
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/abd71645/commons/src/main/java/org/apache/oodt/commons/object/jndi/ObjectContext.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/object/jndi/ObjectContext.java b/commons/src/main/java/org/apache/oodt/commons/object/jndi/ObjectContext.java
index 9785694..a1518bf 100644
--- a/commons/src/main/java/org/apache/oodt/commons/object/jndi/ObjectContext.java
+++ b/commons/src/main/java/org/apache/oodt/commons/object/jndi/ObjectContext.java
@@ -63,12 +63,14 @@ class ObjectContext implements Context {
} catch (Throwable ignored) {}
String registryList = (String) (environment != null ? environment.get("rmiregistries") : null);
- if (registryList != null) for (Iterator i = Utility.parseCommaList(registryList); i.hasNext();) {
+ if (registryList != null) {
+ for (Iterator i = Utility.parseCommaList(registryList); i.hasNext(); ) {
Hashtable rmiEnv = (Hashtable) this.environment.clone();
URI uri = URI.create((String) i.next());
rmiEnv.put("host", uri.getHost());
rmiEnv.put("port", uri.getPort());
contexts.add(new RMIContext(rmiEnv));
+ }
}
Hashtable httpEnv = (Hashtable) this.environment.clone();
@@ -76,17 +78,19 @@ class ObjectContext implements Context {
String className = null;
for (Iterator i = org.apache.oodt.commons.util.Utility.parseCommaList(System.getProperty("org.apache.oodt.commons.object.contexts", ""));
- i.hasNext();) try {
+ i.hasNext();) {
+ try {
className = (String) i.next();
Class clazz = Class.forName(className);
contexts.add(clazz.newInstance());
- } catch (ClassNotFoundException ex) {
+ } catch (ClassNotFoundException ex) {
System.err.println("Ignoring not-found context class `" + className + "': " + ex.getMessage());
- } catch (InstantiationException ex) {
+ } catch (InstantiationException ex) {
System.err.println("Ignoring non-instantiable context class `" + className + "': " + ex.getMessage());
- } catch (IllegalAccessException ex) {
+ } catch (IllegalAccessException ex) {
System.err.println("Ignoring context class `" + className + "' with non-accessible no-args c'tor: "
- + ex.getMessage());
+ + ex.getMessage());
+ }
}
installAliases();
@@ -116,12 +120,18 @@ class ObjectContext implements Context {
* @throws NamingException if an error occurs.
*/
public Object lookup(String name) throws NamingException {
- if (name == null) throw new IllegalArgumentException("Name required");
- if (name.length() == 0) return this;
+ if (name == null) {
+ throw new IllegalArgumentException("Name required");
+ }
+ if (name.length() == 0) {
+ return this;
+ }
// Let alias redirection do its magic
String alias = aliases.getProperty(name);
- if (alias != null) name = alias;
+ if (alias != null) {
+ name = alias;
+ }
for (Object context : contexts) {
Context c = (Context) context;
@@ -140,18 +150,24 @@ class ObjectContext implements Context {
}
public synchronized void bind(String name, Object obj) throws NamingException {
- if (name == null) throw new IllegalArgumentException("Name required");
- if (name.length() == 0) throw new InvalidNameException("Cannot bind object named after context");
+ if (name == null) {
+ throw new IllegalArgumentException("Name required");
+ }
+ if (name.length() == 0) {
+ throw new InvalidNameException("Cannot bind object named after context");
+ }
// If it's an alias name, stop here.
- if (aliases.containsKey(name))
- throw new NameAlreadyBoundException("Name \"" + name + "\" already bound as an aliased name");
+ if (aliases.containsKey(name)) {
+ throw new NameAlreadyBoundException("Name \"" + name + "\" already bound as an aliased name");
+ }
// Make sure it isn't bound anywhere
for (NamingEnumeration e = list(""); e.hasMore();) {
NameClassPair nameClassPair = (NameClassPair) e.next();
- if (name.equals(nameClassPair.getName()))
- throw new NameAlreadyBoundException("Name \"" + name + "\" already bound by a managed subcontext");
+ if (name.equals(nameClassPair.getName())) {
+ throw new NameAlreadyBoundException("Name \"" + name + "\" already bound by a managed subcontext");
+ }
}
doRebind(name, obj);
}
@@ -162,12 +178,17 @@ class ObjectContext implements Context {
/** {@inheritDoc} */
public synchronized void rebind(String name, Object obj) throws NamingException {
- if (name == null) throw new IllegalArgumentException("Name required");
- if (name.length() == 0) throw new InvalidNameException("Cannot rebind object named after context");
+ if (name == null) {
+ throw new IllegalArgumentException("Name required");
+ }
+ if (name.length() == 0) {
+ throw new InvalidNameException("Cannot rebind object named after context");
+ }
// If it's an alias name, remove the alias
- if (aliases.containsKey(name))
- aliases.remove(name);
+ if (aliases.containsKey(name)) {
+ aliases.remove(name);
+ }
doRebind(name, obj);
}
@@ -189,7 +210,9 @@ class ObjectContext implements Context {
} catch (NamingException ignored) {
}
}
- if (!bound) throw new InvalidNameException("Name \"" + name + "\" not compatible with any managed subcontext");
+ if (!bound) {
+ throw new InvalidNameException("Name \"" + name + "\" not compatible with any managed subcontext");
+ }
}
public void rebind(Name name, Object obj) throws NamingException {
@@ -197,8 +220,12 @@ class ObjectContext implements Context {
}
public void unbind(String name) throws NamingException {
- if (name == null) throw new IllegalArgumentException("Name required");
- if (name.length() == 0) throw new InvalidNameException("Cannot unbind object named after context");
+ if (name == null) {
+ throw new IllegalArgumentException("Name required");
+ }
+ if (name.length() == 0) {
+ throw new InvalidNameException("Cannot unbind object named after context");
+ }
// See if it's an aliased name
if (aliases.containsKey(name)) {
@@ -215,7 +242,9 @@ class ObjectContext implements Context {
} catch (NamingException ignore) {
}
}
- if (!unbound) throw new InvalidNameException("Name \"" + name + "\" not compatible with any managed subcontext");
+ if (!unbound) {
+ throw new InvalidNameException("Name \"" + name + "\" not compatible with any managed subcontext");
+ }
}
public void unbind(Name name) throws NamingException {
@@ -223,10 +252,12 @@ class ObjectContext implements Context {
}
public void rename(String oldName, String newName) throws NamingException {
- if (oldName == null || newName == null)
- throw new IllegalArgumentException("Name required");
- if (oldName.length() == 0 || newName.length() == 0)
- throw new InvalidNameException("Cannot rename object named after context");
+ if (oldName == null || newName == null) {
+ throw new IllegalArgumentException("Name required");
+ }
+ if (oldName.length() == 0 || newName.length() == 0) {
+ throw new InvalidNameException("Cannot rename object named after context");
+ }
// See if it's an aliased name
String oldValue = (String) aliases.remove(oldName);
@@ -244,7 +275,9 @@ class ObjectContext implements Context {
} catch (NamingException ignore) {
}
}
- if (!renamed) throw new InvalidNameException("Names not compatible with any managed subcontext");
+ if (!renamed) {
+ throw new InvalidNameException("Names not compatible with any managed subcontext");
+ }
}
public void rename(Name oldName, Name newName) throws NamingException {
@@ -258,13 +291,16 @@ class ObjectContext implements Context {
= eachContext.hasNext()? ((Context) eachContext.next()).list(name) : null;
private boolean open = true;
public Object next() throws NamingException {
- if (!open) throw new NamingException("closed");
- if (enumeration != null && enumeration.hasMore())
- return enumeration.next();
- else if (eachContext.hasNext()) {
+ if (!open) {
+ throw new NamingException("closed");
+ }
+ if (enumeration != null && enumeration.hasMore()) {
+ return enumeration.next();
+ } else if (eachContext.hasNext()) {
enumeration = ((Context) eachContext.next()).list(name);
- if (enumeration.hasMore())
- return enumeration.next();
+ if (enumeration.hasMore()) {
+ return enumeration.next();
+ }
}
throw new NoSuchElementException("No more objects in context");
}
@@ -276,12 +312,14 @@ class ObjectContext implements Context {
return rc;
}
public boolean hasMore() throws NamingException {
- if (!open) return false;
- if (enumeration == null)
- return false;
- else if (enumeration.hasMore())
- return true;
- else if (eachContext.hasNext()) {
+ if (!open) {
+ return false;
+ }
+ if (enumeration == null) {
+ return false;
+ } else if (enumeration.hasMore()) {
+ return true;
+ } else if (eachContext.hasNext()) {
enumeration = ((Context) eachContext.next()).list(name);
return hasMore();
}
@@ -296,8 +334,9 @@ class ObjectContext implements Context {
}
public void close() throws NamingException {
open = false;
- if (enumeration != null)
- enumeration.close();
+ if (enumeration != null) {
+ enumeration.close();
+ }
}
};
}
@@ -313,13 +352,16 @@ class ObjectContext implements Context {
= eachContext.hasNext()? ((Context) eachContext.next()).listBindings(name) : null;
private boolean open = true;
public Object next() throws NamingException {
- if (!open) throw new NamingException("closed");
- if (enumeration != null && enumeration.hasMore())
- return enumeration.next();
- else if (eachContext.hasNext()) {
+ if (!open) {
+ throw new NamingException("closed");
+ }
+ if (enumeration != null && enumeration.hasMore()) {
+ return enumeration.next();
+ } else if (eachContext.hasNext()) {
enumeration = ((Context) eachContext.next()).listBindings(name);
- if (enumeration.hasMore())
- return enumeration.next();
+ if (enumeration.hasMore()) {
+ return enumeration.next();
+ }
}
throw new NoSuchElementException("No more objects in context");
}
@@ -331,12 +373,14 @@ class ObjectContext implements Context {
return rc;
}
public boolean hasMore() throws NamingException {
- if (!open) return false;
- if (enumeration == null)
- return false;
- else if (enumeration.hasMore())
- return true;
- else if (eachContext.hasNext()) {
+ if (!open) {
+ return false;
+ }
+ if (enumeration == null) {
+ return false;
+ } else if (enumeration.hasMore()) {
+ return true;
+ } else if (eachContext.hasNext()) {
enumeration = ((Context) eachContext.next()).listBindings(name);
return hasMore();
}
@@ -351,8 +395,9 @@ class ObjectContext implements Context {
}
public void close() throws NamingException {
open = false;
- if (enumeration != null)
- enumeration.close();
+ if (enumeration != null) {
+ enumeration.close();
+ }
}
};
}
@@ -405,17 +450,23 @@ class ObjectContext implements Context {
}
public Object addToEnvironment(String propName, Object propVal) throws NamingException {
- if (environment == null) environment = new Hashtable();
+ if (environment == null) {
+ environment = new Hashtable();
+ }
return environment.put(propName, propVal);
}
public Object removeFromEnvironment(String propName) throws NamingException {
- if (environment == null) return null;
+ if (environment == null) {
+ return null;
+ }
return environment.remove(propName);
}
public Hashtable getEnvironment() throws NamingException {
- if (environment == null) return new Hashtable();
+ if (environment == null) {
+ return new Hashtable();
+ }
return (Hashtable) environment.clone();
}
@@ -444,9 +495,12 @@ class ObjectContext implements Context {
throw new IllegalStateException("Cannot handle I/O exception reading alias file " + aliasFileName
+ ": " + ex.getMessage());
} finally {
- if (in != null) try {
+ if (in != null) {
+ try {
in.close();
- } catch (IOException ignore) {}
+ } catch (IOException ignore) {
+ }
+ }
}
}
}