Commit 2d2ee266 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

- removed outdated standalone generators, &39

parent 127fb288
Loading
Loading
Loading
Loading
+0 −75
Original line number Diff line number Diff line
package org.etsi.mts.tdl.tools.to.docx.poi;

import java.io.File;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.ocl.common.OCLConstants;
import org.eclipse.ocl.pivot.internal.delegate.OCLInvocationDelegateFactory;
import org.eclipse.ocl.pivot.internal.delegate.OCLSettingDelegateFactory;
import org.eclipse.ocl.pivot.internal.delegate.OCLValidationDelegateFactory;
import org.eclipse.ocl.xtext.essentialocl.EssentialOCLStandaloneSetup;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.etsi.mts.tdl.TPLan2StandaloneSetup;
import org.etsi.mts.tdl.impl.tdlPackageImpl;
import org.etsi.mts.tdl.structuredobjectives.impl.StructuredObjectivesPackageImpl;

import com.google.inject.Injector;

public class GeneratorApp {

	public static void main(String[] args) {
		Generator generator = new Generator();
		try {
			String filename = args[0];
			init();
			Resource resource = load(filename);
			File file = new File(filename);
			String target = file.getName()+".docx";
			generator.generate(resource, target, "TEST-RESOURCE");
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void init() {
		tdlPackageImpl.init();
		StructuredObjectivesPackageImpl.init();
		EssentialOCLStandaloneSetup.doSetup();
		initializeValidator();
	}

	public static Resource load(String filename) {
		new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../");
		Injector injector = new TPLan2StandaloneSetup().createInjectorAndDoEMFRegistration();
		XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
		resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
		Resource resource = resourceSet.getResource(URI.createURI(filename), true);
		return resource;
	}

	public static void initializeValidator() {
	//		OCL.initialize(null);
			String oclDelegateURI = OCLConstants.OCL_DELEGATE_URI+"/Pivot";
			
		    EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
		        new OCLInvocationDelegateFactory(oclDelegateURI));
		    EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
		        new OCLSettingDelegateFactory(oclDelegateURI));
		    EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI,
		        new OCLValidationDelegateFactory(oclDelegateURI));
		    
	//	    EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI, 
	//	    	new OCLSettingDelegateFactory.Global());
	//	    QueryDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI, new OCLQueryDelegateFactory.Global());
		    
	}

	
}
+0 −63
Original line number Diff line number Diff line
package org.etsi.mts.tdl.yang2tdl;

import java.io.File;
import java.util.ArrayList;

import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.etsi.mts.tdl.PackageableElement;
import org.etsi.mts.tdl.helper.TDLHelper;

public class YANGConverter {
	public static void main(String[] args) {
		String inputPath = "samples/simple/sports.yang";
//		inputPath = "samples/simple/links.yang";
//		inputPath = "samples/simple/example.yang";
//		inputPath = "samples/simple/acme.yang";
		inputPath = "samples/simple";
//		inputPath = "samples";
		String output = processToString(inputPath, inputPath+".tdltx");
		System.out.println(output);
	}
	public static String processToString(String inputPath, String outputPath) {
		return processToString(inputPath, outputPath, "SOURCE_MAPPING", "TARGET_MAPPING");
	}
	
	//TODO: will need to resolve related files as well
	public static String processToString(String inputPath, String outputPath, String sourceMapping, String targetMapping) {
		System.out.println("Exporting: "+outputPath+ " : "+ new File(outputPath).getAbsolutePath());
		Yang2TDLTranslator translator = new Yang2TDLTranslator();
		String content = "Package imported {}";
		try {
//			Resource tr = TDLHelper.create(outputPath+".tdl");
			Resource tr = TDLHelper.create(outputPath);
			translator.setTargetResource(tr);
			translator.initTargetResource(translator.getCleanName(new File(inputPath).getName()));
			translator.translate(inputPath);
			//update non-unique names
			//TODO: does not quite work yet
			//TODO: references not updated?
//			int s = 0;
//			ArrayList<String> names = new ArrayList<String>();
//			for (PackageableElement e : translator.getGeneratedPackage().getPackagedElement()) {
//				if (names.contains(e.getName()) ) {
//					e.setName(e.getName()+s);
//					s++;
//				} 
//				names.add(e.getName());
//			}
			content = TDLHelper.getText(tr);
			TDLHelper.store(tr, true);
//			Resource tdl = TDLHelper.load(outputPath+".tdl");
//			Resource tdltx = TDLHelper.create(outputPath);
//			tdltx.getContents().addAll(EcoreUtil.copyAll(tdl.getContents()));
//			content = TDLHelper.getText(tdltx);
//			TDLHelper.store(tdltx);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return content;
	}

}