Skip to content

Commit 8877ba7

Browse files
authored
fix: Fix context object (#2415)
* fix pr builder goals * update links * add context-object to build * add autogenerated content * fix checkstyle findings
1 parent 3d30e92 commit 8877ba7

17 files changed

Lines changed: 254 additions & 94 deletions

File tree

.github/workflows/maven-pr-builder.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
run: sudo apt-get install -y xvfb
6262

6363
- name: Build with Maven and run SonarQube analysis
64-
run: xvfb-run ./mvnw clean -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=iluwatar -Dsonar.projectKey=iluwatar_java-design-patterns -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }} -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
64+
run: xvfb-run ./mvnw clean verify -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=iluwatar -Dsonar.projectKey=iluwatar_java-design-patterns -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }} -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
6565
env:
6666
# These two env variables are needed for sonar analysis
6767
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@startuml
2+
package com.iluwatar.client.session {
3+
class App {
4+
+ App()
5+
+ main(args : String[]) {static}
6+
}
7+
class Request {
8+
- data : String
9+
- session : Session
10+
+ Request(data : String, session : Session)
11+
# canEqual(other : Object) : boolean
12+
+ equals(o : Object) : boolean
13+
+ getData() : String
14+
+ getSession() : Session
15+
+ hashCode() : int
16+
+ setData(data : String)
17+
+ setSession(session : Session)
18+
+ toString() : String
19+
}
20+
class Server {
21+
- LOGGER : Logger {static}
22+
- host : String
23+
- port : int
24+
+ Server(host : String, port : int)
25+
# canEqual(other : Object) : boolean
26+
+ equals(o : Object) : boolean
27+
+ getHost() : String
28+
+ getPort() : int
29+
+ getSession(name : String) : Session
30+
+ hashCode() : int
31+
+ process(request : Request)
32+
+ setHost(host : String)
33+
+ setPort(port : int)
34+
+ toString() : String
35+
}
36+
class Session {
37+
- clientName : String
38+
- id : String
39+
+ Session(id : String, clientName : String)
40+
# canEqual(other : Object) : boolean
41+
+ equals(o : Object) : boolean
42+
+ getClientName() : String
43+
+ getId() : String
44+
+ hashCode() : int
45+
+ setClientName(clientName : String)
46+
+ setId(id : String)
47+
+ toString() : String
48+
}
49+
}
50+
Request --> "-session" Session
51+
@enduml

context-object/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Use the Context Object pattern for:
179179

180180
## Credits
181181

182-
* [J2EE Design Patterns](http://corej2eepatterns.com/ContextObject.htm)
182+
* [Core J2EE Design Patterns](https://amzn.to/3IhcY9w)
183+
* [Core J2EE Design Patterns website - Context Object](http://corej2eepatterns.com/ContextObject.htm)
183184
* [Allan Kelly - The Encapsulate Context Pattern](https://accu.org/journals/overload/12/63/kelly_246/)
184-
* [Arvid S. Krishna et al. - Context Object](https://www.dre.vanderbilt.edu/~schmidt/PDF/Context-Object-Pattern.pdf)
185+
* [Arvid S. Krishna et al. - Context Object](https://www.dre.vanderbilt.edu/~schmidt/PDF/Context-Object-Pattern.pdf)

context-object/src/main/java/com/iluwatar/context/object/App.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,30 @@
1313
@Slf4j
1414
public class App {
1515

16-
private static final String SERVICE = "SERVICE";
16+
private static final String SERVICE = "SERVICE";
1717

18-
/**
19-
* Program entry point.
20-
* @param args command line args
21-
*/
22-
public static void main(String[] args) {
23-
//Initiate first layer and add service information into context
24-
var layerA = new LayerA();
25-
layerA.addAccountInfo(SERVICE);
18+
/**
19+
* Program entry point.
20+
*
21+
* @param args command line args
22+
*/
23+
public static void main(String[] args) {
24+
//Initiate first layer and add service information into context
25+
var layerA = new LayerA();
26+
layerA.addAccountInfo(SERVICE);
2627

27-
LOGGER.info("Context = {}",layerA.getContext());
28+
LOGGER.info("Context = {}", layerA.getContext());
2829

29-
//Initiate second layer and preserving information retrieved in first layer through passing context object
30-
var layerB = new LayerB(layerA);
31-
layerB.addSessionInfo(SERVICE);
30+
//Initiate second layer and preserving information retrieved in first layer through passing context object
31+
var layerB = new LayerB(layerA);
32+
layerB.addSessionInfo(SERVICE);
3233

33-
LOGGER.info("Context = {}",layerB.getContext());
34+
LOGGER.info("Context = {}", layerB.getContext());
3435

35-
//Initiate third layer and preserving information retrieved in first and second layer through passing context object
36-
var layerC = new LayerC(layerB);
37-
layerC.addSearchInfo(SERVICE);
36+
//Initiate third layer and preserving information retrieved in first and second layer through passing context object
37+
var layerC = new LayerC(layerB);
38+
layerC.addSearchInfo(SERVICE);
3839

39-
LOGGER.info("Context = {}",layerC.getContext());
40-
}
40+
LOGGER.info("Context = {}", layerC.getContext());
41+
}
4142
}

context-object/src/main/java/com/iluwatar/context/object/LayerA.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
@Getter
66
public class LayerA {
77

8-
private ServiceContext context;
8+
private ServiceContext context;
99

10-
public LayerA() {
11-
context = ServiceContextFactory.createContext();
12-
}
10+
public LayerA() {
11+
context = ServiceContextFactory.createContext();
12+
}
1313

14-
public void addAccountInfo(String accountService) {
15-
context.setAccountService(accountService);
16-
}
14+
public void addAccountInfo(String accountService) {
15+
context.setAccountService(accountService);
16+
}
1717
}

context-object/src/main/java/com/iluwatar/context/object/LayerB.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
@Getter
66
public class LayerB {
77

8-
private ServiceContext context;
8+
private ServiceContext context;
99

10-
public LayerB(LayerA layerA) {
11-
this.context = layerA.getContext();
12-
}
10+
public LayerB(LayerA layerA) {
11+
this.context = layerA.getContext();
12+
}
1313

14-
public void addSessionInfo(String sessionService) {
15-
context.setSessionService(sessionService);
16-
}
14+
public void addSessionInfo(String sessionService) {
15+
context.setSessionService(sessionService);
16+
}
1717
}

context-object/src/main/java/com/iluwatar/context/object/LayerC.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
@Getter
66
public class LayerC {
77

8-
public ServiceContext context;
8+
public ServiceContext context;
99

10-
public LayerC(LayerB layerB) {
11-
this.context = layerB.getContext();
12-
}
10+
public LayerC(LayerB layerB) {
11+
this.context = layerB.getContext();
12+
}
1313

14-
public void addSearchInfo(String searchService) {
15-
context.setSearchService(searchService);
16-
}
14+
public void addSearchInfo(String searchService) {
15+
context.setSearchService(searchService);
16+
}
1717
}

context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
@Setter
1313
public class ServiceContext {
1414

15-
String AccountService, SessionService, SearchService;
15+
String accountService;
16+
String sessionService;
17+
String searchService;
1618
}

context-object/src/main/java/com/iluwatar/context/object/ServiceContextFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
public class ServiceContextFactory {
77

8-
public static ServiceContext createContext() {
9-
return new ServiceContext();
10-
}
8+
public static ServiceContext createContext() {
9+
return new ServiceContext();
10+
}
1111
}

context-object/src/test/java/com/iluwatar/contect/object/AppTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
public class AppTest {
99

10-
/**
11-
* Test example app runs without error.
12-
*/
13-
@Test
14-
void shouldExecuteWithoutException() {
15-
assertDoesNotThrow(() -> App.main(new String[]{}));
16-
}
10+
/**
11+
* Test example app runs without error.
12+
*/
13+
@Test
14+
void shouldExecuteWithoutException() {
15+
assertDoesNotThrow(() -> App.main(new String[] {}));
16+
}
1717
}

0 commit comments

Comments
 (0)