Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dfuchss/configuration-parser
This project realizes a tool to set values based on configuration files
https://github.com/dfuchss/configuration-parser
configuration java
Last synced: about 8 hours ago
JSON representation
This project realizes a tool to set values based on configuration files
- Host: GitHub
- URL: https://github.com/dfuchss/configuration-parser
- Owner: dfuchss
- License: mit
- Created: 2019-12-12T23:10:00.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-11-03T03:33:09.000Z (17 days ago)
- Last Synced: 2024-11-03T04:20:38.334Z (17 days ago)
- Topics: configuration, java
- Language: Java
- Size: 287 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# configuration-parser
[![Maven Deploy](https://github.com/dfuchss/configuration-parser/actions/workflows/deploy.yml/badge.svg)](https://github.com/dfuchss/configuration-parser/actions/workflows/deploy.yml)
[![Latest Release](https://img.shields.io/github/release/dfuchss/configuration-parser.svg)](https://github.com/dfuchss/configuration-parser/releases/latest)
[![GitHub issues](https://img.shields.io/github/issues/dfuchss/configuration-parser.svg?style=square)](https://github.com/dfuchss/configuration-parser/issues)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=square)](https://github.com/dfuchss/configuration-parser/blob/master/LICENSE.md)This repo contains a small project to set attributes of classes and objects.
# HowTo use ..?
## Use to set Int, Float, ...
If you want to set attributes of a class / Object, you have to make sure:
* The class **implements Configurable**
* You've set the **SetterInfo** annotation to the class (for ResourceBundle)Then just call
* `new ResourceBundleSetter().setAttributes(Foo.class);` for setting static fields of the class* `new ResourceBundleSetter().setAttributes(obj);` for setting non-static fields of an object obj
## Use to set MyType-Fields
If you want to set attributes of a class / Object which contains fields of types you've created or types which I currently not support you have three options to parse these fields:* You can annotate the class (-> type of the attribute) you want to parse with `@ClassParser` and set the parser of this type of objects.
* You can annotate the field which can't be parsed with `@SetParser` and set the parser only for the field.
* If the class (-> type of the attribute) only contains basic attributes (int, float, ...) you can also use the MultiLevelParser (Also this parser will be used if no other parser can be found).
# Maven & Co.
If you want to use maven or some similar tool add the following code to your pom:
```xml
org.fuchss
configuration-parser
X.Y.Z
```
# Examples
## Example 1: Simple Configurable Class
* src/main/java/MyClass.java:
```java
@SetterInfo(res = "conf/myconf")
public class MyClass implements Configurable {
public static long longValue;
public static MoreComplex complex;
}
```
* src/main/resources/conf/myconf.properties:
```
longValue=42
complex.fieldA=ABC
```
* src/main/java/Main.java:
```java
public class Main {
public static void main(String[] args) {
new ResourceBundleSetter().setAttributes(MyClass.class);
}
}
```
## Example 2: Additional Parsers I
* src/main/java/ClassWithParser.java:
```java
@ClassParser(MyParser.class)
public class ClassWithParser implements Configurable {
public int attribute;
}
```
* src/main/java/MyParser.java:
```java
public class MyParser implements Parser {
@Override
public Object parseIt(String definition, String[] path) throws Exception {
ClassWithParser c = new ClassWithParser();
c.attribute = Integer.parseInt(definition);
return c;
}
}
```
## Example 3: Additional Parsers II
* src/main/java/ClassWithoutParser.java:
```java
public class ClassWithoutParser implements Configurable {
public int attribute;
}
```
* src/main/java/MyClass.java:
```java
@SetterInfo(res = "conf/myconf")
public class MyClass implements Configurable {
@SetParser(MyParser.class)
public static ClassWithoutParser attr;
}
```