/
JavaDistributedTemplates.ump
executable file
·138 lines (125 loc) · 3.76 KB
/
JavaDistributedTemplates.ump
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use UmpleNotice.ump;
external interface ILang{}
class JavaDistributedTemplates {
depend cruise.umple.compiler.*;
depend cruise.umple.util.*;
depend java.util.*;
depend cruise.umple.parser.Position;
// Add a newline to the end of the input
private void appendln(StringBuilder buffer, String input, Object... variables)
{
append(buffer, input + "\n", variables);
}
// This method will be used to append formatted strings
// i.e. format("Hello {0} {1}", "andrew","forward");
private void append(StringBuilder buffer, String input, Object... variables)
{
buffer.append(StringFormatter.format(input,variables));
}
emit getproxyReadObjectCode(String remoteName, String packageName,String interfaceName,UmpleClass uClass)(ProxyreadObjectCode);
ProxyreadObjectCode <<!
<<#if (uClass.getExtendsClass() == null||(uClass.getExtendsClass() != null && ! uClass.getExtendsClass().getIsDistributed()))
{
#>>
public String remoteUrl;
public String objectId;
public String remotePort;
<<#}#>>
private static <<=remoteName>> umplenewInstance()
{
return new <<=remoteName>>((UmpleRuntime.UmpleNode)null);
}
protected <<=remoteName>> (UmpleRuntime.UmpleNode node)
{
<<#
if ((uClass.getExtendsClass() != null)&&(uClass.getExtendsClass().getIsDistributed()))
{
#>>
super(node);
<<#
}
else if ((uClass.getExtendsClass() != null)&& !(uClass.getExtendsClass().getIsDistributed()))
{
appendln(realSb,"super();");
}
#>>
}
public void setRealObject(<<=interfaceName>> aObject)
{
<<#
if (uClass.getExtendsClass() != null && uClass.getExtendsClass().getIsDistributed())
{
#>>
super.setRealObject(aObject);
<<#
}
#>>
realObject=aObject;
}
void afterUnmarshal(Unmarshaller u, Object parent)
{
initializeConnection();
}
private void initializeConnection()
{
if(objectId.contains(<<=uClass.getName()>>.class.getName()))
{
boolean success = false;
while (!success) {
try
{
URL url = new URL(remoteUrl+":"+remotePort+"/<<=remoteName>>"+objectId+"?wsdl");
QName qname = new QName("http://<<=packageName>>/","<<=remoteName>>Service");
Service service = Service.create(url, qname);
setRealObject(service.getPort(<<=interfaceName>>.class));
success = true;
}
catch (Exception e)
{
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
try { Thread.sleep(1000); } catch (InterruptedException interruptedException) {};
}
}
}
}
!>>
emit getproxyReadObjectCodeRMI(String remoteName, String packageName,String interfaceName,UmpleClass uClass)(ProxyreadObjectCodeRMI);
ProxyreadObjectCodeRMI <<!
<<#if (uClass.getExtendsClass() == null||(uClass.getExtendsClass() != null && ! uClass.getExtendsClass().getIsDistributed()))
{
#>>
protected <<=interfaceName>> remoteObject;
<<#}#>>
public void setRemoteObject(<<=interfaceName>> aRemoteObject)
{
remoteObject=aRemoteObject;
}
public <<=interfaceName>> getRemoteObject()
{
return (<<=interfaceName>>)remoteObject;
}
private void readObject(java.io.ObjectInputStream in) throws Exception
{
try
{
in.defaultReadObject();
realObject=(<<=interfaceName>>)remoteObject;
}
catch(Exception e)
{
throw e;
}
}
!>>
emit getremoteSingletonCode(String remoteName, String packageName,String interfaceName)(remoteSingleton);
remoteSingleton <<!
protected <<=remoteName>>()
{
}
public <<=remoteName>>(String url,String port,String objectId)
{
Endpoint.publish(url+":"+port+"/<<=remoteName>>"+objectId,this);
}
!>>
}