diff options
| author | Benjamin Culkin <scorpress@gmail.com> | 2024-07-05 12:43:13 -0400 |
|---|---|---|
| committer | Benjamin Culkin <scorpress@gmail.com> | 2024-07-05 12:43:13 -0400 |
| commit | 6d46c473d41c6c47e6b8bd8c676d925e544bd378 (patch) | |
| tree | 796d51bfff52f8f3fa383b2d26847b7c8160677b | |
| parent | 02bc52037e9ccccca672d6156d9c325c74fe28b3 (diff) | |
More cleanup
29 files changed, 278 insertions, 180 deletions
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSCoding.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSCoding.java index c578dbc..330e682 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSCoding.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSCoding.java @@ -39,11 +39,13 @@ public interface NSCoding { public static class _BigDecimalSupport extends _BigIntegerSupport { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** Not yet implemented */ + @Override public Object decodeObject(NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -58,11 +60,13 @@ public interface NSCoding { public static class _BigIntegerSupport extends Support { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** Not yet implemented */ + @Override public Object decodeObject(NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -87,6 +91,7 @@ public interface NSCoding { public static class _DoubleSupport extends _NumberSupport { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -101,6 +106,7 @@ public interface NSCoding { public static class _FloatSupport extends _NumberSupport { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -115,6 +121,7 @@ public interface NSCoding { public static class _LongSupport extends _NumberSupport { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -129,6 +136,7 @@ public interface NSCoding { public static class _IntegerSupport extends _NumberSupport { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -143,6 +151,7 @@ public interface NSCoding { public static class _ShortSupport extends _NumberSupport { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -157,6 +166,7 @@ public interface NSCoding { public static class _ByteSupport extends _NumberSupport { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -171,16 +181,19 @@ public interface NSCoding { public static class _NumberSupport extends Support { /** Not yet implemented */ - public Class classForCoder(Object obj) { + @Override + public Class<?> classForCoder(Object obj) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** Not yet implemented */ + @Override public Object decodeObject(NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -195,11 +208,13 @@ public interface NSCoding { public static class _CharacterSupport extends Support { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** Not yet implemented */ + @Override public Object decodeObject(NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -214,11 +229,13 @@ public interface NSCoding { public static class _DateSupport extends Support { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** Not yet implemented */ + @Override public Object decodeObject(NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -233,11 +250,13 @@ public interface NSCoding { public static class _StringSupport extends Support { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** Not yet implemented */ + @Override public Object decodeObject(NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -252,11 +271,13 @@ public interface NSCoding { public static class _BooleanSupport extends Support { /** Not yet implemented */ + @Override public void encodeWithCoder(Object obj, NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** Not yet implemented */ + @Override public Object decodeObject(NSCoder nscoder) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -270,13 +291,13 @@ public interface NSCoding { /** Helper class for NSCoding. */ public static abstract class Support { - private static NSMutableDictionary classSupportMap = new NSMutableDictionary(16); + private static NSMutableDictionary<Class<?>, Support> classSupportMap = new NSMutableDictionary<>(16); - public static Support supportForClass(Class aClass) { + public static Support supportForClass(Class<?> aClass) { Support support = null; - Class realClass = aClass; + Class<?> realClass = aClass; while (support == null && realClass != null) { - support = (Support) classSupportMap.objectForKey(realClass); + support = classSupportMap.objectForKey(realClass); if (support == null) realClass.getSuperclass(); // Cache if we had to look to a superclass. @@ -286,7 +307,7 @@ public interface NSCoding { return support; } - public static void setSupportForClass(Support support, Class class1) { + public static void setSupportForClass(Support support, Class<?> class1) { classSupportMap.setObjectForKey(support, class1); } @@ -294,7 +315,7 @@ public interface NSCoding { * Return the class of a given object. It boggles the mind as to why this is not * a static, but in the original, it's not. <sigh> */ - public Class classForCoder(Object obj) { + public Class<?> classForCoder(Object obj) { return obj.getClass(); } diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSKeyValueCodingAdditions.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSKeyValueCodingAdditions.java index 72c9fc8..a93fff9 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSKeyValueCodingAdditions.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSKeyValueCodingAdditions.java @@ -49,13 +49,23 @@ public interface NSKeyValueCodingAdditions extends NSKeyValueCoding { * Returns a Map of the specified keys to their values, each of which might be * obtained by calling valueForKey. */ - NSDictionary<String, Object> valuesForKeys(List<String> aKeyList); + default NSDictionary<String, Object> valuesForKeys(List<String> aKeyList) { + NSDictionary<String, Object> ret = new NSMutableDictionary<>(); + + for (String key : aKeyList) { + ret.put(key, valueForKey(key)); + } + + return ret; + } /** * Takes the keys from the specified map as properties and applies the * corresponding values, each of which might be set by calling takeValueForKey. */ - void takeValuesFromDictionary(Map<String, Object> aMap); + default void takeValuesFromDictionary(Map<String, Object> aMap) { + aMap.forEach((key, val) -> takeValueForKey(val, key)); + } /** * Static utility methods that call the appropriate method if the object diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableRange.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableRange.java index 2bfb692..d529f23 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableRange.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableRange.java @@ -85,6 +85,7 @@ public class NSMutableRange extends NSRange { /** * Returns a copy of this range. */ + @Override public Object clone() { return new NSMutableRange(location(), length()); } diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSNotification.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSNotification.java index 4fbd8af..90d09a4 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSNotification.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSNotification.java @@ -33,7 +33,7 @@ public class NSNotification { protected String name; protected Object object; - protected Map userInfo; + protected Map<? extends Object, ? extends Object> userInfo; // for debugging only private Throwable stackTrace; @@ -57,7 +57,7 @@ public class NSNotification { * Constructor specifying name, object, and a Map containing application * specific information. */ - public NSNotification(String aName, Object anObject, Map aUserInfo) { + public NSNotification(String aName, Object anObject, Map<? extends Object, ? extends Object> aUserInfo) { name = aName; object = anObject; if (showStack) @@ -84,7 +84,7 @@ public class NSNotification { * specific information relating to this notification, or null if no such data * exists. */ - public NSDictionary userInfo() { + public NSDictionary<? extends Object, ? extends Object> userInfo() { if (userInfo == null) return null; return new NSDictionary<>(userInfo); @@ -95,7 +95,7 @@ public class NSNotification { * notification, or null if no such data exists. Note: this method is not in the * spec. */ - public Map userInfoMap() { + public Map<? extends Object, ? extends Object> userInfoMap() { return userInfo; } @@ -111,6 +111,7 @@ public class NSNotification { /** * Returns a human-readable string representation. */ + @Override public String toString() { return "[ " + name() + " : " + object() + " : " + userInfo() + " ]"; } diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSNumberFormatter.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSNumberFormatter.java index 7e6386d..11e266c 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSNumberFormatter.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSNumberFormatter.java @@ -33,6 +33,8 @@ import java.text.DecimalFormat; */ public class NSNumberFormatter extends DecimalFormat { + private static final long serialVersionUID = 7972222004050211308L; + public NSNumberFormatter() { super(); } diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSPropertyListSerialization.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSPropertyListSerialization.java index b52dc2d..b819662 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSPropertyListSerialization.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSPropertyListSerialization.java @@ -1,6 +1,11 @@ package net.wotonomy.foundation; +/** + * Class for serializing/unserializing property lists in the .plist format + * + * + */ public class NSPropertyListSerialization { public static final int PLIST_ARRAY = 0; @@ -21,11 +26,11 @@ public class NSPropertyListSerialization { * * @s The string representation of a NSArray object. */ - public static NSArray arrayForString(String s) { + public static NSArray<Object> arrayForString(String s) { s = s.trim(); if (!(s.charAt(0) == TOKEN_BEGIN[PLIST_ARRAY] && s.charAt(s.length() - 1) == TOKEN_END[PLIST_ARRAY])) return null; - NSMutableArray arr = new NSMutableArray(); + NSMutableArray<Object> arr = new NSMutableArray<>(); int pos = 1; int valbegin = -1; while (pos < s.length()) { @@ -88,13 +93,12 @@ public class NSPropertyListSerialization { * * @s The string representation of a NSDictionary. */ - public static NSDictionary dictionaryForString(String s) { + public static NSDictionary<Object, Object> dictionaryForString(String s) { s = s.trim(); if (!(s.charAt(0) == TOKEN_BEGIN[PLIST_DICTIONARY] && s.charAt(s.length() - 1) == TOKEN_END[PLIST_DICTIONARY])) return null; - NSMutableDictionary d = new NSMutableDictionary(); + NSMutableDictionary<Object, Object> d = new NSMutableDictionary<>(); int pos = 1; - boolean parsing = true; Object key = null; int valbegin = -1; while (pos < s.length()) { diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSelector.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSelector.java index 8f5969a..caaea25 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSelector.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSSelector.java @@ -33,6 +33,8 @@ import net.wotonomy.foundation.internal.PropertyComparator; * @version $Revision: 892 $ */ public class NSSelector implements Comparator, Serializable { + private static final long serialVersionUID = 2531682514697198972L; + protected NSMutableDictionary methodMap; // map of classes to methods protected String methodName; protected Class[] parameterTypes; diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimeZone.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimeZone.java index 7c7b4da..411bc3b 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimeZone.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimeZone.java @@ -28,8 +28,7 @@ import java.util.Locale; import java.util.TimeZone; /** - * A channel to the database, representing a communication stream within a - * context of an adaptor. + * A time zone for an NSTimeStamp * * @author cgruber@israfil.net * @author $Author: cgruber $ @@ -37,11 +36,14 @@ import java.util.TimeZone; */ public class NSTimeZone extends TimeZone implements Cloneable, Serializable, NSCoding { - protected static class __NSTZPeriodComparator extends NSComparator { + private static final long serialVersionUID = -2771392108329800748L; + + protected static class __NSTZPeriodComparator extends NSComparator<__NSTZPeriod> { protected boolean _ascending = false; - public int compare(Object obj, Object obj1) throws NSComparator.ComparisonException { + @Override + public int compare(__NSTZPeriod obj, __NSTZPeriod obj1) throws NSComparator.ComparisonException { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -101,6 +103,7 @@ public class NSTimeZone extends TimeZone implements Cloneable, Serializable, NSC return getClass(); } + @Override public Object clone() { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -145,10 +148,12 @@ public class NSTimeZone extends TimeZone implements Cloneable, Serializable, NSC throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public void setID(String s) { throw new IllegalStateException(getClass().getName() + " is immutable."); } + @Override public void setRawOffset(int i) { throw new IllegalStateException(getClass().getName() + " is immutable."); } @@ -185,34 +190,42 @@ public class NSTimeZone extends TimeZone implements Cloneable, Serializable, NSC throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public boolean equals(Object obj) { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public String getDisplayName(boolean flag, int i, Locale locale) { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public String getID() { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public int getOffset(int i, int j, int k, int l, int i1, int j1) { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public int getRawOffset() { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public synchronized int hashCode() { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public boolean hasSameRules(TimeZone timezone) { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public boolean inDaylightTime(Date date) { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -241,10 +254,12 @@ public class NSTimeZone extends TimeZone implements Cloneable, Serializable, NSC throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public String toString() { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public boolean useDaylightTime() { throw new UnsupportedOperationException("Not Yet Implemented"); } diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimestamp.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimestamp.java index 03590f2..57c728d 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimestamp.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimestamp.java @@ -36,10 +36,13 @@ import java.util.TimeZone; public class NSTimestamp extends Timestamp implements NSCoding { + private static final long serialVersionUID = 8450053854095874663L; + public static class IntRef { public int value = 0; + @Override public String toString() { return getClass().getName() + " < value = " + value + " >"; } @@ -71,7 +74,7 @@ public class NSTimestamp extends Timestamp implements NSCoding { return l * 1000L; } - public Class classForCoder() { + public Class<?> classForCoder() { return getClass(); } @@ -205,6 +208,7 @@ public class NSTimestamp extends Timestamp implements NSCoding { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public String toString() { throw new UnsupportedOperationException("Not Yet Implemented"); } @@ -217,44 +221,53 @@ public class NSTimestamp extends Timestamp implements NSCoding { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public void setNanos(int i) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** @deprecated This method deprecated in parent java.util.Date */ + @Override public void setDate(int i) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** @deprecated This method deprecated in parent java.util.Date */ + @Override public void setHours(int i) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** @deprecated This method deprecated in parent java.util.Date */ + @Override public void setMinutes(int i) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** @deprecated This method deprecated in parent java.util.Date */ + @Override public void setMonth(int i) { throw new UnsupportedOperationException("Not Yet Implemented"); } /** @deprecated This method deprecated in parent java.util.Date */ + @Override public void setSeconds(int i) { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public void setTime(long l) { throw new UnsupportedOperationException("Not Yet Implemented"); } + @Override public long getTime() { throw new UnsupportedOperationException("Not Yet Implemented"); } /** @deprecated This method deprecated in parent java.util.Date */ + @Override public void setYear(int i) { throw new UnsupportedOperationException("Not Yet Implemented"); } diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimestampFormatter.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimestampFormatter.java index c8fbc44..3abac66 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimestampFormatter.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSTimestampFormatter.java @@ -34,6 +34,8 @@ import java.text.SimpleDateFormat; */ public class NSTimestampFormatter extends SimpleDateFormat { + private static final long serialVersionUID = -4480420834738564573L; + public NSTimestampFormatter() { super(); } diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Introspector.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Introspector.java index 09687e2..870ff83 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Introspector.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/Introspector.java @@ -35,7 +35,7 @@ import java.util.Set; * <br> * * Of particular note are the get() and set() methods, which will attempt to get - * and set artibrary values on arbitrary objects to the best of its ability, + * and set arbitrary values on arbitrary objects to the best of its ability, * converting values as appropriate. Properties of the form * "property.nestedproperty.anotherproperty" are supported to get and set values * on property values directly.<br> @@ -72,10 +72,10 @@ public class Introspector { // wildcard value - using this class to represent a "wildcard" generic class. // we have to do this when matching methods by parameter types and a // null value is passed in - can't tell what class the null should be. - public static Class WILD = Introspector.class; + public static Class<?> WILD = Introspector.class; // empty class array - prevents having to create one every time - private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0]; // use OGNL for property access private static boolean useOGNL; @@ -99,7 +99,7 @@ public class Introspector { * parameters. * @return The appropriate method for the class, or null if not found. */ - static public Method getPropertyReadMethod(Class objectClass, String aProperty, Class[] paramTypes) { + static public Method getPropertyReadMethod(Class<?> objectClass, String aProperty, Class<?>[] paramTypes) { Method result = null; result = getMethodFromClass(objectClass, aProperty, paramTypes, true); diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NetworkClassLoader.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NetworkClassLoader.java index 7761876..a36c616 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NetworkClassLoader.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/NetworkClassLoader.java @@ -79,8 +79,8 @@ import java.util.Hashtable; */ public class NetworkClassLoader extends ClassLoader { private ClassLoader parent = null; // parent classloader - private Hashtable classCache = new Hashtable(); - private Hashtable urlset = new Hashtable(); + private Hashtable<String, Class<?>> classCache = new Hashtable<>(); + private Hashtable<URL, URLResourceReader> urlset = new Hashtable<>(); /** * Creates a new instance of the class loader. @@ -132,14 +132,15 @@ public class NetworkClassLoader extends ClassLoader { /** * @return An enumeration of URLs where this class loader looks for classes. */ - public Enumeration getURLs() { + public Enumeration<URL> getURLs() { return urlset.keys(); } /** * Call this to bypass the implementation of loadClass. */ - public Class findClass(String name) { + @Override + public Class<?> findClass(String name) { byte[] b = loadClassData(name); if (b == null) return null; @@ -158,7 +159,7 @@ public class NetworkClassLoader extends ClassLoader { protected byte[] loadResource(String resource) { byte[] barray = null; - for (Enumeration e = urlset.keys(); e.hasMoreElements();) { + for (Enumeration<URL> e = urlset.keys(); e.hasMoreElements();) { URL url = (URL) e.nextElement(); try { @@ -182,11 +183,12 @@ public class NetworkClassLoader extends ClassLoader { * Overridden to search for a resource and return a "jar"-style URL or normal * "file" URL as necessary. */ + @Override protected URL findResource(String name) { // System.out.println( "findResource: " + name ); URL url; byte[] barray = null; - for (Enumeration e = urlset.keys(); e.hasMoreElements();) { + for (Enumeration<URL> e = urlset.keys(); e.hasMoreElements();) { url = (URL) e.nextElement(); try { barray = loadResource(url, name); // loads fully: wasteful @@ -216,6 +218,7 @@ public class NetworkClassLoader extends ClassLoader { * @return The resource as the input stream if such a resource exists, otherwise * returns null. */ + @Override public InputStream getResourceAsStream(String name) { // System.out.println( "getResourceAsStream: " + name ); InputStream istream = null; @@ -257,12 +260,13 @@ public class NetworkClassLoader extends ClassLoader { * @param The class data bytes. * @return The class object. */ - protected Class defineClass(String classname, byte[] classdata) { + protected Class<?> defineClass(String classname, byte[] classdata) { return defineClass(classname, classdata, 0, classdata.length); } - public synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - Class c = null; + @Override + public synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { + Class<?> c = null; // Algorithm: (Please do not change the order; unless you // have a good reason to do so). @@ -293,7 +297,7 @@ public class NetworkClassLoader extends ClassLoader { } // Lets see if the class is in the cache.. - c = (Class) classCache.get(name); + c = (Class<?>) classCache.get(name); if (c != null) return c; @@ -328,6 +332,7 @@ public class NetworkClassLoader extends ClassLoader { * This method resets this ClassLoader's state and resets the references for * garbage collection. */ + @Override protected void finalize() throws Throwable { // Cleanup real well. Otherwise, this can be // a major source of memory leaks... diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyListParser.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyListParser.java index 3698325..c44a892 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyListParser.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/PropertyListParser.java @@ -26,7 +26,7 @@ import java.io.*; * return the top-level object represented by the plist. * <p> * - * A property list is a heirarchical data structure containing only Maps, Lists, + * A property list is a hierarchical data structure containing only Maps, Lists, * and Strings -- nothing else. In other words, a property list is either a Map, * List, or String instance, with the restrictions that the collections may only * contain Map, List, or String instances. @@ -79,7 +79,7 @@ import java.io.*; * are thrown with the line number and column of the problem. * <p> * - * Currenty, HashMaps and ArrayLists are the actual Map and List classes used + * Currently, HashMaps and ArrayLists are the actual Map and List classes used * when creating the property list. * <p> * @@ -456,8 +456,8 @@ public class PropertyListParser { return stringBuffer.toString(); } - private List readList() { - List newList = new ArrayList(); + private List<Object> readList() { + List<Object> newList = new ArrayList<>(); currIndex++; // skip over '(' skipCommentWhitespace(); @@ -488,8 +488,8 @@ public class PropertyListParser { return newList; } - private Map readMap() { - HashMap newMap = new HashMap(); + private Map<Object, Object> readMap() { + HashMap<Object, Object> newMap = new HashMap<>(); currIndex++; // skip over open brace skipCommentWhitespace(); diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/URLResourceReader.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/URLResourceReader.java index 8694564..92862f6 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/URLResourceReader.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/URLResourceReader.java @@ -72,7 +72,7 @@ import java.util.zip.ZipInputStream; * @author Harish Prabandham */ public class URLResourceReader { - private Hashtable resourceCache = new Hashtable(); + private Hashtable<String, Object> resourceCache = new Hashtable<>(); private boolean iszip = true; private URL url = null; private boolean cache = true; @@ -147,7 +147,7 @@ public class URLResourceReader { /** * Returns an Enumeration of all "known" resource names. */ - public Enumeration getResourceNames() { + public Enumeration<String> getResourceNames() { return resourceCache.keys(); } @@ -188,6 +188,7 @@ public class URLResourceReader { resourceCache = null; } + @Override public String toString() { return url.toString(); } diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/ValueConverter.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/ValueConverter.java index 3d995e5..551e4ce 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/ValueConverter.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/internal/ValueConverter.java @@ -177,7 +177,7 @@ public class ValueConverter { anObject = preprocess(anObject); if (anObject instanceof Number) { - return new Short(((Number) anObject).shortValue()); + return Short.valueOf(((Number) anObject).shortValue()); } try { @@ -194,16 +194,16 @@ public class ValueConverter { static public Integer getInteger(Object anObject) { if (anObject == null) - return new Integer(0); + return Integer.valueOf(0); if ("".equals(anObject)) - return new Integer(0); + return Integer.valueOf(0); if (anObject instanceof Integer) return (Integer) anObject; anObject = preprocess(anObject); if (anObject instanceof Number) { - return new Integer(((Number) anObject).intValue()); + return Integer.valueOf(((Number) anObject).intValue()); } try { @@ -220,16 +220,16 @@ public class ValueConverter { static public Long getLong(Object anObject) { if (anObject == null) - return new Long(0); + return Long.valueOf(0); if ("".equals(anObject)) - return new Long(0); + return Long.valueOf(0); if (anObject instanceof Long) return (Long) anObject; anObject = preprocess(anObject); if (anObject instanceof Number) { - return new Long(((Number) anObject).longValue()); + return Long.valueOf(((Number) anObject).longValue()); } try { @@ -246,16 +246,16 @@ public class ValueConverter { static public Double getDouble(Object anObject) { if (anObject == null) - return new Double(0.0); + return Double.valueOf(0.0); if ("".equals(anObject)) - return new Double(0); + return Double.valueOf(0); if (anObject instanceof Double) return (Double) anObject; anObject = preprocess(anObject); if (anObject instanceof Number) { - return new Double(((Number) anObject).doubleValue()); + return Double.valueOf(((Number) anObject).doubleValue()); } try { @@ -272,16 +272,16 @@ public class ValueConverter { static public Float getFloat(Object anObject) { if (anObject == null) - return new Float(0.0); + return Float.valueOf(0.0f); if ("".equals(anObject)) - return new Float(0.0); + return Float.valueOf(0.0f); if (anObject instanceof Float) return (Float) anObject; anObject = preprocess(anObject); if (anObject instanceof Number) { - return new Float(((Number) anObject).floatValue()); + return Float.valueOf(((Number) anObject).floatValue()); } try { @@ -298,18 +298,18 @@ public class ValueConverter { static public Character getCharacter(Object anObject) { if (anObject == null) - return new Character((char) 0); + return Character.valueOf((char) 0); if (anObject instanceof Character) return (Character) anObject; anObject = preprocess(anObject); if (anObject instanceof Number) { - return new Character((char) ((Number) anObject).byteValue()); + return Character.valueOf((char) ((Number) anObject).byteValue()); } try { - return new Character(anObject.toString().charAt(0)); + return Character.valueOf(anObject.toString().charAt(0)); } catch (Exception exc) { return null; } @@ -322,16 +322,16 @@ public class ValueConverter { static public Byte getByte(Object anObject) { if (anObject == null) - return new Byte(Byte.MIN_VALUE); + return Byte.valueOf(Byte.MIN_VALUE); if ("".equals(anObject)) - return new Byte(Byte.MIN_VALUE); + return Byte.valueOf(Byte.MIN_VALUE); if (anObject instanceof Byte) return (Byte) anObject; anObject = preprocess(anObject); if (anObject instanceof Number) { - return new Byte(((Number) anObject).byteValue()); + return Byte.valueOf(((Number) anObject).byteValue()); } try { @@ -364,14 +364,14 @@ public class ValueConverter { return (Boolean) anObject; } if (anObject instanceof Number) { - return new Boolean(((Number) anObject).doubleValue() == 0.0); + return Boolean.valueOf(((Number) anObject).doubleValue() == 0.0); } if (anObject instanceof String) { if (anObject.toString().toLowerCase().equals("yes")) { return Boolean.TRUE; } - return new Boolean((String) anObject); + return Boolean.valueOf((String) anObject); } return null; @@ -396,24 +396,25 @@ public class ValueConverter { * in any other way, resorts to creating a new collection of the specified type * containing the specified object. */ - static public Collection getCollection(Object anObject, Class aCollectionClass) { + @SuppressWarnings("unchecked") + static public Collection<?> getCollection(Object anObject, Class<?> aCollectionClass) { if (anObject == null) return null; if (aCollectionClass.isAssignableFrom(anObject.getClass())) { - return (Collection) anObject; + return (Collection<?>) anObject; } - Collection converted = null; + Collection<Object> converted = null; // convert to collection class if (anObject instanceof Collection) { - converted = (Collection) anObject; + converted = (Collection<Object>) anObject; } else // try to convert an array if (anObject.getClass().isArray()) { try { int length = Array.getLength(anObject); - converted = new LinkedList(); + converted = new LinkedList<>(); for (int i = 0; i < length; i++) { converted.add(Array.get(anObject, i)); } @@ -423,25 +424,25 @@ public class ValueConverter { } else // convert map values to collection and pass through if (anObject instanceof Map) { - converted = ((Map) anObject).values(); + converted = ((Map<?, Object>) anObject).values(); } // fall back on list containing the object if (converted == null) { - converted = new LinkedList(); + converted = new LinkedList<>(); converted.add(anObject); } - Collection result = null; + Collection<Object> result = null; if (converted != null) { try { // collections required to have the copy constructor. - Constructor ctor = aCollectionClass.getConstructor(new Class[] { Collection.class }); - result = (Collection) ctor.newInstance(new Object[] { converted }); + Constructor<?> ctor = aCollectionClass.getConstructor(new Class[] { Collection.class }); + result = (Collection<Object>) ctor.newInstance(new Object[] { converted }); } catch (Exception exc) { try { - result = new LinkedList(); + result = new LinkedList<>(); result.addAll(converted); } catch (Exception exc2) { // all attempts failed @@ -456,7 +457,8 @@ public class ValueConverter { /** * Convert the object to the specified array type. */ - static public Object getArray(Object anObject, Class anArrayClass) { + @SuppressWarnings("unchecked") + static public Object getArray(Object anObject, Class<?> anArrayClass) { if (anObject == null) return null; @@ -475,14 +477,14 @@ public class ValueConverter { } // convert map values to collection and pass through if (anObject instanceof Map) { - anObject = ((Map) anObject).values(); + anObject = ((Map<?, Object>) anObject).values(); } // try to convert a collection if (anObject instanceof Collection) { try { - int length = ((Collection) anObject).size(); + int length = ((Collection<?>) anObject).size(); Object result = Array.newInstance(anArrayClass.getComponentType(), length); - Iterator it = ((Collection) anObject).iterator(); + Iterator<?> it = ((Collection<?>) anObject).iterator(); for (int i = 0; i < length; i++) { Array.set(result, i, it.next()); } @@ -545,12 +547,12 @@ public class ValueConverter { public static Object invert(Object anObject) { if (anObject == null) return null; - Class aClass = anObject.getClass(); + Class<?> aClass = anObject.getClass(); if (((anObject instanceof Number) && !(anObject instanceof Byte) && !(anObject instanceof Character)) || (aClass == short.class) || (aClass == int.class) || (aClass == long.class) || (aClass == float.class) || (aClass == double.class)) { - return convertObjectToClass(new Double(getDoubleValue(anObject) * -1), aClass); + return convertObjectToClass(Double.valueOf(getDoubleValue(anObject) * -1), aClass); } Boolean converted = getBoolean(anObject); diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java index 9c77d45..3d39fc0 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/access/EOModel.java @@ -44,8 +44,8 @@ public class EOModel { // This array contains dictionaries with "className" and "name" protected NSMutableArray _entities = new NSMutableArray(); - protected NSMutableDictionary _entitiesByName = new NSMutableDictionary(); - protected NSMutableDictionary _entitiesByClass = new NSMutableDictionary(); + protected NSMutableDictionary<String, EOEntity> _entitiesByName = new NSMutableDictionary<>(); + protected NSMutableDictionary<String, EOEntity> _entitiesByClass = new NSMutableDictionary<>(); protected NSDictionary _connectionDictionary = NSDictionary.EmptyDictionary; protected String _adaptorName = "JDBC"; protected NSMutableDictionary _prototypesByName = new NSMutableDictionary(); @@ -85,7 +85,7 @@ public class EOModel { } catch (IOException e) { throw new IllegalArgumentException("Cannot read index.eomodeld"); } - NSDictionary d = NSPropertyListSerialization.dictionaryForString(x); + NSDictionary<Object, Object> d = NSPropertyListSerialization.dictionaryForString(x); String version = (String) d.objectForKey("EOModelVersion"); if (version == null || !version.startsWith("2.")) throw new IllegalArgumentException("Invalid eomodel version: " + version); diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOEditingContext.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOEditingContext.java index 8342722..defacb1 100644 --- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOEditingContext.java +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOEditingContext.java @@ -1490,7 +1490,8 @@ public class EOEditingContext extends EOObjectStore implements EOObserving { NSNotificationCenter.defaultCenter() .postNotification(new NSNotification(InvalidatedAllObjectsInStoreNotification, this)); } else if (EOGlobalID.GlobalIDChangedNotification.equals(aNotification.name())) { - NSDictionary<EOGlobalID, ?> userInfo = aNotification.userInfo(); + @SuppressWarnings("unchecked") + NSDictionary<EOGlobalID, ?> userInfo = (NSDictionary<EOGlobalID, ?>) aNotification.userInfo(); // if any keys in userInfo are registered ids, // re-register with new permanent values. diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/TypedData.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/TypedData.java new file mode 100644 index 0000000..e732cfd --- /dev/null +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/TypedData.java @@ -0,0 +1,13 @@ +package net.wotonomy.web; + +import net.wotonomy.foundation.NSData; + +final class TypedData { + String type; + NSData data; + + public TypedData(String aType, NSData aData) { + type = aType; + data = aData; + } +}
\ No newline at end of file diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java index 6d0dfc1..570a97d 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java @@ -20,6 +20,7 @@ package net.wotonomy.web; import java.lang.reflect.Constructor; import java.util.List; +import java.util.Locale; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; @@ -593,8 +594,8 @@ public class WOApplication extends HttpServlet { /** * Returns either a dynamic element or a component for the specified name. */ - public WOElement dynamicElementWithName(String anElementName, NSDictionary anAssociationMap, WOElement aBodyElement, - List aLanguageList) { + public WOElement dynamicElementWithName(String anElementName, NSDictionary<String, Object> anAssociationMap, WOElement aBodyElement, + List<Locale> aLanguageList) { WOElement element = null; Class<? extends WODynamicElement> c = null; try { diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.java index 9d35ab4..a2a6734 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponentRequestHandler.java @@ -26,6 +26,7 @@ package net.wotonomy.web; * @version $Revision: 905 $ */ public class WOComponentRequestHandler extends WORequestHandler { + @Override public WOResponse handleRequest(WORequest aRequest) { WOApplication application = aRequest.application(); WOContext context = WOContext.contextWithRequest(aRequest); diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODirectAction.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODirectAction.java index 002e2a3..db3bbc8 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODirectAction.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODirectAction.java @@ -89,13 +89,15 @@ public class WODirectAction { * Returns the existing session, or null if no session exists. */ public WOSession existingSession() { - // FIXME: this is incorrect - // To do this correctly, probably want to use WOSessionStore + // TODO check this actually works + WOSessionStore store = WOSessionStore.serverSessionStore(); HttpSession session = request.servletRequest().getSession(); if (session == null) return null; - WOSession wosession = new WOSession(); - wosession.setServletSession(session); + WOSession wosession = store.restoreSessionWithID(session.getId(), request); + + //WOSession wosession = new WOSession(); + //wosession.setServletSession(session); return wosession; } @@ -105,9 +107,17 @@ public class WODirectAction { * ids/cookies, this will create a new session with each request. */ public WOSession session() { - // FIXME: this is incorrect - WOSession wosession = new WOSession(); - wosession.setServletSession(request.servletRequest().getSession(true)); + // TODO check this actually works + + WOSessionStore store = WOSessionStore.serverSessionStore(); + HttpSession session = request.servletRequest().getSession(); + if (session == null) + return null; + WOSession wosession = store.restoreSessionWithID(session.getId(), request); + if (wosession == null) { + wosession = new WOSession(); + wosession.setServletSession(request.servletRequest().getSession(true)); + } return wosession; } @@ -150,7 +160,7 @@ public class WODirectAction { * this object with matching names whose type is NSArray or is convertable from * a Collection. */ - public void takeFormValueArraysForKeyArray(NSArray anArray) { + public void takeFormValueArraysForKeyArray(NSArray<Object> anArray) { if (anArray == null) return; @@ -190,14 +200,14 @@ public class WODirectAction { * Assigns the form values for the specified keys to properties on this object * with matching names. */ - public void takeFormValuesForKeyArray(NSArray anArray) { + public void takeFormValuesForKeyArray(NSArray<? extends Object> anArray) { if (anArray == null) return; Method m; Object key; Object value; - java.util.Enumeration<Object> e = anArray.objectEnumerator(); + java.util.Enumeration<? extends Object> e = anArray.objectEnumerator(); while (e.hasMoreElements()) { key = e.nextElement(); value = request.formValueForKey(key.toString()); diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODirectActionRequestHandler.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODirectActionRequestHandler.java index 77a5428..9a3fcc3 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODirectActionRequestHandler.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODirectActionRequestHandler.java @@ -46,7 +46,7 @@ public class WODirectActionRequestHandler extends WORequestHandler { String className = "DirectAction"; String actionName = "default"; - NSArray path = aRequest.requestHandlerPathArray(); + NSArray<String> path = aRequest.requestHandlerPathArray(); if (path.count() > 0) { className = path.objectAtIndex(0).toString(); if (path.count() > 1) { @@ -85,7 +85,7 @@ public class WODirectActionRequestHandler extends WORequestHandler { try { if (response == null) { - Class c = null; + Class<? extends WODirectAction> c = null; c = application.getLocalClass(className); if ((c == null) && (path.count() == 1)) { actionName = className; @@ -95,7 +95,7 @@ public class WODirectActionRequestHandler extends WORequestHandler { if (c == null) { throw new RuntimeException("Could not find class named \"" + className + "\": "); } - java.lang.reflect.Constructor ctor = c.getConstructor(new Class[] { WORequest.class }); + java.lang.reflect.Constructor<? extends WODirectAction> ctor = c.getConstructor(new Class[] { WORequest.class }); WODirectAction action = (WODirectAction) ctor.newInstance(new Object[] { aRequest }); action.context = context; // HACK: how else can action call pageWithName? diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODynamicElement.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODynamicElement.java index 6cf7acd..8cae72c 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODynamicElement.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODynamicElement.java @@ -39,14 +39,14 @@ public abstract class WODynamicElement extends WOElement { private static final long serialVersionUID = -5383805382837136590L; protected String name; protected WOElement rootElement; - protected NSDictionary associations; + protected NSDictionary<String, Object> associations; /** * The default constructor. */ protected WODynamicElement() { name = null; - associations = new NSMutableDictionary(); + associations = new NSMutableDictionary<>(); rootElement = null; } @@ -57,7 +57,7 @@ public abstract class WODynamicElement extends WOElement { * and the values are associations to be applied to the context's current * component. */ - public WODynamicElement(String aName, NSDictionary anAssociationMap, WOElement aRootElement) { + public WODynamicElement(String aName, NSDictionary<String, Object> anAssociationMap, WOElement aRootElement) { this(); name = aName; associations = anAssociationMap; @@ -84,9 +84,9 @@ public abstract class WODynamicElement extends WOElement { * @param c The component where the values of the properties have to be * retrieved from. */ - Map urlFields(WOComponent c) { - HashMap map = new HashMap(associations.count()); - Enumeration enumeration = associations.keyEnumerator(); + Map<String, Object> urlFields(WOComponent c) { + HashMap<String, Object> map = new HashMap<>(associations.count()); + Enumeration<String> enumeration = associations.keyEnumerator(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); if (key.charAt(0) == '?') { @@ -147,8 +147,8 @@ public abstract class WODynamicElement extends WOElement { * @param standardProperties An array of Strings with all the associations that * should be excluded from the resulting string. */ - String additionalHTMLProperties(WOComponent c, NSArray standardProperties) { - Enumeration enumeration = associations.keyEnumerator(); + String additionalHTMLProperties(WOComponent c, NSArray<String> standardProperties) { + Enumeration<String> enumeration = associations.keyEnumerator(); StringBuffer buf = new StringBuffer(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WORequest.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WORequest.java index 3991b34..b0acfff 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WORequest.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WORequest.java @@ -330,9 +330,9 @@ public class WORequest extends WOResponse { /** * Returns a dictionary containing all the key-value mappings in the request. */ - public NSDictionary formValues() { - NSMutableDictionary result = new NSMutableDictionary(); - java.util.Enumeration e = request.getParameterNames(); + public NSDictionary<String, NSArray<String>> formValues() { + NSMutableDictionary<String, NSArray<String>> result = new NSMutableDictionary<>(); + java.util.Enumeration<String> e = request.getParameterNames(); String key; while (e.hasMoreElements()) { key = e.nextElement().toString(); @@ -353,9 +353,9 @@ public class WORequest extends WOResponse { * Returns an array of cookie values for the specified key in no particular * order. */ - public NSArray cookieValuesForKey(String aKey) { + public NSArray<String> cookieValuesForKey(String aKey) { // TODO: Test this logic. - NSMutableArray result = new NSMutableArray(); + NSMutableArray<String> result = new NSMutableArray<>(); Cookie[] cookies = request.getCookies(); if (cookies == null) return result; @@ -391,19 +391,19 @@ public class WORequest extends WOResponse { /** * Returns a dictionary of cookie key-value mappings. */ - public NSDictionary cookieValues() { + public NSDictionary<String, NSArray<String>> cookieValues() { // TODO: Test this logic. - NSMutableDictionary result = new NSMutableDictionary(); + NSMutableDictionary<String, NSArray<String>> result = new NSMutableDictionary<>(); Cookie[] cookies = request.getCookies(); if (cookies == null) return result; - NSMutableArray value; + NSMutableArray<String> value; for (int i = 0; i < cookies.length; i++) { - value = (NSMutableArray) result.objectForKey(cookies[i].getName()); + value = (NSMutableArray<String>) result.objectForKey(cookies[i].getName()); if (value == null) { - value = new NSMutableArray(); - result.setObjectForKey(cookies[i].getValue(), cookies[i].getName()); + value = new NSMutableArray<>(); + result.setObjectForKey(value, cookies[i].getName()); } value.addObject(cookies[i].getValue()); } diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResourceManager.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResourceManager.java index 5941ad2..170af3b 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResourceManager.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResourceManager.java @@ -44,20 +44,20 @@ import net.wotonomy.foundation.internal.PropertyListParser; * @version $Revision: 905 $ */ public class WOResourceManager { - private NSMutableDictionary resourceCache; - private NSMutableDictionary dynamicDataCache; - private NSMutableDictionary stringTableCache; - private Map localeCache; // used for wo-style i18n + private NSMutableDictionary<String, Object> resourceCache; + private NSMutableDictionary<String, TypedData> dynamicDataCache; + private NSMutableDictionary<String, Object> stringTableCache; + private Map<String, Locale> localeCache; // used for wo-style i18n private Locale californiaLocale; // used for wo-style i18n /** * Constructor is only accessible to subclasses. */ protected WOResourceManager() { - resourceCache = new NSMutableDictionary(); - dynamicDataCache = new NSMutableDictionary(); - stringTableCache = new NSMutableDictionary(); - localeCache = new HashMap(); + resourceCache = new NSMutableDictionary<>(); + dynamicDataCache = new NSMutableDictionary<>(); + stringTableCache = new NSMutableDictionary<>(); + localeCache = new HashMap<>(); californiaLocale = new Locale("en", "US"); localeCache.put("en", californiaLocale); } @@ -67,7 +67,7 @@ public class WOResourceManager { * retrieved by this method will be placed in the resource manager's global * cache. */ - public byte[] bytesForResourceNamed(String aFileName, String aFrameworkName, NSArray aLanguagesList) { + public byte[] bytesForResourceNamed(String aFileName, String aFrameworkName, NSArray<Locale> aLanguagesList) { String mash = aFileName + aFrameworkName; if (aLanguagesList != null) { mash = mash + aLanguagesList.componentsJoinedByString(":"); @@ -153,7 +153,7 @@ public class WOResourceManager { * * @deprecated Use inputStreamForResourceNamed instead. */ - public String pathForResourceNamed(String aResourceName, String aFrameworkName, NSArray aLanguagesList) { + public String pathForResourceNamed(String aResourceName, String aFrameworkName, NSArray<Locale> aLanguagesList) { throw new RuntimeException("ResourceManager.pathForResourceNamed: deprecated"); } @@ -196,7 +196,7 @@ public class WOResourceManager { * doesn't exist, aDefaultValue is returned. */ public String stringForKey(String aKey, String aFileName, String aDefaultValue, String aFrameworkName, - NSArray aLanguagesList) { + NSArray<Locale> aLanguagesList) { String mash = aFileName + aFrameworkName; if (aLanguagesList != null) { @@ -241,7 +241,7 @@ public class WOResourceManager { /** * Returns a url that invokes the resource manager for the specified resource. */ - public String urlForResourceNamed(String aResourceName, String aFrameworkName, NSArray aLanguagesList, + public String urlForResourceNamed(String aResourceName, String aFrameworkName, NSArray<Locale> aLanguagesList, WORequest aRequest) { StringBuffer buffer = new StringBuffer(); if (aFrameworkName == null) { @@ -264,7 +264,7 @@ public class WOResourceManager { * be put in the resource manager's global cache. */ public InputStream inputStreamForResourceNamed(String aResourceName, String aFrameworkName, - NSArray aLanguagesList) { + NSArray<Locale> aLanguagesList) { if (aResourceName == null) return null; InputStream result = null; @@ -285,8 +285,8 @@ public class WOResourceManager { if (aLanguagesList != null) { String language; Locale locale; - HashSet tried = new HashSet(5); - Enumeration e = aLanguagesList.objectEnumerator(); + HashSet<String> tried = new HashSet<>(5); + Enumeration<Locale> e = aLanguagesList.objectEnumerator(); while (e.hasMoreElements() && result == null) { language = e.nextElement().toString(); @@ -349,16 +349,6 @@ public class WOResourceManager { } return input; } - - private static final class TypedData { - String type; - NSData data; - - public TypedData(String aType, NSData aData) { - type = aType; - data = aData; - } - } } /* diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResourceRequestHandler.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResourceRequestHandler.java index f611149..876052b 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResourceRequestHandler.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResourceRequestHandler.java @@ -32,15 +32,18 @@ import net.wotonomy.foundation.NSMutableDictionary; * @version $Revision: 905 $ */ public class WOResourceRequestHandler extends WORequestHandler { - private NSMutableDictionary resourceCache; + // TODO: should actually use this cache + @SuppressWarnings("unused") + private NSMutableDictionary<String, Object> resourceCache; private WOResourceManager resourceManager; public WOResourceRequestHandler() { // TODO: should probably have some kind of limit on the cache - resourceCache = new NSMutableDictionary(); + resourceCache = new NSMutableDictionary<>(); resourceManager = WOApplication.application().resourceManager(); } + @Override public WOResponse handleRequest(WORequest aRequest) { WOResponse response = new WOResponse(); @@ -48,7 +51,7 @@ public class WOResourceRequestHandler extends WORequestHandler { // TODO: this is just to get things working... String framework = null; - Enumeration e = aRequest.requestHandlerPathArray().objectEnumerator(); + Enumeration<String> e = aRequest.requestHandlerPathArray().objectEnumerator(); if (e.hasMoreElements()) { framework = e.nextElement().toString(); if (framework.equals("application")) { diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOServletSessionStore.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOServletSessionStore.java index 3de29b7..aadc077 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOServletSessionStore.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOServletSessionStore.java @@ -45,6 +45,7 @@ public class WOServletSessionStore extends WOSessionStore { * the servlet container to dispose of the HttpSession which contains our * WOSession. */ + @Override public WOSession removeSessionWithID(String sessionID) { return null; } @@ -54,6 +55,7 @@ public class WOServletSessionStore extends WOSessionStore { * parameter is ignored, and the session is removed from the store until * saveSessionForContext is called. */ + @Override public WOSession restoreSessionWithID(String sessionID, WORequest aRequest) { WOSession result = null; HttpSession servletSession = aRequest.servletRequest().getSession(); @@ -107,6 +109,7 @@ public class WOServletSessionStore extends WOSessionStore { /** * Places the context's session into the store. */ + @Override public void saveSessionForContext(WOContext context) { // System.out.println( "saveSessionForContext: " + context + " : " + // context.session() ); @@ -126,6 +129,7 @@ public class WOServletSessionStore extends WOSessionStore { loader = aClassLoader; } + @Override protected Class<?> resolveClass(ObjectStreamClass v) throws IOException, ClassNotFoundException { return loader.loadClass(v.getName()); } diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOSession.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOSession.java index c8c1f4d..d0f91e9 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOSession.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOSession.java @@ -20,15 +20,13 @@ package net.wotonomy.web; import java.io.Serializable; import java.util.LinkedList; -import java.util.List; -import java.util.Map; import jakarta.servlet.http.HttpSession; + import net.wotonomy.control.EOEditingContext; import net.wotonomy.control.KeyValueCodingUtilities; import net.wotonomy.foundation.NSArray; import net.wotonomy.foundation.NSDate; -import net.wotonomy.foundation.NSDictionary; import net.wotonomy.foundation.NSKeyValueCodingAdditions; import net.wotonomy.foundation.NSKeyValueCodingSupport; import net.wotonomy.foundation.NSMutableArray; @@ -58,16 +56,15 @@ public class WOSession implements Serializable, NSKeyValueCodingAdditions { // FIXME: transient until ec's implement serializable private transient EOEditingContext defaultEditingContext; - private NSMutableDictionary state; - private NSMutableDictionary pages; - private NSMutableDictionary permanentPages; - private NSMutableArray stateStack; - private NSMutableArray pageStack; - private NSMutableArray permanentPageStack; + private NSMutableDictionary<String, Object> state; + private NSMutableDictionary<String, Object> pages; + private NSMutableDictionary<String, Object> permanentPages; + private NSMutableArray<String> pageStack; + private NSMutableArray<String> permanentPageStack; private boolean terminating; // used by WOResourceManager to cache dynamic resources - transient NSMutableDictionary dynamicDataCache; + transient NSMutableDictionary<String, TypedData> dynamicDataCache; public static final String WOSessionDidTimeOutNotification = "WOSessionDidTimeOutNotification"; public static final String WOSessionDidRestoreNotification = "WOSessionDidRestoreNotification"; @@ -78,12 +75,12 @@ public class WOSession implements Serializable, NSKeyValueCodingAdditions { */ public WOSession() { session = null; - state = new NSMutableDictionary(); - pages = new NSMutableDictionary(); - permanentPages = new NSMutableDictionary(); - stateStack = NSMutableArray.mutableArrayBackedByList(new LinkedList()); - pageStack = NSMutableArray.mutableArrayBackedByList(new LinkedList()); - permanentPageStack = NSMutableArray.mutableArrayBackedByList(new LinkedList()); + state = new NSMutableDictionary<>(); + pages = new NSMutableDictionary<>(); + permanentPages = new NSMutableDictionary<>(); + NSMutableArray.mutableArrayBackedByList(new LinkedList<>()); + pageStack = NSMutableArray.mutableArrayBackedByList(new LinkedList<>()); + permanentPageStack = NSMutableArray.mutableArrayBackedByList(new LinkedList<>()); defaultEditingContext = null; terminating = false; } @@ -215,7 +212,7 @@ public class WOSession implements Serializable, NSKeyValueCodingAdditions { * preference. The application will be responsible for localizing the content * based on the languages found in this array. */ - public void setLanguages(NSArray anArray) { + public void setLanguages(NSArray<Object> anArray) { throw new RuntimeException("Not implemented yet."); } @@ -224,7 +221,7 @@ public class WOSession implements Serializable, NSKeyValueCodingAdditions { * preference. The application will be responsible for localizing the content * based on the languages found in this array. */ - public NSArray languages() { + public NSArray<Object> languages() { throw new RuntimeException("Not implemented yet."); } @@ -303,7 +300,7 @@ public class WOSession implements Serializable, NSKeyValueCodingAdditions { * Returns a list of pages accessed by this session in order of their access and * named by calling WOComponent.descriptionForResponse. */ - public NSArray statistics() { + public NSArray<Object> statistics() { throw new RuntimeException("Not implemented yet."); } @@ -409,24 +406,19 @@ public class WOSession implements Serializable, NSKeyValueCodingAdditions { // interface NSKeyValueCodingAdditions + @Override public Object valueForKeyPath(String aPath) { // currently key value coding support also handles keypaths return valueForKey(aPath); } + @Override public void takeValueForKeyPath(Object aValue, String aPath) { // currently key value coding support also handles keypaths takeValueForKey(aValue, aPath); } - public NSDictionary valuesForKeys(List aKeyList) { - throw new RuntimeException("Not implemented yet."); - } - - public void takeValuesFromDictionary(Map aValueMap) { - throw new RuntimeException("Not implemented yet."); - } - + @Override public Object valueForKey(String aKey) { // System.out.println( "valueForKey: " + aKey + "->" + this ); Object result = objectForKey(aKey); if (result == null) @@ -434,11 +426,13 @@ public class WOSession implements Serializable, NSKeyValueCodingAdditions { return result; } + @Override public void takeValueForKey(Object aValue, String aKey) { // System.out.println( "takeValueForKey: " + aKey + " : " // + aValue + "->" + this ); setObjectForKey(aValue, aKey); } + @Override public Object storedValueForKey(String aKey) { Object result = objectForKey(aKey); if (result == null) @@ -446,18 +440,22 @@ public class WOSession implements Serializable, NSKeyValueCodingAdditions { return result; } + @Override public void takeStoredValueForKey(Object aValue, String aKey) { setObjectForKey(aValue, aKey); } + @Override public Object handleQueryWithUnboundKey(String aKey) { return NSKeyValueCodingSupport.handleQueryWithUnboundKey(this, aKey); } + @Override public void handleTakeValueForUnboundKey(Object aValue, String aKey) { NSKeyValueCodingSupport.handleTakeValueForUnboundKey(this, aValue, aKey); } + @Override public void unableToSetNullForKey(String aKey) { NSKeyValueCodingSupport.unableToSetNullForKey(this, aKey); } diff --git a/wotonomy-web-test/src/main/java/DirectAction.java b/wotonomy-web-test/src/main/java/DirectAction.java index f5dc851..4229275 100644 --- a/wotonomy-web-test/src/main/java/DirectAction.java +++ b/wotonomy-web-test/src/main/java/DirectAction.java @@ -1,8 +1,5 @@ -import java.io.PrintStream; import java.util.Date; -import net.wotonomy.foundation.NSArray; -import net.wotonomy.foundation.NSDictionary; import net.wotonomy.web.*; public class DirectAction extends WODirectAction { @@ -15,7 +12,8 @@ public class DirectAction extends WODirectAction { System.out.println("DirectAction()"); } - public WOActionResults defaultAction() { + @Override + public WOActionResults defaultAction() { return pageWithName("Main"); } |
