com.vectorprint.configuration.generated.parser.PropertiesParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Config Show documentation
Show all versions of Config Show documentation
This project is about configuration of applications and about parameterization of Objects.
This library offers annotations (and annotation processors), parsers, typing, observing changes, serialization,
cloning and more when working with settings and/or object parameters. Settings and its features can be declared using an xml format.
The library offers syntax support for settings and parameters in a loosely coupled manner. You are not restricted to built in syntax, you
can provide your own.
At runtime this library tracks keys for which a default is used because they are not found in settings. Also it tracks
unused keys.
You can stack features for settings such as caching, preparing keys and values, readonlyness, threadsafety, helpsupport, reading / parsing from input. You can easily develop
your own features for settings.
/* PropertiesParser.java */
/* Generated by: ParserGeneratorCC: Do not edit this line. PropertiesParser.java */
package com.vectorprint.configuration.generated.parser;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.io.Writer;
import java.io.IOException;
import com.vectorprint.ArrayHelper;
import com.vectorprint.configuration.EnhancedMap;
import com.vectorprint.configuration.Settings;
import com.vectorprint.configuration.decoration.ParsingProperties;
import com.vectorprint.configuration.binding.settings.AbstractPropertiesParser;
import com.vectorprint.VectorPrintRuntimeException;
/**
* A parser for properties in the form key=value, values can span lines by escaping the end of a line:
*
# To change this template, choose Tools | Templates
# and open the template in the editor.
diameter=7
marks=0;89;95
markcolors=#ee0000;#f7931e;#\
8cc63f
lightmarkcolors=#ff0000;#ff9922;#90cf49
*
*/
public class PropertiesParser extends AbstractPropertiesParser implements PropertiesParserConstants {
private EnhancedMap properties = null;
public void parse(EnhancedMap settings) {
this.properties = settings;
try {
parseSettings();
} catch(Exception e) {
throw new VectorPrintRuntimeException(e);
}
}
public void serialize(EnhancedMap p, Writer w) throws IOException {
for (Map.Entry e : p.entrySet()) {
if (p instanceof ParsingProperties) {
ParsingProperties pp = (ParsingProperties) p;
for (String c : pp.getCommentBeforeKey(e.getKey())) {
w.append(c);
}
}
w.append(e.getKey());
w.append('=');
if (e.getValue()!=null) {
for (String v : e.getValue()) {
w.append(v);
w.append(';');
}
}
w.append(System.getProperty("line.separator"));
}
if (p instanceof ParsingProperties) {
ParsingProperties pp = (ParsingProperties) p;
for (String c : pp.getTrailingComment()) {
w.append(c);
}
}
}
final public EnhancedMap parseSettings() throws ParseException {List kv = null;Token cm; List comments = new ArrayList(1);String key = null;
label_1:
while (true) {
switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) {
case COMMENT:
case KEY:{
break;
}
default:
jj_la1[0] = jj_gen;
break label_1;
}
switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) {
case KEY:{
kv = keyValue();
key = kv.get(0);
if (properties instanceof ParsingProperties) {
for (String s : comments) {
((ParsingProperties)properties).addCommentBeforeKey(key,s);
}
}
comments.clear();
kv.remove(0);
properties.put(key,ArrayHelper.toArray(kv));
break;
}
case COMMENT:{
cm = jj_consume_token(COMMENT);
comments.add(cm.image);
break;
}
default:
jj_la1[1] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
if (properties instanceof ParsingProperties) {
for (String s : comments) {
((ParsingProperties)properties).addTrailingComment(s);
}
}
jj_consume_token(0);
{if ("" != null) return properties;}
throw new IllegalStateException ("Missing return statement in function");
}
final public List keyValue() throws ParseException {List kv = new ArrayList(2); Token t = null; String v = null;
t = jj_consume_token(KEY);
kv.add(t.image);
jj_consume_token(EQ);
v = value();
kv.add(v);
label_2:
while (true) {
switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) {
case SEMICOLON:{
break;
}
default:
jj_la1[2] = jj_gen;
break label_2;
}
jj_consume_token(SEMICOLON);
v = value();
if (v!=null&&!v.isEmpty()) kv.add(v);
}
switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) {
case EOL:{
jj_consume_token(EOL);
break;
}
case 0:{
jj_consume_token(0);
break;
}
default:
jj_la1[3] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
{if ("" != null) return kv;}
throw new IllegalStateException ("Missing return statement in function");
}
final public String value() throws ParseException {StringBuilder v = new StringBuilder();Token t = null;
label_3:
while (true) {
switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) {
case ESCAPEDSEMICOLON:
case VALUE:{
break;
}
default:
jj_la1[4] = jj_gen;
break label_3;
}
switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) {
case ESCAPEDSEMICOLON:{
jj_consume_token(ESCAPEDSEMICOLON);
v.append(';');
break;
}
case VALUE:{
t = jj_consume_token(VALUE);
v.append(t.image);
break;
}
default:
jj_la1[5] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
{if ("" != null) return v.toString();}
throw new IllegalStateException ("Missing return statement in function");
}
/** Generated Token Manager. */
public PropertiesParserTokenManager token_source;
SimpleCharStream jj_input_stream;
/** Current token. */
public Token token;
/** Next token. */
public Token jj_nt;
private int jj_ntk;
private int jj_gen;
final private int[] jj_la1 = new int[6];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
}
private static void jj_la1_init_0() {
jj_la1_0 = new int[] {0x280,0x280,0x4000,0x10001,0x28000,0x28000,};
}
/**
* Constructor with InputStream.
* @param stream input stream
*/
public PropertiesParser(final java.io.InputStream stream) {
this(stream, null);
}
/**
* Constructor with InputStream and supplied encoding
* @param stream input stream
* @param encoding charset to be used
*/
public PropertiesParser(final java.io.InputStream stream, final java.nio.charset.Charset encoding) {
jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1);
token_source = new PropertiesParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 6; i++) jj_la1[i] = -1;
}
/**
* Reinitialise
* @param stream input stream
*/
public void ReInit(final java.io.InputStream stream) {
ReInit(stream, null);
}
/**
* Reinitialise
* @param stream input stream
* @param encoding charset to be used
*/
public void ReInit(final java.io.InputStream stream, final java.nio.charset.Charset encoding) {
jj_input_stream.reInit(stream, encoding, 1, 1);
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 6; i++) jj_la1[i] = -1;
}
/**
* Constructor with InputStream.
* @param stream char stream
*/
public PropertiesParser(final java.io.Reader stream) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
token_source = new PropertiesParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 6; i++)
jj_la1[i] = -1;
}
/**
* Reinitialise
* @param stream char stream
*/
public void ReInit(final java.io.Reader stream) {
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
} else {
jj_input_stream.reInit(stream, 1, 1);
}
if (token_source == null) {
token_source = new PropertiesParserTokenManager(jj_input_stream);
}
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 6; i++)
jj_la1[i] = -1;
}
/**
* Constructor with generated Token Manager.
* @param tm Token manager to use
*/
public PropertiesParser(final PropertiesParserTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 6; i++) jj_la1[i] = -1;
}
/**
* Reinitialise
* @param tm Token manager to use
*/
public void ReInit(final PropertiesParserTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 6; i++) jj_la1[i] = -1;
}
private Token jj_consume_token(final int kind) throws ParseException {
final Token oldToken = token;
if (token.next != null)
token = token.next;
else {
token.next = token_source.getNextToken();
token = token.next;
}
jj_ntk = -1;
if (token.kind == kind) {
jj_gen++;
return token;
}
token = oldToken;
jj_kind = kind;
throw generateParseException();
}
/**
* @return the next Token.
*/
public final Token getNextToken() {
if (token.next != null)
token = token.next;
else
token = token.next = token_source.getNextToken();
jj_ntk = -1;
jj_gen++;
return token;
}
/**
* @param index index to be retrieved
* @return the specific Token.
*/
public final Token getToken(final int index) {
Token t = token;
for (int i = 0; i < index; i++) {
if (t.next == null)
t.next = token_source.getNextToken();
t = t.next;
}
return t;
}
private int jj_ntk_f() {
jj_nt = token.next;
if (jj_nt == null) {
token.next = token_source.getNextToken();
jj_ntk = token.next.kind;
return jj_ntk;
}
jj_ntk = jj_nt.kind;
return jj_ntk;
}
private java.util.List jj_expentries = new java.util.ArrayList<>();
private int[] jj_expentry;
private int jj_kind = -1;
/**
* Generate ParseException.
* @return new Exception object. Never null
*/
public ParseException generateParseException() {
jj_expentries.clear();
boolean[] la1tokens = new boolean[18];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 6; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<false
.
*/
public final boolean trace_enabled() {
return false;
}
/** Enable tracing. */
public final void enable_tracing() {}
/** Disable tracing. */
public final void disable_tracing() {}
}