KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > cmrtransaction > ejb > TreeFacadeSession


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.cmrtransaction.ejb;
23
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import javax.ejb.CreateException JavaDoc;
28 import javax.ejb.EJBException JavaDoc;
29 import javax.ejb.FinderException JavaDoc;
30 import javax.ejb.ObjectNotFoundException JavaDoc;
31 import javax.ejb.RemoveException JavaDoc;
32 import javax.ejb.SessionBean JavaDoc;
33 import javax.ejb.SessionContext JavaDoc;
34 import javax.naming.InitialContext JavaDoc;
35 import javax.naming.NamingException JavaDoc;
36 import javax.rmi.PortableRemoteObject JavaDoc;
37
38 import org.jboss.test.cmp2.cmrtransaction.interfaces.TreeLocalHome;
39 import org.jboss.test.cmp2.cmrtransaction.interfaces.TreeLocal;
40
41
42 /**
43  *
44  * @author B Stansberry brian_stansberry@wanconcepts.com
45  */

46 public class TreeFacadeSession implements SessionBean JavaDoc
47 {
48     // ------------------------------------------------------- Instance Fields
49

50     private transient TreeLocalHome treeHome = null;
51
52     // -------------------------------------------------------- Bean Lifecycle
53

54
55     public TreeFacadeSession() {}
56
57     public void ejbCreate() throws CreateException JavaDoc {}
58     public void setSessionContext(SessionContext JavaDoc sessionContext) {}
59     public void ejbRemove() throws EJBException JavaDoc {}
60     public void ejbActivate() throws EJBException JavaDoc {}
61     public void ejbPassivate() throws EJBException JavaDoc {}
62
63     // ------------------------------------------------------------ TreeFacade
64

65
66     public void setup()
67     {
68         try
69         {
70             TreeLocalHome tlh = getTreeLocalHome();
71             TreeLocal tl = null;
72             try
73             {
74                 tl = tlh.findByPrimaryKey("Parent");
75                 tl.remove();
76             }
77             catch (ObjectNotFoundException JavaDoc f) {}
78             try
79             {
80                 tl = tlh.findByPrimaryKey("Child 1");
81                 tl.remove();
82             }
83             catch (ObjectNotFoundException JavaDoc f) {}
84             try
85             {
86                 tl = tlh.findByPrimaryKey("Child 2");
87                 tl.remove();
88             }
89             catch (ObjectNotFoundException JavaDoc f) {}
90         }
91         catch (NamingException JavaDoc n)
92         {
93             throw new EJBException JavaDoc(n);
94         }
95         catch (RemoveException JavaDoc r)
96         {
97             throw new EJBException JavaDoc(r);
98         }
99         catch (FinderException JavaDoc f)
100         {
101             throw new EJBException JavaDoc(f);
102         }
103     }
104
105
106     public void createNodes()
107     {
108         try
109         {
110             TreeLocalHome tlh = getTreeLocalHome();
111             TreeLocal parent = null;
112             parent = tlh.create("Parent", null);
113             tlh.create("Child 1", parent);
114             tlh.create("Child 2", null);
115         }
116         catch (NamingException JavaDoc n)
117         {
118             throw new EJBException JavaDoc(n);
119         }
120         catch (CreateException JavaDoc c)
121         {
122             throw new EJBException JavaDoc(c);
123         }
124     }
125
126
127     public void rearrangeNodes()
128     {
129         try
130         {
131             TreeLocalHome tlh = getTreeLocalHome();
132             TreeLocal target = tlh.findByPrimaryKey("Child 2");
133             TreeLocal sibling = null;
134             sibling = tlh.findByPrimaryKey("Child 1");
135             /*
136             TreeLocal parent = tlh.findByPrimaryKey("Parent");
137             Collection coll = parent.getMenuChildren();
138             Iterator iter = coll.iterator();
139             sibling = (TreeLocal) iter.next();
140             */

141             target.setMenuParent(sibling.getMenuParent());
142             target.setPrecededBy(sibling);
143         }
144         catch (NamingException JavaDoc n)
145         {
146             throw new EJBException JavaDoc(n);
147         }
148         catch (FinderException JavaDoc f)
149         {
150             throw new EJBException JavaDoc(f);
151         }
152     }
153
154
155     // ------------------------------------------------------- Private Methods
156

157     private TreeLocalHome getTreeLocalHome() throws NamingException JavaDoc
158     {
159         if (treeHome == null)
160         {
161             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
162             Object JavaDoc obj = ctx.lookup("java:/comp/env/ejb/cmrTransactionTest/CMRTreeLocal");
163             treeHome = (TreeLocalHome)
164                     PortableRemoteObject.narrow(obj, TreeLocalHome.class);
165         }
166         return treeHome;
167     }
168
169 }
170
Popular Tags