Subversion Repositories SmartDukaan

Rev

Rev 16 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16 Rev 17
Line 29... Line 29...
29
import in.shop2020.metamodel.jaxb.FeatureDefinitionType;
29
import in.shop2020.metamodel.jaxb.FeatureDefinitionType;
30
import in.shop2020.metamodel.jaxb.SlideDefinitionType;
30
import in.shop2020.metamodel.jaxb.SlideDefinitionType;
31
import in.shop2020.metamodel.jaxb.SlideFeatureDefinitionType;
31
import in.shop2020.metamodel.jaxb.SlideFeatureDefinitionType;
32
import in.shop2020.metamodel.jaxb.UnitType;
32
import in.shop2020.metamodel.jaxb.UnitType;
33
 
33
 
34
import java.io.File;
-
 
35
import java.io.FileInputStream;
34
import java.io.FileInputStream;
36
import java.io.FileOutputStream;
-
 
37
import java.io.ObjectInputStream;
-
 
38
import java.io.ObjectOutputStream;
-
 
39
import java.util.ArrayList;
35
import java.util.ArrayList;
40
import java.util.HashMap;
36
import java.util.HashMap;
41
import java.util.Iterator;
37
import java.util.Iterator;
42
import java.util.List;
38
import java.util.List;
43
import java.util.Map;
39
import java.util.Map;
Line 48... Line 44...
48
 
44
 
49
import org.apache.commons.lang.ArrayUtils;
45
import org.apache.commons.lang.ArrayUtils;
50
import org.apache.commons.lang.StringUtils;
46
import org.apache.commons.lang.StringUtils;
51
 
47
 
52
/**
48
/**
-
 
49
 * MM - Meta-Model Tool
-
 
50
 * Imports and exports model definitions. Validates against meta model
53
 * 
51
 * 
54
 * @author naveen
52
 * @author naveen
55
 *
53
 *
56
 */
54
 */
57
public class MM {
55
public class MM {
Line 68... Line 66...
68
	
66
	
69
	/**
67
	/**
70
	 * @param args
68
	 * @param args
71
	 */
69
	 */
72
	public static void main(String[] args) throws Exception {
70
	public static void main(String[] args) throws Exception {
73
		System.out.println("MM "+ args[0] + " " + args[1]);
-
 
74
		
-
 
75
		String[] definitionSetNames = new String[] {"units", 
71
		String[] definitionSetNames = new String[] {"units", 
76
				"datatypedefinitions", "featuredefinitions", "slidedefinitions", 
72
				"datatypedefinitions", "featuredefinitions", "slidedefinitions", 
77
				"categories"};
73
				"categories"};
78
		
74
		
79
		String[] commands = new String[] {"show", "import"};
75
		String[] commands = new String[] {"show", "import"};
Line 83... Line 79...
83
		
79
		
84
		if(args.length < 2) {
80
		if(args.length < 2) {
85
			System.out.println(usage);
81
			System.out.println(usage);
86
			System.exit(-1);
82
			System.exit(-1);
87
		}
83
		}
-
 
84
		System.out.println("MM "+ args[0] + " " + args[1]);
-
 
85
		
88
		String inputCommand = args[0];
86
		String inputCommand = args[0];
89
		String inputDefinitionSet = args[1];
87
		String inputDefinitionSet = args[1];
90
		
88
		
91
		if(!ArrayUtils.contains(commands, inputCommand)) {
89
		if(!ArrayUtils.contains(commands, inputCommand)) {
92
			System.out.println(usage);
90
			System.out.println(usage);
Line 144... Line 142...
144
			// Tree
142
			// Tree
145
			String categoryTreeDBFile = DEFINITIONS_DB_PATH + "categorytree" + 
143
			String categoryTreeDBFile = DEFINITIONS_DB_PATH + "categorytree" + 
146
				".ser";
144
				".ser";
147
			
145
			
148
			if(root != null) {
146
			if(root != null) {
149
				this.store(root, categoryTreeDBFile);
147
				DBUtils.store(root, categoryTreeDBFile);
150
			}
148
			}
151
			
149
			
152
			// Map
150
			// Map
153
			objectToStore = categoriesMap;
151
			objectToStore = categoriesMap;
154
		}
152
		}
Line 173... Line 171...
173
 
171
 
174
			objectToStore = slideDefsMap;
172
			objectToStore = slideDefsMap;
175
		}
173
		}
176
		
174
		
177
		if(objectToStore != null) {
175
		if(objectToStore != null) {
178
			this.store(objectToStore, this.dbFile);
176
			DBUtils.store(objectToStore, this.dbFile);
179
		}
177
		}
180
	}
178
	}
181
 
179
 
182
	/**
180
	/**
183
	 * 
181
	 * 
184
	 */
182
	 */
185
	public void showDefinitionSet() throws Exception {
183
	public void showDefinitionSet() throws Exception {
186
		System.out.println("showDefinitionSet()");
184
		System.out.println("showDefinitionSet()");
187
		
185
		
188
		Object obj = this.read(this.dbFile);
186
		Object obj = DBUtils.read(this.dbFile);
189
		System.out.println(obj);
187
		System.out.println(obj);
190
		
188
		
191
		if(this.definitionSetName.equals("categories")) {
189
		if(this.definitionSetName.equals("categories")) {
192
			String categoryTreeDBFile = DEFINITIONS_DB_PATH + "categorytree" + 
190
			String categoryTreeDBFile = DEFINITIONS_DB_PATH + "categorytree" + 
193
				".ser";
191
				".ser";
194
			
192
			
195
			Category root = (Category)this.read(categoryTreeDBFile);
193
			Category root = (Category)DBUtils.read(categoryTreeDBFile);
196
			System.out.println(root);
194
			System.out.println(root);
197
			System.out.println("root.getChildrenCategory().size: " + 
195
			System.out.println("root.getChildrenCategory().size: " + 
198
					root.getChildrenCategory().size());
196
					root.getChildrenCategory().size());
199
		}
197
		}
200
	}
198
	}
Line 576... Line 574...
576
        return (DefinitionType)element.getValue();
574
        return (DefinitionType)element.getValue();
577
	}
575
	}
578
	
576
	
579
	/**
577
	/**
580
	 * 
578
	 * 
581
	 * @param objectToStore
-
 
582
	 */
-
 
583
	private void store(Object objectToStore, String dbFile) throws Exception {
-
 
584
		System.out.println("store()");
-
 
585
		
-
 
586
		FileOutputStream fos = new FileOutputStream(new File(dbFile));
-
 
587
		ObjectOutputStream out = new ObjectOutputStream(fos);
-
 
588
		
-
 
589
		out.writeObject(objectToStore);
-
 
590
		out.close();
-
 
591
		System.out.println("Serialization complete");
-
 
592
	}
-
 
593
	
-
 
594
	/**
-
 
595
	 * 
-
 
596
	 */
-
 
597
	private Object read(String dbFile) throws Exception {
-
 
598
		System.out.println("read()");
-
 
599
 
-
 
600
		FileInputStream fis = new FileInputStream(new File(dbFile));
-
 
601
		ObjectInputStream in = new ObjectInputStream(fis);
-
 
602
		Object obj = in.readObject();
-
 
603
		in.close();
-
 
604
		
-
 
605
		System.out.println("De-serialization complete");
-
 
606
		return obj;
-
 
607
	}
-
 
608
	
-
 
609
	/**
-
 
610
	 * 
-
 
611
	 * @param jaxbEdImp
579
	 * @param jaxbEdImp
612
	 * @return EditorialImportance
580
	 * @return EditorialImportance
613
	 */
581
	 */
614
	private EditorialImportance convertEditorialImportance(
582
	private EditorialImportance convertEditorialImportance(
615
			EditorialImportanceType jaxbEdImp) {
583
			EditorialImportanceType jaxbEdImp) {