summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/dev/DevObjectOutcomeInitiator.java
blob: e4fb80e1c21e67f6510fa2d887dcd76eafc468bc (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.c2kernel.dev;

import com.c2kernel.common.InvalidData;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lifecycle.ActivityDef;
import com.c2kernel.lifecycle.CompositeActivityDef;
import com.c2kernel.lifecycle.instance.stateMachine.StateMachine;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.persistency.outcome.OutcomeInitiator;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.DescriptionObject;
import com.c2kernel.utils.Logger;

public class DevObjectOutcomeInitiator implements OutcomeInitiator {

	public DevObjectOutcomeInitiator() {
	}

	@Override
	public String initOutcome(Job job) throws InvalidData {
		String type = job.getActPropString("SchemaType");
		
		// create empty object for activities and state machine
		DescriptionObject emptyObj = null;
		if (type.equals("CompositeActivityDef"))
			emptyObj = new CompositeActivityDef();
		else if (type.equals("ElementaryActivityDef"))
			emptyObj = new ActivityDef();
		else if (type.equals("StateMachine"))
			emptyObj = new StateMachine();
		
		if (emptyObj != null) {
			try {
				emptyObj.setName(job.getItemProxy().getName());
				return Gateway.getMarshaller().marshall(emptyObj);
			} catch (Exception e) {
				Logger.error("Error creating empty "+type);
				Logger.error(e);
				return null;
			}
		}
			
		// else load empty one from factory
		DomainPath factoryPath; String schema;
		if (type.equals("Schema")) {
			factoryPath = new DomainPath("/desc/dev/SchemaFactory");
			schema = "Schema";
		}
		else if (type.equals("Script")) {
			factoryPath = new DomainPath("/desc/dev/ScriptFactory");
			schema = "Script";
		}
		else 
			throw new InvalidData("Unknown dev object type: "+type);
		ItemProxy factory;
		Viewpoint newInstance;
		try {
			factory = Gateway.getProxyManager().getProxy(factoryPath);
			newInstance = factory.getViewpoint(schema, "last");
			return newInstance.getOutcome().getData();
		} catch (Exception e) {
			Logger.error(e);
			throw new InvalidData("Error loading new "+schema);
		}
			
	}

}