?? conceptstrcontroller.java
字號:
/* */package org.impact.stars.control.ejb;import java.rmi.RemoteException;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.ejb.CreateException;import javax.ejb.DuplicateKeyException;import javax.ejb.FinderException;import javax.ejb.RemoveException;import javax.ejb.EJBException;import java.util.Collection;import java.util.ArrayList;import java.util.Iterator;import org.impact.stars.util.Debug;import org.impact.stars.util.JNDINames;import org.impact.stars.util.EJBUtil;import org.impact.stars.util.EJBKeys;import org.impact.stars.conceptmd.conceptstr.ejb.ConceptstrLocal;import org.impact.stars.conceptmd.conceptstr.ejb.ConceptstrLocalHome;import org.impact.stars.conceptmd.concept.ejb.ConceptLocal;import org.impact.stars.conceptmd.concept.model.ConceptModel;import org.impact.stars.conceptmd.concept.ejb.ConceptLocalHome;import org.impact.stars.organizationmd.profilemgr.ejb.ProfileMgrLocal;import org.impact.stars.organizationmd.profilemgr.ejb.ProfileMgrLocalHome;import org.impact.stars.control.event.ConceptstrEvent;import org.impact.stars.control.event.StarsEvent;import org.impact.stars.control.exceptions.StarsEventException;import org.impact.stars.conceptmd.concept.exceptions.ConceptAppException;import org.impact.stars.control.exceptions.StarsAppException;/*import org.impact.stars.control.exceptions.DuplicateAccountException;*/public class ConceptstrController extends StateControllerSupport { public void perform(StarsEvent event) throws StarsEventException { ConceptstrEvent ce = (ConceptstrEvent)event; switch (ce.getActionType()) { case ConceptstrEvent.CREATE_CONCEPTSTR: { Debug.println("ConceptstrController (ejb): CREATE_CONCEPTSTR event"); try { ConceptstrLocalHome home = EJBUtil.getConceptstrLocalHome(); ConceptstrLocal cptstr = home.create(ce.getConceptstrID(), ce.getName(), ce.getProjectID(), ce.getDescription()); //String cstrID, String name, String projectID, String description Debug.println("ConceptstrController: created conceptstr for " + ce.getConceptstrID()); } catch (CreateException cre) { throw new StarsAppException("Unable to create a new conceptstr for " + ce.getConceptstrID() + " at this time"); } catch (javax.naming.NamingException nme) { throw new EJBException("Irrecoverable error creating conceptstr: " + ce); } } break; case ConceptstrEvent.UPDATE_CONCEPTSTR_DATA: { Debug.println("ConceptstrController (ejb): UPDATE_CONCEPTSTR_DATA event"); try { Debug.println("ConceptstrController (ejb): updating concept concept for " + ce.getConceptstrID()); ConceptstrLocalHome home = EJBUtil.getConceptstrLocalHome(); ConceptstrLocal cptstr = home.findByPrimaryKey(ce.getConceptstrID()); cptstr.updateConceptstr(ce.getName(), ce.getProjectID(), ce.getDescription()); } catch (javax.ejb.FinderException fde) { throw new StarsAppException("Unable to find an concept/profile with concept id : " + ce.getConceptstrID()); } catch (javax.ejb.NoSuchEntityException nee) { throw new StarsAppException("Unable to find an concept/profile with concept id : " + ce.getConceptstrID()); } catch (javax.naming.NamingException nme) { Debug.println("ConceptstrController naming exception: " + nme); throw new EJBException("Irrecoverable error while updating concept : " + nme); } } break; case ConceptstrEvent.DELETE_CONCEPTSTR: { //delete the entire concept structure Debug.println("ConceptstrController (ejb): DELETE_CONCEPTSTR event"); try { Debug.println("ConceptstrController (ejb): deleting concept concept for " + ce.getConceptstrID()); ConceptstrLocalHome cstrhome = EJBUtil.getConceptstrLocalHome(); ConceptstrLocal cptstr = cstrhome.findByPrimaryKey(ce.getConceptstrID()); ArrayList cptcollection = cptstr.getConceptList(); //remove all of the concepts if (cptcollection != null) { Iterator itr = cptcollection.iterator(); while (itr.hasNext()) { ConceptLocal cpt = (ConceptLocal)itr.next(); cpt.remove(); } } //remove this conceptstr cptstr.remove(); }catch (javax.ejb.FinderException fe) { throw new StarsAppException("Unable to find an concept/profile with concept id : " + ce.getConceptstrID()); } catch (javax.ejb.RemoveException rme) { throw new StarsAppException("Unable to remove an concept/profile with concept id : " + ce.getConceptstrID()); } catch (javax.naming.NamingException nme) { Debug.println("ConceptstrController naming exception: " + nme); throw new EJBException("Irrecoverable error while updating concept : " + nme); } } break; case ConceptstrEvent.RESTRUCT_CONCEPTSTR_DATA: { Debug.println("ConceptstrController (ejb): RESTRUCT_CONCEPTSTR_DATA event"); try { Debug.println("ConceptstrController (ejb): deleting concept concept for " + ce.getConceptstrID()); ConceptstrLocalHome cstrhome = EJBUtil.getConceptstrLocalHome(); ConceptstrLocal cptstr = cstrhome.findByPrimaryKey(ce.getConceptstrID()); removeBranch(ce.getUpdateConceptID()); addConcepts(ce.getConceptstrID(), ce.getUpdateConceptList()); }catch (javax.ejb.FinderException fe) { throw new StarsAppException("Unable to find an concept/profile with concept id : " + ce.getConceptstrID()); } catch (javax.naming.NamingException nme) { Debug.println("ConceptstrController naming exception: " + nme); throw new EJBException("Irrecoverable error while updating concept : " + nme); } } break; default: Debug.print("ConcpetController: no action performed"); break; } } private void removeBranch(String conceptID)throws StarsEventException { try{ ConceptLocalHome chome = EJBUtil.getConceptLocalHome(); ConceptLocal clocal = chome.findByPrimaryKey(conceptID); Collection cptcollection = chome.findChildren(conceptID); if (cptcollection != null) { Iterator itr = cptcollection.iterator(); while (itr.hasNext()) { ConceptLocal cpt = (ConceptLocal)itr.next(); removeBranch(cpt.getConceptID()); cpt.remove(); } } clocal.remove(); }catch (javax.ejb.FinderException fe) { throw new StarsAppException("Unable to find an concept/profile with concept id : " + conceptID ); } catch (javax.ejb.RemoveException rme) { throw new StarsAppException("Unable to remove an concept/profile with concept id : " + conceptID ); } catch (javax.naming.NamingException nme) { Debug.println("ConceptstrController naming exception: " + nme); throw new EJBException("Irrecoverable error while updating concept : " + nme); } } private void addConcepts(String cstr, Collection conceptlist)throws StarsEventException { Debug.println("ConceptController (ejb): addconcepts"); try { if (conceptlist != null) { ConceptLocalHome home = EJBUtil.getConceptLocalHome(); Iterator itr = conceptlist.iterator(); while (itr.hasNext()) { ConceptModel cpt = (ConceptModel)itr.next(); ConceptLocal cptlocal = home.create(cstr, cpt.getConceptID(), cpt.getName(), cpt.getParentID(), cpt.getType(), cpt.getPstakeholder(), cpt.getShared(), cpt.getProposetime(), cpt.getDefinition(), cpt.getDescription()); } } Debug.println("ConceptController: created concepts for new " + cstr); } catch (CreateException cre) { throw new StarsAppException("Unable to create a new concept for " ); } catch (javax.naming.NamingException nme) { throw new EJBException("Irrecoverable error creating concept: " ); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -