summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-02-12 03:30:45 (EST)
committerStefan Liebig2008-02-12 03:30:45 (EST)
commit85487faa5753d0ed9d485b4432f4015859b5dc97 (patch)
treed5a0f63771802a1f905869d0d6375f80d0722413
parent7a9035108842fc987d2012787e99716c454fe02e (diff)
downloadorg.eclipse.riena-85487faa5753d0ed9d485b4432f4015859b5dc97.zip
org.eclipse.riena-85487faa5753d0ed9d485b4432f4015859b5dc97.tar.gz
org.eclipse.riena-85487faa5753d0ed9d485b4432f4015859b5dc97.tar.bz2
Pre/PostCondition -> Assert
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/cache/GenericObjectCache.java19
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/exception/ExceptionHelper.java29
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/marker/AbstractMarker.java9
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/util/ReflectionUtils.java51
-rw-r--r--org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/SimplePrincipal.java168
5 files changed, 143 insertions, 133 deletions
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/cache/GenericObjectCache.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/cache/GenericObjectCache.java
index c0d85d4..1a5676e 100644
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/cache/GenericObjectCache.java
+++ b/org.eclipse.riena.core/src/org/eclipse/riena/core/cache/GenericObjectCache.java
@@ -100,9 +100,10 @@ public class GenericObjectCache implements IGenericObjectCache {
* @see org.eclipse.riena.core.cache.IGenericObjectCache#get(java.lang.Object)
*/
public Object get(Object key) {
- // PreCondition.assertTrue("get with single parameter cannot be used for
+ // Assert.isTrue(!isGlobalCache(),"get with single parameter cannot be
+ // used for
// global caches. use two parameter
- // version ", !isGlobalCache());
+ // version ");
return get(key, GenericObjectCache.class);
}
@@ -186,15 +187,15 @@ public class GenericObjectCache implements IGenericObjectCache {
private void printStat() {
statDisplayCount++;
if (statDisplayCount > 100) {
- LOGGER
- .log(LogService.LOG_INFO, name + "Hit / NotFound / Miss / Timeout " + statHit + " / " + statNotFound + " / " + statMiss + " / "
- + statTimeout);
+ LOGGER.log(LogService.LOG_INFO, name + "Hit / NotFound / Miss / Timeout " + statHit + " / " + statNotFound
+ + " / " + statMiss + " / " + statTimeout);
statDisplayCount = 0;
}
}
public String getStatistic() {
- return name + "Hit / NotFound / Miss / Timeout " + statHit + " / " + statNotFound + " / " + statMiss + " / " + statTimeout;
+ return name + "Hit / NotFound / Miss / Timeout " + statHit + " / " + statNotFound + " / " + statMiss + " / "
+ + statTimeout;
}
private void touchValue(Object value) {
@@ -214,9 +215,9 @@ public class GenericObjectCache implements IGenericObjectCache {
* java.lang.Object)
*/
public void put(Object key, Object value) {
- // PreCondition.assertTrue("objects in global caches must be
- // serializable", (!globalCache) || value instanceof
- // Serializable);
+ // Assert.isTrue((!globalCache) || value instanceof
+ // Serializable,"objects in global caches must be
+ // serializable" );
LOGGER.log(LogService.LOG_DEBUG, "put = " + key + " , " + value + "");
processQueue();
ICacheEntry entry;
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/exception/ExceptionHelper.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/exception/ExceptionHelper.java
index 0db98bb..53d4dcf 100644
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/exception/ExceptionHelper.java
+++ b/org.eclipse.riena.core/src/org/eclipse/riena/core/exception/ExceptionHelper.java
@@ -20,9 +20,8 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
-import org.eclipse.riena.core.contract.PostConditionException;
-import org.eclipse.riena.core.contract.PreCondition;
-import org.eclipse.riena.core.contract.PreConditionException;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.AssertionFailedException;
/**
* This class provides several static methods needed by the exception handling
@@ -199,7 +198,8 @@ public final class ExceptionHelper {
StringBuilder buffer = new StringBuilder();
for (int i = throwables.size() - 1; i > -1; i--) {
throwable = throwables.get(i);
- buffer.append("Exception: ").append(throwable.getClass().getName()).append(": ").append(throwable.getMessage());
+ buffer.append("Exception: ").append(throwable.getClass().getName()).append(": ").append(
+ throwable.getMessage());
StackTraceElement[] trace = throwable.getStackTrace();
@@ -219,8 +219,8 @@ public final class ExceptionHelper {
className = steClassName;
}
}
- buffer.append(LINE_SEPARATOR).append(className).append(DOT_STR).append(ste.getMethodName()).append("()").append(",").append(
- ste.getLineNumber()).append(pkgName);
+ buffer.append(LINE_SEPARATOR).append(className).append(DOT_STR).append(ste.getMethodName()).append(
+ "()").append(",").append(ste.getLineNumber()).append(pkgName);
}
}
buffer.append(LINE_SEPARATOR);
@@ -318,7 +318,8 @@ public final class ExceptionHelper {
Constructor<?> constructor;
try {
- constructor = StackTraceElement.class.getDeclaredConstructor(new Class[] { String.class, String.class, String.class, int.class });
+ constructor = StackTraceElement.class.getDeclaredConstructor(new Class[] { String.class, String.class,
+ String.class, int.class });
} catch (NoSuchMethodException e) {
throw new ExceptionFailure("Could not get the constructor of StackTraceElement.", e);
}
@@ -326,7 +327,8 @@ public final class ExceptionHelper {
try {
// initialize the return vector
- StackTraceElement[] resultStackTrace = (StackTraceElement[]) Array.newInstance(StackTraceElement.class, stackTraceElements.length);
+ StackTraceElement[] resultStackTrace = (StackTraceElement[]) Array.newInstance(StackTraceElement.class,
+ stackTraceElements.length);
// fill stacktrace for each available line
for (int i = 0; i < stackTraceElements.length; i++) {
@@ -345,7 +347,8 @@ public final class ExceptionHelper {
int lineNumber = Integer.parseInt(items[3]);
// create a new instance for the array
- resultStackTrace[i] = (StackTraceElement) constructor.newInstance(new Object[] { declaringClass, methodName, fileName, lineNumber });
+ resultStackTrace[i] = (StackTraceElement) constructor.newInstance(new Object[] { declaringClass,
+ methodName, fileName, lineNumber });
}
return resultStackTrace;
@@ -362,7 +365,7 @@ public final class ExceptionHelper {
* @pre map != null
*/
public static Object[] createArrayFromMap(Map<String, ? extends Object> map) {
- PreCondition.assertNotNull("map should not be null!", map);
+ Assert.isNotNull(map, "map should not be null");
String[] messagePartNames = Failure.getMessagePartNames();
Object[] args = new Object[messagePartNames.length];
@@ -383,10 +386,8 @@ public final class ExceptionHelper {
public static Failure toFailure(Throwable t) {
if (!(t instanceof Failure)) {
String msgText = null;
- if (t instanceof PreConditionException) {
- msgText = "PreCondition violated";
- } else if (t instanceof PostConditionException) {
- msgText = "PostCondition violated";
+ if (t instanceof AssertionFailedException) {
+ msgText = "Assertion violated";
} else {
msgText = "Unexpected exception occurred";
}
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/marker/AbstractMarker.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/marker/AbstractMarker.java
index cf4a321..f61f498 100644
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/marker/AbstractMarker.java
+++ b/org.eclipse.riena.core/src/org/eclipse/riena/core/marker/AbstractMarker.java
@@ -16,7 +16,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import org.eclipse.riena.core.contract.PreCondition;
+import org.eclipse.core.runtime.Assert;
/**
* An abstract implementation of the {@link IMarker IMarker}interface which
@@ -26,13 +26,14 @@ import org.eclipse.riena.core.contract.PreCondition;
public abstract class AbstractMarker implements IMarker {
private Map<String, Object> attributeMap = new HashMap<String, Object>(0, 1.0f);
- private Set<IMarkerAttributeChangeListener> attributeChangeListeners = new HashSet<IMarkerAttributeChangeListener>(1, 1.0f);
+ private Set<IMarkerAttributeChangeListener> attributeChangeListeners = new HashSet<IMarkerAttributeChangeListener>(
+ 1, 1.0f);
/**
* @see IMarker#getAttribute(String)
*/
public Object getAttribute(String name) {
- PreCondition.assertNotNullAndNotZeroLength("name", name);
+ Assert.isNotNull(name, "name must not be null");
return attributeMap.get(name);
}
@@ -58,7 +59,7 @@ public abstract class AbstractMarker implements IMarker {
* @see IMarker#setAttribute(String, Object)
*/
public void setAttribute(String name, Object value) {
- PreCondition.assertNotNullAndNotZeroLength("name", name);
+ Assert.isNotNull(name, "name must not be null");
Object oldValue = attributeMap.get(name);
if ((value != null && !value.equals(oldValue)) || (value == null && oldValue != null)) {
attributeMap.put(name, value);
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/util/ReflectionUtils.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/util/ReflectionUtils.java
index 3689f78..42503f3 100644
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/util/ReflectionUtils.java
+++ b/org.eclipse.riena.core/src/org/eclipse/riena/core/util/ReflectionUtils.java
@@ -18,7 +18,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
-import org.eclipse.riena.core.contract.PreCondition;
+import org.eclipse.core.runtime.Assert;
/**
* The <code>ReflectionUtils</code> class is a collection of usefull helpers
@@ -48,12 +48,13 @@ public final class ReflectionUtils {
* @pre className != null
*/
public static Object newInstance(String className, Object... args) {
- PreCondition.assertNotNull("className must be given!", className);
+ Assert.isNotNull(className, "className must be given!");
try {
return newInstance(Class.forName(className), args);
} catch (Exception e) {
- throw new ReflectionFailure("Error creating instance for " + className + "with parameters " + Arrays.asList(args) + "!", e);
+ throw new ReflectionFailure("Error creating instance for " + className + "with parameters "
+ + Arrays.asList(args) + "!", e);
}
}
@@ -69,14 +70,15 @@ public final class ReflectionUtils {
* @pre clazz != null
*/
public static <T> T newInstance(Class<T> clazz, Object... args) {
- PreCondition.assertNotNull("clazz must be given!", clazz);
+ Assert.isNotNull(clazz, "clazz must be given!");
try {
Class<?>[] clazzes = classesFromObjects(args);
Constructor<T> constructor = findMatchingConstructor(clazz, clazzes);
return constructor.newInstance(args);
} catch (Exception e) {
- throw new ReflectionFailure("Error creating instance for " + clazz.getName() + "with parameters " + Arrays.asList(args) + "!", e);
+ throw new ReflectionFailure("Error creating instance for " + clazz.getName() + "with parameters "
+ + Arrays.asList(args) + "!", e);
}
}
@@ -92,9 +94,8 @@ public final class ReflectionUtils {
* @pre invocationHandler != null
*/
public static Object newInstance(String interfaceName, InvocationHandler invocationHandler) {
- PreCondition.assertNotNull("interfaceName must be given!", interfaceName);
- PreCondition.assertNotNull("invocationHandler must be given!", invocationHandler);
-
+ Assert.isNotNull(interfaceName, "interfaceName must be given!");
+ Assert.isNotNull(invocationHandler, "invocationHandler must be given!");
try {
return newInstance(Class.forName(interfaceName), invocationHandler);
} catch (Exception e) {
@@ -115,8 +116,8 @@ public final class ReflectionUtils {
*/
@SuppressWarnings("unchecked")
public static <T> T newInstance(Class<T> interfaze, InvocationHandler invocationHandler) {
- PreCondition.assertNotNull("interfaceName must be given!", interfaze);
- PreCondition.assertNotNull("invocationHandler must be given!", invocationHandler);
+ Assert.isNotNull(interfaze, "interfaceName must be given");
+ Assert.isNotNull(invocationHandler, "invocationHandler must be given");
Class proxyClass = Proxy.getProxyClass(interfaze.getClassLoader(), new Class<?>[] { interfaze });
try {
@@ -185,8 +186,9 @@ public final class ReflectionUtils {
* @pre expectedException != null
*/
@SuppressWarnings("unchecked")
- public static <T extends Throwable> Object invoke(Object instance, String methodName, Class<T> expectedException, Object... args) throws T {
- PreCondition.assertNotNull("expectedException should not be null!", expectedException);
+ public static <T extends Throwable> Object invoke(Object instance, String methodName, Class<T> expectedException,
+ Object... args) throws T {
+ Assert.isNotNull(expectedException, "expectedException should not be null!");
try {
return invoke(instance, methodName, args);
@@ -216,8 +218,9 @@ public final class ReflectionUtils {
* @pre expectedException != null
*/
@SuppressWarnings("unchecked")
- public static <T extends Throwable> Object invokeHidden(Object instance, String methodName, Class<T> expectedException, Object... args) throws T {
- PreCondition.assertNotNull("expectedException should not be null!", expectedException);
+ public static <T extends Throwable> Object invokeHidden(Object instance, String methodName,
+ Class<T> expectedException, Object... args) throws T {
+ Assert.isNotNull(expectedException, "expectedException should not be null!");
try {
return invokeHidden(instance, methodName, args);
@@ -247,8 +250,8 @@ public final class ReflectionUtils {
* @pre methodName != null
*/
private static Object invoke(boolean open, Object instance, String methodName, Object... args) {
- PreCondition.assertNotNull("instance must be given!", instance);
- PreCondition.assertNotNull("methodName must be given!", methodName);
+ Assert.isNotNull(instance, "instance must be given!");
+ Assert.isNotNull(methodName, "methodName must be given!");
Class<?> clazz = getClass(instance);
Class<?>[] clazzes = classesFromObjects(args);
@@ -261,7 +264,8 @@ public final class ReflectionUtils {
try {
return method.invoke(instance, args);
} catch (InvocationTargetException ite) {
- throw new InvocationTargetFailure("Calling #" + methodName + " on " + instance + " failed.", ite.getTargetException());
+ throw new InvocationTargetFailure("Calling #" + methodName + " on " + instance + " failed.", ite
+ .getTargetException());
} catch (IllegalArgumentException e) {
throw new ReflectionFailure("Calling #" + methodName + " on " + instance + " failed.", e);
} catch (IllegalAccessException e) {
@@ -271,7 +275,8 @@ public final class ReflectionUtils {
clazz = clazz.getSuperclass();
}
- throw new ReflectionFailure("Could not invoke hidden method " + methodName + " on " + instance.getClass().getName() + "!");
+ throw new ReflectionFailure("Could not invoke hidden method " + methodName + " on "
+ + instance.getClass().getName() + "!");
}
/**
@@ -291,9 +296,9 @@ public final class ReflectionUtils {
* @pre value != null
*/
public static void setHidden(Object instance, String fieldName, Object value) {
- PreCondition.assertNotNull("instance must be given!", instance);
- PreCondition.assertNotNull("fieldName must be given!", fieldName);
- PreCondition.assertNotNull("value must be given!", value);
+ Assert.isNotNull(instance, "instance must be given!");
+ Assert.isNotNull(fieldName, "fieldName must be given!");
+ Assert.isNotNull(value, "value must be given!");
Class<?> clazz = getClass(instance);
try {
@@ -319,8 +324,8 @@ public final class ReflectionUtils {
* @pre fieldName != null
*/
public static Object getHidden(Object instance, String fieldName) {
- PreCondition.assertNotNull("instance must be given!", instance);
- PreCondition.assertNotNull("fieldName must be given!", fieldName);
+ Assert.isNotNull(instance, "instance must be given!");
+ Assert.isNotNull(fieldName, "fieldName must be given!");
Class<?> clazz = getClass(instance);
try {
diff --git a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/SimplePrincipal.java b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/SimplePrincipal.java
index 237f999..55adbf3 100644
--- a/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/SimplePrincipal.java
+++ b/org.eclipse.riena.security.common/src/org/eclipse/riena/security/common/authentication/SimplePrincipal.java
@@ -19,99 +19,101 @@ import java.security.Principal;
*/
public class SimplePrincipal implements Principal, Serializable {
- private String name;
+ private String name;
- /**
- * constructor.
- */
- public SimplePrincipal() {
- super();
- }
+ /**
+ * constructor.
+ */
+ public SimplePrincipal() {
+ super();
+ }
- /**
- * Create a <code>SimplePrincipal</code> with a given <code>name</code>.
- *
- * @param name
- * the name of the principal
- * @pre name != null && name.length() > 0
- */
- public SimplePrincipal(String name) {
- super();
- // PreCondition.assertTrue( "the Name must not be null or empty", name != null && name.length() > 0 );
+ /**
+ * Create a <code>SimplePrincipal</code> with a given <code>name</code>.
+ *
+ * @param name
+ * the name of the principal
+ * @pre name != null && name.length() > 0
+ */
+ public SimplePrincipal(String name) {
+ super();
+ // Assert.isTrue( name != null && name.length() > 0 ,"the Name must not
+ // be null or empty");
- setName(name);
- }
+ setName(name);
+ }
- /**
- * Create a <code>SimplePrincipal</code> with a given name. The name is a composite of <code>proxyName</code>
- * and <code>representedName</code>.
- *
- * @param proxyName
- * name of the proxy
- * @param representedName
- */
- public SimplePrincipal(String proxyName, String representedName) {
- this(proxyName + "," + representedName);
- }
+ /**
+ * Create a <code>SimplePrincipal</code> with a given name. The name is a
+ * composite of <code>proxyName</code> and <code>representedName</code>.
+ *
+ * @param proxyName
+ * name of the proxy
+ * @param representedName
+ */
+ public SimplePrincipal(String proxyName, String representedName) {
+ this(proxyName + "," + representedName);
+ }
- /**
- * @see java.security.Principal#getName()
- */
- public String getName() {
- return name;
- }
+ /**
+ * @see java.security.Principal#getName()
+ */
+ public String getName() {
+ return name;
+ }
- /**
- * Sets the name of this principal
- *
- * @param name
- * The name to set.
- * @pre name != null && name.length() > 0
- * @pre getName() == null;
- */
- public void setName(String name) {
- // PreCondition.assertTrue( "the Name must not be null or empty!", name != null && name.length() > 0 );
- // PreCondition.assertTrue( "Name can only by set once!", this.name == null );
- this.name = name;
- }
+ /**
+ * Sets the name of this principal
+ *
+ * @param name
+ * The name to set.
+ * @pre name != null && name.length() > 0
+ * @pre getName() == null;
+ */
+ public void setName(String name) {
+ // Assert.isTrue( "the Name must not be null or empty!", name != null &&
+ // name.length() > 0 );
+ // Assert.isTrue( "Name can only by set once!", this.name == null );
+ this.name = name;
+ }
- /**
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object object) {
- if (this == object) {
- return true;
- }
- if (!(object instanceof SimplePrincipal)) {
- return false;
- }
- SimplePrincipal that = (SimplePrincipal) object;
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object object) {
+ if (this == object) {
+ return true;
+ }
+ if (!(object instanceof SimplePrincipal)) {
+ return false;
+ }
+ SimplePrincipal that = (SimplePrincipal) object;
- if (this.name == null) {
- return that.name == null;
- }
+ if (this.name == null) {
+ return that.name == null;
+ }
- return this.name.equals(that.name);
- }
+ return this.name.equals(that.name);
+ }
- /**
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- if (name == null) {
- return getClass().hashCode();
- } else {
- return getClass().hashCode() & name.hashCode();
- }
- }
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ if (name == null) {
+ return getClass().hashCode();
+ } else {
+ return getClass().hashCode() & name.hashCode();
+ }
+ }
- /**
- * overwrite super.toString()
- *
- * @return string representation of object
- */
- public String toString() {
- return "(" + this.getClass().getName() + ":" + name + ")";
- }
+ /**
+ * overwrite super.toString()
+ *
+ * @return string representation of object
+ */
+ public String toString() {
+ return "(" + this.getClass().getName() + ":" + name + ")";
+ }
} \ No newline at end of file