From 61aeaaf89164aa93280527c7eb80cf4c1432fbee Mon Sep 17 00:00:00 2001 From: Andrew John Hughes Date: Thu, 21 Oct 2010 21:12:21 +0100 Subject: Fix most warnings arising from NetX code. 2010-10-20 Andrew John Hughes * netx/javax/jnlp/ServiceManager.java: (lookupTable): Add generic types. * netx/net/sourceforge/jnlp/AppletDesc.java: (parameters): Likewise. (AppletDesc(String,String,URL,int,int,Map)): Likewise. (getParameters()): Likewise. * netx/net/sourceforge/jnlp/ApplicationDesc.java: (getArguments()): Remove redundant cast. (addArgument(String)): Add generic typing. * netx/net/sourceforge/jnlp/ExtensionDesc.java: (extToPart): Add generic types. (eagerExtParts): Likewise. * netx/net/sourceforge/jnlp/InformationDesc.java: (info): Likewise. (getIcons(Object)): Add generic typing. (getAssociations()): Likewise. (getRelatedContents()): Likewise. (getItem(Object)): Likewise. (getItems(Object)): Likewise. (addItem(String,Object)): Likewise. * netx/net/sourceforge/jnlp/JNLPFile.java: (resources): Likewise. (InformationDesc.getItems(Object)): Likewise. (getResources(Class)): Likewise. * netx/net/sourceforge/jnlp/LaunchException.java: (getCauses()): Likewise. * netx/net/sourceforge/jnlp/Launcher.java: (launchApplication(JNLPFile)): Likewise. * netx/net/sourceforge/jnlp/NetxPanel.java: (NetxPanel(URL,Hashtable)): Likewise. (NetxPanel(URL,Hashtable,boolean)): Likewise. * netx/net/sourceforge/jnlp/Node.java: (getChildNodes()): Likewise. * netx/net/sourceforge/jnlp/Parser.java: (getResources(Node,boolean)): Likewise. (getInfo(Node)): Likewise. (getInformationDesc(Node)): Likewise. (getApplet(Node)): Likewise. (getApplication(Node)): Likewise. (splitString(String)): Likewise. (getLocales(Node)): Likewise. (getChildNodes(Node,String)): Likewise. * netx/net/sourceforge/jnlp/PluginBridge.java: Fix variable naming and add generic types. (cacheJars): Changed from cache_jars. (cacheExJars): Changed from cache_ex-jars. (atts): Add generic typing. (PluginBridge(URL,URL,String,String,int,int,Hashtable)): Likewise. (getInformation(Locale)): Likewise. (getResources(Locale,String,String)): Likewise. (getJARs()): Avoid excessive copying; filtering already performed by getResources in JNLPFile. * netx/net/sourceforge/jnlp/ResourcesDesc.java: (resources): Add generic typing. (getJREs()): Likewise. (getJARs()): Likewise. (getJARs(String)): Likewise. (getExtensions()): Likewise. (getPackages()): Likewise. (getPackages(String)): Likewise. (getProperties()): Likewise. (getPropertiesMap()): Likewise. (getResources(Class)): Make generic. * netx/net/sourceforge/jnlp/Version.java: (matches(Version)): Add generic types. (matchesAny(Version)): Likewise. (matchesSingle(String)): Likewise. (matches(String,String)): Likewise. (equal(List,List)): Likewise. (greater(List,List)): Likewise. (compare(String,String)): Use Integer.valueOf. (normalize(List,int)): Add generic types, using a List of lists rather than an array of lists. (getVersionStrings()): Add generic types. (getParts()): Likewise. * netx/net/sourceforge/jnlp/cache/CacheUtil.java: (waitForResources(ApplicationInstance,ResourceTracker, URL,String)): Likewise. * netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java: (getListener(ApplicatonInstance,String,URL)): Use setVisible instead of show(). (disposeListener(DownloadServiceListener)): Use setVisible instead of hide(). (DownloadPanel.urls): Add generic typing. (DownloadPanel.panels): Likewise. (DownloadPanel.update(URL,String,long,long,int)): Fix formatting. Add generic types. * netx/net/sourceforge/jnlp/cache/Resource.java: (resources): Add generic typing. (trackers): Likewise. (getResource(URL,Version,UpdatePolicy)): Use generic types. (getTracker()): Likewise. (addTracker(ResourceTracker)): Likewise. (fireDownloadEvent()): Likewise. * netx/net/sourceforge/jnlp/cache/ResourceTracker.java: (prefetchTrackers): Add generic typing. (queue): Likewise. (active): Likewise. (resources): Likewise. (listeners): Likewise. (fireDownloadEvent(Resource)): Remove unneeded cast. (getPrefetch()): Use generic typing. (selectByFlag(List,int,int)): Likewise. (getResource(URL)): Likewise. * netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java: (weakClips): Add generic types. (destroy()): Use generic typing. (getApplets()): Likewise. (getStreamKeys()): Likewise. * netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java: (weakWindows): Add generic types. (installEnvironment()): Likewise. (destroy()): Remove redundant cast. * netx/net/sourceforge/jnlp/runtime/Boot.java: Extend PrivilegedAction. (run()): Add generic typing. (getOptions(String)): Likewise. * netx/net/sourceforge/jnlp/runtime/Boot13.java: (main(String[]): Likewise. * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: Fix formatting. (urlToLoader): Add generic types. (resourcePermissions): Likewise. (available): Likewise. (jarEntries): Likewise. (getInstance(JNLPFile,UpdatePolicy)): Remove redundant cast. (getInstance(URL,String,Version,UpdatePolicy)): Likewise. (initializeExtensions()): Add generic types. (initializePermissions()): Likewise. (initializeResources()): Likewise. (getPermissions(CodeSource)): Likewise. (fillInPartJars(List)): Likewise. (activateJars(List)): Likewise. (loadClass(String)): Likewise. Suppress warnings due to sun.misc.JarIndex usage. (findResources(String)): Mark as overriding. Add generic types. (getExtensionName()): Add @Deprecated annotation. (getExtensionHREF()): Likewise. * netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java: (weakWindows): Add generic typing. (weakApplications): Likewise. (getApplication(Window)): Remove redundant casts. Add w, which is window cast to Window. * netx/net/sourceforge/jnlp/services/ServiceUtil.java: (invoke(Object,Method,Object[])): Use generic types. * netx/net/sourceforge/jnlp/services/XPersistenceService.java: (getNames(URL)): Likewise. * netx/net/sourceforge/jnlp/tools/JarSigner.java: (verifyJars(List,ResourceTracker)): Remove redundant cast. * netx/net/sourceforge/jnlp/util/WeakList.java: Redesign as a generic type. (refs): Add generic types. (deref(WeakReference)): Likewise. (get(int)): Likewise. (set(int,Object)): Likewise. (add(int,E)): Likewise. (remove()): Likewise. (hardList()): Likewise. * netx/net/sourceforge/nanoxml/XMLElement.java: (attributes): Add generic typing. (children): Likewise. (entities): Likewise. (XMLElement()): Use generic types. (XMLElement(Hashtable): Likewise. (resolveEntity(StringBuffer)): Remove redundant cast. --- netx/net/sourceforge/jnlp/PluginBridge.java | 140 +++++++++++++--------------- 1 file changed, 65 insertions(+), 75 deletions(-) (limited to 'netx/net/sourceforge/jnlp/PluginBridge.java') diff --git a/netx/net/sourceforge/jnlp/PluginBridge.java b/netx/net/sourceforge/jnlp/PluginBridge.java index 9c847e5..9312097 100644 --- a/netx/net/sourceforge/jnlp/PluginBridge.java +++ b/netx/net/sourceforge/jnlp/PluginBridge.java @@ -40,64 +40,65 @@ public class PluginBridge extends JNLPFile String name; String[] jars = new String[0]; - String[] cache_jars = new String[0]; - String[] cache_ex_jars = new String[0]; - Hashtable atts; + String[] cacheJars = new String[0]; + String[] cacheExJars = new String[0]; + Hashtable atts; public PluginBridge(URL codebase, URL documentBase, String jar, String main, - int width, int height, Hashtable atts) + int width, int height, Hashtable atts) throws Exception { specVersion = new Version("1.0"); fileVersion = new Version("1.1"); this.codeBase = codebase; this.sourceLocation = documentBase; - + if (atts.containsKey("jnlp_href")){ try { - URL jnlp = new URL(codeBase.toExternalForm() + (String) atts.get("jnlp_href")); - JNLPFile jnlp_file = new JNLPFile(jnlp); - Map jnlp_params = jnlp_file.getApplet().getParameters(); - + URL jnlp = new URL(codeBase.toExternalForm() + atts.get("jnlp_href")); + JNLPFile jnlpFile = new JNLPFile(jnlp); + Map jnlpParams = jnlpFile.getApplet().getParameters(); + // Change the parameter name to lowercase to follow conventions. - Iterator it = jnlp_params.keySet().iterator(); - while(it.hasNext()){ - String key = (String) it.next(); - atts.put(key.toLowerCase(), jnlp_params.get(key)); + for (Map.Entry entry : jnlpParams.entrySet()){ + atts.put(entry.getKey().toLowerCase(), entry.getValue()); } } catch (MalformedURLException e) { // Don't fail because we cannot get the jnlp file. Parameters are optional not required. // it is the site developer who should ensure that file exist. - System.err.println("Unable to get JNLP file at: " + codeBase.toExternalForm() - + (String) atts.get("jnlp_href")); + System.err.println("Unable to get JNLP file at: " + codeBase.toExternalForm() + + atts.get("jnlp_href")); } } // also, see if cache_archive is specified - if (atts.get("cache_archive") != null && ((String) atts.get("cache_archive")).length() > 0) { + String cacheArchive = atts.get("cache_archive"); + if (cacheArchive != null && cacheArchive.length() > 0) { String[] versions = new String[0]; // are there accompanying versions? - if (atts.get("cache_version") != null) { - versions = ((String) atts.get("cache_version")).split(","); + String cacheVersion = atts.get("cache_version"); + if (cacheVersion != null) { + versions = cacheVersion.split(","); } - String[] jars = ((String) atts.get("cache_archive")).split(","); - cache_jars = new String[jars.length]; + String[] jars = cacheArchive.split(","); + cacheJars = new String[jars.length]; for (int i=0; i < jars.length; i++) { - cache_jars[i] = jars[i].trim(); + cacheJars[i] = jars[i].trim(); if (versions.length > 0) { - cache_jars[i] += ";" + versions[i].trim(); + cacheJars[i] += ";" + versions[i].trim(); } } } - if (atts.get("cache_archive_ex") != null && ((String) atts.get("cache_archive_ex")).length() > 0) { - cache_ex_jars = ((String) atts.get("cache_archive_ex")).split(","); + String cacheArchiveEx = atts.get("cache_archive_ex"); + if (cacheArchiveEx != null && cacheArchiveEx.length() > 0) { + cacheExJars = cacheArchiveEx.split(","); } if (jar != null && jar.length() > 0) { @@ -109,7 +110,7 @@ public class PluginBridge extends JNLPFile } this.atts = atts; - name = (String) atts.get("name"); + name = atts.get("name"); if (name == null) name = "Applet"; else @@ -140,11 +141,10 @@ public class PluginBridge extends JNLPFile public InformationDesc getInformation(final Locale locale) { return new InformationDesc(this, new Locale[] {locale}) { - protected List getItems(Object key) + protected List getItems(Object key) { // Should we populate this list with applet attribute tags? - List result = new ArrayList(); - return result; + return new ArrayList(); } }; } @@ -153,102 +153,92 @@ public class PluginBridge extends JNLPFile final String arch) { return new ResourcesDesc(this, new Locale[] {locale}, new String[] {os}, - new String[] {arch}) { - public List getResources(Class launchType) + new String[] {arch}) { + @Override + public List getResources(Class launchType) { - List result = new ArrayList(); - result.addAll(sharedResources.getResources(launchType)); - // Need to add the JAR manually... //should this be done to sharedResources on init? - try + if (launchType.equals(JARDesc.class)) { - if (launchType.equals(JARDesc.class)) + try { + List jarDescs = new ArrayList(); + jarDescs.addAll(sharedResources.getResources(JARDesc.class)); + for (int i = 0; i < jars.length; i++) if (jars[i].length() > 0) - result.add(new JARDesc(new URL(codeBase, jars[i]), + jarDescs.add(new JARDesc(new URL(codeBase, jars[i]), null, null, false, true, false, true)); boolean cacheable = true; - if (atts.get("cache_option") != null && - ((String) atts.get("cache_option")).equalsIgnoreCase("no")) + String cacheOption = atts.get("cache_option"); + if (cacheOption != null && cacheOption.equalsIgnoreCase("no")) cacheable = false; - for (int i = 0; i < cache_jars.length; i++) { + for (int i = 0; i < cacheJars.length; i++) { - String[] jar_and_ver = cache_jars[i].split(";"); + String[] jarAndVer = cacheJars[i].split(";"); - String jar = jar_and_ver[0]; + String jar = jarAndVer[0]; Version version = null; if (jar.length() == 0) continue; - if (jar_and_ver.length > 1) { - version = new Version(jar_and_ver[1]); + if (jarAndVer.length > 1) { + version = new Version(jarAndVer[1]); } - result.add(new JARDesc(new URL(codeBase, jar), + jarDescs.add(new JARDesc(new URL(codeBase, jar), version, null, false, true, false, cacheable)); } - for (int i = 0; i < cache_ex_jars.length; i++) { + for (int i = 0; i < cacheExJars.length; i++) { - if (cache_ex_jars[i].length() == 0) + if (cacheExJars[i].length() == 0) continue; - String[] jar_info = cache_ex_jars[i].split(";"); + String[] jarInfo = cacheExJars[i].split(";"); - String jar = jar_info[0].trim(); + String jar = jarInfo[0].trim(); Version version = null; boolean lazy = true; - if (jar_info.length > 1) { + if (jarInfo.length > 1) { // format is name[[;preload];version] - if (jar_info[1].equals("preload")) { + if (jarInfo[1].equals("preload")) { lazy = false; } else { - version = new Version(jar_info[1].trim()); + version = new Version(jarInfo[1].trim()); } - if (jar_info.length > 2) { + if (jarInfo.length > 2) { lazy = false; - version = new Version(jar_info[2].trim()); + version = new Version(jarInfo[2].trim()); } } - result.add(new JARDesc(new URL(codeBase, jar), + jarDescs.add(new JARDesc(new URL(codeBase, jar), version, null, lazy, true, false, false)); } + // We know this is a safe list of JarDesc objects + @SuppressWarnings("unchecked") + List result = (List) jarDescs; + return result; } + catch (MalformedURLException ex) { /* Ignored */ } } - catch (MalformedURLException ex) - { } - return result; - } + return sharedResources.getResources(launchType); + } + @Override public JARDesc[] getJARs() { - List resources = getResources(JARDesc.class); - ArrayList jars = new ArrayList(); - - //Only get the JARDescs - for (int i = 0; i < resources.size(); i++) { - Object resource = resources.get(i); - if (resource instanceof JARDesc) - jars.add((JARDesc) resource); - } - - Object[] objectArray = jars.toArray(); - JARDesc[] jarArray = new JARDesc[objectArray.length]; - - for (int i = 0; i < objectArray.length; i++) - jarArray[i] = (JARDesc) objectArray[i]; - - return jarArray; + List jarDescs = getResources(JARDesc.class); + return jarDescs.toArray(new JARDesc[jarDescs.size()]); } public void addResource(Object resource) -- cgit v1.2.3