1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
10 package test
.Ice
.servantLocator
;
12 import test
.Ice
.servantLocator
.Test
.Cookie
;
13 import test
.Ice
.servantLocator
.Test
.TestImpossibleException
;
14 import test
.Ice
.servantLocator
.Test
.TestIntfUserException
;
15 import Ice
.ObjectNotExistException
;
16 import Ice
.SocketException
;
17 import Ice
.UnknownException
;
18 import Ice
.UnknownLocalException
;
19 import Ice
.UnknownUserException
;
21 public final class ServantLocatorI
implements Ice
.ServantLocator
24 ServantLocatorI(String category
)
31 protected synchronized void
43 throw new RuntimeException();
48 locate(Ice
.Current current
, Ice
.LocalObjectHolder cookie
) throws Ice
.UserException
55 test(current
.id
.category
.equals(_category
) || _category
.length() == 0);
57 if(current
.id
.name
.equals("unknown"))
62 test(current
.id
.name
.equals("locate") || current
.id
.name
.equals("finished"));
63 if(current
.id
.name
.equals("locate"))
69 // Ensure locate() is only called once per request.
71 test(_requestId
== -1);
72 _requestId
= current
.requestId
;
74 cookie
.value
= new CookieI();
80 finished(Ice
.Current current
, Ice
.Object servant
, java
.lang
.Object cookie
) throws Ice
.UserException
88 // Ensure finished() is only called once per request.
90 test(_requestId
== current
.requestId
);
93 test(current
.id
.category
.equals(_category
) || _category
.length() == 0);
94 test(current
.id
.name
.equals("locate") || current
.id
.name
.equals("finished"));
96 if(current
.id
.name
.equals("finished"))
101 Cookie co
= (Cookie
)cookie
;
102 test(co
.message().equals("blahblah"));
105 public synchronized void
106 deactivate(String category
)
117 exception(Ice
.Current current
) throws Ice
.UserException
119 if(current
.operation
.equals("ice_ids"))
121 throw new TestIntfUserException();
123 else if(current
.operation
.equals("requestFailedException"))
125 throw new ObjectNotExistException();
127 else if(current
.operation
.equals("unknownUserException"))
129 throw new UnknownUserException("reason");
131 else if(current
.operation
.equals("unknownLocalException"))
133 throw new UnknownLocalException("reason");
135 else if(current
.operation
.equals("unknownException"))
137 throw new UnknownException("reason");
140 // User exceptions are checked exceptions in Java, so it's not
141 // possible to throw it from the servant locator.
143 // else if(current.operation.equals("userException"))
145 // throw new TestIntfUserException();
147 else if(current
.operation
.equals("localException"))
149 throw new SocketException(0);
151 else if(current
.operation
.equals("javaException"))
153 throw new java
.lang
.RuntimeException("message");
155 else if(current
.operation
.equals("impossibleException"))
157 throw new TestIntfUserException(); // Yes, it really is meant to be TestIntfUserException.
159 else if(current
.operation
.equals("intfUserException"))
161 throw new TestImpossibleException(); // Yes, it really is meant to be TestImpossibleException.
163 else if(current
.operation
.equals("asyncResponse"))
165 throw new TestImpossibleException();
167 else if(current
.operation
.equals("asyncException"))
169 throw new TestImpossibleException();
173 private boolean _deactivated
;
174 private final String _category
;
175 private int _requestId
;