Esempio n. 1
0
  /** Figure out which ClassLoader to use. For JDK 1.2 and later use the context ClassLoader. */
  static ClassLoader findClassLoader() throws ConfigurationError {
    SecuritySupport ss = SecuritySupport.getInstance();

    // Figure out which ClassLoader to use for loading the provider
    // class.  If there is a Context ClassLoader then use it.
    ClassLoader context = ss.getContextClassLoader();
    ClassLoader system = ss.getSystemClassLoader();

    ClassLoader chain = system;
    while (true) {
      if (context == chain) {
        // Assert: we are on JDK 1.1 or we have no Context ClassLoader
        // or any Context ClassLoader in chain of system classloader
        // (including extension ClassLoader) so extend to widest
        // ClassLoader (always look in system ClassLoader if Xalan
        // is in boot/extension/system classpath and in current
        // ClassLoader otherwise); normal classloaders delegate
        // back to system ClassLoader first so this widening doesn't
        // change the fact that context ClassLoader will be consulted
        ClassLoader current = ObjectFactory.class.getClassLoader();

        chain = system;
        while (true) {
          if (current == chain) {
            // Assert: Current ClassLoader in chain of
            // boot/extension/system ClassLoaders
            return system;
          }
          if (chain == null) {
            break;
          }
          chain = ss.getParentClassLoader(chain);
        }

        // Assert: Current ClassLoader not in chain of
        // boot/extension/system ClassLoaders
        return current;
      }

      if (chain == null) {
        // boot ClassLoader reached
        break;
      }

      // Check for any extension ClassLoaders in chain up to
      // boot ClassLoader
      chain = ss.getParentClassLoader(chain);
    }
    ;

    // Assert: Context ClassLoader not in chain of
    // boot/extension/system ClassLoaders
    return context;
  } // findClassLoader():ClassLoader
Esempio n. 2
0
 /* 192:    */
 /* 193:    */ static ClassLoader findClassLoader()
     /* 194:    */ throws ObjectFactory.ConfigurationError
       /* 195:    */ {
   /* 196:396 */ SecuritySupport ss = SecuritySupport.getInstance();
   /* 197:    */
   /* 198:    */
   /* 199:    */
   /* 200:400 */ ClassLoader context = ss.getContextClassLoader();
   /* 201:401 */ ClassLoader system = ss.getSystemClassLoader();
   /* 202:    */
   /* 203:403 */ ClassLoader chain = system;
   /* 204:    */ for (; ; )
   /* 205:    */ {
     /* 206:405 */ if (context == chain)
     /* 207:    */ {
       /* 208:414 */ ClassLoader current = ObjectFactory.class.getClassLoader();
       /* 209:    */
       /* 210:416 */ chain = system;
       /* 211:    */ for (; ; )
       /* 212:    */ {
         /* 213:418 */ if (current == chain) {
           /* 214:421 */ return system;
           /* 215:    */ }
         /* 216:423 */ if (chain == null) {
           /* 217:    */ break;
           /* 218:    */ }
         /* 219:426 */ chain = ss.getParentClassLoader(chain);
         /* 220:    */ }
       /* 221:431 */ return current;
       /* 222:    */ }
     /* 223:434 */ if (chain == null) {
       /* 224:    */ break;
       /* 225:    */ }
     /* 226:441 */ chain = ss.getParentClassLoader(chain);
     /* 227:    */ }
   /* 228:446 */ return context;
   /* 229:    */ }
Esempio n. 3
0
  /**
   * Find the name of service provider using Jar Service Provider Mechanism
   *
   * @return instance of provider class if found or null
   */
  private static String findJarServiceProviderName(String factoryId) {
    SecuritySupport ss = SecuritySupport.getInstance();
    String serviceId = SERVICES_PATH + factoryId;
    InputStream is = null;

    // First try the Context ClassLoader
    ClassLoader cl = findClassLoader();

    is = ss.getResourceAsStream(cl, serviceId);

    // If no provider found then try the current ClassLoader
    if (is == null) {
      ClassLoader current = ObjectFactory.class.getClassLoader();
      if (cl != current) {
        cl = current;
        is = ss.getResourceAsStream(cl, serviceId);
      }
    }

    if (is == null) {
      // No provider found
      return null;
    }

    if (DEBUG) debugPrintln("found jar resource=" + serviceId + " using ClassLoader: " + cl);

    // Read the service provider name in UTF-8 as specified in
    // the jar spec.  Unfortunately this fails in Microsoft
    // VJ++, which does not implement the UTF-8
    // encoding. Theoretically, we should simply let it fail in
    // that case, since the JVM is obviously broken if it
    // doesn't support such a basic standard.  But since there
    // are still some users attempting to use VJ++ for
    // development, we have dropped in a fallback which makes a
    // second attempt using the platform's default encoding. In
    // VJ++ this is apparently ASCII, which is a subset of
    // UTF-8... and since the strings we'll be reading here are
    // also primarily limited to the 7-bit ASCII range (at
    // least, in English versions), this should work well
    // enough to keep us on the air until we're ready to
    // officially decommit from VJ++. [Edited comment from
    // jkesselm]
    BufferedReader rd;
    try {
      rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
    } catch (java.io.UnsupportedEncodingException e) {
      rd = new BufferedReader(new InputStreamReader(is));
    }

    String factoryClassName = null;
    try {
      // XXX Does not handle all possible input as specified by the
      // Jar Service Provider specification
      factoryClassName = rd.readLine();
    } catch (IOException x) {
      // No provider found
      return null;
    } finally {
      try {
        // try to close the reader.
        rd.close();
      }
      // Ignore the exception.
      catch (IOException exc) {
      }
    }

    if (factoryClassName != null && !"".equals(factoryClassName)) {
      if (DEBUG) debugPrintln("found in resource, value=" + factoryClassName);

      // Note: here we do not want to fall back to the current
      // ClassLoader because we want to avoid the case where the
      // resource file was found using one ClassLoader and the
      // provider class was instantiated using a different one.
      return factoryClassName;
    }

    // No provider found
    return null;
  }
Esempio n. 4
0
  /**
   * Finds the name of the required implementation class in the specified order. The specified order
   * is the following:
   *
   * <ol>
   *   <li>query the system property using <code>System.getProperty</code>
   *   <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
   *   <li>read <code>META-INF/services/<i>factoryId</i></code> file
   *   <li>use fallback classname
   * </ol>
   *
   * @return name of class that provides factory service, never null
   * @param factoryId Name of the factory to find, same as a property name
   * @param propertiesFilename The filename in the $java.home/lib directory of the properties file.
   *     If none specified, ${java.home}/lib/xalan.properties will be used.
   * @param fallbackClassName Implementation class name, if nothing else is found. Use null to mean
   *     no fallback.
   * @exception ObjectFactory.ConfigurationError
   */
  static String lookUpFactoryClassName(
      String factoryId, String propertiesFilename, String fallbackClassName) {
    SecuritySupport ss = SecuritySupport.getInstance();

    // Use the system property first
    try {
      String systemProp = ss.getSystemProperty(factoryId);
      if (systemProp != null) {
        if (DEBUG) debugPrintln("found system property, value=" + systemProp);
        return systemProp;
      }
    } catch (SecurityException se) {
      // Ignore and continue w/ next location
    }

    // Try to read from propertiesFilename, or
    // $java.home/lib/xalan.properties
    String factoryClassName = null;
    // no properties file name specified; use
    // $JAVA_HOME/lib/xalan.properties:
    if (propertiesFilename == null) {
      File propertiesFile = null;
      boolean propertiesFileExists = false;
      try {
        String javah = ss.getSystemProperty("java.home");
        propertiesFilename =
            javah + File.separator + "lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
        propertiesFile = new File(propertiesFilename);
        propertiesFileExists = ss.getFileExists(propertiesFile);
      } catch (SecurityException e) {
        // try again...
        fLastModified = -1;
        fXalanProperties = null;
      }

      synchronized (ObjectFactory.class) {
        boolean loadProperties = false;
        FileInputStream fis = null;
        try {
          // file existed last time
          if (fLastModified >= 0) {
            if (propertiesFileExists
                && (fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
              loadProperties = true;
            } else {
              // file has stopped existing...
              if (!propertiesFileExists) {
                fLastModified = -1;
                fXalanProperties = null;
              } // else, file wasn't modified!
            }
          } else {
            // file has started to exist:
            if (propertiesFileExists) {
              loadProperties = true;
              fLastModified = ss.getLastModified(propertiesFile);
            } // else, nothing's changed
          }
          if (loadProperties) {
            // must never have attempted to read xalan.properties
            // before (or it's outdeated)
            fXalanProperties = new Properties();
            fis = ss.getFileInputStream(propertiesFile);
            fXalanProperties.load(fis);
          }
        } catch (Exception x) {
          fXalanProperties = null;
          fLastModified = -1;
          // assert(x instanceof FileNotFoundException
          //        || x instanceof SecurityException)
          // In both cases, ignore and continue w/ next location
        } finally {
          // try to close the input stream if one was opened.
          if (fis != null) {
            try {
              fis.close();
            }
            // Ignore the exception.
            catch (IOException exc) {
            }
          }
        }
      }
      if (fXalanProperties != null) {
        factoryClassName = fXalanProperties.getProperty(factoryId);
      }
    } else {
      FileInputStream fis = null;
      try {
        fis = ss.getFileInputStream(new File(propertiesFilename));
        Properties props = new Properties();
        props.load(fis);
        factoryClassName = props.getProperty(factoryId);
      } catch (Exception x) {
        // assert(x instanceof FileNotFoundException
        //        || x instanceof SecurityException)
        // In both cases, ignore and continue w/ next location
      } finally {
        // try to close the input stream if one was opened.
        if (fis != null) {
          try {
            fis.close();
          }
          // Ignore the exception.
          catch (IOException exc) {
          }
        }
      }
    }
    if (factoryClassName != null) {
      if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value=" + factoryClassName);
      return factoryClassName;
    }

    // Try Jar Service Provider Mechanism
    return findJarServiceProviderName(factoryId);
  } // lookUpFactoryClass(String,String):String
  /**
   * Finds the implementation Class object in the specified order. The specified order is the
   * following:
   *
   * <ol>
   *   <li>query the system property using <code>System.getProperty</code>
   *   <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
   *   <li>read <code>META-INF/services/<i>factoryId</i></code> file
   *   <li>use fallback classname
   * </ol>
   *
   * @return Class object of factory, never null
   * @param factoryId Name of the factory to find, same as a property name
   * @param propertiesFilename The filename in the $java.home/lib directory of the properties file.
   *     If none specified, ${java.home}/lib/xerces.properties will be used.
   * @param fallbackClassName Implementation class name, if nothing else is found. Use null to mean
   *     no fallback.
   * @exception ObjectFactory.ConfigurationError
   */
  static Object createObject(String factoryId, String propertiesFilename, String fallbackClassName)
      throws ConfigurationError {
    if (DEBUG) debugPrintln("debug is on");

    ClassLoader cl = findClassLoader();

    // Use the system property first
    try {
      String systemProp = SecuritySupport.getInstance().getSystemProperty(factoryId);
      if (systemProp != null && systemProp.length() > 0) {
        if (DEBUG) debugPrintln("found system property, value=" + systemProp);
        return newInstance(systemProp, cl, true);
      }
    } catch (SecurityException se) {
      // Ignore and continue w/ next location
    }

    // Try to read from propertiesFilename, or $java.home/lib/xerces.properties
    String factoryClassName = null;
    // no properties file name specified; use $JAVA_HOME/lib/xerces.properties:
    if (propertiesFilename == null) {
      File propertiesFile = null;
      boolean propertiesFileExists = false;
      try {
        String javah = SecuritySupport.getInstance().getSystemProperty("java.home");
        propertiesFilename =
            javah + File.separator + "lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
        propertiesFile = new File(propertiesFilename);
        propertiesFileExists = SecuritySupport.getInstance().getFileExists(propertiesFile);
      } catch (SecurityException e) {
        // try again...
        fLastModified = -1;
        fXercesProperties = null;
      }

      synchronized (ObjectFactory.class) {
        boolean loadProperties = false;
        FileInputStream fis = null;
        try {
          // file existed last time
          if (fLastModified >= 0) {
            if (propertiesFileExists
                && (fLastModified
                    < (fLastModified =
                        SecuritySupport.getInstance().getLastModified(propertiesFile)))) {
              loadProperties = true;
            } else {
              // file has stopped existing...
              if (!propertiesFileExists) {
                fLastModified = -1;
                fXercesProperties = null;
              } // else, file wasn't modified!
            }
          } else {
            // file has started to exist:
            if (propertiesFileExists) {
              loadProperties = true;
              fLastModified = SecuritySupport.getInstance().getLastModified(propertiesFile);
            } // else, nothing's changed
          }
          if (loadProperties) {
            // must never have attempted to read xerces.properties before (or it's outdeated)
            fXercesProperties = new Properties();
            fis = SecuritySupport.getInstance().getFileInputStream(propertiesFile);
            fXercesProperties.load(fis);
          }
        } catch (Exception x) {
          fXercesProperties = null;
          fLastModified = -1;
          // assert(x instanceof FileNotFoundException
          //        || x instanceof SecurityException)
          // In both cases, ignore and continue w/ next location
        } finally {
          // try to close the input stream if one was opened.
          if (fis != null) {
            try {
              fis.close();
            }
            // Ignore the exception.
            catch (IOException exc) {
            }
          }
        }
      }
      if (fXercesProperties != null) {
        factoryClassName = fXercesProperties.getProperty(factoryId);
      }
    } else {
      FileInputStream fis = null;
      try {
        fis = SecuritySupport.getInstance().getFileInputStream(new File(propertiesFilename));
        Properties props = new Properties();
        props.load(fis);
        factoryClassName = props.getProperty(factoryId);
      } catch (Exception x) {
        // assert(x instanceof FileNotFoundException
        //        || x instanceof SecurityException)
        // In both cases, ignore and continue w/ next location
      } finally {
        // try to close the input stream if one was opened.
        if (fis != null) {
          try {
            fis.close();
          }
          // Ignore the exception.
          catch (IOException exc) {
          }
        }
      }
    }
    if (factoryClassName != null) {
      if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value=" + factoryClassName);
      return newInstance(factoryClassName, cl, true);
    }

    // Try Jar Service Provider Mechanism
    Object provider = findJarServiceProvider(factoryId);
    if (provider != null) {
      return provider;
    }

    if (fallbackClassName == null) {
      throw new ConfigurationError("Provider for " + factoryId + " cannot be found", null);
    }

    if (DEBUG) debugPrintln("using fallback, value=" + fallbackClassName);
    return newInstance(fallbackClassName, cl, true);
  } // createObject(String,String,String):Object
Esempio n. 6
0
 /*  79:    */
 /*  80:    */ static String lookUpFactoryClassName(
     String factoryId, String propertiesFilename, String fallbackClassName)
       /*  81:    */ {
   /*  82:261 */ SecuritySupport ss = SecuritySupport.getInstance();
   /*  83:    */ try
   /*  84:    */ {
     /*  85:265 */ String systemProp = ss.getSystemProperty(factoryId);
     /*  86:266 */ if (systemProp != null)
     /*  87:    */ {
       /*  88:267 */ debugPrintln("found system property, value=" + systemProp);
       /*  89:268 */ return systemProp;
       /*  90:    */ }
     /*  91:    */ }
   /*  92:    */ catch (SecurityException se) {
   }
   /*  93:276 */ String factoryClassName = null;
   /*  94:279 */ if (propertiesFilename == null)
   /*  95:    */ {
     /*  96:280 */ File propertiesFile = null;
     /*  97:281 */ boolean propertiesFileExists = false;
     /*  98:    */ try
     /*  99:    */ {
       /* 100:283 */ String javah = ss.getSystemProperty("java.home");
       /* 101:284 */ propertiesFilename =
           javah + File.separator + "lib" + File.separator + "xalan.properties";
       /* 102:    */
       /* 103:286 */ propertiesFile = new File(propertiesFilename);
       /* 104:287 */ propertiesFileExists = ss.getFileExists(propertiesFile);
       /* 105:    */ }
     /* 106:    */ catch (SecurityException javah)
     /* 107:    */ {
       /* 108:290 */ fLastModified = -1L;
       /* 109:291 */ fXalanProperties = null;
       /* 110:    */ }
     /* 111:294 */ synchronized (ObjectFactory.class)
     /* 112:    */ {
       /* 113:295 */ boolean loadProperties = false;
       /* 114:296 */ FileInputStream fis = null;
       /* 115:    */ try
       /* 116:    */ {
         /* 117:299 */ if (fLastModified >= 0L)
         /* 118:    */ {
           /* 119:300 */ if ((propertiesFileExists)
               && (fLastModified
                   < (ObjectFactory.fLastModified = ss.getLastModified(propertiesFile))))
           /* 120:    */ {
             /* 121:302 */ loadProperties = true;
             /* 122:    */ }
           /* 123:305 */ else if (!propertiesFileExists)
           /* 124:    */ {
             /* 125:306 */ fLastModified = -1L;
             /* 126:307 */ fXalanProperties = null;
             /* 127:    */ }
           /* 128:    */ }
         /* 129:312 */ else if (propertiesFileExists)
         /* 130:    */ {
           /* 131:313 */ loadProperties = true;
           /* 132:314 */ fLastModified = ss.getLastModified(propertiesFile);
           /* 133:    */ }
         /* 134:317 */ if (loadProperties)
         /* 135:    */ {
           /* 136:320 */ fXalanProperties = new Properties();
           /* 137:321 */ fis = ss.getFileInputStream(propertiesFile);
           /* 138:322 */ fXalanProperties.load(fis);
           /* 139:    */ }
         /* 140:    */ }
       /* 141:    */ catch (Exception x)
       /* 142:    */ {
         /* 143:325 */ fXalanProperties = null;
         /* 144:326 */ fLastModified = -1L;
         /* 145:    */ }
       /* 146:    */ finally
       /* 147:    */ {
         /* 148:333 */ if (fis != null) {
           /* 149:    */ try
           /* 150:    */ {
             /* 151:335 */ fis.close();
             /* 152:    */ }
           /* 153:    */ catch (IOException exc) {
           }
           /* 154:    */ }
         /* 155:    */ }
       /* 156:    */ }
     /* 157:342 */ if (fXalanProperties != null) {
       /* 158:343 */ factoryClassName = fXalanProperties.getProperty(factoryId);
       /* 159:    */ }
     /* 160:    */ }
   /* 161:    */ else
   /* 162:    */ {
     /* 163:346 */ FileInputStream fis = null;
     /* 164:    */ try
     /* 165:    */ {
       /* 166:348 */ fis = ss.getFileInputStream(new File(propertiesFilename));
       /* 167:349 */ Properties props = new Properties();
       /* 168:350 */ props.load(fis);
       /* 169:351 */ factoryClassName = props.getProperty(factoryId);
       /* 170:    */ }
     /* 171:    */ catch (Exception x) {
     } finally
     /* 172:    */ {
       /* 173:359 */ if (fis != null) {
         /* 174:    */ try
         /* 175:    */ {
           /* 176:361 */ fis.close();
           /* 177:    */ }
         /* 178:    */ catch (IOException exc) {
         }
         /* 179:    */ }
       /* 180:    */ }
     /* 181:    */ }
   /* 182:368 */ if (factoryClassName != null)
   /* 183:    */ {
     /* 184:369 */ debugPrintln("found in " + propertiesFilename + ", value=" + factoryClassName);
     /* 185:    */
     /* 186:371 */ return factoryClassName;
     /* 187:    */ }
   /* 188:375 */ return findJarServiceProviderName(factoryId);
   /* 189:    */ }
Esempio n. 7
0
 /* 307:    */
 /* 308:    */ private static String findJarServiceProviderName(String factoryId) /* 309:    */ {
   /* 310:537 */ SecuritySupport ss = SecuritySupport.getInstance();
   /* 311:538 */ String serviceId = "META-INF/services/" + factoryId;
   /* 312:539 */ InputStream is = null;
   /* 313:    */
   /* 314:    */
   /* 315:542 */ ClassLoader cl = findClassLoader();
   /* 316:    */
   /* 317:544 */ is = ss.getResourceAsStream(cl, serviceId);
   /* 318:547 */ if (is == null)
   /* 319:    */ {
     /* 320:548 */ ClassLoader current = ObjectFactory.class.getClassLoader();
     /* 321:549 */ if (cl != current)
     /* 322:    */ {
       /* 323:550 */ cl = current;
       /* 324:551 */ is = ss.getResourceAsStream(cl, serviceId);
       /* 325:    */ }
     /* 326:    */ }
   /* 327:555 */ if (is == null) {
     /* 328:557 */ return null;
     /* 329:    */ }
   /* 330:560 */ debugPrintln("found jar resource=" + serviceId + " using ClassLoader: " + cl);
   /* 331:    */ BufferedReader rd;
   /* 332:    */ try
   /* 333:    */ {
     /* 334:581 */ rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
     /* 335:    */ }
   /* 336:    */ catch (UnsupportedEncodingException e)
   /* 337:    */ {
     /* 338:583 */ rd = new BufferedReader(new InputStreamReader(is));
     /* 339:    */ }
   /* 340:586 */ String factoryClassName = null;
   /* 341:    */ try
   /* 342:    */ {
     /* 343:590 */ factoryClassName = rd.readLine();
     /* 344:    */ }
   /* 345:    */ catch (IOException x)
   /* 346:    */ {
     /* 347:593 */ return null;
     /* 348:    */ }
   /* 349:    */ finally
   /* 350:    */ {
     /* 351:    */ try
     /* 352:    */ {
       /* 353:598 */ rd.close();
       /* 354:    */ }
     /* 355:    */ catch (IOException exc) {
     }
     /* 356:    */ }
   /* 357:604 */ if ((factoryClassName != null) && (!"".equals(factoryClassName)))
   /* 358:    */ {
     /* 359:606 */ debugPrintln("found in resource, value=" + factoryClassName);
     /* 360:    */
     /* 361:    */
     /* 362:    */
     /* 363:    */
     /* 364:    */
     /* 365:    */
     /* 366:613 */ return factoryClassName;
     /* 367:    */ }
   /* 368:617 */ return null;
   /* 369:    */ }