aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java')
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java54
1 files changed, 9 insertions, 45 deletions
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
index 243d238..f8ac3cc 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
@@ -5,15 +5,13 @@ import java.util.List;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
-import org.openecomp.sdc.toscaparser.ToscaParser;
-import org.openecomp.sdc.toscaparser.ToscaParserFactory;
-import org.openecomp.sdc.toscaparser.api.NodeTemplate;
-import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
+import org.openecomp.sdc.toscaparser.NodeTemplate;
+import org.openecomp.sdc.toscaparser.ToscaTemplate;
+import org.openecomp.sdc.toscaparser.common.JToscaException;
-public class SdcToscaParserFactory implements AutoCloseable{
+public class SdcToscaParserFactory{
private static SdcToscaParserFactory instance;
- private static ToscaParserFactory toscaParserFactory;
private SdcToscaParserFactory(){}
@@ -26,7 +24,6 @@ public class SdcToscaParserFactory implements AutoCloseable{
synchronized (SdcToscaParserFactory.class) {
if (instance == null) {
instance = new SdcToscaParserFactory();
- toscaParserFactory = new ToscaParserFactory();
}
}
}
@@ -38,48 +35,15 @@ public class SdcToscaParserFactory implements AutoCloseable{
* @param csarPath - the path to CSAR file.
* @return ISdcCsarHelper object.
* @throws SdcToscaParserException - in case the path or CSAR are invalid.
+ * @throws JToscaException
*/
- public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException{
+ public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException, JToscaException, IOException{
//TODO add logic to check if legal file and csar
synchronized (SdcToscaParserFactory.class) {
- if (toscaParserFactory == null){
- throw new SdcToscaParserException("The factory is closed. It was probably closed too soon.");
- }
- try {
- ToscaParser create = toscaParserFactory.create();
- ToscaTemplate parse = create.parse(csarPath);
- SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(parse);
- return sdcCsarHelperImpl;
- } catch (IOException e) {
- throw new SdcToscaParserException("Exception when creating the parser: "+e.getMessage());
- }
+ ToscaTemplate tosca = new ToscaTemplate(csarPath, null, true, null);
+ SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(tosca);
+ return sdcCsarHelperImpl;
}
}
- /**
- * Close the SdcToscaParserFactory.
- */
- public void close() {
- if (toscaParserFactory != null){
- synchronized (SdcToscaParserFactory.class) {
- if (toscaParserFactory != null) {
- try {
- toscaParserFactory.close();
- toscaParserFactory = null;
- } catch (IOException e) {
- //TODO add logging
- }
- }
- }
- }
- }
-
- public static void main(String[] args) throws SdcToscaParserException {
- try (SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance()){ //Autoclosable
- ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper("C:\\Users\\pa0916\\Desktop\\Work\\ASDC\\CSARs\\csar_hello_world.zip");
- //Can run methods on the helper
- List<NodeTemplate> allottedResources = sdcCsarHelper.getAllottedResources();
- //..............
- }
- }
} \ No newline at end of file