KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > asyncinvoke > BaseInvocation


1 /*
2  * Created on Mar 23, 2005
3  */

4 package com.nightlabs.ipanema.asyncinvoke;
5
6 import java.io.Serializable JavaDoc;
7 import java.util.Hashtable JavaDoc;
8
9 import javax.jdo.PersistenceManager;
10 import javax.jdo.PersistenceManagerFactory;
11 import javax.naming.InitialContext JavaDoc;
12
13 import com.nightlabs.ModuleException;
14 import com.nightlabs.ipanema.base.IpanemaPrincipal;
15 import com.nightlabs.ipanema.base.Lookup;
16 import com.nightlabs.ipanema.servermanager.IpanemaServerManager;
17 import com.nightlabs.ipanema.servermanager.IpanemaServerManagerFactory;
18
19 /**
20  * @author Marco Schulze - marco at nightlabs dot de
21  */

22 public abstract class BaseInvocation
23 implements Serializable JavaDoc
24 {
25     private transient IpanemaPrincipal callerPrincipal;
26
27     public BaseInvocation()
28     {
29     }
30
31     /**
32      * @return Returns the lookup.
33      */

34     public Lookup getLookup()
35     {
36         return getPrincipal().getLookup();
37     }
38
39     /**
40      * @return Returns the callerPrincipal.
41      */

42     public IpanemaPrincipal getPrincipal()
43     {
44         return callerPrincipal;
45     }
46     /**
47      * @param callerPrincipal The callerPrincipal to set.
48      */

49     public void setPrincipal(IpanemaPrincipal callerPrincipal)
50     {
51         this.callerPrincipal = callerPrincipal;
52     }
53     
54     protected PersistenceManagerFactory getPersistenceManagerFactory()
55         throws ModuleException
56     {
57         return getPrincipal().getLookup().getPersistenceManagerFactory();
58     }
59     
60     /**
61      * This method is a shortcut to <code>getPrincipal().getLookup().getPersistenceManager()</code>.
62      * It might fail with stateless session beans!
63      *
64      * @return Returns the PersistenceManager assigned to the current user.
65      * @throws ModuleException
66      *
67      * @see getPrincipal()
68      */

69     protected PersistenceManager getPersistenceManager()
70         throws ModuleException
71     {
72         return getPrincipal().getLookup().getPersistenceManager();
73     }
74     
75     protected InitialContext JavaDoc getInitialContext()
76         throws ModuleException
77     {
78         return getPrincipal().getLookup().getInitialContext();
79     }
80
81     /**
82      * Use this method whenever you want to communicate with another
83      * organisation. This method configures an InitialContext to connect
84      * to the right server and to authenticate correctly according
85      * to the Ipanema way of organisation@organisation-authentication.
86      * <br/><br/>
87      * This method is a shortcut to
88      * <code>getPrincipal().getLookup().getInitialContext(organisationID)</code>.
89      *
90      * @param organisationID The organisationID with wich to communicate.
91      * @return Returns an InitialContext that is configured properly to authenticate at and communicate with another organisation (wherever it may be - e.g. on another server).
92      * @throws ModuleException
93      */

94     protected InitialContext JavaDoc getInitialContext(String JavaDoc organisationID)
95         throws ModuleException
96     {
97         return getPrincipal().getLookup().getInitialContext(organisationID);
98     }
99
100     /**
101      * This method returns the properties that are used by
102      * <code>getInitialContext(String organisationID)</code>. It is meant
103      * to be used with *Util classes that expect a Hashtable/Properties instance
104      * to create a home interface.
105      * <br/><br/>
106      * This method is a shortcut to
107      * <code>getPrincipal().getLookup().getInitialContextProps(organisationID)</code>
108      *
109      * @param organisationID
110      * @return Returns an instance of Properties to be used in <code>new InitialContext(Properties)</code>.
111      * @throws ModuleException
112      *
113      * @see getInitialContext(String organisationID)
114      */

115     protected Hashtable JavaDoc getInitialContextProps(String JavaDoc organisationID)
116         throws ModuleException
117     {
118         return getPrincipal().getLookup().getInitialContextProps(organisationID);
119     }
120
121     protected IpanemaServerManagerFactory getIpanemaServerManagerFactory()
122         throws ModuleException
123     {
124         return getPrincipal().getLookup().getIpanemaServerManagerFactory();
125     }
126     
127     protected IpanemaServerManager getIpanemaServerManager()
128     throws ModuleException
129     {
130         return getPrincipal().getLookup().getIpanemaServerManager();
131     }
132
133     protected String JavaDoc getOrganisationID()
134     throws ModuleException
135     {
136         return getPrincipal().getOrganisationID();
137     }
138
139     protected String JavaDoc getUserID()
140     throws ModuleException
141     {
142         return new String JavaDoc(getPrincipal().getUserID());
143     }
144     
145     protected boolean userIsOrganisation()
146     throws ModuleException
147     {
148         return getPrincipal().userIsOrganisation();
149     }
150     
151     protected String JavaDoc getPrincipalString()
152         throws ModuleException
153     {
154         return getPrincipal().toString();
155     }
156 }
157
Popular Tags