Modified: river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/RFC3986URLClassLoader.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/RFC3986URLClassLoader.java?rev=1609703&r1=1609702&r2=1609703&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/RFC3986URLClassLoader.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/RFC3986URLClassLoader.java Fri Jul 11 12:01:53 2014 @@ -23,7 +23,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -34,7 +33,6 @@ import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.JarURLConnection; import java.net.MalformedURLException; -import java.net.SocketPermission; import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; @@ -45,7 +43,6 @@ import java.security.AccessControlContex import java.security.AccessController; import java.security.CodeSource; import java.security.Permission; -import java.security.PermissionCollection; import java.security.PrivilegedAction; import java.security.cert.Certificate; import java.util.ArrayList; @@ -131,12 +128,9 @@ public class RFC3986URLClassLoader exten String codebaseAnnotationProperty = null; String prop = AccessController.doPrivileged( new GetPropertyAction("net.jini.loader.codebaseAnnotation")); - if (prop != null && prop.trim().length() > 0) { - codebaseAnnotationProperty = prop; - } - if (codebaseAnnotationProperty == null) uri = true; - else if (Uri.asciiStringsUpperCaseEqual(codebaseAnnotationProperty, "URL")) uri = false; - else uri = true; + if (prop != null && prop.trim().length() > 0) codebaseAnnotationProperty = prop; + uri = codebaseAnnotationProperty == null || + !Uri.asciiStringsUpperCaseEqual(codebaseAnnotationProperty, "URL"); } private final List<URL> originalUrls; // Copy on Write @@ -367,10 +361,20 @@ public class RFC3986URLClassLoader exten } } // The package is defined and isn't sealed, safe to define class. - if (uri) return loader.defineClass(origName, clBuf, 0, clBuf.length, - new UriCodeSource(codeSourceUrl, (Certificate[]) null, null)); - return loader.defineClass(origName, clBuf, 0, clBuf.length, - new CodeSource(codeSourceUrl, (Certificate[]) null)); + if (uri) return loader.defineClass( + origName, + clBuf, + 0, + clBuf != null ? clBuf.length: 0, + new UriCodeSource(codeSourceUrl, (Certificate[]) null, null) + ); + return loader.defineClass( + origName, + clBuf, + 0, + clBuf != null ? clBuf.length: 0, + new CodeSource(codeSourceUrl, (Certificate[]) null) + ); } URL findResource(String name) { @@ -460,8 +464,8 @@ public class RFC3986URLClassLoader exten urls.remove(url); urls = new ArrayList<URL>(urls); // Defensive copy to avoid sync } - for (URL url : urls) { - URLHandler h = getSubHandler(url); + for (URL u : urls) { + URLHandler h = getSubHandler(u); if (h != null) { h.findResources(name, resources); } @@ -499,8 +503,8 @@ public class RFC3986URLClassLoader exten urls.remove(url); urls = new ArrayList<URL>(urls); // Defensive copy. } - for (URL url : urls) { - URLHandler h = getSubHandler(url); + for (URL u : urls) { + URLHandler h = getSubHandler(u); if (h != null) { Class<?> res = h.findClass(packageName, name, origName); if (res != null) { @@ -557,7 +561,13 @@ public class RFC3986URLClassLoader exten CodeSource codeS = uri ? new UriCodeSource(codeSourceUrl, entry.getCertificates(),null) : new CodeSource(codeSourceUrl, entry.getCertificates()); - return loader.defineClass(origName, clBuf, 0, clBuf.length, codeS); + return loader.defineClass( + origName, + clBuf, + 0, + clBuf != null ? clBuf.length: 0, + codeS + ); } URL findResourceInOwn(String name) { @@ -585,8 +595,8 @@ public class RFC3986URLClassLoader exten urls.remove(url); urls = new ArrayList<URL>(urls); // Defensive copy. } - for (URL url : urls) { - URLHandler h = getSubHandler(url); + for (URL u : urls) { + URLHandler h = getSubHandler(u); if (h != null) { res = h.findResource(name); if (res != null) { @@ -627,10 +637,10 @@ public class RFC3986URLClassLoader exten } private URLHandler createURLSubJarHandler(URL url) { - String prefixName; + String prfixName; String file = url.getFile(); if (url.getFile().endsWith("!/")) { //$NON-NLS-1$ - prefixName = ""; + prfixName = ""; } else { int sepIdx = file.lastIndexOf("!/"); //$NON-NLS-1$ if (sepIdx == -1) { @@ -638,7 +648,7 @@ public class RFC3986URLClassLoader exten return null; } sepIdx += 2; - prefixName = file.substring(sepIdx); + prfixName = file.substring(sepIdx); } try { URL jarURL = ((JarURLConnection) url @@ -646,8 +656,8 @@ public class RFC3986URLClassLoader exten JarURLConnection juc = (JarURLConnection) new URL( "jar", "", //$NON-NLS-1$ //$NON-NLS-2$ jarURL.toExternalForm() + "!/").openConnection(); //$NON-NLS-1$ - JarFile jf = juc.getJarFile(); - URLJarHandler jarH = new URLJarHandler(url, jarURL, jf, prefixName, loader); + JarFile jfile = juc.getJarFile(); + URLJarHandler jarH = new URLJarHandler(url, jarURL, jfile, prfixName, loader); // TODO : to think what we should do with indexes & manifest.class file here return jarH; } catch (IOException e) { @@ -771,14 +781,14 @@ public class RFC3986URLClassLoader exten UriCodeSource(URL url, Certificate [] certs, Collection<Permission> perms){ super(url, certs); - Uri uri = null; + Uri uRi = null; try { - uri = Uri.urlToUri(url); + uRi = Uri.urlToUri(url); } catch (URISyntaxException ex) { }//Ignore - this.uri = uri; + this.uri = uRi; int hash = 7; hash = 23 * hash + (this.uri != null ? this.uri.hashCode() : 0); - hash = 23 * hash + (certs != null ? certs.hashCode() : 0); + hash = 23 * hash + (certs != null ? Arrays.hashCode(certs) : 0); hashCode = hash; } @@ -787,6 +797,7 @@ public class RFC3986URLClassLoader exten return hashCode; } + @Override public boolean equals(Object o){ if (!(o instanceof UriCodeSource)) return false; if (uri == null) return super.equals(o); @@ -797,8 +808,8 @@ public class RFC3986URLClassLoader exten if ( mine == null && theirs == null) return true; if ( mine == null && theirs != null) return false; if ( mine != null && theirs == null) return false; - if (Arrays.asList(getCertificates()).equals(Arrays.asList(that.getCertificates()))) return true; - return false; + return (Arrays.asList(getCertificates()).equals( + Arrays.asList(that.getCertificates()))); } Object writeReplace() throws ObjectStreamException { @@ -873,6 +884,7 @@ public class RFC3986URLClassLoader exten public Enumeration<URL> findResources(final String name) throws IOException { List<URL> result = AccessController.doPrivileged( new PrivilegedAction<List<URL>>() { + @Override public List<URL> run() { List<URL> results = new LinkedList<URL>(); findResourcesImpl(name, results); @@ -985,6 +997,7 @@ public class RFC3986URLClassLoader exten * * @return the list of all known URLs of this instance. */ + @Override public URL[] getURLs() { return originalUrls.toArray(new URL[originalUrls.size()]); } @@ -1012,6 +1025,7 @@ public class RFC3986URLClassLoader exten final AccessControlContext context = AccessController.getContext(); RFC3986URLClassLoader sub = AccessController .doPrivileged(new PrivilegedAction<RFC3986URLClassLoader>() { + @Override public RFC3986URLClassLoader run() { return new SubURLClassLoader(urls, context); } @@ -1037,6 +1051,7 @@ public class RFC3986URLClassLoader exten final AccessControlContext context = AccessController.getContext(); RFC3986URLClassLoader sub = AccessController .doPrivileged(new PrivilegedAction<RFC3986URLClassLoader>() { + @Override public RFC3986URLClassLoader run() { return new SubURLClassLoader(urls, parentCl, context); } @@ -1079,17 +1094,17 @@ public class RFC3986URLClassLoader exten // capture the context of the thread that creates this URLClassLoader creationContext = context; int nbUrls = searchUrls.length; - List<URL> originalUrls = new ArrayList<URL>(nbUrls); + List<URL> origUrls = new ArrayList<URL>(nbUrls); handlerList = new ArrayList<URLHandler>(nbUrls); searchList = Collections.synchronizedList(new LinkedList<URL>()); for (int i = 0; i < nbUrls; i++) { - originalUrls.add(searchUrls[i]); + origUrls.add(searchUrls[i]); try { searchList.add(createSearchURL(searchUrls[i])); } catch (MalformedURLException e) { } } - this.originalUrls = new CopyOnWriteArrayList<URL>(originalUrls); + this.originalUrls = new CopyOnWriteArrayList<URL>(origUrls); } /** @@ -1111,6 +1126,7 @@ public class RFC3986URLClassLoader exten throws ClassNotFoundException { Class<?> cls = AccessController.doPrivileged( new PrivilegedAction<Class<?>>() { + @Override public Class<?> run() { return findClassImpl(clsName); } @@ -1167,6 +1183,7 @@ public class RFC3986URLClassLoader exten return null; } URL result = AccessController.doPrivileged(new PrivilegedAction<URL>() { + @Override public URL run() { return findResourceImpl(name); } @@ -1318,6 +1335,7 @@ public class RFC3986URLClassLoader exten * @throws IllegalArgumentException * if a package with the given name already exists. */ + @Override protected Package definePackage(String packageName, Manifest manifest, URL url) throws IllegalArgumentException { Attributes mainAttributes = manifest.getMainAttributes();
Modified: river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/URIEncoderDecoder.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/URIEncoderDecoder.java?rev=1609703&r1=1609702&r2=1609703&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/URIEncoderDecoder.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/URIEncoderDecoder.java Fri Jul 11 12:01:53 2014 @@ -18,15 +18,11 @@ package org.apache.river.api.net; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.util.HashMap; import java.util.Locale; import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.river.impl.Messages; @@ -35,7 +31,7 @@ import org.apache.river.impl.Messages; /** * This class is used to encode a string using the format required by {@code * application/x-www-form-urlencoded} MIME content type. It contains helper - * methods used by the URI class, and performs encoding and decoding in a + * methods used by the Uri class, and performs encoding and decoding in a * slightly different way than {@code URLEncoder} and {@code URLDecoder}. * @since 3.0.0 */ @@ -55,7 +51,7 @@ class URIEncoderDecoder { int l = legals.length; for (int i = 0; i< l; i++){ char ch = legals[i]; - byte[] bytes = new byte[0]; + byte[] bytes; try { bytes = new String(new char[] { ch }).getBytes(encoding); } catch (UnsupportedEncodingException ex) { @@ -109,12 +105,12 @@ class URIEncoderDecoder { continue; } - if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') - || (ch >= '0' && ch <= '9') || legal.indexOf(ch) > -1 -// || (ch > 127 -// && !Character.isSpaceChar(ch) && !Character -// .isISOControl(ch)) - )) { + if ( !((ch >= 'a' && ch <= 'z') + || (ch >= 'A' && ch <= 'Z') + || (ch >= '0' && ch <= '9') + || legal.indexOf(ch) > -1 ) + ) + { throw new URISyntaxException(s, Messages.getString("luni.7F"), i); //$NON-NLS-1$ } i++; @@ -157,13 +153,13 @@ class URIEncoderDecoder { StringBuilder buf = new StringBuilder(s.length() + 24); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); - if ( (ch >= 'a' && ch <= 'z') + if ( + (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || legal.indexOf(ch) > -1 -// || (ch > 127 && !Character.isSpaceChar(ch) && !Character -// .isISOControl(ch)) - ) { + ) + { buf.append(ch); } else { byte[] bytes = new String(new char[] { ch }).getBytes(encoding); Modified: river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/Uri.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/Uri.java?rev=1609703&r1=1609702&r2=1609703&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/Uri.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/Uri.java Fri Jul 11 12:01:53 2014 @@ -23,12 +23,6 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.util.Collections; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; import org.apache.river.impl.Messages; @@ -289,6 +283,8 @@ public final class Uri implements Compar /** Fixes windows file URI string by converting back slashes to forward * slashes and inserting a forward slash before the drive letter if it is * missing. No normalisation or modification of case is performed. + * @param uri String representation of URI + * @return fixed URI String */ public static String fixWindowsURI(String uri) { if (uri == null) return null; @@ -780,8 +776,9 @@ public final class Uri implements Compar * the URI this instance has to compare with. * @return the value representing the order of the two instances. */ + @Override public int compareTo(Uri uri) { - int ret = 0; + int ret; // compare schemes if (scheme == null && uri.scheme != null) { @@ -790,9 +787,7 @@ public final class Uri implements Compar return 1; } else if (scheme != null && uri.scheme != null) { ret = scheme.compareToIgnoreCase(uri.scheme); - if (ret != 0) { - return ret; - } + if (ret != 0) return ret; } // compare opacities @@ -920,6 +915,7 @@ public final class Uri implements Compar * * @param unescapedString * @return an RFC3986 compliant Uri. + * @throws java.net.URISyntaxException */ public static Uri escapeAndCreate(String unescapedString) throws URISyntaxException{ return new Uri(quoteComponent(unescapedString, allLegalUnescaped)); @@ -932,6 +928,7 @@ public final class Uri implements Compar * The escape character % is not re-encoded. * @param nonCompliantEscapedString * @return an RFC3986 compliant Uri. + * @throws java.net.URISyntaxException */ public static Uri parseAndCreate(String nonCompliantEscapedString) throws URISyntaxException{ return new Uri(quoteComponent(nonCompliantEscapedString, allLegal)); @@ -948,7 +945,7 @@ public final class Uri implements Compar return s; } - int index = 0, previndex = 0; + int index, previndex = 0; while ((index = s.indexOf('%', previndex)) != -1) { result.append(s.substring(previndex, index + 1)); // Convert to upper case ascii @@ -967,31 +964,7 @@ public final class Uri implements Compar private boolean equalsHexCaseInsensitive(String first, String second) { //Hex will always be upper case. if (first != null) return first.equals(second); - if (second != null) return false; - return true; -// if (first.indexOf('%') != second.indexOf('%')) { -// return first.equals(second); -// } -// -// int index = 0, previndex = 0; -// while ((index = first.indexOf('%', previndex)) != -1 -// && second.indexOf('%', previndex) == index) { -// boolean match = first.substring(previndex, index).equals( -// second.substring(previndex, index)); -// if (!match) { -// return false; -// } -// -// match = first.substring(index + 1, index + 3).equalsIgnoreCase( -// second.substring(index + 1, index + 3)); -// if (!match) { -// return false; -// } -// -// index += 3; -// previndex = index; -// } -// return first.substring(previndex).equals(second.substring(previndex)); + return second == null; } /** @@ -1038,8 +1011,6 @@ public final class Uri implements Compar || fileSchemeCaseInsensitiveOS // Upper case comparison required for Windows & VMS. && asciiStringsUpperCaseEqual(path, uri.path) -// path.toUpperCase(Locale.ENGLISH).equals( -// uri.path.toUpperCase(Locale.ENGLISH)) ))) { return false; @@ -1579,7 +1550,7 @@ public final class Uri implements Compar // break the path into segments and store in the list int current = 0; - int index2 = 0; + int index2; index = (pathlen > 0 && path.charAt(0) == '/') ? 1 : 0; while ((index2 = path.indexOf('/', index + 1)) != -1) { seglist[current++] = path.substring(index, index2); @@ -1712,18 +1683,18 @@ public final class Uri implements Compar } } - String query = relative.query; + String qry = relative.query; // the result URI is the remainder of the relative URI's path - String path = relativePath.substring(thisPath.length()); + String pth = relativePath.substring(thisPath.length()); return new Uri( null, null, - setSchemeSpecificPart(null, path, query), + setSchemeSpecificPart(null, pth, qry), null, null, null, -1, - path, - query, + pth, + qry, relative.fragment, false, false, @@ -1829,13 +1800,15 @@ public final class Uri implements Compar // ssp = [//authority][path][?query] StringBuilder ssp = new StringBuilder(); if (authority != null) { - ssp.append("//" + authority); //$NON-NLS-1$ + ssp.append("//"); //$NON-NLS-1$ + ssp.append(authority); } if (path != null) { ssp.append(path); } if (query != null) { - ssp.append("?" + query); //$NON-NLS-1$ + ssp.append("?"); //$NON-NLS-1$ + ssp.append(query); } // reset string, so that it can be re-calculated correctly when asked. return ssp.toString(); @@ -1934,11 +1907,13 @@ public final class Uri implements Compar result.append(authority); } else { if (userinfo != null) { - result.append(userinfo + "@"); //$NON-NLS-1$ + result.append(userinfo); //$NON-NLS-1$ + result.append("@"); } result.append(toAsciiLowerCase(host)); if (port != -1) { - result.append(":" + port); //$NON-NLS-1$ + result.append(":"); //$NON-NLS-1$ + result.append(port); } } } Modified: river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/UriParser.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/UriParser.java?rev=1609703&r1=1609702&r2=1609703&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/UriParser.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/UriParser.java Fri Jul 11 12:01:53 2014 @@ -18,9 +18,6 @@ package org.apache.river.api.net; import java.io.File; import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; import java.util.StringTokenizer; import org.apache.river.impl.Messages; @@ -104,7 +101,7 @@ final class UriParser { query = temp.substring(index + 1); temp.delete(index, temp.length()); validateQuery(uri, query, index2 + 1 + index); - if (query == "") query = null; + if ("".equals(query)) query = null; } // Authority and Path if (temp.length() >= 2 && temp.charAt(0) == fSlash && temp.charAt(1) == fSlash) { @@ -134,9 +131,6 @@ final class UriParser { authority = null; } // Authority validated by userinfo, host and port, later. -// else { -// validateAuthority(uri, authority, index1 + 3); -// } } else { // no authority specified String legal; @@ -222,21 +216,6 @@ final class UriParser { } } -// private void validateAuthority(String uri, String authority, int index) throws URISyntaxException { -// try { -// URIEncoderDecoder.validate(authority, "@[]" + Uri.someLegal); //$NON-NLS-1$ -// } catch (URISyntaxException e) { -// throw new URISyntaxException(uri, Messages.getString("luni.87", e.getReason()), index + e.getIndex()); -// } -// } -// -// private void validatePath(String uri, String path, int index) throws URISyntaxException { -// try { -// URIEncoderDecoder.validate(path, "/@" + Uri.someLegal); //$NON-NLS-1$ -// } catch (URISyntaxException e) { -// throw new URISyntaxException(uri, Messages.getString("luni.88", e.getReason()), index + e.getIndex()); -// } -// } private void validateSegment(String uri, String segment, int index, String legal) throws URISyntaxException { try { URIEncoderDecoder.validate(segment, legal); //$NON-NLS-1$ @@ -278,7 +257,7 @@ final class UriParser { } String temp; String tempUserinfo = null; - String tempHost = null; + String tempHost; int index; int hostindex = 0; int tempPort = -1; @@ -340,13 +319,6 @@ final class UriParser { } catch (URISyntaxException e) { throw new URISyntaxException(uri, Messages.getString("luni.8C", e.getReason()), index + e.getIndex()); } -// -// for (int i = 0; i < userinfo.length(); i++) { -// char ch = userinfo.charAt(i); -// if (ch == ']' || ch == '[') { -// throw new URISyntaxException(uri, Messages.getString("luni.8C"), index + i); -// } -// } } /** @@ -403,7 +375,7 @@ final class UriParser { return false; } } - if (!label.equals(host)) { + if ( label != null && !label.equals(host)) { char ch = label.charAt(0); if (ch >= '0' && ch <= '9') { return false; @@ -436,7 +408,7 @@ final class UriParser { if (num < 0 || num > 255) { return false; } - } catch (Exception e) { + } catch (NumberFormatException e) { return false; } return true; @@ -449,7 +421,7 @@ final class UriParser { int numberOfPeriods = 0; String word = ""; //$NON-NLS-1$ char c = 0; - char prevChar = 0; + char prevChar; int offset = 0; // offset for [] ip addresses if (length < 2) { return false; @@ -544,7 +516,7 @@ final class UriParser { // If we have an empty word at the end, it means we ended in // either a : or a . // If we did not end in :: then this is invalid - if (word == "" && ipAddress.charAt(length - 1 - offset) != ':' && ipAddress.charAt(length - 2 - offset) != ':') { + if (word.equals("") && ipAddress.charAt(length - 1 - offset) != ':' && ipAddress.charAt(length - 2 - offset) != ':') { return false; } } @@ -553,19 +525,12 @@ final class UriParser { private boolean isValidIP4Word(String word) { char c; - if (word.length() < 1 || word.length() > 3) { - return false; - } + if (word.length() < 1 || word.length() > 3) return false; for (int i = 0; i < word.length(); i++) { c = word.charAt(i); - if (!(c >= '0' && c <= '9')) { - return false; - } + if (!(c >= '0' && c <= '9')) return false; } - if (Integer.parseInt(word) > 255) { - return false; - } - return true; + return (Integer.parseInt(word) <= 255); } private boolean isValidHexChar(char c) { @@ -604,7 +569,7 @@ final class UriParser { // break the path into segments and store in the list int current = 0; - int index2 = 0; + int index2; index = (pathlen > 0 && path.charAt(0) == '/') ? 1 : 0; while ((index2 = path.indexOf('/', index + 1)) != -1) { seglist[current++] = path.substring(index, index2); @@ -681,13 +646,15 @@ final class UriParser { // ssp = [//authority][path][?query] StringBuilder ssp = new StringBuilder(); if (authority != null) { - ssp.append("//" + authority); //$NON-NLS-1$ + ssp.append("//"); //$NON-NLS-1$ + ssp.append(authority); } if (path != null) { ssp.append(path); } if (query != null) { - ssp.append("?" + query); //$NON-NLS-1$ + ssp.append("?"); //$NON-NLS-1$ + ssp.append(query); } // reset string, so that it can be re-calculated correctly when asked. return ssp.toString(); Copied: river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/PortableFactoryTest.java (from r1599197, river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/SerialReflectionFactoryTest.java) URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/PortableFactoryTest.java?p2=river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/PortableFactoryTest.java&p1=river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/SerialReflectionFactoryTest.java&r1=1599197&r2=1609703&rev=1609703&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/SerialReflectionFactoryTest.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/PortableFactoryTest.java Fri Jul 11 12:01:53 2014 @@ -30,20 +30,20 @@ import org.junit.Test; * * @author peter */ -public class SerialReflectionFactoryTest { +public class PortableFactoryTest { - private final SerialReflectionFactory stringInstance; + private final PortableFactory stringInstance; private final String str; - public SerialReflectionFactoryTest() { + public PortableFactoryTest() { str = "Fat Bear"; Class[] cl = {(new char [0]).getClass()}; Object [] chars = {str.toCharArray()}; - stringInstance = new SerialReflectionFactory(str.getClass(), null, cl , chars); + stringInstance = new PortableFactory(str.getClass(), null, cl , chars); } /** - * Test of hashCode method, of class SerialReflectionFactory. + * Test of hashCode method, of class PortableFactory. */ @Test public void testHashCode() throws IOException { @@ -55,7 +55,7 @@ public class SerialReflectionFactoryTest } /** - * Test of equals method, of class SerialReflectionFactory. + * Test of equals method, of class PortableFactory. */ @Test public void testEquals() throws IOException { @@ -64,9 +64,9 @@ public class SerialReflectionFactoryTest Class[] cl = {(new char [0]).getClass()}; Object [] chars = {str.toCharArray()}; // More than one way to create a string. - Object secondInstance = new SerialReflectionFactory(str.getClass(), null, cl, chars ); - SerialReflectionFactory thirdInstance = - new SerialReflectionFactory(new StringBuilder(str), "toString", null, null ); + Object secondInstance = new PortableFactory(str.getClass(), null, cl, chars ); + PortableFactory thirdInstance = + new PortableFactory(new StringBuilder(str), "toString", null, null ); Object result = stringInstance.create(); Assert.assertEquals(stringInstance, secondInstance); // Demonstrate that equal objects can have different serial form. @@ -78,7 +78,7 @@ public class SerialReflectionFactoryTest } /** - * Test of writeExternal method, of class SerialReflectionFactory. + * Test of writeExternal method, of class PortableFactory. */ @Test public void testWriteExternal() throws Exception { @@ -92,7 +92,7 @@ public class SerialReflectionFactoryTest } /** - * Test of readExternal method, of class SerialReflectionFactory. + * Test of readExternal method, of class PortableFactory. */ @Test public void testReadExternal() throws Exception { Copied: river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/PortableObjectOutputStreamTest.java (from r1599197, river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java) URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/PortableObjectOutputStreamTest.java?p2=river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/PortableObjectOutputStreamTest.java&p1=river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java&r1=1599197&r2=1609703&rev=1609703&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/DistributedObjectOutputStreamTest.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/api/io/PortableObjectOutputStreamTest.java Fri Jul 11 12:01:53 2014 @@ -23,40 +23,40 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; import org.junit.Test; import static org.junit.Assert.*; -import tests.support.DistributedObject; +import tests.support.PortableObject; /** * * @author peter */ -public class DistributedObjectOutputStreamTest { +public class PortableObjectOutputStreamTest { - public DistributedObjectOutputStreamTest() { + public PortableObjectOutputStreamTest() { } /** - * Test of create method, of class DistributedObjectOutputStream. + * Test of create method, of class PortableObjectOutputStream. */ @Test public void testCreate() throws Exception { System.out.println("create: test constructor, static method and object method"); - DistributedObject expResult = new DistributedObject("Testing"); + PortableObject expResult = new PortableObject("Testing"); ByteArrayOutputStream out = new ByteArrayOutputStream(); - ObjectOutputStream outst = DistributedObjectOutputStream.create(out); + ObjectOutputStream outst = PortableObjectOutputStream.create(out); outst.writeObject(expResult); - ObjectInputStream in = DistributedObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); + ObjectInputStream in = PortableObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); Object result = in.readObject(); assertEquals(expResult.toString(), result.toString()); out = new ByteArrayOutputStream(); - outst = DistributedObjectOutputStream.create(out); - expResult = new DistributedObject("Testing", 1); + outst = PortableObjectOutputStream.create(out); + expResult = new PortableObject("Testing", 1); outst.writeObject(expResult); - in = DistributedObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); + in = PortableObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); result = in.readObject(); assertEquals(expResult.toString(), result.toString()); - expResult = new DistributedObject("Testing", 2); + expResult = new PortableObject("Testing", 2); outst.writeObject(expResult); - in = DistributedObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); + in = PortableObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); result = in.readObject(); assertEquals(expResult.toString(), result.toString()); } @@ -64,18 +64,18 @@ public class DistributedObjectOutputStre @Test public void testPrimitives() throws Exception { System.out.println("create: test constructor, static method and object method"); - DistributedObject expResult = new DistributedObject(Boolean.TRUE); + PortableObject expResult = new PortableObject(Boolean.TRUE); ByteArrayOutputStream out = new ByteArrayOutputStream(); - ObjectOutputStream outst = DistributedObjectOutputStream.create(out); + ObjectOutputStream outst = PortableObjectOutputStream.create(out); outst.writeObject(expResult); - ObjectInputStream in = DistributedObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); + ObjectInputStream in = PortableObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); Object result = in.readObject(); assertEquals(expResult.toString(), result.toString()); out = new ByteArrayOutputStream(); - outst = DistributedObjectOutputStream.create(out); - expResult = new DistributedObject(true); + outst = PortableObjectOutputStream.create(out); + expResult = new PortableObject(true); outst.writeObject(expResult); - in = DistributedObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); + in = PortableObjectInputStream.create(new ByteArrayInputStream(out.toByteArray())); result = in.readObject(); assertEquals(expResult.toString(), result.toString()); Copied: river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/PortableObject.java (from r1599197, river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java) URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/PortableObject.java?p2=river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/PortableObject.java&p1=river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java&r1=1599197&r2=1609703&rev=1609703&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/DistributedObject.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/test/src/tests/support/PortableObject.java Fri Jul 11 12:01:53 2014 @@ -17,17 +17,17 @@ package tests.support; import java.io.Serializable; -import org.apache.river.api.io.Distributed; -import org.apache.river.api.io.SerialReflectionFactory; +import org.apache.river.api.io.Portable; +import org.apache.river.api.io.PortableFactory; /** * * @author peter */ -public class DistributedObject implements Distributed { +public class PortableObject implements Portable { - public static DistributedObject create(String str){ - return new DistributedObject(str); + public static PortableObject create(String str){ + return new PortableObject(str); } private final String testString; @@ -39,63 +39,63 @@ public class DistributedObject implement */ private final int method; - public DistributedObject(String str){ + public PortableObject(String str){ testString = str; method = 0; } - public DistributedObject(Number num){ + public PortableObject(Number num){ testString = num.toString(); method = 5; } - public DistributedObject(Character ch){ + public PortableObject(Character ch){ testString = ch.toString(); method = 4; } - public DistributedObject(Boolean b){ + public PortableObject(Boolean b){ testString = b.toString(); method = 3; } - public DistributedObject(boolean b){ + public PortableObject(boolean b){ testString = Boolean.toString(b); method = 6; } - public DistributedObject(String str, int method){ + public PortableObject(String str, int method){ testString = str; this.method = method; } - public SerialReflectionFactory substitute() { + public PortableFactory factory() { Class[] signature = new Class[1]; Object[] parameters = new Object[1]; parameters[0] = testString; switch (method){ case 0: signature[0] = String.class; - return new SerialReflectionFactory(this.getClass(), null, signature, parameters ); + return new PortableFactory(this.getClass(), null, signature, parameters ); case 1 : signature[0] = String.class; - return new SerialReflectionFactory(this.getClass(), "create", signature, parameters); + return new PortableFactory(this.getClass(), "create", signature, parameters); case 2: Builder builder = new Builder().setString(testString); - return new SerialReflectionFactory(builder, "build", null, null); + return new PortableFactory(builder, "build", null, null); case 3: signature[0] = Boolean.class; parameters[0] = Boolean.valueOf(testString); - return new SerialReflectionFactory(this.getClass(), null, signature, parameters); + return new PortableFactory(this.getClass(), null, signature, parameters); case 4: signature[0] = Character.class; parameters[0] = Character.valueOf(testString.charAt(0)); - return new SerialReflectionFactory(this.getClass(), null, signature, parameters); + return new PortableFactory(this.getClass(), null, signature, parameters); case 6: signature[0] = Boolean.TYPE; parameters[0] = Boolean.valueOf(testString); - return new SerialReflectionFactory(this.getClass(), null, signature, parameters); + return new PortableFactory(this.getClass(), null, signature, parameters); default: return null; } @@ -119,8 +119,8 @@ public class DistributedObject implement return this; } - public DistributedObject build(){ - return new DistributedObject(str); + public PortableObject build(){ + return new PortableObject(str); } }
