Code Monkey home page Code Monkey logo

Comments (3)

lviggiano avatar lviggiano commented on June 14, 2024

Duplicate keys are not supported by properties files. This means that they would be invalid Java properties files.

Multiline values are supported by properties files out of the box. Example:

you can do something like this:

config.prop=Sometext,\
                  OtherText,\
                  ...

The above will work just fine as:

@Key("config.prop");
public String configProp();     

Another option is to use XML. It will be released in the next version. See XML Support :

<config>
   <prop>
      Sometext
      OtherText
      ...
   </prop>
</config>

Then, for the above xml you can define the newline as separator, or define a SeparatorClass.

@Separator("\n")  //newline
@Key("config.prop");
public String configProp();     

Indexed properties are an option to map legacy configuration files, that are using this notation. Which is quite wrong from my point of view, since properties files do support multiline values out of the box, plus owner adds support for
collections, so the best way to implement this is the first example in this comment, unless there is some good reason I am missing.
Adding indexed properties adds some overhead on properties lookup since we need then to check for multivalues every time a property is requested, then since they are indexed we also need to sort them and return in the proper order, plus... what would be the correct behavior if one index is missing? example:

server.0=...
server.1=...   
server.3=...              # server.2 is missing!
server.4=...

So, I will consider this feature for future development if I get some good understanding what problem the indexed properties are solving that isn't already solved by multiline properties values (supported by default in Java properties files) and owner collections support.

from owner.

Ronmck avatar Ronmck commented on June 14, 2024

Do you support this type of XML structure, I want get elements by value.

env.name this the key for each of my servers.

<servers>
    <env>
        <name>DEV</name>
        <hostname>locahost1</hostname>
        <port>60000</port>
        <user>myuser1</user>
        <password>mypass1</password>
    </env>
    <env>
        <name>SIT</name>
        <hostname>locahost2</hostname>
        <port>60010</port>
        <user>myuser2</user>
        <password>mypass2</password>
    </env>
    <env>
        <name>UAT</name>
        <hostname>locahost3</hostname>
        <port>60020</port>
        <user>myuser3</user>
        <password>mypass3</password>
    </env>
    <env>
        <name>SVP</name>
        <hostname>locahost4</hostname>
        <port>60030</port>
        <user>myuser4</user>
        <password>mypass4</password>
    </env>
</servers>

from owner.

lviggiano avatar lviggiano commented on June 14, 2024

@Ronmck: No, your xml can't be supported at the moment. You can change it a follows:

<servers>
    <dev>
        <name>DEV</name>
        <hostname>locahost1</hostname>
        <port>60000</port>
        <user>myuser1</user>
        <password>mypass1</password>
    </dev>
    <sit>
        <name>SIT</name>
        <hostname>locahost2</hostname>
        <port>60010</port>
        <user>myuser2</user>
        <password>mypass2</password>
    </sit>
    <uat>
        <name>UAT</name>
        <hostname>locahost3</hostname>
        <port>60020</port>
        <user>myuser3</user>
        <password>mypass3</password>
    </uat>
    <svp>
        <name>SVP</name>
        <hostname>locahost4</hostname>
        <port>60030</port>
        <user>myuser4</user>
        <password>mypass4</password>
    </svp>
</servers>

This one should work fine.

I want to modify OWNER to support something like this:

interface MyConfig extends Config {
    @Key("servers.${env}.name");
    String name();

    @Key("servers.${env}.hostname");
    String hostname();

    @Key("servers.${env}.port");
    Integer port();
}

ConfigFactory.setProperty("env", "dev"); 
MyConfig cfg = ConfigFactory.create(MyConfig.class);

This way you can select ${env} in the ConfigFactory (or from the system properties) and have the above interface map to the appropriate section.

This is not working at the moment, but it is easy to implement and it will be available in the next release.

from owner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.