public static Properties getProperties() {
    if (properties == null) {
      loadConfig(null);
    }

    return (Properties) properties.clone();
  }
  /**
   * This is called with the properties that are supplied in the deployment.xml Do any
   * initialization here.
   *
   * @param p
   */
  public Log4jSocketImporterConfig(Properties p) {
    Properties properties = (Properties) p.clone();
    String portStr = properties.getProperty(PORT_CONFIG);
    if (portStr == null || portStr.trim().length() == 0) {
      throw new RuntimeException(
          PORT_CONFIG + " must be specified as a log4j socket importer property");
    }
    m_port = Integer.parseInt(portStr);

    try {
      m_serverSocket = new ServerSocket(m_port);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    m_tableName = properties.getProperty(EVENT_TABLE_CONFIG);
    if (m_tableName == null || m_tableName.trim().length() == 0) {
      throw new RuntimeException(
          EVENT_TABLE_CONFIG + " must be specified as a log4j socket importer property");
    }

    try {
      m_resourceID = new URI(URI_SCHEME, portStr, null);
    } catch (URISyntaxException e) { // Will not happen
      throw new RuntimeException(e);
    }
  }
  public ClientService(final Properties properties) {

    // show the copyright banner during statup.
    Banner.banner();

    this.properties = (Properties) properties.clone();
  }
  public TicketInfo copyTicket() {
    TicketInfo t = new TicketInfo();

    t.tickettype = tickettype;
    t.m_iTicketId = m_iTicketId;
    t.m_iTicketNCF = m_iTicketNCF; // NCF
    t.m_dDate = m_dDate;
    t.m_sActiveCash = m_sActiveCash;
    t.attributes = (Properties) attributes.clone();
    t.m_User = m_User;
    t.m_Customer = m_Customer;

    t.m_aLines = new ArrayList<TicketLineInfo>();
    for (TicketLineInfo l : m_aLines) {
      t.m_aLines.add(l.copyTicketLine());
    }
    t.refreshLines();

    t.payments = new LinkedList<PaymentInfo>();
    for (PaymentInfo p : payments) {
      t.payments.add(p.copyPayment());
    }

    // taxes are not copied, must be calculated again.

    return t;
  }
Example #5
0
 /**
  * Creates a new SPEC properties object, initialized with properties and titles read from files as
  * above.
  *
  * @param baseDir base directory / URL prefix
  * @param specFileName Default name of file with inital properties specified by SPEC. Path name is
  *     relative to baseDir
  * @param userFileName full URL of file with inital properties specified by user
  * @param titleFileName Default name of file with property titles. Path name is relative to
  *     baseDir
  */
 public SpecProps(
     String baseDir,
     String specFileName,
     String userFileName,
     String titleFileName,
     Color setupColor) {
   specDir = baseDir;
   specFile = specFileName;
   userFile = userFileName;
   titleFile = titleFileName;
   this.setupColor = setupColor;
   Properties userProps = getProperties(userFile);
   specProps = merge(specDir + specFile, userProps);
   title = getOrderedProperties(specDir + titleFile);
   props = (Properties) specProps.clone();
   Locale locale = Locale.getDefault();
   if (getBoolean("spec.initial.specDates"))
     locale = new Locale(get("spec.initial.language", "en"), get("spec.initial.country", "US"));
   props.put(
       "spec.test.date", DateFormat.getDateInstance(DateFormat.LONG, locale).format(new Date()));
   props.put("spec.other.testTime", DateFormat.getDateTimeInstance().format(new Date()));
   try {
     String s = props.getProperty("spec.initial.maxRows");
     if (s != null) maxRows = Integer.parseInt(s);
   } catch (NumberFormatException e) {
     // retain default value as initialized
   }
 }
  /**
   * Creates a proxy for java.sql.Connection that routes requests between the given list of
   * host:port and uses the given properties when creating connections.
   *
   * @param hosts
   * @param props
   * @throws SQLException
   */
  LoadBalancingConnectionProxy(List hosts, Properties props) throws SQLException {
    this.hostList = hosts;

    int numHosts = this.hostList.size();

    this.liveConnections = new HashMap(numHosts);
    this.connectionsToHostsMap = new HashMap(numHosts);
    this.responseTimes = new long[numHosts];
    this.hostsToListIndexMap = new HashMap(numHosts);

    for (int i = 0; i < numHosts; i++) {
      this.hostsToListIndexMap.put(this.hostList.get(i), new Integer(i));
    }

    this.localProps = (Properties) props.clone();
    this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
    this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);
    this.localProps.setProperty("useLocalSessionState", "true");

    String strategy = this.localProps.getProperty("loadBalanceStrategy", "random");

    if ("random".equals(strategy)) {
      this.balancer = new RandomBalanceStrategy();
    } else if ("bestResponseTime".equals(strategy)) {
      this.balancer = new BestResponseTimeBalanceStrategy();
    } else {
      throw SQLError.createSQLException(
          Messages.getString("InvalidLoadBalanceStrategy", new Object[] {strategy}),
          SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
    }

    pickNewConnection();
  }
 /**
  * INTERNAL: Clears customization from connection. Called only if connection is customized
  * (isActive()==true). If the method fails due to SQLException it should "eat" it (just like
  * DatasourceAccessor.closeConnection method). isActive method called after this method should
  * always return false.
  */
 public void clear() {
   try {
     clearConnectionCache();
     if (this.session.shouldLog(SessionLog.FINEST, SessionLog.CONNECTION)) {
       Properties logProperties = proxyProperties;
       if (proxyProperties.containsKey(OracleConnection.PROXY_USER_PASSWORD)) {
         logProperties = (Properties) proxyProperties.clone();
         logProperties.setProperty(OracleConnection.PROXY_USER_PASSWORD, "******");
       }
       Object[] args = new Object[] {oracleConnection, logProperties};
       ((AbstractSession) this.session)
           .log(
               SessionLog.FINEST,
               SessionLog.CONNECTION,
               "proxy_connection_customizer_closing_proxy_session",
               args);
     }
     oracleConnection.close(OracleConnection.PROXY_SESSION);
   } catch (SQLException exception) {
     // Ignore
     this.session
         .getSessionLog()
         .logThrowable(SessionLog.WARNING, SessionLog.CONNECTION, exception);
   } finally {
     oracleConnection = null;
   }
 }
  private static final MDRepository getRepository(
      Properties properties, InputStream xmiInputStream) {
    try {
      // The system relies on properties set in the virtual machine (system wide)
      Properties systemProperties = System.getProperties();
      Map<Object, Object> backup = new Properties();
      @SuppressWarnings("all")
      Map<Object, Object> m = (Map<Object, Object>) systemProperties.clone();
      backup.putAll(m);

      systemProperties.putAll(properties);

      String storageFactoryClassName =
          System.getProperty(
              "org.netbeans.mdr.storagemodel.StorageFactoryClassName",
              ""); //$NON-NLS-1$ //$NON-NLS-2$

      try {
        MDRepository mdRepository = new NBMDRepositoryImpl();

        RefPackage cwmPackageM3 = mdRepository.getExtent(CWM);
        if (cwmPackageM3 == null && xmiInputStream != null) {
          cwmPackageM3 = mdRepository.createExtent(CWM);
          BufferedInputStream inputStream = new BufferedInputStream(xmiInputStream);
          XMIReaderFactory.getDefault().createXMIReader().read(inputStream, null, cwmPackageM3);
        }

        return mdRepository;
      } catch (Exception e) {
        throw new RuntimeException("Unable to access class [" + storageFactoryClassName + "]", e);
      }
    } catch (Exception e) {
      throw new RuntimeException("Cannot access repository", e);
    }
  }
 @Override
 public ConnectionInfo clone() throws CloneNotSupportedException {
   ConnectionInfo clone = (ConnectionInfo) super.clone();
   clone.prop = (Properties) prop.clone();
   clone.filePasswordHash = Utils.cloneByteArray(filePasswordHash);
   clone.fileEncryptionKey = Utils.cloneByteArray(fileEncryptionKey);
   clone.userPasswordHash = Utils.cloneByteArray(userPasswordHash);
   return clone;
 }
Example #10
0
 /**
  * Given two Properties objects, forms a single Properties object with hash values from both the
  * objects.
  */
 private static Properties merge(Properties primary, Properties secondary) {
   Properties p = (Properties) secondary.clone();
   for (Enumeration e = primary.propertyNames(); e.hasMoreElements(); ) {
     String name = (String) e.nextElement();
     String value = primary.getProperty(name, "");
     p.put(name, value);
   }
   return p;
 }
Example #11
0
  /**
   * Restore default values to preferences and notify listeners.
   *
   * @param quiet display one info message log if true (debugging purpose).
   */
  public final void resetToDefaultPreferences(final boolean quiet) {
    _currentProperties = (Properties) _defaultProperties.clone();

    if (!quiet) {
      _logger.info("Restoring default preferences.");
    }

    // Notify all preferences listener.
    triggerObserversNotification();
  }
Example #12
0
 /** @since Ant 1.5 */
 public Object clone() {
   try {
     JUnitTest t = (JUnitTest) super.clone();
     t.props = props == null ? null : (Properties) props.clone();
     t.formatters = (Vector) formatters.clone();
     return t;
   } catch (CloneNotSupportedException e) {
     // plain impossible
     return this;
   }
 }
  /**
   * @hidden For internal use only. Overrides Object.clone() to clone all properties, used by this
   *     class and EnvironmentConfig.
   */
  @Override
  protected EnvironmentMutableConfig clone() {

    try {
      EnvironmentMutableConfig copy = (EnvironmentMutableConfig) super.clone();
      copy.props = (Properties) props.clone();
      return copy;
    } catch (CloneNotSupportedException willNeverOccur) {
      return null;
    }
  }
  public void setSystemProperties() {

    java.lang.System.setProperties((java.util.Properties) defaultProperties.clone());
    java.lang.System.setProperty("java.vm.vendor", "Oracle Corporation");
    java.lang.System.setProperty("java.specification.version", "1.8");
    java.lang.System.setProperty(
        "java.home", "/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre");
    java.lang.System.setProperty("java.awt.headless", "true");
    java.lang.System.setProperty("user.home", "/Users/hhildebrand");
    java.lang.System.setProperty("user.dir", "/Users/hhildebrand/git/Ultrastructure/model");
    java.lang.System.setProperty(
        "java.io.tmpdir", "/var/folders/_r/y4_0rwd16zgblwjq7b_tbhk80000gn/T/");
    java.lang.System.setProperty("awt.toolkit", "sun.lwawt.macosx.LWCToolkit");
    java.lang.System.setProperty("file.encoding", "UTF-8");
    java.lang.System.setProperty("file.separator", "/");
    java.lang.System.setProperty("java.awt.graphicsenv", "sun.awt.CGraphicsEnvironment");
    java.lang.System.setProperty("java.awt.printerjob", "sun.lwawt.macosx.CPrinterJob");
    java.lang.System.setProperty(
        "java.class.path",
        "/var/folders/_r/y4_0rwd16zgblwjq7b_tbhk80000gn/T/EvoSuite_pathingJar8602748439413877740.jar");
    java.lang.System.setProperty("java.class.version", "52.0");
    java.lang.System.setProperty(
        "java.endorsed.dirs",
        "/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/endorsed");
    java.lang.System.setProperty(
        "java.ext.dirs",
        "/Users/hhildebrand/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java");
    java.lang.System.setProperty("java.library.path", "lib");
    java.lang.System.setProperty("java.runtime.name", "Java(TM) SE Runtime Environment");
    java.lang.System.setProperty("java.runtime.version", "1.8.0_45-b14");
    java.lang.System.setProperty("java.specification.name", "Java Platform API Specification");
    java.lang.System.setProperty("java.specification.vendor", "Oracle Corporation");
    java.lang.System.setProperty("java.vendor", "Oracle Corporation");
    java.lang.System.setProperty("java.vendor.url", "http://java.oracle.com/");
    java.lang.System.setProperty("java.version", "1.8.0_45");
    java.lang.System.setProperty("java.vm.info", "mixed mode");
    java.lang.System.setProperty("java.vm.name", "Java HotSpot(TM) 64-Bit Server VM");
    java.lang.System.setProperty(
        "java.vm.specification.name", "Java Virtual Machine Specification");
    java.lang.System.setProperty("java.vm.specification.vendor", "Oracle Corporation");
    java.lang.System.setProperty("java.vm.specification.version", "1.8");
    java.lang.System.setProperty("java.vm.version", "25.45-b02");
    java.lang.System.setProperty("line.separator", "\n");
    java.lang.System.setProperty("os.arch", "x86_64");
    java.lang.System.setProperty("os.name", "Mac OS X");
    java.lang.System.setProperty("os.version", "10.11.3");
    java.lang.System.setProperty("path.separator", ":");
    java.lang.System.setProperty("user.country", "US");
    java.lang.System.setProperty("user.language", "en");
    java.lang.System.setProperty("user.name", "hhildebrand");
    java.lang.System.setProperty("user.timezone", "America/Los_Angeles");
  }
Example #15
0
  public void setOutputProperties(Properties oformat) throws IllegalArgumentException {

    if (oformat.get(publicProperty) == null) {
      // Optimize case where we don't need to map
      transformer.setOutputProperties(oformat);
    } else {
      Properties newProperties = (Properties) oformat.clone();

      newProperties.put(privateProperty, oformat.get(publicProperty));
      newProperties.remove(publicProperty);

      transformer.setOutputProperties(newProperties);
    }
  }
Example #16
0
 /** INTERNAL: Clone the login. This also clones the platform as it is internal to the login. */
 public Object clone() {
   DatasourceLogin clone = null;
   try {
     clone = (DatasourceLogin) super.clone();
   } catch (Exception exception) {
     // should not happen...do nothing
   }
   if (getConnector() != null) {
     clone.setConnector((Connector) getConnector().clone());
   }
   clone.setDatasourcePlatform((Platform) getDatasourcePlatform().clone());
   clone.setProperties((Properties) properties.clone());
   return clone;
 }
  protected java.sql.Connection connectReplicationConnection(String url, Properties info)
      throws SQLException {
    Properties parsedProps = parseURL(url, info);

    if (parsedProps == null) {
      return null;
    }

    Properties masterProps = (Properties) parsedProps.clone();
    Properties slavesProps = (Properties) parsedProps.clone();

    // Marker used for further testing later on, also when
    // debugging
    slavesProps.setProperty("com.mysql.jdbc.ReplicationConnection.isSlave", "true");

    int numHosts = Integer.parseInt(parsedProps.getProperty(NUM_HOSTS_PROPERTY_KEY));

    if (numHosts < 2) {
      throw SQLError.createSQLException(
          "Must specify at least one slave host to connect to for master/slave replication load-balancing functionality",
          SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE,
          null);
    }

    for (int i = 1; i < numHosts; i++) {
      int index = i + 1;

      masterProps.remove(HOST_PROPERTY_KEY + "." + index);
      masterProps.remove(PORT_PROPERTY_KEY + "." + index);

      slavesProps.setProperty(
          HOST_PROPERTY_KEY + "." + i, parsedProps.getProperty(HOST_PROPERTY_KEY + "." + index));
      slavesProps.setProperty(
          PORT_PROPERTY_KEY + "." + i, parsedProps.getProperty(PORT_PROPERTY_KEY + "." + index));
    }

    masterProps.setProperty(NUM_HOSTS_PROPERTY_KEY, "1");
    slavesProps.remove(HOST_PROPERTY_KEY + "." + numHosts);
    slavesProps.remove(PORT_PROPERTY_KEY + "." + numHosts);
    slavesProps.setProperty(NUM_HOSTS_PROPERTY_KEY, String.valueOf(numHosts - 1));
    slavesProps.setProperty(HOST_PROPERTY_KEY, slavesProps.getProperty(HOST_PROPERTY_KEY + ".1"));
    slavesProps.setProperty(PORT_PROPERTY_KEY, slavesProps.getProperty(PORT_PROPERTY_KEY + ".1"));

    return new ReplicationConnection(masterProps, slavesProps);
  }
Example #18
0
  /* (non-Javadoc)
   * @see org.hibernate.cache.CacheProvider#start(java.util.Properties)
   */
  @SuppressWarnings({"rawtypes"})
  public void start() throws CacheException {
    String conf = "/memcached.properties";
    InputStream in = getClass().getResourceAsStream(conf);
    Properties memcached_conf = new Properties();
    try {
      memcached_conf.load(in);
    } catch (IOException e) {
      throw new CacheException("Unabled to load properties from " + conf, e);
    } finally {
      IOUtils.closeQuietly(in);
    }

    String servers = memcached_conf.getProperty(SERVERS_CONF);
    if (StringUtils.isBlank(servers)) {
      throw new CacheException("configuration 'memcached.servers' get a empty value");
    }
    SockIOPool pool = SockIOPool.getInstance();
    pool.setServers(servers.split(","));

    Properties base_conf = (Properties) memcached_conf.clone();
    base_conf.remove(SERVERS_CONF);
    Iterator keys = base_conf.keySet().iterator();
    while (keys.hasNext()) {
      String key = (String) keys.next();
      if (key.startsWith(CACHE_IDENT)) {
        _cache_properties.put(key.substring(CACHE_IDENT.length()), base_conf.getProperty(key));
        keys.remove();
      }
    }
    try {
      BeanUtils.populate(pool, base_conf);
    } catch (Exception e) {
      throw new CacheException("Unabled to set properties to SockIOPool", e);
    }

    pool.initialize();

    Logger.getLogger(MemCachedClient.class.getName()).setLevel(Logger.LEVEL_WARN);

    _CacheManager = new Hashtable<String, MemCache>();
  }
Example #19
0
  /**
   * SECURE: The password in the login properties is encrypted. Return a clone of the properties
   * with the password decrypted.
   */
  private Properties prepareProperties(Properties properties) {
    Properties result = (Properties) properties.clone();
    String password = result.getProperty("password");
    if (password != null) {
      // Fix for bug # 2700529
      // The securable object is initialized on first call of
      // getSecurableObject. When setting an encrypted password
      // we don't make this call since it is already encrypted, hence,
      // we do not initialize the securable object on the holder.
      //
      // If neither setPassword or setEncryptedPassword is called
      // (example, user sets properties via the setProperties method),
      // when the user tries to connect they  will get a null pointer
      // exception. So if the holder does not hold
      // a securable object or the setEncryptedPassword flag is not true,
      // don't bother trying to decrypt.
      if (getSecurableObjectHolder().hasSecurableObject() || isEncryptedPasswordSet) {
        result.put(
            "password", getSecurableObjectHolder().getSecurableObject().decryptPassword(password));
      }
    }

    return result;
  }
Example #20
0
  /**
   * Creates a copy of this layer.
   *
   * @see Object#clone
   * @return a clone of this layer, as complete as possible
   * @exception CloneNotSupportedException
   */
  @Override
  public Object clone() throws CloneNotSupportedException {
    TileLayer clone = (TileLayer) super.clone();

    // Clone the layer data
    clone.map = new Tile[map.length][];
    clone.tileInstanceProperties = new HashMap<Object, Properties>();

    for (int i = 0; i < map.length; i++) {
      clone.map[i] = new Tile[map[i].length];
      System.arraycopy(map[i], 0, clone.map[i], 0, map[i].length);

      for (int j = 0; j < map[i].length; j++) {
        Properties p = getTileInstancePropertiesAt(i, j);

        if (p != null) {
          Integer key = i + j * bounds.width;
          clone.tileInstanceProperties.put(key, (Properties) p.clone());
        }
      }
    }

    return clone;
  }
Example #21
0
 /**
  * Returns a Map of all <code>key=value</code> properties in the file as <code>
  * &lt;key (java.lang.String), value (java.lang.String)></code> <br>
  * <br>
  * Example:
  *
  * <blockquote>
  *
  * <pre>
  * PropertiesFile settings = new PropertiesFile("settings.properties");
  * Map<String, String> mappedSettings;
  *
  * try {
  * 	 mappedSettings = settings.returnMap();
  * } catch (Exception ex) {
  * 	 log.info("Failed mapping settings.properties");
  * }
  * </pre>
  *
  * </blockquote>
  *
  * @return <code>map</code> - Simple Map HashMap of the entire <code>key=value</code> as <code>
  *     &lt;key (java.lang.String), value (java.lang.String)></code>
  * @throws Exception If the properties file doesn't exist.
  */
 @SuppressWarnings("unchecked")
 public Map<String, String> returnMap() throws Exception {
   return (Map<String, String>) props.clone();
 }
  /** @see org.apache.maven.plugin.eclipse.writers.EclipseWriter#write() */
  public void write() throws MojoExecutionException {

    // check if it's necessary to create project specific settings
    Properties coreSettings = new Properties();

    String source = IdeUtils.getCompilerSourceVersion(config.getProject());
    String encoding = IdeUtils.getCompilerSourceEncoding(config.getProject());
    String target = IdeUtils.getCompilerTargetVersion(config.getProject());

    if (source != null) {
      coreSettings.put(PROP_JDT_CORE_COMPILER_SOURCE, source);
      coreSettings.put(PROP_JDT_CORE_COMPILER_COMPLIANCE, source);
    }

    if (encoding != null) {
      File basedir = config.getProject().getBasedir();
      List compileSourceRoots = config.getProject().getCompileSourceRoots();
      if (compileSourceRoots != null) {
        for (Object compileSourceRoot : compileSourceRoots) {
          String sourcePath = (String) compileSourceRoot;
          String relativePath =
              IdeUtils.toRelativeAndFixSeparator(basedir, new File(sourcePath), false);
          coreSettings.put(PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding);
        }
      }
      List testCompileSourceRoots = config.getProject().getTestCompileSourceRoots();
      if (testCompileSourceRoots != null) {
        for (Object testCompileSourceRoot : testCompileSourceRoots) {
          String sourcePath = (String) testCompileSourceRoot;
          String relativePath =
              IdeUtils.toRelativeAndFixSeparator(basedir, new File(sourcePath), false);
          coreSettings.put(PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding);
        }
      }
      List resources = config.getProject().getResources();
      if (resources != null) {
        for (Object resource1 : resources) {
          Resource resource = (Resource) resource1;
          String relativePath =
              IdeUtils.toRelativeAndFixSeparator(basedir, new File(resource.getDirectory()), false);
          coreSettings.put(PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding);
        }
      }
      List testResources = config.getProject().getTestResources();
      if (testResources != null) {
        for (Object testResource : testResources) {
          Resource resource = (Resource) testResource;
          String relativePath =
              IdeUtils.toRelativeAndFixSeparator(basedir, new File(resource.getDirectory()), false);
          coreSettings.put(PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding);
        }
      }
    }

    if (target != null && !JDK_1_2_SOURCES.equals(target)) {
      coreSettings.put(
          "org.eclipse.jdt.core.compiler.codegen.targetPlatform", target); // $NON-NLS-1$
    }

    // write the settings, if needed
    if (!coreSettings.isEmpty()) {
      File settingsDir =
          new File(
              config.getEclipseProjectDirectory(),
              EclipseWorkspaceWriter.DIR_DOT_SETTINGS); // $NON-NLS-1$

      settingsDir.mkdirs();

      coreSettings.put(PROP_ECLIPSE_PREFERENCES_VERSION, "1"); // $NON-NLS-1$

      try {
        File oldCoreSettingsFile;

        File coreSettingsFile =
            new File(settingsDir, EclipseWorkspaceWriter.ECLIPSE_JDT_CORE_PREFS_FILE);

        if (coreSettingsFile.exists()) {
          oldCoreSettingsFile = coreSettingsFile;

          Properties oldsettings = new Properties();
          oldsettings.load(new FileInputStream(oldCoreSettingsFile));

          Properties newsettings = (Properties) oldsettings.clone();
          newsettings.putAll(coreSettings);

          if (!oldsettings.equals(newsettings)) {
            newsettings.store(new FileOutputStream(coreSettingsFile), null);
          }
        } else {
          coreSettings.store(new FileOutputStream(coreSettingsFile), null);

          log.info(
              Messages.getString(
                  "EclipseSettingsWriter.wrotesettings", //$NON-NLS-1$
                  coreSettingsFile.getCanonicalPath()));
        }
      } catch (FileNotFoundException e) {
        throw new MojoExecutionException(
            Messages.getString("EclipseSettingsWriter.cannotcreatesettings"), e); // $NON-NLS-1$
      } catch (IOException e) {
        throw new MojoExecutionException(
            Messages.getString("EclipseSettingsWriter.errorwritingsettings"), e); // $NON-NLS-1$
      }
    } else {
      log.info(Messages.getString("EclipseSettingsWriter.usingdefaults")); // $NON-NLS-1$
    }
  }
  /** @see org.apache.maven.plugin.eclipse.writers.EclipseWriter#write() */
  public void write() throws MojoExecutionException {

    // check if it's necessary to create project specific settings
    Properties ajdtSettings = new Properties();

    IdeDependency[] deps = config.getDeps();
    int ajdtDepCount = 0;
    int ajdtWeaveDepCount = 0;
    for (int i = 0; i < deps.length; i++) {
      if (deps[i].isAjdtDependency()) {
        addDependency(ajdtSettings, deps[i], ASPECT_DEP_PROP, ++ajdtDepCount);
      }

      if (deps[i].isAjdtWeaveDependency()) {
        addDependency(ajdtSettings, deps[i], WEAVE_DEP_PROP, ++ajdtWeaveDepCount);
      }
    }

    // write the settings, if needed
    if (!ajdtSettings.isEmpty()) {
      File settingsDir =
          new File(config.getEclipseProjectDirectory(), DIR_DOT_SETTINGS); // $NON-NLS-1$

      settingsDir.mkdirs();

      ajdtSettings.put(PROP_ECLIPSE_PREFERENCES_VERSION, "1"); // $NON-NLS-1$

      try {
        File oldAjdtSettingsFile;

        File ajdtSettingsFile = new File(settingsDir, FILE_AJDT_PREFS);

        if (ajdtSettingsFile.exists()) {
          oldAjdtSettingsFile = ajdtSettingsFile;

          Properties oldsettings = new Properties();
          oldsettings.load(new FileInputStream(oldAjdtSettingsFile));

          Properties newsettings = (Properties) oldsettings.clone();
          newsettings.putAll(ajdtSettings);

          if (!oldsettings.equals(newsettings)) {
            newsettings.store(new FileOutputStream(ajdtSettingsFile), null);
          }
        } else {
          ajdtSettings.store(new FileOutputStream(ajdtSettingsFile), null);

          log.info(
              Messages.getString(
                  "EclipseSettingsWriter.wrotesettings", //$NON-NLS-1$
                  ajdtSettingsFile.getCanonicalPath()));
        }
      } catch (FileNotFoundException e) {
        throw new MojoExecutionException(
            Messages.getString("EclipseSettingsWriter.cannotcreatesettings"), e); // $NON-NLS-1$
      } catch (IOException e) {
        throw new MojoExecutionException(
            Messages.getString("EclipseSettingsWriter.errorwritingsettings"), e); // $NON-NLS-1$
      }
    }
  }
 @AfterClass
 public static void clearEvoSuiteFramework() {
   Sandbox.resetDefaultSecurityManager();
   java.lang.System.setProperties((java.util.Properties) defaultProperties.clone());
 }
Example #25
0
 /**
  * Returns the group's property-override list.
  *
  * @return the property-override list, or <code>null</code>
  * @since 1.2
  */
 public Properties getPropertyOverrides() {
   return (props != null) ? (Properties) props.clone() : null;
 }
Example #26
0
 /**
  * Create a new Generator object with a given property set. The property set will be duplicated.
  *
  * @param Properties properties object to help populate the control context.
  */
 public Generator(Properties props) {
   this.props = (Properties) props.clone();
 }
Example #27
0
 public Object clone() throws CloneNotSupportedException {
   MapObject clone = (MapObject) super.clone();
   clone.bounds = new Rectangle(bounds);
   clone.properties = (Properties) properties.clone();
   return clone;
 }
  /**
   * INTERNAL: Applies customization to connection. Called only if connection is not already
   * customized (isActive()==false). The method may throw SQLException wrapped into
   * DatabaseException. isActive method called after this method should return true only in case the
   * connection was actually customized.
   */
  public void customize() {
    // Lazily initialize proxy properties - customize method may be never called
    // in case of ClientSession using external connection pooling.
    if (proxyProperties == null) {
      buildProxyProperties();
    }

    Connection connection = accessor.getConnection();
    if (connection instanceof OracleConnection) {
      oracleConnection = (OracleConnection) connection;
    } else {
      connection = session.getServerPlatform().unwrapConnection(connection);
      if (connection instanceof OracleConnection) {
        oracleConnection = (OracleConnection) connection;
      } else {
        throw ValidationException.oracleJDBC10_1_0_2ProxyConnectorRequiresOracleConnection();
      }
    }
    try {
      clearConnectionCache();
      Object[] args = null;
      if (this.session.shouldLog(SessionLog.FINEST, SessionLog.CONNECTION)) {
        Properties logProperties = proxyProperties;
        if (proxyProperties.containsKey(OracleConnection.PROXY_USER_PASSWORD)) {
          logProperties = (Properties) proxyProperties.clone();
          logProperties.setProperty(OracleConnection.PROXY_USER_PASSWORD, "******");
        }
        args = new Object[] {oracleConnection, logProperties};
      }
      if (oracleConnection.isProxySession()) {
        // Unexpectedly oracleConnection already has a proxy session - probably it was not closed
        // when connection was returned back to connection pool.
        // That may happen on jta transaction rollback (especially triggered outside of user's
        // thread - such as timeout)
        // when beforeCompletion is never issued
        // and application server neither closes proxySession nor allows access to connection in
        // afterCompletion.
        try {
          if (args != null) {
            ((AbstractSession) this.session)
                .log(
                    SessionLog.FINEST,
                    SessionLog.CONNECTION,
                    "proxy_connection_customizer_already_proxy_session",
                    args);
          }
          oracleConnection.close(OracleConnection.PROXY_SESSION);
        } catch (SQLException exception) {
          // Ignore
          this.session
              .getSessionLog()
              .logThrowable(SessionLog.WARNING, SessionLog.CONNECTION, exception);
        }
      }
      oracleConnection.openProxySession(proxyType, proxyProperties);
      // 12c driver will default to an autoCommit setting of true on calling openProxySession
      oracleConnection.setAutoCommit(false);
      if (args != null) {
        ((AbstractSession) this.session)
            .log(
                SessionLog.FINEST,
                SessionLog.CONNECTION,
                "proxy_connection_customizer_opened_proxy_session",
                args);
      }
    } catch (SQLException exception) {
      oracleConnection = null;
      throw DatabaseException.sqlException(exception);
    } catch (NoSuchMethodError noSuchMethodError) {
      oracleConnection = null;
      throw ValidationException.oracleJDBC10_1_0_2ProxyConnectorRequiresOracleConnectionVersion();
    }
  }
  /**
   * Load the properties file from a resource stream. If a key name such as "org.apache.xslt.xxx",
   * fix up the start of string to be a curly namespace. If a key name starts with
   * "xslt.output.xxx", clip off "xslt.output.". If a key name *or* a key value is discovered, check
   * for \u003a in the text, and fix it up to be ":", since earlier versions of the JDK do not
   * handle the escape sequence (at least in key names).
   *
   * @param resourceName non-null reference to resource name.
   * @param defaults Default properties, which may be null.
   */
  private static Properties loadPropertiesFile(final String resourceName, Properties defaults)
      throws IOException {

    // This static method should eventually be moved to a thread-specific class
    // so that we can cache the ContextClassLoader and bottleneck all properties file
    // loading throughout Xalan.

    Properties props = new Properties(defaults);

    InputStream is = null;
    BufferedInputStream bis = null;

    try {
      if (ACCESS_CONTROLLER_CLASS != null) {
        is =
            (InputStream)
                AccessController.doPrivileged(
                    new PrivilegedAction() {
                      public Object run() {
                        return OutputPropertiesFactory.class.getResourceAsStream(resourceName);
                      }
                    });
      } else {
        // User may be using older JDK ( JDK < 1.2 )
        is = OutputPropertiesFactory.class.getResourceAsStream(resourceName);
      }

      bis = new BufferedInputStream(is);
      props.load(bis);
    } catch (IOException ioe) {
      if (defaults == null) {
        throw ioe;
      } else {
        throw new WrappedRuntimeException(
            Utils.messages.createMessage(
                MsgKey.ER_COULD_NOT_LOAD_RESOURCE, new Object[] {resourceName}),
            ioe);
        // "Could not load '"+resourceName+"' (check CLASSPATH), now using just the defaults ",
        // ioe);
      }
    } catch (SecurityException se) {
      // Repeat IOException handling for sandbox/applet case -sc
      if (defaults == null) {
        throw se;
      } else {
        throw new WrappedRuntimeException(
            Utils.messages.createMessage(
                MsgKey.ER_COULD_NOT_LOAD_RESOURCE, new Object[] {resourceName}),
            se);
        // "Could not load '"+resourceName+"' (check CLASSPATH, applet security), now using just the
        // defaults ", se);
      }
    } finally {
      if (bis != null) {
        bis.close();
      }
      if (is != null) {
        is.close();
      }
    }

    // Note that we're working at the HashTable level here,
    // and not at the Properties level!  This is important
    // because we don't want to modify the default properties.
    // NB: If fixupPropertyString ends up changing the property
    // name or value, we need to remove the old key and re-add
    // with the new key and value.  However, then our Enumeration
    // could lose its place in the HashTable.  So, we first
    // clone the HashTable and enumerate over that since the
    // clone will not change.  When we migrate to Collections,
    // this code should be revisited and cleaned up to use
    // an Iterator which may (or may not) alleviate the need for
    // the clone.  Many thanks to Padraig O'hIceadha
    // <*****@*****.**> for finding this problem.  Bugzilla 2000.

    Enumeration keys = ((Properties) props.clone()).keys();
    while (keys.hasMoreElements()) {
      String key = (String) keys.nextElement();
      // Now check if the given key was specified as a
      // System property. If so, the system property
      // overides the default value in the propery file.
      String value = null;
      try {
        value = SecuritySupport.getSystemProperty(key);
      } catch (SecurityException se) {
        // No-op for sandbox/applet case, leave null -sc
      }
      if (value == null) value = (String) props.get(key);

      String newKey = fixupPropertyString(key, true);
      String newValue = null;
      try {
        newValue = SecuritySupport.getSystemProperty(newKey);
      } catch (SecurityException se) {
        // No-op for sandbox/applet case, leave null -sc
      }
      if (newValue == null) newValue = fixupPropertyString(value, false);
      else newValue = fixupPropertyString(newValue, false);

      if (key != newKey || value != newValue) {
        props.remove(key);
        props.put(newKey, newValue);
      }
    }

    return props;
  }
  private java.sql.Connection connectReplicationConnection(String url, Properties info)
      throws SQLException {
    Properties parsedProps = parseURL(url, info);

    if (parsedProps == null) {
      return null;
    }

    Properties masterProps = (Properties) parsedProps.clone();
    Properties slavesProps = (Properties) parsedProps.clone();

    // Marker used for further testing later on, also when
    // debugging
    slavesProps.setProperty("com.mysql.jdbc.ReplicationConnection.isSlave", "true");

    String hostValues = parsedProps.getProperty(HOST_PROPERTY_KEY);

    if (hostValues != null) {
      StringTokenizer st = new StringTokenizer(hostValues, ",");

      StringBuffer masterHost = new StringBuffer();
      StringBuffer slaveHosts = new StringBuffer();

      if (st.hasMoreTokens()) {
        String[] hostPortPair = parseHostPortPair(st.nextToken());

        if (hostPortPair[HOST_NAME_INDEX] != null) {
          masterHost.append(hostPortPair[HOST_NAME_INDEX]);
        }

        if (hostPortPair[PORT_NUMBER_INDEX] != null) {
          masterHost.append(":");
          masterHost.append(hostPortPair[PORT_NUMBER_INDEX]);
        }
      }

      boolean firstSlaveHost = true;

      while (st.hasMoreTokens()) {
        String[] hostPortPair = parseHostPortPair(st.nextToken());

        if (!firstSlaveHost) {
          slaveHosts.append(",");
        } else {
          firstSlaveHost = false;
        }

        if (hostPortPair[HOST_NAME_INDEX] != null) {
          slaveHosts.append(hostPortPair[HOST_NAME_INDEX]);
        }

        if (hostPortPair[PORT_NUMBER_INDEX] != null) {
          slaveHosts.append(":");
          slaveHosts.append(hostPortPair[PORT_NUMBER_INDEX]);
        }
      }

      if (slaveHosts.length() == 0) {
        throw SQLError.createSQLException(
            "Must specify at least one slave host to connect to for master/slave replication load-balancing functionality",
            SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);
      }

      masterProps.setProperty(HOST_PROPERTY_KEY, masterHost.toString());
      slavesProps.setProperty(HOST_PROPERTY_KEY, slaveHosts.toString());
    }

    return new ReplicationConnection(masterProps, slavesProps);
  }