ICE 3.4.2
[php5-ice-freebsdport.git] / java / test / Ice / servantLocator / ServantLocatorI.java
blobdcf7e8941f93a00e7388f6cf303d3dacb3d4f4d2
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
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
23 public
24 ServantLocatorI(String category)
26 _category = category;
27 _deactivated = false;
28 _requestId = -1;
31 protected synchronized void
32 finalize()
33 throws Throwable
35 test(_deactivated);
38 private static void
39 test(boolean b)
41 if(!b)
43 throw new RuntimeException();
47 public Ice.Object
48 locate(Ice.Current current, Ice.LocalObjectHolder cookie) throws Ice.UserException
50 synchronized(this)
52 test(!_deactivated);
55 test(current.id.category.equals(_category) || _category.length() == 0);
57 if(current.id.name.equals("unknown"))
59 return null;
62 test(current.id.name.equals("locate") || current.id.name.equals("finished"));
63 if(current.id.name.equals("locate"))
65 exception(current);
69 // Ensure locate() is only called once per request.
71 test(_requestId == -1);
72 _requestId = current.requestId;
74 cookie.value = new CookieI();
76 return new TestI();
79 public void
80 finished(Ice.Current current, Ice.Object servant, java.lang.Object cookie) throws Ice.UserException
82 synchronized(this)
84 test(!_deactivated);
88 // Ensure finished() is only called once per request.
90 test(_requestId == current.requestId);
91 _requestId = -1;
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"))
98 exception(current);
101 Cookie co = (Cookie)cookie;
102 test(co.message().equals("blahblah"));
105 public synchronized void
106 deactivate(String category)
108 synchronized(this)
110 test(!_deactivated);
112 _deactivated = true;
116 private void
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"))
144 // {
145 // throw new TestIntfUserException();
146 // }
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;