summaryrefslogtreecommitdiff
path: root/resources/boot/SC/LocalObjectDefCreator.xml
blob: 32b154cafd6e27e2bab75d5fd1f3eb30f6e9b1ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?xml version="1.0" encoding="UTF-8"?>
<cristalscript>
	<output name="errors" type="com.c2kernel.scripting.ErrorInfo"/>
	<script language="javascript" name="LocalObjectDefCreator"><![CDATA[
		importClass(Packages.com.c2kernel.utils.CastorXMLUtility);
		importClass(Packages.com.c2kernel.utils.Resource);
		importClass(Packages.com.c2kernel.process.Bootstrap);
		importClass(Packages.com.c2kernel.lifecycle.CompositeActivityDef);
		importClass(Packages.com.c2kernel.lifecycle.ActivityDef);
	
		var type = job.getActPropString("NewType");
		var name = job.getOutcome().getField("ObjectName");
		var folder = job.getOutcome().getField("SubFolder");
		// Find the root of that object type
		var domPath = Bootstrap.getTypeRoot(type).toString();
		if (folder != null) domPath = domPath + "/" + folder.getData();
		
		var params = new Array(2);
		params[0] = name;
		params[1] = domPath;
		
		// Create the new item
		try {
			agent.execute(item, "CreateItemFromDescription", params);
		} catch (e) {
			throw "Could not create "+name+": "+e.message;
		}
		
		// Store a fresh one in the new item

		var newObj;
		// Activities are serialized new instances
		if (type.equals("EA") || type.equals("CA")) {
			var newAct = type.equals("CA")?new CompositeActivityDef(): new ActivityDef();
			newAct.setName(name);
			newObj = CastorXMLUtility.marshall(newAct);
			}
		else { 
			// Empty schemas and scripts are stored as outcomes of the factory.
			var fileType = type.equals("OD")?"Schema":"Script";
			newObj = item.getObject("/ViewPoint/"+fileType+"/last").getOutcome().getData();
		}
		// Store the new object with the 'EditDefinition' activity
		var newPath = new Packages.com.c2kernel.lookup.DomainPath(domPath+"/"+name);
		var newItem = agent.getItem(newPath);
		newItem.requestAction(agent.getSystemKey(), "workflow/domain/EditDefinition", 4, newObj);
		
		// If this script is running in the Cristal GUI, open the new item.
		var tree = Packages.com.c2kernel.gui.MainFrame.treeBrowser;
		if (tree != null) // open new item in the gui
			tree.push(newPath);
			
		]]></script>
</cristalscript>