Author: deepal
Date: Tue Feb 5 02:08:48 2008
New Revision: 13262
Log:
making the necessary changes after running the findbug tool
Modified:
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/ResourceImporter.java
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/utils/RegistryClientUtils.java
Modified:
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/ResourceImporter.java
==============================================================================
---
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/ResourceImporter.java
(original)
+++
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/ResourceImporter.java
Tue Feb 5 02:08:48 2008
@@ -25,6 +25,7 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
@@ -100,9 +101,9 @@
}
private void putFile(String rootPath, File file, String toPath) throws
RegistryException {
-
+ FileInputStream fileStream = null;
try {
- FileInputStream fileStream = new FileInputStream(file);
+ fileStream = new FileInputStream(file);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
int b;
while ((b = fileStream.read()) != -1) {
@@ -120,6 +121,15 @@
String msg = "Could not read from the file " + file.getPath();
log.error(msg, e);
throw new RegistryException(msg);
+ } finally{
+ if (fileStream !=null){
+ try {
+ fileStream.close();
+ } catch (IOException e) {
+ log.info("Error while closing the file: " +
file.getName());
+ }
+
+ }
}
}
Modified:
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
---
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
(original)
+++
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
Tue Feb 5 02:08:48 2008
@@ -381,7 +381,9 @@
if (conn != null) {
try {
conn.close();
- } catch (SQLException ignore) {}
+ } catch (SQLException ignore) {
+
log.info(Messages.getMessage("exception.closing.db"));
+ }
}
}
}
@@ -829,11 +831,8 @@
resourcePath = getCurrentPath(resourcePath);
Connection conn = getConnection();
-
- Comment[] comments = new Comment[0];
-
try {
- comments = commentsDAO.getComments(resourcePath, conn);
+ return commentsDAO.getComments(resourcePath, conn);
} catch (SQLException e) {
String msg = Messages.getMessage("get.comments.fail",
resourcePath);
@@ -844,11 +843,9 @@
try {
conn.close();
} catch (SQLException e) {
- e.printStackTrace();
+ log.info(Messages.getMessage("exception.closing.db"));
}
}
-
- return comments;
}
////////////////////////////////////////////////////////
Modified:
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
==============================================================================
---
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
(original)
+++
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
Tue Feb 5 02:08:48 2008
@@ -150,7 +150,7 @@
ResultSet results = s.executeQuery();
while (results.next()) {
long commentID =
results.getLong(DatabaseConstants.COMMENT_ID_FIELD);
- commentIDList.add(new Long(commentID));
+ commentIDList.add(Long.valueOf(commentID));
}
long[] commentIDs = new long[commentIDList.size()];
Modified:
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java
==============================================================================
---
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java
(original)
+++
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java
Tue Feb 5 02:08:48 2008
@@ -31,13 +31,9 @@
public class QueryProcessorManager {
- private DataSource dataSource;
private Map queryProcessors = new HashMap();
public QueryProcessorManager(DataSource dataSource, Realm realm) throws
RegistryException {
-
- this.dataSource = dataSource;
-
queryProcessors.put(
RegistryConstants.SQL_QUERY_MEDIA_TYPE, new
SQLQueryProcessor(dataSource, realm));
Modified:
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
==============================================================================
---
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
(original)
+++
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
Tue Feb 5 02:08:48 2008
@@ -90,7 +90,9 @@
if (conn != null) {
try {
conn.close();
- } catch (SQLException ignore) {}
+ } catch (SQLException ignore) {
+ log.info("Error while closing the DB connection");
+ }
}
}
}
Modified:
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/utils/RegistryClientUtils.java
==============================================================================
---
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/utils/RegistryClientUtils.java
(original)
+++
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/utils/RegistryClientUtils.java
Tue Feb 5 02:08:48 2008
@@ -22,6 +22,8 @@
import org.wso2.registry.RegistryException;
import org.wso2.registry.Resource;
import org.wso2.registry.i18n.Messages;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.FileInputStream;
@@ -35,6 +37,8 @@
*/
public class RegistryClientUtils {
+ private static final Log log =
LogFactory.getLog(RegistryClientUtils.class);
+
/**
* This method can be used to import a local file system into a running
instance of a registry.
* Need to create a file object representing the local file and the need
to tell where to add
@@ -107,19 +111,27 @@
if (resource != null) {
if (resource.isDirectory()) {
File file = new File(toFile, resource.getPath());
- file.mkdirs();
- String childNodes[] = (String[])resource.getContent();
- for (String childNode : childNodes) {
- processExport(childNode, toFile, registry);
+ boolean fileFlag = file.mkdirs();
+ if (!fileFlag) {
+ log.info("Unable to create the directory " +
resource.getPath());
+ } else {
+ String childNodes[] = (String[])resource.getContent();
+ for (String childNode : childNodes) {
+ processExport(childNode, toFile, registry);
+ }
}
} else {
File file = new File(toFile, resource.getPath());
try {
- file.createNewFile();
- FileOutputStream out = new FileOutputStream(file);
- out.write((byte[])resource.getContent());
- out.flush();
- out.close();
+ boolean fileFlag = file.createNewFile();
+ if (!fileFlag) {
+ log.info("Unable to create the file " +
resource.getPath());
+ } else {
+ FileOutputStream out = new FileOutputStream(file);
+ out.write((byte[])resource.getContent());
+ out.flush();
+ out.close();
+ }
} catch (IOException e) {
throw new RegistryException(Messages.getMessage(
"error.creating.file", resource.getPath()));
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev