Skip to content

Commit

Permalink
web services and bug fixes for distributed java systems (#1064)
Browse files Browse the repository at this point in the history
* Inheritence bug fixed

* Web services work partially

* May29 some bug fixes

* WS does not send the object type
fixes for the inheritence in web serives and config file

* fixes for the inheritence in web serives and config file

* june13 fix for pattern 1 default component

* Many bugs fixed for inheritence,web service marshalling and unmarshalling and more tests

* fixed some issues
  • Loading branch information
amidzak committed Jun 23, 2017
1 parent a2086ef commit c3ec7f3
Show file tree
Hide file tree
Showing 106 changed files with 14,844 additions and 630 deletions.
48 changes: 44 additions & 4 deletions UmpleToJava/UmpleTLTemplates/JavaClassGenerator.ump
Expand Up @@ -93,15 +93,32 @@ class JavaClassGenerator {
<<# if (uClass.numberOfComments() > 0) { append(realSb, "\n{0}", Comment.format("Javadoc",uClass.getComments())); } #>>
<<# for (Position p : uClass.getPositions()) { #>>
// line <<= p.getLineNumber() >> "<<= uClass.getRelativePath(p.getFilename(),"Java") >>"
<<# } #>>
<<# }
if(model.getDistributed() && model.getDistributeTechnology().equals("WS")){
if(model.getDistributePattern()==0 && uClass.getDistributeTechnology().equals("WS")){
String classPackageName=(uClass.getPackageName().length() == 0 ? "" : uClass.getPackageName() + ".")+"I"+uClass.getName()+"Impl";
#>>
@WebService(endpointInterface = "<<#append(realSb,classPackageName);#>>")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(factoryMethod="umplenewInstance", propOrder={<<#if (uClass.getExtendsClass() == null||(uClass.getExtendsClass() != null && ! uClass.getExtendsClass().getIsDistributed()))
{
#>>"remoteUrl", "objectId", "remotePort"<<#
}#>>})
<<#}
else
appendln(realSb,NL+"@XmlAccessorType(XmlAccessType.FIELD)");
}
#>>
public <<# if (uClass.getIsAbstract()) { append(realSb, "{0} ", "abstract"); } #>>class <<=uClass.getName()>><<= gen.translate("isA",uClass) >><<#
boolean hasParentInterface=uClass.hasParentInterface();

if(uClass.getNeedsDefaultInterface())
{
if (hasParentInterface == false){
if(model.getDistributePattern()==0)
append(realSb," implements java.io.Serializable,I"+uClass.getName()+"Impl");
if(model.getDistributePattern()==0){
append(realSb," implements java.io.Serializable");
append(realSb,", I"+uClass.getName()+"Impl");
}
else if(model.getDistributePattern()==1&&uClass.getIsDistributed())
append(realSb," implements java.io.Serializable , I"+uClass.getName());
else if(model.getDistributePattern()==2)
Expand All @@ -110,13 +127,27 @@ if(uClass.getNeedsDefaultInterface())
}
else{
if(model.getDistributePattern()==0)
append(realSb," ,java.io.Serializable,I"+uClass.getName()+"Impl");
{
append(realSb," ,java.io.Serializable");
append(realSb,", I"+uClass.getName()+"Impl");
}
else if(model.getDistributePattern()==1&&uClass.getIsDistributed())
append(realSb," ,java.io.Serializable , I"+uClass.getName());
else if(model.getDistributePattern()==2)
append(realSb," ,java.io.Serializable ,I"+uClass.getName().substring(0,uClass.getName().length()-4));
}
}
else if(model.getDistributed())
{
if (hasParentInterface == false){
if(!uClass.getIsDistributed())
append(realSb," implements java.io.Serializable");
}
else{
if(!uClass.getIsDistributed())
append(realSb," ,java.io.Serializable");
}
}

for (StateMachine smq : uClass.getStateMachines())
{
Expand Down Expand Up @@ -226,6 +257,11 @@ for (StateMachine smq : uClass.getStateMachines())

public void setSelf(<<=uClass.getName().substring(0,uClass.getName().length()-4)>> proxy)
{
<<#if (uClass.getExtendsClass()!=null && uClass.getExtendsClass().getIsDistributed())
{
#>>
super.setSelf(proxy);
<<#}#>>
self=proxy;
}

Expand All @@ -238,6 +274,10 @@ for (StateMachine smq : uClass.getStateMachines())

if(uClass.getIsDistributed()&&model.getDistributePattern()==1)
self="self";
String isTransient="";
if (uClass.getIsDistributed() && model.getDistributePattern()==0)
isTransient=" transient ";

#>><<@ UmpleToJava.members_AllStatics >><<@ UmpleToJava.members_AllAttributes >><<@ UmpleToJava.members_AllStateMachines >><<@ UmpleToJava.members_AllDoActivities >><<@ UmpleToJava.members_AllAssociations >><<@ UmpleToJava.members_AllHelpers >>
<<#return realSb.toString();
}
Expand Down
138 changes: 138 additions & 0 deletions UmpleToJava/UmpleTLTemplates/JavaDistributedTemplates.ump
@@ -0,0 +1,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);
}

!>>
}

0 comments on commit c3ec7f3

Please sign in to comment.