Commit 3f43017e authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ decoupling of dependencies, #145

+ register and consume services dynamically through activators, restructure helper and resource handler, uniform interfaces for converters and translators
parent 2d2ee266
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -5,7 +5,12 @@ Bundle-Vendor: My Company
Bundle-Version: 1.0.0.qualifier
Export-Package: org.etsi.mts.tdl,
 org.etsi.mts.tdl.parser.antlr.internal,
 org.etsi.mts.tdl.services
 org.etsi.mts.tdl.services,
 org.etsi.mts.tdl.scoping,
 org.etsi.mts.tdl.parser.antlr,
 org.etsi.mts.tdl.validation,
 org.etsi.mts.tdl.generator,
 org.etsi.mts.tdl.serializer
Bundle-SymbolicName: org.etsi.mts.tdl.TDLan2; singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: org.etsi.mts.tdl.model,
@@ -18,4 +23,4 @@ Require-Bundle: org.etsi.mts.tdl.model,
 org.eclipse.xtext.util,
 org.eclipse.xtend.lib;bundle-version="2.14.0"
Bundle-RequiredExecutionEnvironment: JavaSE-11
Import-Package: org.apache.log4j
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ Bundle-Name: ASN.1 to TDL Generator
Bundle-SymbolicName: org.etsi.mts.tdl.asn2tdl
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: org.etsi.mts.tdl.asn2tdl
Bundle-Activator: org.etsi.mts.tdl.asn2tdl.Activator
Bundle-Vendor: ETSI
Require-Bundle: org.eclipse.core.runtime,
 org.eclipse.core.resources,
+42 −0
Original line number Diff line number Diff line
package org.etsi.mts.tdl.asn2tdl;

import java.io.File;

import org.eclipse.emf.ecore.resource.Resource;
import org.etsi.mts.tdl.resources.ResourceHandler;
import org.etsi.mts.tdl.transform.Converter;

public class ASNConverter implements Converter {
	public String processToString(String inputPath, String outputPath) {
		return processToString(inputPath, outputPath, "SOURCE_MAPPING", "TARGET_MAPPING");
	}
	
	public String processToString(String inputPath, String outputPath, String sourceMapping, String targetMapping) {
		System.out.println("Exporting: "+outputPath+ " : "+ new File(outputPath).getAbsolutePath());
		ASN2TDLTranslator translator = new ASN2TDLTranslator();
		String content = "Package imported {}";
		try {
			Resource tr = ResourceHandler.create(outputPath);
			translator.setTargetResource(tr);
			translator.initTargetResource(translator.cleanName(new File(inputPath).getName()));
			translator.translate(inputPath);
			content = ResourceHandler.getText(tr);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return content;
	}

	@Override
	public String getExtension() {
		return "asn";
	}

	@Override
	public String processToString(String inputPath, String outputPath, String sourceMapping, String targetMapping,
			boolean inline) {
		return processToString(inputPath, outputPath, sourceMapping, targetMapping);
	}

}
+59 −0
Original line number Diff line number Diff line
package org.etsi.mts.tdl.asn2tdl;

import java.util.Hashtable;

import org.etsi.mts.tdl.transform.AbstractTranslator;
import org.etsi.mts.tdl.transform.Converter;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

/**
 * The activator class controls the plug-in life cycle
 */
//public class Activator extends Plugin {
public class Activator implements BundleActivator {

	// The plug-in ID
	public static final String PLUGIN_ID = "org.etsi.mts.tdl.asn2tdl"; //$NON-NLS-1$

	// The shared instance
	private static Activator plugin;
	
	/**
	 * The constructor
	 */
	public Activator() {
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
//		super.start(context);
		Hashtable<String, String> properties = new Hashtable<String, String>();
		properties.put("type", PLUGIN_ID);
		context.registerService(Converter.class.getName(), new ASNConverter(), properties);
		context.registerService(AbstractTranslator.class.getName(), new ASN2TDLTranslator(), properties);
		plugin = this;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		plugin = null;
//		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static Activator getDefault() {
		return plugin;
	}

}
+5 −1
Original line number Diff line number Diff line
@@ -4,10 +4,14 @@ Bundle-Name: Common
Bundle-SymbolicName: org.etsi.mts.tdl.common
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: org.etsi.mts.tdl.common
Bundle-Activator: org.etsi.mts.tdl.common.Activator
Require-Bundle: org.eclipse.xtext,
 org.etsi.mts.tdl.model,
 org.eclipse.core.runtime,
 org.eclipse.osgi
 org.eclipse.osgi,
 org.eclipse.core.resources,
 org.eclipse.emf.common,
 org.eclipse.xtext.xbase
Export-Package: org.etsi.mts.tdl,
 org.etsi.mts.tdl.resources,
 org.etsi.mts.tdl.scoping,
Loading