Skip to content

Commit 3d838ab

Browse files
authored
and idolaters, and all liars
But the fearful, and unbelieving, and the abominable, and murderers, and whoremongers, and sorcerers, and idolaters, and all liars, shall have their part in the lake which burneth with fire and brimstone: which is the second death. (Revelation 21:8)
1 parent 276b205 commit 3d838ab

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
//But the fearful, and unbelieving, and the abominable, and murderers, and whoremongers, and sorcerers,
3+
//and idolaters, and all liars, shall have their part in the lake which burneth with fire and brimstone: which is the second death. (Revelation 21:8)
4+
5+
package com.javarush.task.task32.task3212.contex;
6+
7+
import com.javarush.task.task32.task3212.service.impl.EJBServiceImpl;
8+
import com.javarush.task.task32.task3212.service.impl.JMSServiceImpl;
9+
10+
public class InitialContext {
11+
public Object lookup(String jndiName) {
12+
13+
if (jndiName.equalsIgnoreCase("EJBService")) {
14+
System.out.println("Looking up and creating a new EJBService object");
15+
return new EJBServiceImpl();
16+
} else if (jndiName.equalsIgnoreCase("JMSService")) {
17+
System.out.println("Looking up and creating a new JMSService object");
18+
return new JMSServiceImpl();
19+
}
20+
return null;
21+
}
22+
}
23+
24+
/*
25+
Service Locator
26+
27+
Прочитать о паттерне Service locator.
28+
29+
30+
31+
Реализуй логику метода getService(String jndiName) в ServiceLocator.
32+
33+
В нем будет реализована работа с контекстом и кэшем.
34+
35+
36+
37+
1) Верни из кэша нужный сервис.
38+
39+
2) Если в кэше нет нужного сервиса то:
40+
41+
2.1) Создай контекст.
42+
43+
2.2) Возьми у контекста нужный сервис.
44+
45+
2.3) Добавь сервис в кеш и верни его.
46+
47+
48+
49+
50+
51+
Требования:
52+
53+
1. Класс ServiceLocator должен содержать метод Service getService(String jndiName).
54+
55+
2. Если нужный сервис находится в кэше, метод getService(String jndiName) должен возвращать сервис из кэша.
56+
57+
3. Если нужный сервис НЕ находится в кэше, метод getService(String jndiName) должен создавать контекст.
58+
59+
4. Если нужный сервис НЕ находится в кэше, метод getService(String jndiName) должен искать нужный сервис в контексте.
60+
61+
5. Если нужный сервис НЕ находится в кэше, метод getService(String jndiName) должен добавлять в кэш сервис, найденный в контексте и возвращать его.
62+
*/

0 commit comments

Comments
 (0)