Exemplo n.º 1
0
    /**
     * Returns a properties map representing the {@link OSGiBeanProperties} instance.
     *
     * @param osgiBeanProperties the instance of {@link OSGiBeanProperties} read for properties
     * @return a properties map representing the {@link OSGiBeanProperties} instance. The map will
     *     be empty if the {@link OSGiBeanProperties} instance has no properties.
     */
    public static Map<String, Object> toMap(OSGiBeanProperties osgiBeanProperties) {

      Map<String, Object> properties = new HashMap<>();

      for (String property : osgiBeanProperties.property()) {
        String[] parts = property.split(StringPool.EQUAL, 2);

        if (parts.length <= 1) {
          continue;
        }

        String key = parts[0];
        String className = String.class.getSimpleName();

        if (key.indexOf(StringPool.COLON) != -1) {
          String[] keyParts = StringUtil.split(key, StringPool.COLON);

          key = keyParts[0];
          className = keyParts[1];
        }

        String value = parts[1];

        _put(key, value, className, properties);
      }

      String portalPropertyPrefix = osgiBeanProperties.portalPropertyPrefix();

      if (Validator.isNotNull(portalPropertyPrefix)) {
        Properties portalProperties =
            PropsUtil.getProperties(
                portalPropertyPrefix, osgiBeanProperties.portalPropertiesRemovePrefix());

        properties.putAll(PropertiesUtil.toMap(portalProperties));
      }

      return properties;
    }