1 package hero.session; 2 23 24 import hero.interfaces.Constants; 25 import hero.interfaces.BnEdgeLocal; 26 import hero.interfaces.BnEdgeLocalHome; 27 import hero.interfaces.BnEdgeValue; 28 import hero.interfaces.BnNodeHookLocal; 29 import hero.interfaces.BnNodeHookValue; 30 import hero.interfaces.BnNodeInterHookLocal; 31 import hero.interfaces.BnNodeLightValue; 32 import hero.interfaces.BnNodeLocal; 33 import hero.interfaces.BnNodeLocalHome; 34 import hero.interfaces.BnNodePropertyLocal; 35 import hero.interfaces.BnNodePropertyValue; 36 import hero.interfaces.BnNodeValue; 37 import hero.interfaces.BnAgentEdgeLocal; 38 import hero.interfaces.BnAgentEdgeLocalHome; 39 import hero.interfaces.BnAgentEdgeValue; 40 import hero.interfaces.BnAgentLocal; 41 import hero.interfaces.BnAgentLocalHome; 42 import hero.interfaces.BnAgentValue; 43 import hero.interfaces.BnProjectHookLocal; 44 import hero.interfaces.BnProjectHookValue; 45 import hero.interfaces.BnProjectInterHookLocal; 46 import hero.interfaces.BnProjectLocal; 47 import hero.interfaces.BnProjectLocalHome; 48 import hero.interfaces.BnProjectPropertyLocal; 49 import hero.interfaces.BnProjectPropertyValue; 50 import hero.interfaces.BnProjectValue; 51 import hero.interfaces.BnRoleLocal; 52 import hero.interfaces.BnRoleLocalHome; 53 import hero.interfaces.BnRoleValue; 54 import hero.interfaces.BnUserLightValue; 55 import hero.interfaces.BnUserLocal; 56 import hero.interfaces.BnUserLocalHome; 57 import hero.interfaces.BnUserUtil; 58 import hero.util.EventConstants; 59 import hero.util.HeroException; 60 import hero.interfaces.JMSServicesSessionUtil; 61 import hero.interfaces.JMSServicesSessionLocalHome; 62 import hero.interfaces.JMSServicesSessionLocal; 63 64 65 import hero.util.BonitaConfig; 66 import hero.util.NodeHooks; 67 import hero.util.NodeInEdges; 68 import hero.util.NodeOutEdges; 69 import hero.util.NodeProperties; 70 import hero.util.ProjectHooks; 71 import hero.util.ProjectNodes; 72 import hero.util.ProjectProperties; 73 import hero.util.ProjectRoles; 74 import hero.util.ProjectUsers; 75 import java.io.StringWriter ; 76 import java.rmi.RemoteException ; 77 import java.util.ArrayList ; 78 import java.util.Collection ; 79 import java.util.Date ; 80 import java.util.Iterator ; 81 82 import javax.ejb.CreateException ; 83 import javax.ejb.FinderException ; 84 import javax.ejb.SessionBean ; 85 import javax.ejb.SessionContext ; 86 import javax.ejb.EJBException ; 87 import javax.naming.Context ; 88 89 import org.apache.log4j.Category; 90 import org.exolab.castor.xml.MarshalException; 91 import org.exolab.castor.xml.Marshaller; 92 import org.exolab.castor.xml.ValidationException; 93 import hero.util.StrutsNodeValue; 94 95 96 124 125 public class ProjectSoapXMLBean implements SessionBean , EventConstants { 126 127 private static final Category trace = Category.getInstance(ProjectSoapXMLBean.class); 132 133 137 private SessionContext mContext; 138 139 private BnProjectLocalHome pHome; 140 private BnProjectLocal mProject; 141 private JMSServicesSessionLocal jms; 142 private Collection subProjects = new ArrayList (); 143 private ArrayList visited = new ArrayList (); 144 private BonitaConfig bonitaConfig; 145 146 150 158 public String getName() throws HeroException { 159 if (this.getProjectConfigTrace()) 160 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 161 return mProject.getName(); 162 } 163 164 171 172 public String getProjectDetails() throws HeroException { 173 if (this.getProjectConfigTrace()) 174 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 175 try { 176 BnProjectValue pl = mProject.getBnProjectValue(); 178 StringWriter sw = new StringWriter (); 179 Marshaller.marshal(pl, sw); 180 return (sw.toString()); 181 } catch (MarshalException ex1) { 182 throw new HeroException(ex1.getMessage()); 183 } catch (ValidationException ex2) { 184 throw new HeroException(ex2.getMessage()); 185 } 186 } 187 188 195 196 public String getNodeDetails(String node) throws HeroException { 197 if (this.getProjectConfigTrace()) 198 trace.info(" Parameter: node=" + node + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 199 try { 200 BnNodeLocal nd = mProject.getBnNode(node); 201 BnNodeLightValue nl = nd.getBnNodeLightValue(); 202 203 StringWriter sw = new StringWriter (); 204 Marshaller.marshal(nl, sw); 205 return (sw.toString()); 206 } catch (MarshalException ex1) { 207 throw new HeroException(ex1.getMessage()); 208 } catch (ValidationException ex2) { 209 throw new HeroException(ex2.getMessage()); 210 } 211 } 212 213 222 public String getNodeLightValue(String name) 223 throws HeroException { 224 if (this.getProjectConfigTrace()) 225 trace.info(" Parameter: name=" + name + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 226 BnNodeLocalHome nHome; 227 BnNodeLocal mNode; 228 BnNodeLightValue nv; 229 try { 230 nHome = hero.interfaces.BnNodeUtil.getLocalHome(); 231 } catch (javax.naming.NamingException be) { 232 throw new HeroException(be.getMessage()); 233 } 234 try { 235 mNode = nHome.findByName(name, mProject.getId()); 236 nv = mNode.getBnNodeLightValue(); 237 StringWriter sw = new StringWriter (); 238 Marshaller.marshal(nv, sw); 239 return (sw.toString()); 240 } catch (MarshalException ex1) { 241 throw new HeroException(ex1.getMessage()); 242 } catch (ValidationException ex2) { 243 throw new HeroException(ex2.getMessage()); 244 } catch (FinderException fe) { 245 throw new HeroException("In BnNode does not exist"); 246 } 247 } 248 249 259 public String getNodeDeadline(String nodeName) throws HeroException { 260 if (this.getProjectConfigTrace()) 261 trace.info(" Parameter: nodeName=" + nodeName + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 262 BnNodeLocal nd = mProject.getBnNode(nodeName); 263 267 if (nd.getDeadlines().size() != 0) { 268 Collection co = nd.getDeadlines(); 269 Iterator it = co.iterator(); 270 Date date = null; 271 while (it.hasNext()){ 272 date = (Date )it.next(); 273 } 274 return(date.toString()); 275 } 276 else 277 return (null); 278 } 279 280 288 public String getNodeDescription(String name) throws HeroException { 289 if (this.getProjectConfigTrace()) 290 trace.info(" Parameter: name=" + name + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 291 BnNodeLocal nd = mProject.getBnNode(name); 292 return (nd.getDescription()); 293 } 294 295 302 303 public String getNodeRole(String node) throws HeroException { 304 if (this.getProjectConfigTrace()) 305 trace.info(" Parameter: node=" + node + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 306 try { 307 BnNodeLocal nd = mProject.getBnNode(node); 308 BnRoleValue rl = ((BnRoleLocal) nd.getBnRole()).getBnRoleValue(); 309 310 StringWriter sw = new StringWriter (); 311 Marshaller.marshal(rl, sw); 312 return (sw.toString()); 313 } catch (MarshalException ex1) { 314 throw new HeroException(ex1.getMessage()); 315 } catch (ValidationException ex2) { 316 throw new HeroException(ex2.getMessage()); 317 } 318 } 319 320 330 public String getNodeRoleName(String nodeName) throws HeroException { 331 if (this.getProjectConfigTrace()) 332 trace.info(" Parameter: nodeName=" + nodeName+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 333 BnNodeLocal nd = mProject.getBnNode(nodeName); 334 return (((BnRoleLocal) nd.getBnRole()).getName()); 335 } 336 337 346 public String getAgentValue(String name) throws HeroException { 347 if (this.getProjectConfigTrace()) 348 trace.info(" Parameter: name=" + name+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 349 BnAgentLocalHome nHome; 350 BnAgentLocal mAgent; 351 BnAgentValue av; 352 try { 353 nHome = hero.interfaces.BnAgentUtil.getLocalHome(); 354 } catch (javax.naming.NamingException be) { 355 throw new HeroException(be.getMessage()); 356 } 357 try { 358 mAgent = nHome.findByName(name, mProject.getId()); 359 av = mAgent.getBnAgentValue(); 360 StringWriter sw = new StringWriter (); 361 Marshaller.marshal(av, sw); 362 return (sw.toString()); 363 } catch (FinderException fe) { 364 throw new HeroException("In Agent does not exist"); 365 } catch (MarshalException ex1) { 366 throw new HeroException(ex1.getMessage()); 367 } catch (ValidationException ex2) { 368 throw new HeroException(ex2.getMessage()); 369 } 370 } 371 372 381 public String getAgentEdgeValue(String name) 382 throws HeroException { 383 if (this.getProjectConfigTrace()) 384 trace.info(" Parameter: name=" + name+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 385 BnAgentEdgeLocalHome nHome; 386 BnAgentEdgeLocal mAgentEdge; 387 BnAgentEdgeValue av; 388 try { 389 nHome = hero.interfaces.BnAgentEdgeUtil.getLocalHome(); 390 } catch (javax.naming.NamingException be) { 391 throw new HeroException(be.getMessage()); 392 } 393 try { 394 mAgentEdge = nHome.findByName(name, mProject.getId()); 395 av = mAgentEdge.getBnAgentEdgeValue(); 396 StringWriter sw = new StringWriter (); 397 Marshaller.marshal(av, sw); 398 return (sw.toString()); 399 } catch (FinderException fe) { 400 throw new HeroException("In BnAgentEdge does not exist"); 401 } catch (MarshalException ex1) { 402 throw new HeroException(ex1.getMessage()); 403 } catch (ValidationException ex2) { 404 throw new HeroException(ex2.getMessage()); 405 } 406 } 407 408 409 416 417 public String getNodeExecutor(String node) throws HeroException { 418 if (this.getProjectConfigTrace()) 419 trace.info(" Parameter: node=" + node+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 420 BnUserLocalHome uHome; 421 BnUserLocal user; 422 try { 423 BnNodeLocal nd = mProject.getBnNode(node); 424 try { 425 uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil.getLocalHome(); 426 } catch (javax.naming.NamingException be) { 427 throw new HeroException(be.getMessage()); 428 } 429 try { 430 user = uHome.findByName(nd.getExecutor()); 431 } catch (FinderException f) { 432 throw new HeroException("FinderException"); 433 } 434 BnUserLightValue ul = user.getBnUserLightValue(); 435 436 StringWriter sw = new StringWriter (); 437 Marshaller.marshal(ul, sw); 438 return (sw.toString()); 439 } catch (MarshalException ex1) { 440 throw new HeroException(ex1.getMessage()); 441 } catch (ValidationException ex2) { 442 throw new HeroException(ex2.getMessage()); 443 } 444 } 445 446 455 public int getNodeState(String name) throws HeroException { 456 if (this.getProjectConfigTrace()) 457 trace.info(" Parameter: name=" + name+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 458 BnNodeLocal nd = mProject.getBnNode(name); 459 return (nd.getState()); 460 } 461 462 471 public int getNodeType(String name) throws HeroException { 472 if (this.getProjectConfigTrace()) 473 trace.info(" Parameter: name=" + name+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 474 BnNodeLocal nd = mProject.getBnNode(name); 475 return (nd.getType()); 476 } 477 478 487 public String getNodeValue(String name) throws HeroException { 488 if (this.getProjectConfigTrace()) 489 trace.info(" Parameter: name=" + name+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 490 BnNodeLocalHome nHome; 491 BnNodeLocal mNode; 492 BnNodeValue nv; 493 try { 494 nHome = hero.interfaces.BnNodeUtil.getLocalHome(); 495 } catch (javax.naming.NamingException be) { 496 throw new HeroException(be.getMessage()); 497 } 498 try { 499 mNode = nHome.findByName(name, mProject.getId()); 500 nv = mNode.getBnNodeValue(); 501 StringWriter sw = new StringWriter (); 502 Marshaller.marshal(nv, sw); 503 return (sw.toString()); 504 } catch (MarshalException ex1) { 505 throw new HeroException(ex1.getMessage()); 506 } catch (ValidationException ex2) { 507 throw new HeroException(ex2.getMessage()); 508 } catch (FinderException fe) { 509 throw new HeroException("This Node does not exist"); 510 } 511 } 512 513 520 521 public String getNodes() throws HeroException { 522 if (this.getProjectConfigTrace()) 523 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 524 ProjectNodes nb = new ProjectNodes(); 525 Collection nodes = new ArrayList (); 526 ArrayList ns = new ArrayList (); 527 StringWriter sw = new StringWriter (); 528 529 nodes = mProject.getBnNodes(); 530 Iterator i = nodes.iterator(); 531 while (i.hasNext()) { 532 BnNodeLocal n = (BnNodeLocal) i.next(); 533 StrutsNodeValue snv = new StrutsNodeValue(); 534 snv.setProjectName(mProject.getName()); 535 snv.setName(n.getName()); 536 snv.setCreator(n.getCreator()); 537 snv.setRole(n.getBnRole().getName()); 538 snv.setState(Constants.Nd.nodeStateName[n.getState()]); 539 snv.setType(Constants.Nd.nodeTypeName[n.getType()]); 540 if (n.getDescription() != null) 541 snv.setDescription(n.getDescription()); 542 if (n.getExecutor() != null) 543 snv.setExecutor(n.getExecutor()); 544 snv.setAnticipable(n.getAnticipable()); 545 if (n.getDeadlines().size() != 0) { 546 Collection co = n.getDeadlines(); 547 Iterator it = co.iterator(); 548 Date date = null; 549 while (it.hasNext()){ 550 date = (Date )it.next(); 551 } 552 snv.setDeadline(date.toString()); 553 } 554 ns.add(snv); 555 } 556 nb.setNodes(ns.toArray()); 557 558 try { 559 Marshaller.marshal(nb, sw); 560 } catch (MarshalException e) { 561 e.printStackTrace(); 562 } catch (ValidationException e) { 563 e.printStackTrace(); 564 } 565 return (sw.toString()); 566 } 567 568 575 public Collection getNodesNames() throws HeroException { 576 if (this.getProjectConfigTrace()) 577 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 578 579 ArrayList names = new ArrayList (); 581 Collection nodes = mProject.getBnNodes(); 582 Iterator i = nodes.iterator(); 583 while (i.hasNext()) { 584 BnNodeLocal n = (BnNodeLocal) i.next(); 585 names.add(n.getName()); 586 } 587 return ((Collection ) names); 588 } 589 590 597 598 public String getUsers() throws HeroException { 599 if (this.getProjectConfigTrace()) 600 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 601 ProjectUsers ub = new ProjectUsers(); 602 Collection us = new ArrayList (); 603 604 try { 605 Collection users = mProject.getBnUsers(); 606 Iterator i = users.iterator(); 607 while (i.hasNext()) { 608 BnUserLocal u = (BnUserLocal) i.next(); 609 BnUserLightValue ul = u.getBnUserLightValue(); 610 us.add(ul); 611 } 612 ub.setUser(us); 613 StringWriter sw = new StringWriter (); 614 Marshaller.marshal(ub, sw); 615 return (sw.toString()); 616 } catch (MarshalException ex1) { 617 throw new HeroException(ex1.getMessage()); 618 } catch (ValidationException ex2) { 619 throw new HeroException(ex2.getMessage()); 620 } 621 } 622 623 633 public Collection getUserRolesInProjectNames(String userName) 634 throws HeroException { 635 if (this.getProjectConfigTrace()) 636 trace.info(" Parameter: userName=" + userName+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 637 BnUserLocalHome uHome; 638 BnUserLocal user; 639 ArrayList result = new ArrayList (); 640 try { 641 uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil.getLocalHome(); 642 } catch (javax.naming.NamingException be) { 643 throw new HeroException(be.getMessage()); 644 } 645 try { 646 user = uHome.findByName(userName); 647 } catch (FinderException f) { 648 throw new HeroException("FinderException"); 649 } 650 651 Collection userRoles = user.getBnRoles(); 652 Collection projectRoles = mProject.getBnRoles(); 653 for (Iterator i = userRoles.iterator(); i.hasNext();) { 654 BnRoleLocal ur = (BnRoleLocal) i.next(); 655 for (Iterator j = projectRoles.iterator(); j.hasNext();) { 656 BnRoleLocal up = (BnRoleLocal) j.next(); 657 if (ur.getId().equals(up.getId())) 658 result.add(ur.getBnRoleValue().getName()); 659 } 660 } 661 return result; 662 } 663 664 671 672 public String getRoles() throws HeroException { 673 if (this.getProjectConfigTrace()) 674 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 675 ProjectRoles rb = new ProjectRoles(); 676 Collection rs = new ArrayList (); 677 678 try { 679 Collection roles = mProject.getBnRoles(); 680 Iterator i = roles.iterator(); 681 while (i.hasNext()) { 682 BnRoleLocal r = (BnRoleLocal) i.next(); 683 BnRoleValue rl = r.getBnRoleValue(); 684 rs.add(rl); 685 } 686 rb.setRole(rs); 687 StringWriter sw = new StringWriter (); 688 Marshaller.marshal(rb, sw); 689 return (sw.toString()); 690 } catch (MarshalException ex1) { 691 throw new HeroException(ex1.getMessage()); 692 } catch (ValidationException ex2) { 693 throw new HeroException(ex2.getMessage()); 694 } 695 } 696 697 705 public Collection getRolesNames() throws HeroException { 706 if (this.getProjectConfigTrace()) 707 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 708 Collection roles = mProject.getBnRoles(); 709 ArrayList result = new ArrayList (); 710 for (Iterator i = roles.iterator(); i.hasNext();) { 711 result.add(((BnRoleLocal) i.next()).getName()); 712 } 713 return result; 714 } 715 716 723 724 public String getUserRoles(String userName) throws HeroException { 725 if (this.getProjectConfigTrace()) 726 trace.info(" Parameter: userName=" + userName+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 727 BnUserLocalHome uHome; 728 BnUserLocal user; 729 Collection result = new ArrayList (); 730 ProjectRoles rb = new ProjectRoles(); 731 try { 732 uHome = (BnUserLocalHome) BnUserUtil.getLocalHome(); 733 } catch (javax.naming.NamingException be) { 734 throw new HeroException(be.getMessage()); 735 } 736 try { 737 user = uHome.findByName(userName); 738 } catch (FinderException f) { 739 throw new HeroException("FinderException"); 740 } 741 Collection userRoles = user.getBnRoles(); 742 Collection projectRoles = mProject.getBnRoles(); 743 for (Iterator i = userRoles.iterator(); i.hasNext();) { 744 BnRoleLocal ur = (BnRoleLocal) i.next(); 745 for (Iterator j = projectRoles.iterator(); j.hasNext();) { 746 BnRoleLocal up = (BnRoleLocal) j.next(); 747 if (ur.getId() == up.getId()) 748 result.add(ur.getBnRoleValue()); 749 } 750 } 751 try { 752 rb.setRole(result); 753 StringWriter sw = new StringWriter (); 754 Marshaller.marshal(rb, sw); 755 return (sw.toString()); 756 } catch (MarshalException ex1) { 757 throw new HeroException(ex1.getMessage()); 758 } catch (ValidationException ex2) { 759 throw new HeroException(ex2.getMessage()); 760 } 761 } 762 763 773 public String getUserRolesInProject(String userName) 774 throws HeroException { 775 if (this.getProjectConfigTrace()) 776 trace.info(" Parameter: userName=" + userName+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 777 BnUserLocalHome uHome; 778 BnUserLocal user; 779 ArrayList result = new ArrayList (); 780 ProjectRoles rb = new ProjectRoles(); 781 try { 782 uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil.getLocalHome(); 783 } catch (javax.naming.NamingException be) { 784 throw new HeroException(be.getMessage()); 785 } 786 try { 787 user = uHome.findByName(userName); 788 } catch (FinderException f) { 789 throw new HeroException("FinderException"); 790 } 791 Collection userRoles = user.getBnRoles(); 792 Collection projectRoles = mProject.getBnRoles(); 793 for (Iterator i = userRoles.iterator(); i.hasNext();) { 794 BnRoleLocal ur = (BnRoleLocal) i.next(); 795 for (Iterator j = projectRoles.iterator(); j.hasNext();) { 796 BnRoleLocal up = (BnRoleLocal) j.next(); 797 if (ur.getId() == up.getId()) 798 result.add(ur.getBnRoleValue()); 799 } 800 } 801 try { 802 rb.setRole(result); 803 StringWriter sw = new StringWriter (); 804 Marshaller.marshal(rb, sw); 805 return (sw.toString()); 806 } catch (MarshalException ex1) { 807 throw new HeroException(ex1.getMessage()); 808 } catch (ValidationException ex2) { 809 throw new HeroException(ex2.getMessage()); 810 } 811 } 812 813 814 821 822 public String getProperties() throws HeroException { 823 if (this.getProjectConfigTrace()) 824 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 825 ProjectProperties pb = new ProjectProperties(); 826 Collection ps = new ArrayList (); 827 828 try { 829 Collection properties = mProject.getBnProperties(); 830 Iterator i = properties.iterator(); 831 while (i.hasNext()) { 832 BnProjectPropertyLocal pp = (BnProjectPropertyLocal) i.next(); 833 BnProjectPropertyValue ppv = pp.getBnProjectPropertyValue(); 834 ps.add(ppv); 835 } 836 pb.setProperty(ps); 837 StringWriter sw = new StringWriter (); 838 Marshaller.marshal(pb, sw); 839 return (sw.toString()); 840 } catch (MarshalException ex1) { 841 throw new HeroException(ex1.getMessage()); 842 } catch (ValidationException ex2) { 843 throw new HeroException(ex2.getMessage()); 844 } 845 } 846 847 854 855 public String getHooks() throws HeroException { 856 if (this.getProjectConfigTrace()) 857 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 858 ProjectHooks hb = new ProjectHooks(); 859 Collection hs = new ArrayList (); 860 861 try { 862 Collection hooks = mProject.getBnHooks(); 863 Iterator i = hooks.iterator(); 864 while (i.hasNext()) { 865 BnProjectHookLocal ph = (BnProjectHookLocal) i.next(); 866 BnProjectHookValue phv = ph.getBnProjectHookValue(); 867 hs.add(phv); 868 } 869 hb.setHook(hs); 870 StringWriter sw = new StringWriter (); 871 Marshaller.marshal(hb, sw); 872 return (sw.toString()); 873 } catch (MarshalException ex1) { 874 throw new HeroException(ex1.getMessage()); 875 } catch (ValidationException ex2) { 876 throw new HeroException(ex2.getMessage()); 877 } 878 } 879 880 888 public String getInterHooks() throws HeroException { 889 if (this.getProjectConfigTrace()) 890 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 891 try{ 892 Collection hk = new ArrayList (); 893 ProjectHooks hb = new ProjectHooks(); 894 BnProjectInterHookLocal pl; 895 Collection pls = mProject.getBnInterHooks(); 896 897 for (Iterator i = pls.iterator(); i.hasNext();) { 898 pl = (BnProjectInterHookLocal) i.next(); 899 hk.add(pl.getBnProjectInterHookValue()); 900 } 901 hb.setHook(hk); 902 StringWriter sw = new StringWriter (); 903 Marshaller.marshal(hb, sw); 904 return (sw.toString()); 905 } catch (MarshalException ex1) { 906 throw new HeroException(ex1.getMessage()); 907 } catch (ValidationException ex2) { 908 throw new HeroException(ex2.getMessage()); 909 } 910 } 911 912 921 public String getNodeInterHooks(String nodeName) throws HeroException { 922 if (this.getProjectConfigTrace()) 923 trace.info(" Parameter: nodeName=" + nodeName+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 924 try{ 925 Collection hk = new ArrayList (); 926 BnNodeInterHookLocal pl; 927 ProjectHooks hb = new ProjectHooks(); 928 929 BnNodeLocal nd = mProject.getBnNode(nodeName); 930 931 Collection pls = nd.getBnInterHooks(); 932 933 for (Iterator i = pls.iterator(); i.hasNext();) { 934 pl = (BnNodeInterHookLocal) i.next(); 935 hk.add(pl.getBnNodeInterHookValue()); 936 } 937 hb.setHook(hk); 938 StringWriter sw = new StringWriter (); 939 Marshaller.marshal(hb, sw); 940 return (sw.toString()); 941 } catch (MarshalException ex1) { 942 throw new HeroException(ex1.getMessage()); 943 } catch (ValidationException ex2) { 944 throw new HeroException(ex2.getMessage()); 945 } 946 } 947 948 957 public String getNodeInterHookValue(String node, String hook) 958 throws HeroException { 959 if (this.getProjectConfigTrace()) 960 trace.info(" Parameter: node=" + node+ " hook= "+hook+"process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 961 String value = null; 962 BnNodeLocal nd = mProject.getBnNode(node); 963 Collection hooks = nd.getBnInterHooks(); 964 for (Iterator ih = hooks.iterator(); ih.hasNext();) { 965 BnNodeInterHookLocal hk = (BnNodeInterHookLocal) ih.next(); 966 if (hk.getName().equals(hook)) { 967 value = hk.getScript(); 968 } 969 } 970 return value; 971 } 972 973 983 public String getNodeInterHook(String nodeName, String interHook) throws HeroException { 984 if (this.getProjectConfigTrace()) 985 trace.info(" Parameter: nodeName" + nodeName+ " interHook= "+interHook+"process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 986 try{ 987 BnNodeInterHookLocal hl; 988 BnNodeLocal nd = mProject.getBnNode(nodeName); 989 Collection hls = nd.getBnInterHooks(); 990 991 for (Iterator i = hls.iterator(); i.hasNext();) { 992 hl = (BnNodeInterHookLocal) i.next(); 993 if (hl.getName().equals(interHook)) { 994 StringWriter sw = new StringWriter (); 995 Marshaller.marshal(hl.getBnNodeInterHookValue(), sw); 996 return (sw.toString()); 997 } 998 } 999 } catch (MarshalException ex1) { 1000 throw new HeroException(ex1.getMessage()); 1001 } catch (ValidationException ex2) { 1002 throw new HeroException(ex2.getMessage()); 1003 } 1004 return null; 1005 } 1006 1007 1015 public Collection getAllUsers() throws HeroException { 1016 if (this.getProjectConfigTrace()) 1017 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 1018 BnUserLocalHome uHome; 1019 Collection users; 1020 try { 1021 uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil.getLocalHome(); 1022 } catch (javax.naming.NamingException be) { 1023 throw new HeroException(be.getMessage()); 1024 } 1025 try { 1026 users = uHome.findAll(); 1027 } catch (FinderException f) { 1028 throw new HeroException("FinderException in findByAll users"); 1029 } 1030 ArrayList result = new ArrayList (); 1031 for (Iterator i = users.iterator(); i.hasNext();) { 1032 result.add(((BnUserLocal) i.next()).getName()); 1033 } 1034 return result; 1035 } 1036 1037 1044 1045 public String getNodeProperties(String nodeName) throws HeroException { 1046 if (this.getProjectConfigTrace()) 1047 trace.info(" Parameter: nodeName=" + nodeName+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1048 NodeProperties nb = new NodeProperties(); 1049 Collection ns = new ArrayList (); 1050 1051 try { 1052 BnNodeLocal nl = mProject.getBnNode(nodeName); 1053 Collection properties = nl.getBnProperties(); 1054 Iterator i = properties.iterator(); 1055 while (i.hasNext()) { 1056 BnNodePropertyLocal np = (BnNodePropertyLocal) i.next(); 1057 BnNodePropertyValue npv = np.getBnNodePropertyValue(); 1058 ns.add(npv); 1059 } 1060 nb.setProjectName(mProject.getName()); 1061 nb.setProperty(ns); 1062 StringWriter sw = new StringWriter (); 1063 Marshaller.marshal(nb, sw); 1064 return (sw.toString()); 1065 } catch (MarshalException ex1) { 1066 throw new HeroException(ex1.getMessage()); 1067 } catch (ValidationException ex2) { 1068 throw new HeroException(ex2.getMessage()); 1069 } 1070 } 1071 1072 1082 public String getNodeProperty(String nodeName, String key) throws HeroException { 1083 if (this.getProjectConfigTrace()) 1084 trace.info(" Parameter: nodeName" + nodeName+ " key= "+key+"process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1085 try{ 1086 BnNodePropertyLocal pl; 1087 BnNodeLocal nd = mProject.getBnNode(nodeName); 1088 Collection pls = nd.getBnProperties(); 1089 1090 for (Iterator i = pls.iterator(); i.hasNext();) { 1091 pl = (BnNodePropertyLocal) i.next(); 1092 if (pl.getTheKey().equals(key)) { 1093 StringWriter sw = new StringWriter (); 1094 Marshaller.marshal(pl.getBnNodePropertyValue(), sw); 1095 return (sw.toString()); 1096 } 1097 } 1098 } catch (MarshalException ex1) { 1099 throw new HeroException(ex1.getMessage()); 1100 } catch (ValidationException ex2) { 1101 throw new HeroException(ex2.getMessage()); 1102 } 1103 return (null); 1104 } 1105 1106 1113 1114 public String getNodeHooks(String nodeName) throws HeroException { 1115 if (this.getProjectConfigTrace()) 1116 trace.info(" Parameter: nodeName=" + nodeName+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1117 NodeHooks nb = new NodeHooks(); 1118 Collection hs = new ArrayList (); 1119 1120 try { 1121 BnNodeLocal nl = mProject.getBnNode(nodeName); 1122 Collection hooks = nl.getBnHooks(); 1123 Iterator i = hooks.iterator(); 1124 while (i.hasNext()) { 1125 BnNodeHookLocal nh = (BnNodeHookLocal) i.next(); 1126 BnNodeHookValue nhv = nh.getBnNodeHookValue(); 1127 hs.add(nhv); 1128 } 1129 nb.setProjectName(mProject.getName()); 1130 nb.setHook(hs); 1131 StringWriter sw = new StringWriter (); 1132 Marshaller.marshal(nb, sw); 1133 return (sw.toString()); 1134 } catch (MarshalException ex1) { 1135 throw new HeroException(ex1.getMessage()); 1136 } catch (ValidationException ex2) { 1137 throw new HeroException(ex2.getMessage()); 1138 } 1139 } 1140 1141 1149 public String getCreator() throws HeroException { 1150 if (this.getProjectConfigTrace()) 1151 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 1152 return mProject.getCreator(); 1153 } 1154 1155 1165 public String getNodeInEdges(String name) throws HeroException { 1166 if (this.getProjectConfigTrace()) 1167 trace.info(" Parameter: name=" + name+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1168 NodeInEdges eb = new NodeInEdges(); 1169 Collection in = new ArrayList (); 1170 1171 try { 1172 BnNodeLocal nd = mProject.getBnNode(name); 1173 1174 Collection edgesIn = nd.getInBnEdges(); 1175 Iterator i = edgesIn.iterator(); 1176 while (i.hasNext()) 1177 in.add(((BnEdgeLocal) i.next()).getBnEdgeValue()); 1178 1179 eb.setProjectName(mProject.getName()); 1180 eb.setInEdge(in); 1181 StringWriter sw = new StringWriter (); 1182 Marshaller.marshal(eb, sw); 1183 return (sw.toString()); 1184 } catch (MarshalException ex1) { 1185 throw new HeroException(ex1.getMessage()); 1186 } catch (ValidationException ex2) { 1187 throw new HeroException(ex2.getMessage()); 1188 } 1189 } 1190 1191 1199 public String getEdgeCondition(String edge) 1200 throws HeroException { 1201 if (this.getProjectConfigTrace()) 1202 trace.info(" Parameter: edge=" + edge+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1203 BnEdgeLocal e = mProject.getBnEdge(edge); 1204 return(e.getCondition()); 1205 } 1206 1207 1215 public String getEdgeInNode(String edgeName) throws HeroException { 1216 if (this.getProjectConfigTrace()) 1217 trace.info(" Parameter: edgeName=" + edgeName+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1218 BnEdgeLocal e = mProject.getBnEdge(edgeName); 1219 return (((BnNodeLocal) e.getInBnNode()).getName()); 1220 } 1221 1222 1230 public String getEdgeOutNode(String edgeName) throws HeroException { 1231 if (this.getProjectConfigTrace()) 1232 trace.info(" Parameter: edgeName=" + edgeName+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1233 BnEdgeLocal e = mProject.getBnEdge(edgeName); 1234 return (((BnNodeLocal) e.getOutBnNode()).getName()); 1235 } 1236 1237 1245 public Collection getEdgesNames() throws HeroException { 1246 if (this.getProjectConfigTrace()) 1247 trace.info("process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 1248 ArrayList names = new ArrayList (); 1250 Collection edges = mProject.getBnEdges(); 1251 Iterator i = edges.iterator(); 1252 while (i.hasNext()) { 1253 BnEdgeLocal n = (BnEdgeLocal) i.next(); 1254 names.add(n.getName()); 1255 } 1256 return ((Collection ) names); 1257 } 1258 1259 1269 public String getNodeOutEdges(String name) throws HeroException { 1270 if (this.getProjectConfigTrace()) 1271 trace.info(" Parameter: name=" + name+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1272 NodeOutEdges eb = new NodeOutEdges(); 1273 Collection out = new ArrayList (); 1274 1275 try { 1276 BnNodeLocal nd = mProject.getBnNode(name); 1277 1278 Collection edgesOut = nd.getOutBnEdges(); 1279 Iterator i = edgesOut.iterator(); 1280 while (i.hasNext()) 1281 out.add(((BnEdgeLocal) i.next()).getBnEdgeValue()); 1282 1283 eb.setProjectName(mProject.getName()); 1284 eb.setOutEdge(out); 1285 StringWriter sw = new StringWriter (); 1286 Marshaller.marshal(eb, sw); 1287 return (sw.toString()); 1288 } catch (MarshalException ex1) { 1289 throw new HeroException(ex1.getMessage()); 1290 } catch (ValidationException ex2) { 1291 throw new HeroException(ex2.getMessage()); 1292 } 1293 } 1294 1295 1304 public String getEdgeValue(String name) throws HeroException { 1305 if (this.getProjectConfigTrace()) 1306 trace.info(" Parameter: name=" + name+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1307 BnEdgeLocalHome eHome; 1308 BnEdgeLocal mEdge; 1309 BnEdgeValue ev; 1310 try { 1311 eHome = hero.interfaces.BnEdgeUtil.getLocalHome(); 1312 } catch (javax.naming.NamingException be) { 1313 throw new HeroException(be.getMessage()); 1314 } 1315 try { 1316 mEdge = eHome.findByName(name, mProject.getId()); 1317 ev = mEdge.getBnEdgeValue(); 1318 StringWriter sw = new StringWriter (); 1319 Marshaller.marshal(ev, sw); 1320 return (sw.toString()); 1321 } catch (MarshalException ex1) { 1322 throw new HeroException(ex1.getMessage()); 1323 } catch (ValidationException ex2) { 1324 throw new HeroException(ex2.getMessage()); 1325 } catch (FinderException fe) { 1326 throw new HeroException("BnEdge does not exist"); 1327 } 1328 } 1329 1330 1338 public boolean getNodeAnticipable(String name) throws HeroException { 1339 if (this.getProjectConfigTrace()) 1340 trace.info(" Parameter: name=" + name+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1341 BnNodeLocal nd = mProject.getBnNode(name); 1342 return (nd.getAnticipable()); 1343 } 1344 1345 1353 public String getInterHookValue(String hook) throws HeroException { 1354 String value= null; 1355 if (this.getProjectConfigTrace()) 1356 trace.info(" Parameter: hook=" + hook+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1357 Collection hooks = mProject.getBnInterHooks(); 1358 for (Iterator ih = hooks.iterator(); ih.hasNext();) { 1359 BnProjectInterHookLocal hk = (BnProjectInterHookLocal) ih.next(); 1360 if (hk.getName().equals(hook)) { 1361 value=hk.getScript(); 1362 } 1363 } 1364 return value; 1365 } 1366 1367 1375 public String getProjectNameOfInstance(String instanceName) throws HeroException { 1376 if (this.getProjectConfigTrace()) 1377 trace.info(" Parameter: instanceName=" + instanceName+ "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 1378 if (instanceName.matches(".*"+"_instance"+".*")){ 1379 int i = instanceName.indexOf("_instance"); 1380 return(instanceName.substring(0,i)); 1381 } 1382 else 1383 throw new HeroException(instanceName+" is not a project instance..."); 1384 } 1385 1386 1395 public void initProject(String projectName) throws HeroException { 1396 if (this.getProjectConfigTrace()) 1397 trace.info(" Parameter: projectName=" + projectName+ " started by " + mContext.getCallerPrincipal().getName()); 1398 Context lContext; 1399 BnUserLocalHome uhome = null; 1400 BnRoleLocalHome rhome = null; 1401 try { 1402 pHome = hero.interfaces.BnProjectUtil.getLocalHome(); 1403 this.mProject = pHome.findByName(projectName); 1404 } catch (javax.naming.NamingException ne) { 1405 throw new HeroException(ne.getMessage()); 1406 } catch (javax.ejb.FinderException fe) { 1407 throw new HeroException(fe.getMessage()); 1408 } 1409 } 1410 1411 private boolean getProjectConfigTrace() throws HeroException{ 1412 if (this.getName()!=null) 1413 return (bonitaConfig.getProcessTrace(this.getName())); 1414 else 1415 return true; 1416 } 1417 1418 1426 public void ejbCreate() throws CreateException { 1427 } 1428 1429 1432 public void ejbPostCreate(String oldProject, String newProject) 1433 throws CreateException , RemoteException { 1434 } 1435 1436 1439 public void setSessionContext(final javax.ejb.SessionContext context) { 1440 mContext = context; 1441 try{ 1442 JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome(); 1443 this.jms=home.create(); 1444 this.bonitaConfig = new BonitaConfig(); 1445 }catch(Exception e){throw new EJBException (e.getMessage());} 1446 } 1447 1448 1451 1452 public void ejbRemove() { 1453 } 1454 1455 1458 1459 public void ejbActivate() { 1460 } 1461 1462 1465 1466 public void ejbPassivate() { 1467 } 1468 1469} 1470 1471 | Popular Tags |