/at.owlsoft.owl.rmi.server/src/at/owlsoft/owl/communication/corba/CorbaSystemUser.java

https://github.com/OwlSoft/Owl · Java · 235 lines · 213 code · 22 blank · 0 comment · 5 complexity · a2ff611556725a6c4735989f31d0e1c8 MD5 · raw file

  1. package at.owlsoft.owl.communication.corba;
  2. import org.omg.PortableServer.POA;
  3. import org.omg.PortableServer.POAPackage.ServantNotActive;
  4. import org.omg.PortableServer.POAPackage.WrongPolicy;
  5. import at.owlsoft.owl.corbamodel.accounting.ICorbaActivity;
  6. import at.owlsoft.owl.corbamodel.accounting.ICorbaActivityHelper;
  7. import at.owlsoft.owl.corbamodel.user.CorbaSystemUserStatus;
  8. import at.owlsoft.owl.corbamodel.user.ICorbaRole;
  9. import at.owlsoft.owl.corbamodel.user.ICorbaRoleHelper;
  10. import at.owlsoft.owl.corbamodel.user.ICorbaSystemUserPOA;
  11. import at.owlsoft.owl.corbamodel.user.ICorbaSystemUserStatusEntry;
  12. import at.owlsoft.owl.corbamodel.user.ICorbaSystemUserStatusEntryHelper;
  13. import at.owlsoft.owl.corbamodel.user.ICorbaSystemUserTransaction;
  14. import at.owlsoft.owl.corbamodel.user.ICorbaSystemUserTransactionHelper;
  15. import at.owlsoft.owl.model.accounting.IActivity;
  16. import at.owlsoft.owl.model.user.IRole;
  17. import at.owlsoft.owl.model.user.ISystemUser;
  18. import at.owlsoft.owl.model.user.ISystemUserStatusEntry;
  19. import at.owlsoft.owl.model.user.ISystemUserTransaction;
  20. public class CorbaSystemUser extends ICorbaSystemUserPOA
  21. {
  22. private ISystemUser _user;
  23. private POA _rootPOA;
  24. public void setUser(ISystemUser systemUser)
  25. {
  26. _user = systemUser;
  27. }
  28. public void setRootPOA(POA rootPOA)
  29. {
  30. _rootPOA = rootPOA;
  31. }
  32. @Override
  33. public int getUserID()
  34. {
  35. return _user.getUserID();
  36. }
  37. @Override
  38. public int getCardID()
  39. {
  40. return _user.getCardID();
  41. }
  42. @Override
  43. public String getUsername()
  44. {
  45. return _user.getUsername();
  46. }
  47. @Override
  48. public String getPassword()
  49. {
  50. return _user.getPassword();
  51. }
  52. @Override
  53. public String getEmail()
  54. {
  55. return _user.getEmail();
  56. }
  57. @Override
  58. public String getFirstName()
  59. {
  60. return _user.getFirstName();
  61. }
  62. @Override
  63. public String getLastName()
  64. {
  65. return _user.getLastName();
  66. }
  67. @Override
  68. public long getBirthday()
  69. {
  70. return _user.getBirthday().getTime();
  71. }
  72. @Override
  73. public int getActivityCount()
  74. {
  75. return _user.getActivityCount();
  76. }
  77. @Override
  78. public ICorbaActivity[] getActivities()
  79. {
  80. try
  81. {
  82. ICorbaActivity[] temp = new ICorbaActivity[_user.getActivities()
  83. .size()];
  84. int index = 0;
  85. for (IActivity activity : _user.getActivities())
  86. {
  87. CorbaActivity cactivity = new CorbaActivity();
  88. cactivity.setActivity(activity);
  89. cactivity.setRootPOA(_rootPOA);
  90. org.omg.CORBA.Object ref = _rootPOA
  91. .servant_to_reference(cactivity);
  92. temp[index] = ICorbaActivityHelper.narrow(ref);
  93. index++;
  94. }
  95. return temp;
  96. }
  97. catch (ServantNotActive e)
  98. {
  99. e.printStackTrace();
  100. throw new RuntimeException(e);
  101. }
  102. catch (WrongPolicy e)
  103. {
  104. e.printStackTrace();
  105. throw new RuntimeException(e);
  106. }
  107. }
  108. @Override
  109. public ICorbaRole[] getRoles()
  110. {
  111. try
  112. {
  113. ICorbaRole[] temp = new ICorbaRole[_user.getRoles().size()];
  114. int index = 0;
  115. for (IRole role : _user.getRoles())
  116. {
  117. CorbaRole crole = new CorbaRole();
  118. crole.setRole(role);
  119. org.omg.CORBA.Object ref = _rootPOA.servant_to_reference(crole);
  120. temp[index] = ICorbaRoleHelper.narrow(ref);
  121. index++;
  122. }
  123. return temp;
  124. }
  125. catch (ServantNotActive e)
  126. {
  127. e.printStackTrace();
  128. throw new RuntimeException(e);
  129. }
  130. catch (WrongPolicy e)
  131. {
  132. e.printStackTrace();
  133. throw new RuntimeException(e);
  134. }
  135. }
  136. @Override
  137. public ICorbaSystemUserTransaction[] getSystemUserTransactions()
  138. {
  139. try
  140. {
  141. ICorbaSystemUserTransaction[] temp = new ICorbaSystemUserTransaction[_user
  142. .getSystemUserTransactions().size()];
  143. int index = 0;
  144. for (ISystemUserTransaction transaction : _user
  145. .getSystemUserTransactions())
  146. {
  147. CorbaSystemUserTransaction ctransaction = new CorbaSystemUserTransaction();
  148. ctransaction.setTransaction(transaction);
  149. org.omg.CORBA.Object ref = _rootPOA
  150. .servant_to_reference(ctransaction);
  151. temp[index] = ICorbaSystemUserTransactionHelper.narrow(ref);
  152. index++;
  153. }
  154. return temp;
  155. }
  156. catch (ServantNotActive e)
  157. {
  158. e.printStackTrace();
  159. throw new RuntimeException(e);
  160. }
  161. catch (WrongPolicy e)
  162. {
  163. e.printStackTrace();
  164. throw new RuntimeException(e);
  165. }
  166. }
  167. @Override
  168. public ICorbaSystemUserStatusEntry[] getSystemUserStatusEntries()
  169. {
  170. try
  171. {
  172. ICorbaSystemUserStatusEntry[] temp = new ICorbaSystemUserStatusEntry[_user
  173. .getSystemUserStatusEntries().size()];
  174. int index = 0;
  175. for (ISystemUserStatusEntry statusEntry : _user
  176. .getSystemUserStatusEntries())
  177. {
  178. CorbaSystemUserStatusEntry cstatusEntry = new CorbaSystemUserStatusEntry();
  179. cstatusEntry.setStatusEntry(statusEntry);
  180. org.omg.CORBA.Object ref = _rootPOA
  181. .servant_to_reference(cstatusEntry);
  182. temp[index] = ICorbaSystemUserStatusEntryHelper.narrow(ref);
  183. index++;
  184. }
  185. return temp;
  186. }
  187. catch (ServantNotActive e)
  188. {
  189. e.printStackTrace();
  190. throw new RuntimeException(e);
  191. }
  192. catch (WrongPolicy e)
  193. {
  194. e.printStackTrace();
  195. throw new RuntimeException(e);
  196. }
  197. }
  198. @Override
  199. public CorbaSystemUserStatus getCurrentStatus()
  200. {
  201. switch (_user.getCurrentStatus())
  202. {
  203. case Active:
  204. return CorbaSystemUserStatus.Active;
  205. case InactiveBecauseMembershipFee:
  206. return CorbaSystemUserStatus.InactiveBecauseMembershipFee;
  207. case InactiveBecauseOverdue:
  208. return CorbaSystemUserStatus.InactiveBecauseOverdue;
  209. default:
  210. throw new RuntimeException("Unknown SystemUserStatus");
  211. }
  212. }
  213. }