Skip to content

Commit

Permalink
multiple ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Mar 22, 2023
1 parent 33a5d6b commit 2576667
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/main/java/io/github/eocqrs/kafka/xml/ConsumerXmlMapParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package io.github.eocqrs.kafka.xml;

import com.jcabi.xml.XML;
import org.cactoos.Input;

/**
* Consumer XML Params.
Expand All @@ -40,4 +41,24 @@ final class ConsumerXmlMapParams extends XmlMapParams {
ConsumerXmlMapParams(final XML configuration) {
super(configuration, KfCustomer.CONSUMER);
}

/**
* Ctor.
*
* @param resource The resource with xml settings.
* @throws Exception When something went wrong.
*/
ConsumerXmlMapParams(final Input resource) throws Exception {
super(resource, KfCustomer.CONSUMER);
}

/**
* Ctor.
*
* @param name Name of the resource.
* @throws Exception When something went wrong.
*/
ConsumerXmlMapParams(final String name) throws Exception {
super(name, KfCustomer.CONSUMER);
}
}
21 changes: 21 additions & 0 deletions src/main/java/io/github/eocqrs/kafka/xml/ProducerXmlMapParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package io.github.eocqrs.kafka.xml;

import com.jcabi.xml.XML;
import org.cactoos.Input;

/**
* Producer XML Params.
Expand All @@ -40,4 +41,24 @@ final class ProducerXmlMapParams extends XmlMapParams {
ProducerXmlMapParams(final XML configuration) {
super(configuration, KfCustomer.PRODUCER);
}

/**
* Ctor.
*
* @param resource The resource with xml settings.
* @throws Exception When something went wrong.
*/
ProducerXmlMapParams(final Input resource) throws Exception {
super(resource, KfCustomer.PRODUCER);
}

/**
* Ctor.
*
* @param name Name of the resource.
* @throws Exception When something went wrong.
*/
ProducerXmlMapParams(final String name) throws Exception {
super(name, KfCustomer.PRODUCER);
}
}
36 changes: 35 additions & 1 deletion src/main/java/io/github/eocqrs/kafka/xml/XmlMapParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import lombok.RequiredArgsConstructor;
import org.cactoos.Input;
import org.cactoos.Scalar;
import org.cactoos.io.ResourceOf;
import org.cactoos.text.Concatenated;

import java.util.Locale;
Expand All @@ -39,7 +41,6 @@
* @author Ivan Ivanchuk (l3r8y@duck.com)
* @since 0.0.2
*/
@RequiredArgsConstructor
abstract class XmlMapParams implements Scalar<Map<String, Object>> {

/**
Expand All @@ -57,6 +58,39 @@ abstract class XmlMapParams implements Scalar<Map<String, Object>> {
*/
private final KfCustomer customer;

/**
* Ctor.
*
* @param config XML config.
* @param cust Customer type.
*/
protected XmlMapParams(final XML config, final KfCustomer cust) {
this.configuration = config;
this.customer = cust;
}

/**
* A ctor that takes an Input and converts it to XMLDocument.
*
* @param resource Resource with settings.
* @param cust Customer type.
* @throws Exception When something went wrong.
*/
protected XmlMapParams(final Input resource, final KfCustomer cust) throws Exception {
this(new XMLDocument(resource.stream()), cust);
}

/**
* A constructor that takes a String and converts it to ResourceOf.
*
* @param name Name of resource.
* @param cust Customer type.
* @throws Exception When something went wrong.
*/
protected XmlMapParams(final String name, final KfCustomer cust) throws Exception {
this(new ResourceOf(name), cust);
}

@Override
public final Map<String, Object> value() throws Exception {
final String parent = this.customer.toString().toLowerCase(Locale.ROOT);
Expand Down

0 comments on commit 2576667

Please sign in to comment.