Ejemplo n.º 1
0
  /**
   * This is usually extracted from the the database using JDBC, but this is really inconvenient for
   * users who are trying to generate SQL at some. A specific version of the data has been written
   * into the property list of the framework and this can be used as a hard-coded equivalent.
   */
  public NSDictionary jdbcInfo() {
    // you can swap this code out to write the property list out in order
    // to get a fresh copy of the JDBCInfo.plist.
    //    try {
    //      String jdbcInfoS = NSPropertyListSerialization.stringFromPropertyList(super.jdbcInfo());
    //      FileOutputStream fos = new FileOutputStream("/tmp/JDBCInfo.plist");
    //      fos.write(jdbcInfoS.getBytes());
    //      fos.close();
    //    }
    //    catch(Exception e) {
    //      throw new IllegalStateException("problem writing JDBCInfo.plist",e);
    //    }

    NSDictionary jdbcInfo;
    // have a look at the JDBC connection URL to see if the flag has been set to
    // specify that the hard-coded jdbcInfo information should be used.
    if (shouldUseBundledJdbcInfo()) {
      if (NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelDetailed)) {
        NSLog.debug.appendln(
            "Loading jdbcInfo from JDBCInfo.plist as opposed to using the JDBCPlugIn default implementation.");
      }

      InputStream jdbcInfoStream =
          NSBundle.bundleForClass(getClass()).inputStreamForResourcePath("JDBCInfo.plist");
      if (jdbcInfoStream == null) {
        throw new IllegalStateException("Unable to find 'JDBCInfo.plist' in this plugin jar.");
      }

      try {
        jdbcInfo =
            (NSDictionary)
                NSPropertyListSerialization.propertyListFromData(
                    new NSData(jdbcInfoStream, 2048), "US-ASCII");
      } catch (IOException e) {
        throw new RuntimeException("Failed to load 'JDBCInfo.plist' from this plugin jar.", e);
      } finally {
        try {
          jdbcInfoStream.close();
        } catch (IOException e) {
        }
      }
    } else {
      jdbcInfo = super.jdbcInfo();
    }
    return jdbcInfo;
  }
Ejemplo n.º 2
0
  public NSDictionary preferences() {
    NSDictionary result = (NSDictionary) valueForBinding("prefsDict");
    if (result == null) {
      java.io.InputStream inputStream =
          application()
              .resourceManager()
              .inputStreamForResourceNamed(
                  (String) valueForBinding("prefsFile"),
                  (String) valueForBinding("framework"),
                  null);

      // read in the data, log exceptions
      try {
        NSData prefsData = new NSData(inputStream, inputStream.available());
        result = (NSDictionary) NSPropertyListSerialization.propertyListFromData(prefsData, "UTF8");
        inputStream.close();
      } catch (Exception exception) {
        NSLog.out.appendln("UploadAnchor:  failed to read preferences file" + exception);
      }
    }
    return result;
  }