Skip to content
Permalink
Browse files
JSIEVE-92 Code analisys improvements
git-svn-id: https://svn.apache.org/repos/asf/james/jsieve/trunk@1425888 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ieugen committed Dec 26, 2012
1 parent 0ec0466 commit a69ca25bbad90f5f50f63fe45562f1d16f9641cb
Showing 52 changed files with 292 additions and 481 deletions.
@@ -79,7 +79,7 @@ public List<Argument> getArgumentList() {
* @return TestList
*/
public TestList getTestList() {
TestList testList = null;
TestList testList;
if (null == (testList = getTestListBasic())) {
updateTestList();
return getTestList();
@@ -155,8 +155,6 @@ public Object execute(MailAdapter mail, SieveContext context)
// so need to use the coordinate recorded from the parse
context.setCoordinate(coordinate);
final ExecutableCommand executable = context.getCommandManager().getCommand(getName());
final Object result = executable.execute(mail, getArguments(),
getBlock(), context);
return result;
return executable.execute(mail, getArguments(),getBlock(), context);
}
}
@@ -63,7 +63,7 @@ public CommandManagerImpl(final ConcurrentMap<String, String> classNameMap) {
* @throws LookupException
*/
private Class lookup(String name) throws LookupException {
Class cmdClass = null;
Class cmdClass;
try {
cmdClass = getClass().getClassLoader()
.loadClass(getClassName(name));
@@ -19,18 +19,17 @@

package org.apache.jsieve;

import java.util.List;

import org.apache.jsieve.exception.SieveException;
import org.apache.jsieve.mail.MailAdapter;

import java.util.List;

/**
* <p>
* A parsed representation of the RFC3028 BNF...
* </p>
*
* <p/>
* <code>commands = *command</code>
*
*/
public class Commands implements Executable {
/**
@@ -47,7 +46,7 @@ private Commands() {

/**
* Constructor for Commands.
*
*
* @param commands
*/
public Commands(List<Command> commands) {
@@ -57,7 +56,7 @@ public Commands(List<Command> commands) {

/**
* Returns the commands.
*
*
* @return List
*/
public List<Command> getChildren() {
@@ -66,9 +65,8 @@ public List<Command> getChildren() {

/**
* Sets the commands.
*
* @param commands
* The commands to set
*
* @param commands The commands to set
*/
protected void setChildren(List<Command> commands) {
fieldChildren = commands;
@@ -79,9 +77,9 @@ protected void setChildren(List<Command> commands) {
*/
public Object execute(MailAdapter mail, SieveContext context)
throws SieveException {
for (Command command:fieldChildren) {
for (Command command : fieldChildren) {
command.execute(mail, context);
};
}
return null;
}

@@ -99,7 +99,7 @@ public boolean isImplicitlyDeclared(final String comparatorName) {
* @throws LookupException
*/
public Class lookup(String name) throws LookupException {
Class comparatorClass = null;
Class comparatorClass;
try {
comparatorClass = getClass().getClassLoader().loadClass(
getClassName(name));
@@ -19,17 +19,17 @@

package org.apache.jsieve;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.SAXException;

/**
* <p>
* <code>ConfigurationManager</code> parses the XML statements
@@ -50,10 +50,10 @@
* Each configuration manager instance may be safely accessed by concurrent threads.
* </p>
* <p>
* The managers constructed by
* The managers constructed by
* </p>
* <ul>
* <li>{@link #getCommandManager()}</li>
* <li>{@link #getCommandManager()}</li>
* <li>{@link #getComparatorManager()}</li>
* <li>{@link #getTestManager()}</li>
* </ul>
@@ -91,7 +91,7 @@ public class ConfigurationManager {
* A Map of the Comparator names and their associated class names.
*/
private ConcurrentMap<String, String> fieldComparatorMap;

/**
* The initial size for the {@link ConcurrentHashMap} concurrency level.
*/
@@ -100,10 +100,10 @@ public class ConfigurationManager {
private static final Log LOG = LogFactory.getLog("org.apache.jsieve");

private Log log = LOG;

/**
* Constructor for ConfigurationManager.
*
*
* @throws SieveConfigurationException
*/
public ConfigurationManager() throws SieveConfigurationException {
@@ -123,6 +123,7 @@ public ConfigurationManager() throws SieveConfigurationException {

/**
* Gets the current initial size for the {@link ConcurrentHashMap} concurrency level.
*
* @return number of concurrent threads estimated for initial sizing
*/
public int getInitialConcurrencyLevel() {
@@ -131,14 +132,14 @@ public int getInitialConcurrencyLevel() {

/**
* Sets the current initial size for the {@link ConcurrentHashMap} concurrency level.
*
* @param initialConcurrencyLevel number of concurrent threads estimated for initial sizing
*/
public void setInitialConcurrencyLevel(int initialConcurrencyLevel) {
this.initialConcurrencyLevel = initialConcurrencyLevel;
}



/**
* <p>
* Method getConfigStream answers an InputStream over the Sieve
@@ -150,7 +151,7 @@ public void setInitialConcurrencyLevel(int initialConcurrencyLevel) {
* is found then this is returned. Otherwise, the classloader used to load
* this class is searched for the resource.
* </p>
*
*
* @return InputStream
* @throws IOException
*/
@@ -178,7 +179,7 @@ private InputStream getConfigStream(String configName) throws IOException {
/**
* Method getCommandMap answers a Map of Command names and their associated
* class names, lazily initialized if required.
*
*
* @return Map not null
*/
public ConcurrentMap<String, String> getCommandMap() {
@@ -191,7 +192,7 @@ public ConcurrentMap<String, String> getCommandMap() {
/**
* Method getTestMap answers a Map of Test names and their associated class
* names, lazily initialized if required.
*
*
* @return Map not null
*/
public ConcurrentMap<String, String> getTestMap() {
@@ -204,7 +205,7 @@ public ConcurrentMap<String, String> getTestMap() {
/**
* Method getComparatorMap answers a Map of Comparator names and their
* associated class names, lazily initialized if required.
*
*
* @return Map not null
*/
public ConcurrentMap<String, String> getComparatorMap() {
@@ -217,7 +218,7 @@ public ConcurrentMap<String, String> getComparatorMap() {
/**
* Method parse uses the Digester to parse the XML statements in the Sieve
* configuration file into Java objects.
*
*
* @throws SAXException
* @throws IOException
*/
@@ -227,16 +228,16 @@ private void parse() throws SAXException, IOException {
setComparatorMap(loadConfiguration(COMPARATORSMAP_PROPERTIES));
}

private ConcurrentMap<String,String> loadConfiguration(final String name) throws IOException {
private ConcurrentMap<String, String> loadConfiguration(final String name) throws IOException {
final Properties properties = loadProperties(name);
final ConcurrentMap<String, String> result =
new ConcurrentHashMap<String, String>(properties.size(), 1.0f, initialConcurrencyLevel);
for (final Map.Entry<Object, Object> entry: properties.entrySet()) {
final ConcurrentMap<String, String> result =
new ConcurrentHashMap<String, String>(properties.size(), 1.0f, initialConcurrencyLevel);
for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
result.put(entry.getKey().toString(), entry.getValue().toString());
}
return result;
}

private Properties loadProperties(final String name) throws IOException {
final InputStream is = getConfigStream(name);
final Properties p = new Properties();
@@ -246,29 +247,26 @@ private Properties loadProperties(final String name) throws IOException {

/**
* Sets the commandMap.
*
* @param commandMap
* The commandMap to set
*
* @param commandMap The commandMap to set
*/
private void setCommandMap(ConcurrentMap<String, String> commandMap) {
fieldCommandMap = commandMap;
}

/**
* Sets the testMap.
*
* @param testMap
* The testMap to set
*
* @param testMap The testMap to set
*/
private void setTestMap(ConcurrentMap<String, String> testMap) {
fieldTestMap = testMap;
}

/**
* Sets the comparatorMap.
*
* @param comparatorMap
* The comparatorMap to set
*
* @param comparatorMap The comparatorMap to set
*/
private void setComparatorMap(ConcurrentMap<String, String> comparatorMap) {
fieldComparatorMap = comparatorMap;
@@ -289,7 +287,7 @@ public TestManager getTestManager() {
public Log getLog() {
return log;
}

public void setLog(Log log) {
this.log = log;
}
@@ -104,9 +104,9 @@ protected void setValue(Token aToken) {
endIndex--;
}

setValue(new Integer(Integer.parseInt(aToken.image.substring(0,
setValue(Integer.parseInt(aToken.image.substring(0,
endIndex))
* magnitude));
* magnitude);
}

/**
@@ -112,8 +112,7 @@ public SyntaxException syntaxException(CharSequence message) {
logDiagnosticsInfo(log);
}
final String fullMessage = addStartLineAndColumn(message);
final SyntaxException result = new SyntaxException(fullMessage);
return result;
return new SyntaxException(fullMessage);
}

/**
@@ -134,8 +133,7 @@ public CommandException commandException(CharSequence message) {
logDiagnosticsInfo(log);
}
final String fullMessage = addStartLineAndColumn(message);
final CommandException result = new CommandException(fullMessage);
return result;
return new CommandException(fullMessage);
}

/**
@@ -97,7 +97,7 @@ protected Object visitChildren(SimpleNode node, Object data)
@SuppressWarnings("unchecked")
public Object visit(ASTargument node, Object data) throws SieveException {
List<String> children = new ArrayList<String>(node.jjtGetNumChildren());
Argument argument = null;
Argument argument;

if (null != node.getValue()) {
argument = (Argument) node.getValue();
@@ -52,7 +52,7 @@ public StringListArgument(List<String> stringList) {
* @return List
*/
public List<String> getList() {
List<String> list = null;
List<String> list;
if (null == (list = getListBasic())) {
updateList();
return getList();
@@ -45,7 +45,7 @@ public class Test implements Executable {
*/
public Object execute(MailAdapter mail, SieveContext context)
throws SieveException {
return new Boolean(isTestPassed(mail, context));
return isTestPassed(mail, context);
}

/**
@@ -56,7 +56,7 @@ public Object execute(MailAdapter mail, SieveContext context)
* @throws LookupException
* @throws SieveException
*/
public boolean isTestPassed(MailAdapter mail, SieveContext context) throws LookupException, SieveException {
public boolean isTestPassed(MailAdapter mail, SieveContext context) throws SieveException {
Log log = context.getLog();
if (log.isDebugEnabled()) {
log.debug(toString());
@@ -74,7 +74,7 @@ public TestList(Test child) {
*/
public Object execute(MailAdapter mail, SieveContext context)
throws SieveException {
return new Boolean(allTestsPass(mail, context));
return allTestsPass(mail, context);
}

/**
@@ -64,7 +64,7 @@ public TestManagerImpl(final ConcurrentMap<String, String> classNameMap) {
* @throws LookupException
*/
public Class lookup(String name) throws LookupException {
Class testClass = null;
Class testClass;

try {
testClass = getClass().getClassLoader().loadClass(
@@ -57,8 +57,7 @@ protected Object execute(MailAdapter mail, Block block, SieveContext context)

try {
// Execute the Block
Object result = block.execute(mail, context);
return result;
return block.execute(mail, context);
} finally {
// Always restore the old ConditionManager
context.setConditionManager(oldManager);

0 comments on commit a69ca25

Please sign in to comment.