1 22 package org.jboss.test.cmp2.cmrtransaction.ejb; 23 24 import java.util.Collection ; 25 26 import javax.ejb.EJBException ; 27 import javax.ejb.EntityBean ; 28 import javax.ejb.EntityContext ; 29 import javax.ejb.RemoveException ; 30 import javax.ejb.EJBLocalObject ; 31 import javax.ejb.CreateException ; 32 33 import org.jboss.test.cmp2.cmrtransaction.interfaces.TreeLocal; 34 35 36 39 public abstract class TreeEntity implements EntityBean 40 { 41 43 44 46 public abstract String getId(); 47 public abstract void setId(String id); 48 public abstract int getSortOrder(); 49 public abstract void setSortOrder(int sortOrder); 50 public abstract Collection getMenuChildren(); 51 52 53 public abstract void setMenuChildren(Collection menuChildren); 55 public abstract TreeLocal getMenuParent(); 56 57 public abstract void setMenuParent(TreeLocal menuParent); 58 59 61 62 private EntityContext entityContext = null; 63 64 65 67 public TreeEntity() {} 68 69 70 public String ejbCreate(String name, TreeLocal parent) 71 throws CreateException 72 { 73 setId(name); 74 setSortOrder(0); 75 76 return null; 77 } 78 79 public void ejbPostCreate(String name, TreeLocal parent) 80 { 81 setMenuParent(parent); 82 } 83 84 85 public void ejbRemove() throws RemoveException , EJBException {} 86 public void ejbActivate() throws EJBException {} 87 public void ejbPassivate() throws EJBException {} 88 public void ejbLoad() throws EJBException {} 89 public void ejbStore() throws EJBException {} 90 91 public void setEntityContext(EntityContext entityContext) throws EJBException 92 { 93 this.entityContext = entityContext; 94 } 95 96 public EntityContext getEntityContext() 97 { 98 return entityContext; 99 } 100 101 public void unsetEntityContext() throws EJBException 102 { 103 entityContext = null; 104 } 105 106 107 109 public void setPrecededBy(TreeLocal precedingNode) 110 { 111 EJBLocalObject self = getEntityContext().getEJBLocalObject(); 112 if (precedingNode == null) 113 { 114 setSortOrder(1); 115 } 116 else if (self.isIdentical(precedingNode)) 117 { 118 System.out.println("MenuResource " + getId() + ": " 119 + "attempt to set menu resource " 120 + precedingNode.getId() 121 + " as preceding node; cannot set a node as " 122 + "its own preceding node."); 123 } 124 else if (ejbEquals(getMenuParent(), precedingNode.getMenuParent())) 125 { 126 setSortOrder(precedingNode.getSortOrder() + 1); 127 } 128 else 129 { 130 System.out.println("MenuResource " + getId() + ": " 131 + "attempt to set menu resource " 132 + precedingNode.getId() 133 + " as preceding node; invalid as node has a " 134 + "different menu parent."); 135 } 136 } 137 138 139 141 142 155 private boolean ejbEquals(EJBLocalObject a, EJBLocalObject b) 156 { 157 boolean result = false; 158 159 if (a == b) 160 { 161 result = true; } 163 else if ((a == null) || (b == null)) 164 { 165 result = false; 166 } 167 else 168 { 169 result = a.isIdentical(b); 170 } 171 172 return result; 173 } 174 175 176 } 177 | Popular Tags |