docs: public URL getCodeBase(BaseAppletReference applet)
      {
          URL urlCodeBase = null;
          if (applet != null)
              applet = applet.getApplet();    // Get the Applet if this is an applet.
          else
              if (Application.getRootApplet() != null)   // If they didn't pass me an applet, get the applet from the static reference.
                  applet = Application.getRootApplet().getApplet();
          if (applet != null)
              urlCodeBase = applet.getCodeBase();   // In an applet window.
          else
          { // Standalone.
              if (this.getMuffinManager() != null)
                  if (this.getMuffinManager().isServiceAvailable())
                      urlCodeBase = this.getMuffinManager().getCodeBase();
          }
          String strCodeBase = this.getProperty(Params.CODEBASE);
          if ((strCodeBase != null) && (strCodeBase.length() > 0) && (Character.isLetter(strCodeBase.charAt(0))))
          {   // If they explicitly specify a codebase, use it.
              try {
                  URL newUrlCodeBase = new URL(strCodeBase);
                  urlCodeBase = newUrlCodeBase;
              } catch (MalformedURLException e) {
                  if (urlCodeBase != null)
                  {   // Always. Use codebase with new path
                      try {
                          urlCodeBase = new URL(urlCodeBase.getProtocol(), urlCodeBase.getHost(), urlCodeBase.getPort(), strCodeBase);
                      } catch (MalformedURLException e1) {
                          e1.printStackTrace();
                      }
                  }
              }
          }
          else
              strCodeBase = null;
          if (urlCodeBase == null)
          {
              if ((strCodeBase == null) || (strCodeBase.length() == 0))
              {   // Now we're really guessing - Try the server for a codebase, then try the localhost
                  strCodeBase = this.getProperty(Params.REMOTE_HOST);
                  if ((strCodeBase == null) || (strCodeBase.length() == 0))
                  {
                      try   {
                          strCodeBase = InetAddress.getLocalHost().getHostName();
                      } catch (Exception ex)  {
                          strCodeBase = "localhost";
                      }
                  }
              }
              if (strCodeBase != null)
              {
                  try   {
                      int protocolEnd = strCodeBase.indexOf(':');
                      if ((protocolEnd == -1) || (protocolEnd > 6))
                      {
                          if ((getConnectionType() != PROXY)
                              && ((strCodeBase.startsWith("/")) || (strCodeBase.startsWith(System.getProperty("file.separator")))))
                                  strCodeBase = "file:" + strCodeBase;
                          else
                              strCodeBase = "http://" + strCodeBase;
                      }
                      urlCodeBase = new URL(strCodeBase);
                  } catch (MalformedURLException ex)  {
                      ex.printStackTrace();
                  }
              }
          }
          return urlCodeBase;
      }