CPD Results

The following document contains the results of PMD's CPD 5.0.2.

Duplications

File Line
de\smartics\properties\impl\config\domain\key\envapp\EnvAppDefinitionKeyHelper.java 179
de\smartics\properties\impl\config\domain\key\rtaware\TenantUserDefinitionKeyHelper.java 204
        .configurationKeyFactory().createDefaultKey();
    // throw new IllegalArgumentException(
    // "Path '" + path + "' does not contain an environment or group.");
  }

  private static String chopFile(final String pathWithFile)
  {
    if (pathWithFile.endsWith(".properties"))
    {
      final int lastSlash = pathWithFile.lastIndexOf('/');
      if (lastSlash != -1)
      {
        final String path = pathWithFile.substring(0, lastSlash);
        return path;
      }

      return "";
    }
    return pathWithFile;
  }

  private ConfigurationKey<?> fetchExplicitKey(final String path)
  {
    ConfigurationKey<?> key = context.getKey(path);
    if (key == null)
    {
      key = context.getKey(null);
    }
    return key;
  }

  private boolean isGroup(final String token)
  {
    if (context.isRegisteredEnvironment(token)
        || context.isRegisteredNode(token))
    {
      return false;
    }

    return context.isGroup(token);
  }

  private ConfigurationKey<?> parseEnvironmentKey(final String environment,
File Line
de\smartics\properties\impl\config\domain\key\envapp\EnvAppDefinitionConfigParser.java 117
de\smartics\properties\impl\config\domain\key\rtaware\TenantUserDefinitionConfigParser.java 119
            new EnvAppPropertiesDefinitionContext(tlds, environments, nodes,
                groups, files);
      }
      return context;
    }
    catch (final JDOMException e)
    {
      throw new ConfigException(systemId(ConfigCode.CONFIG_FILE_CANNOT_BE_READ,
          e, systemId));
    }
    catch (final IOException e)
    {
      throw new ConfigException(systemId(ConfigCode.CONFIG_FILE_CANNOT_BE_READ,
          e, systemId));
    }
  }

  private static void checkNamespace(final String systemId,
      final Document document)
  {
    final Namespace actualNamespace = document.getRootElement().getNamespace();
    if (!NS.equals(actualNamespace))
    {
      throw new ConfigException(namespace(systemId, NS.getURI(),
          actualNamespace.getURI()));
    }
  }

  @Override
  protected ConfigurationKey<?> readKey(final Element element)
File Line
de\smartics\properties\impl\config\domain\key\envapp\EnvAppDefinitionConfigParser.java 89
de\smartics\properties\impl\config\domain\key\rtaware\TenantUserDefinitionConfigParser.java 91
  public EnvAppPropertiesDefinitionContext parse(final String systemId,
      final InputStream input) throws ConfigException
  {
    try
    {
      final SAXBuilder parser = new SAXBuilder();
      final Document document = parser.build(input, systemId);

      checkNamespace(systemId, document);

      final Element rootNode = document.getRootElement();
      final Set<String> tlds = readSet(rootNode, "tlds", "tld", null);
      final Set<String> environments =
          readSet(rootNode, "environments", "environment");
      final Set<String> nodes = readSet(rootNode, "nodes", "node");
      final Set<String> groups = readSet(rootNode, "groups", "group");
      final PropertyResourceMatchers files = readFiles(systemId, rootNode);

      final EnvAppPropertiesDefinitionContext context;
File Line
de\smartics\properties\impl\config\domain\key\envapp\EnvAppDefinitionKeyHelper.java 221
de\smartics\properties\impl\config\domain\key\rtaware\TenantUserDefinitionKeyHelper.java 318
  private ConfigurationKey<?> parseEnvironmentKey(final String environment,
      final StringTokenizer tokenizer)
  {
    final EnvironmentId envId;
    final ApplicationId appId;
    if (tokenizer.hasMoreTokens())
    {
      final String token = tokenizer.nextToken();
      if (isGroup(token))
      {
        envId = new EnvironmentId(environment);
        appId = parseAppId(token, tokenizer);
      }
      else
      {
        envId = new EnvironmentId(environment, token);
        if (tokenizer.hasMoreTokens())
        {
          appId = parseAppId(tokenizer.nextToken(), tokenizer);
        }
        else
        {
          appId = ANY_APP;
        }
      }
    }
    else
    {
      envId = new EnvironmentId(environment);
      appId = ANY_APP;
    }

    final ConfigurationKey<?> key = new EnvAppConfigurationKey(envId, appId);
File Line
de\smartics\properties\impl\config\ds\DataSourceConfigurationPropertiesLoader.java 99
de\smartics\properties\spi\config\cache\CacheConfigurationPropertiesLoader.java 112
              e.getMessage(), e));
    }
  }

  private Properties loadProperties() throws IOException, IllegalStateException
  {
    final Enumeration<URL> urlsEnum =
        Thread.currentThread().getContextClassLoader()
            .getResources(CLASSPATH_LOCATION);
    final List<URL> urls = Collections.list(urlsEnum);
    final int count = urls.size();
    if (count == 1)
    {
      final URL url = urls.get(0);
      final Properties properties = new Properties();
      final InputStream in = new BufferedInputStream(url.openStream());
      try
      {
        properties.load(in);
      }
      finally
      {
        IOUtils.closeQuietly(in);
      }
      properties.setProperty(DataSourceConfiguration.CONFIG_SOURCE_ID,
File Line
de\smartics\properties\spi\config\support\AbstractConfigurationPropertiesManagement.java 480
de\smartics\properties\spi\config\support\ConfigurationPropertiesManagementWithDefaults.java 368
  }

  private static PropertyValueResolveException wrapWithPropertyValueSourceInformation(
      final PropertyValueResolveException e,
      final PropertyDescriptor descriptor, final Property property)
  {
    final PropertyValueResolveException cause =
        isResolvementFailureOfPlaceholder(e, property)
            ? new PropertyValueResolveException(
                new PropertyExpressionMessageBean(e, descriptor,
                    property.getValue())) : e;

    if (!(cause instanceof PropertyValueResolveWithSourceException))
    {
      final PropertyLocation source = property.getSource();
      return new PropertyValueResolveWithSourceException(
          new PropertyExpressionWithSourceMessageBean(cause, source));
    }

    return e;
  }

  private static boolean isResolvementFailureOfPlaceholder(
      final PropertyValueResolveException e, final Property property)
  {
    return !property.getName().equals(e.getPropertyKey().getName());
File Line
de\smartics\properties\api\config\domain\PropertyStoreCode.java 72
de\smartics\properties\impl\config\jndi\JndiPropertyStoreCode.java 72
  private PropertyStoreCode(final Integer minorNumber)
  {
    this.info =
        new NumberCodeInfo("Store", PROPERTY_STORE_CODE_START, minorNumber);
  }

  // ******************************** Methods *******************************

  // --- init ---------------------------------------------------------------

  // --- get&set ------------------------------------------------------------

  @Override
  public String getCode()
  {
    return info.getCode();
  }

  @Override
  public String getComponentId()
  {
    return info.getComponentId();
  }

  @Override
  public String getDisplayId()
  {
    return info.toString();
  }

  @Override
  public Integer getMajorNumber()
  {
    return info.getMajorNumber();
  }

  @Override
  public Integer getMinorNumber()
  {
    return info.getMinorNumber();
  }

  // --- business -----------------------------------------------------------

  // --- object basics ------------------------------------------------------

  /**
   * Returns the string representation of the object.
   *
   * @return the string representation of the object.
   */
  @Override
  public String toString()
  {
    return getDisplayId();
  }
}