Skip to content

Commit 75aa136

Browse files
committed
Added/updated code comments.
1 parent 66db356 commit 75aa136

7 files changed

Lines changed: 276 additions & 14 deletions

File tree

src/main/java/eu/europa/ted/efx/EfxTranslator.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/*
2+
* Copyright 2022 European Union
3+
*
4+
* Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European
5+
* Commission – subsequent versions of the EUPL (the "Licence"); You may not use this work except in
6+
* compliance with the Licence. You may obtain a copy of the Licence at:
7+
* https://joinup.ec.europa.eu/software/page/eupl
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the Licence
10+
* is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the Licence for the specific language governing permissions and limitations under
12+
* the Lic
13+
*/
114
package eu.europa.ted.efx;
215

316
import java.io.IOException;
@@ -6,28 +19,85 @@
619
import eu.europa.ted.efx.component.EfxTranslatorFactory;
720
import eu.europa.ted.efx.interfaces.TranslatorDependencyFactory;
821

22+
/**
23+
* Provided for convenience, this class exposes static methods that allow you to quickly instantiate
24+
* an EFX translator to translate EFX expressions and templates.
25+
*/
926
public class EfxTranslator {
1027

28+
/**
29+
* Instantiates an EFX expression translator and translates a given expression.
30+
*
31+
* @param dependencyFactory A {@link TranslatorDependencyFactory} to be used for instantiating the
32+
* dependencies of the EFX expression translator.
33+
* @param sdkVersion The version of the eForms SDK that defines the EFX grammar used by the
34+
* expression to be translated.
35+
* @param expression The EFX expression to translate.
36+
* @param expressionParameters The values of any parameters that the EFX expression requires.
37+
* @return The translated expression in the target script language supported by the given
38+
* {@link TranslatorDependencyFactory}.
39+
* @throws InstantiationException
40+
*/
1141
public static String translateExpression(final TranslatorDependencyFactory dependencyFactory, final String sdkVersion,
1242
final String expression, final String... expressionParameters) throws InstantiationException {
1343
return EfxTranslatorFactory.getEfxExpressionTranslator(sdkVersion, dependencyFactory)
1444
.translateExpression(expression, expressionParameters);
1545
}
1646

47+
/**
48+
* Instantiates an EFX template translator and translates the EFX template contained in the given
49+
* file.
50+
*
51+
* @param dependencyFactory A {@link TranslatorDependencyFactory} to be used for instantiating the
52+
* dependencies of the EFX template translator.
53+
* @param sdkVersion The version of the eForms SDK that defines the EFX grammar used by the EFX
54+
* template to be translated.
55+
* @param pathname The path to the file containing the EFX template to translate.
56+
* @return The translated template in the target markup language supported by the given
57+
* {@link TranslatorDependencyFactory}.
58+
* @throws IOException
59+
* @throws InstantiationException
60+
*/
1761
public static String translateTemplate(final TranslatorDependencyFactory dependencyFactory, final String sdkVersion,
1862
final Path pathname)
1963
throws IOException, InstantiationException {
2064
return EfxTranslatorFactory.getEfxTemplateTranslator(sdkVersion, dependencyFactory)
2165
.renderTemplate(pathname);
2266
}
2367

68+
/**
69+
* Instantiates an EFX template translator and translates the given EFX template.
70+
*
71+
* @param dependencyFactory A {@link TranslatorDependencyFactory} to be used for instantiating the
72+
* dependencies of the EFX template translator.
73+
* @param sdkVersion The version of the eForms SDK that defines the EFX grammar used by the EFX
74+
* template to be translated.
75+
* @param template A string containing the EFX template to translate.
76+
* @return The translated template in the target markup language supported by the given
77+
* {@link TranslatorDependencyFactory}.
78+
* @throws InstantiationException
79+
*/
2480
public static String translateTemplate(final TranslatorDependencyFactory dependencyFactory, final String sdkVersion,
2581
final String template)
2682
throws InstantiationException {
2783
return EfxTranslatorFactory.getEfxTemplateTranslator(sdkVersion, dependencyFactory)
2884
.renderTemplate(template);
2985
}
3086

87+
/**
88+
* Instantiates an EFX template translator and translates the EFX template contained in the given
89+
* InputStream.
90+
*
91+
* @param dependencyFactory A {@link TranslatorDependencyFactory} to be used for instantiating the
92+
* dependencies of the EFX template translator.
93+
* @param sdkVersion The version of the eForms SDK that defines the EFX grammar used by the EFX
94+
* template to be translated.
95+
* @param stream An InputStream containing the EFX template to be translated.
96+
* @return The translated template in the target markup language supported by the given
97+
* {@link TranslatorDependencyFactory}.
98+
* @throws IOException
99+
* @throws InstantiationException
100+
*/
31101
public static String translateTemplate(final TranslatorDependencyFactory dependencyFactory, final String sdkVersion,
32102
final InputStream stream)
33103
throws IOException, InstantiationException {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1+
/*
2+
* Copyright 2022 European Union
3+
*
4+
* Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European
5+
* Commission – subsequent versions of the EUPL (the "Licence"); You may not use this work except in
6+
* compliance with the Licence. You may obtain a copy of the Licence at:
7+
* https://joinup.ec.europa.eu/software/page/eupl
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the Licence
10+
* is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the Licence for the specific language governing permissions and limitations under
12+
* the Lic
13+
*/
14+
115
package eu.europa.ted.efx.interfaces;
216

17+
/**
18+
* Defines the API of an EFX expression translator.
19+
*
20+
* Note that the behaviour of the translator is defined once during its instantiation using a
21+
* TranslatorDependencyFactory.
22+
*/
323
public interface EfxExpressionTranslator {
24+
25+
/**
26+
* Translate the given EFX expression,
27+
*
28+
* @param expression A string containing the EFX expression to be translated.
29+
* @param expressionParameters The values of any parameters that the given expression expects.
30+
* @return
31+
*/
432
String translateExpression(final String expression, final String... expressionParameters);
533
}
Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
1+
/*
2+
* Copyright 2022 European Union
3+
*
4+
* Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European
5+
* Commission – subsequent versions of the EUPL (the "Licence"); You may not use this work except in
6+
* compliance with the Licence. You may obtain a copy of the Licence at:
7+
* https://joinup.ec.europa.eu/software/page/eupl
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the Licence
10+
* is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the Licence for the specific language governing permissions and limitations under
12+
* the Lic
13+
*/
114
package eu.europa.ted.efx.interfaces;
215

316
import java.io.IOException;
417
import java.io.InputStream;
518
import java.nio.file.Path;
619

20+
/**
21+
* Defines the API of an EFX template translator.
22+
*
23+
* Note that the behaviour of the translator is defined once during its instantiation using a
24+
* TranslatorDependencyFactory.
25+
*/
726
public interface EfxTemplateTranslator extends EfxExpressionTranslator {
27+
828
/**
9-
* Opens the indicated EFX file and translates the EFX template it contains.
29+
* Translate the EFX template stored in a file, given the pathname of the file.
30+
*
31+
* @param pathname The path and filename of the EFX template file to translate.
32+
* @return A string containing the translated template.
33+
* @throws IOException
1034
*/
1135
String renderTemplate(Path pathname) throws IOException;
1236

1337
/**
14-
* Translates the template contained in the string passed as a parameter.
38+
* Translate the EFX template stored in the given string.
39+
*
40+
* @param template A string containing an EFX template to be translated.
41+
* @return A string containing the translated template.
1542
*/
1643
String renderTemplate(String template);
1744

45+
/**
46+
* Translate the EFX template given as an InputStream.
47+
*
48+
* @param stream An InputStream with the EFX template to be translated.
49+
* @return A string containing the translated template.
50+
* @throws IOException
51+
*/
1852
String renderTemplate(InputStream stream) throws IOException;
1953
}

src/main/java/eu/europa/ted/efx/interfaces/MarkupGenerator.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/*
2+
* Copyright 2022 European Union
3+
*
4+
* Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European
5+
* Commission – subsequent versions of the EUPL (the "Licence"); You may not use this work except in
6+
* compliance with the Licence. You may obtain a copy of the Licence at:
7+
* https://joinup.ec.europa.eu/software/page/eupl
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the Licence
10+
* is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the Licence for the specific language governing permissions and limitations under
12+
* the Lic
13+
*/
114
package eu.europa.ted.efx.interfaces;
215

316
import java.util.List;

src/main/java/eu/europa/ted/efx/interfaces/ScriptGenerator.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/*
2+
* Copyright 2022 European Union
3+
*
4+
* Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European
5+
* Commission – subsequent versions of the EUPL (the "Licence"); You may not use this work except in
6+
* compliance with the Licence. You may obtain a copy of the Licence at:
7+
* https://joinup.ec.europa.eu/software/page/eupl
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the Licence
10+
* is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the Licence for the specific language governing permissions and limitations under
12+
* the Lic
13+
*/
114
package eu.europa.ted.efx.interfaces;
215

316
import java.util.List;
@@ -15,6 +28,17 @@
1528
import eu.europa.ted.efx.model.Expression.StringExpression;
1629
import eu.europa.ted.efx.model.Expression.TimeExpression;
1730

31+
/**
32+
* A ScriptGenerator is used by the EFX expression translator to translate specific computations to
33+
* the target language script.
34+
*
35+
* Each method defined by this interface corresponds to a specific computation that needs to be
36+
* translated. The parameters necessary for each computation are passed to the method already
37+
* translated to the target language. Each method should appropriately combine the given parameters
38+
* to form the target language script and return it as an {@link Expression}.
39+
*
40+
* As a reference implementation you can use the XPathScriptGenerator class.
41+
*/
1842
public interface ScriptGenerator {
1943

2044
/**

src/main/java/eu/europa/ted/efx/interfaces/SymbolResolver.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,55 @@
1+
/*
2+
* Copyright 2022 European Union
3+
*
4+
* Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European
5+
* Commission – subsequent versions of the EUPL (the "Licence"); You may not use this work except in
6+
* compliance with the Licence. You may obtain a copy of the Licence at:
7+
* https://joinup.ec.europa.eu/software/page/eupl
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the Licence
10+
* is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the Licence for the specific language governing permissions and limitations under
12+
* the Lic
13+
*/
114
package eu.europa.ted.efx.interfaces;
215

316
import java.util.List;
417
import eu.europa.ted.efx.model.Expression.PathExpression;
518

619
/**
7-
* EFX expressions contain references to eForms fields and nodes. These references are in the form
8-
* of field or node identifiers (a.k.a. symbols). The role of the {@link SymbolResolver} is to
9-
* provide further information on these referenced fields or nodes by looking them up in a
10-
* repository.
20+
* A SymbolResolver is a mechanism used by EFX translators to resolve symbols.
21+
*
22+
* EFX expressions contain references to eForms entities (fields, nodes or codelists). These
23+
* references are in the form of entity identifiers (a.k.a. symbols). The role of the
24+
* {@link SymbolResolver} is to provide further information on these referenced entities by looking
25+
* them up in a symbol dictionary (or repository). This symbol repository is typically the eForms
26+
* SDK itself.
1127
*/
1228
public interface SymbolResolver {
1329

1430
/**
1531
* Gets the identifier of the parent node of the given field.
1632
*
33+
* This information is typically retrieved directly from the eForms SDK.
34+
*
1735
* @param fieldId The identifier of the field to look for.
1836
* @return The identifier of the parent node of the given field.
1937
*/
2038
public String getParentNodeOfField(final String fieldId);
2139

2240
/**
23-
* Gets the path that can be used to locate the give field in the data source, relative to another
24-
* given path.
41+
* Gets the path that can be used to locate the given field in the data source, relative to
42+
* another given path.
43+
*
44+
* The "path" points to a location in the data source. The path will be eventually used to retrieve
45+
* the data from the data source. Typically, the data source is an XML file, in which case the
46+
* path should be an XPath. If the data source is a JSON file, then the path should be a JsonPath.
47+
* If you intend to use a function call to retrieve the data from the data source then that is what
48+
* you should return as path. In general keep in mind that the path is used as target language script.
2549
*
2650
* @param fieldId The identifier of the field to look for.
2751
* @param contextPath The path relative to which we expect to find the return value.
28-
* @return The path to the given field relative to the given context path.
52+
* @return The path to the given field relative to the given contextPath.
2953
*/
3054
public PathExpression getRelativePathOfField(final String fieldId,
3155
final PathExpression contextPath);
@@ -34,6 +58,8 @@ public PathExpression getRelativePathOfField(final String fieldId,
3458
* Gets the path that can be used to locate the given node in the data source, relative to another
3559
* given path.
3660
*
61+
* See {@link getRelativePathOfField} for a description of the concept of "path".
62+
*
3763
* @param nodeId The identifier of the node to look for.
3864
* @param contextPath The path relative to which we expect to find the return value.
3965
* @return The path to the given node relative to the given context path.
@@ -46,6 +72,8 @@ public PathExpression getRelativePathOfNode(final String nodeId,
4672
/**
4773
* Gets the absolute path that can be used to locate a field in the data source.
4874
*
75+
* See {@link getRelativePathOfField} for a description of the concept of "path".
76+
*
4977
* @param fieldId The identifier of the field to look for.
5078
* @return The absolute path to the field as a PathExpression.
5179
*/
@@ -54,6 +82,8 @@ public PathExpression getRelativePathOfNode(final String nodeId,
5482
/**
5583
* Gets the absolute path the can be used to locate a node in the data source.
5684
*
85+
* See {@link getRelativePathOfField} for a description of the concept of "path".
86+
*
5787
* @param nodeId The identifier of the node to look for.
5888
* @return The absolute path to the node as a PathExpression.
5989
*/
@@ -62,6 +92,8 @@ public PathExpression getRelativePathOfNode(final String nodeId,
6292
/**
6393
* Gets the type of the given field.
6494
*
95+
* This information is typically retrieved directly from the eForms SDK.
96+
*
6597
* @param fieldId The identifier of the field to look for.
6698
* @return The type of the field as a string.
6799
*/
@@ -71,6 +103,8 @@ public PathExpression getRelativePathOfNode(final String nodeId,
71103
* Gets the codelist associated with the given field. If the codelist is a tailored codelist then
72104
* this method will return the identifier of its parent codelist.
73105
*
106+
* This information is typically retrieved directly from the eForms SDK.
107+
*
74108
* @param fieldId The identifier of the field to look for.
75109
* @return The "root" codelist associated ith the given field.
76110
*/
@@ -79,6 +113,8 @@ public PathExpression getRelativePathOfNode(final String nodeId,
79113
/**
80114
* Gets the list of all codes in a given codelist as a list of strings.
81115
*
116+
* This information is typically retrieved directly from the eForms SDK.
117+
*
82118
* @param codelistId The identifier of the codelist to expand.
83119
* @return The list of codes in the given codelist.
84120
*/

0 commit comments

Comments
 (0)