How johnyzhub/jee-cdi2 works
Project Type & Purpose
• The README clearly states “JEE 7 CDI 2.x Practice Project.” This project serves as a demonstration of Java EE’s Contexts and Dependency Injection (CDI) features.
• The file tree reveals three main modules:
– BookStore: Contains core business logic, entities, producers, decorators, interceptors, events, qualifying annotations, and services.
– BookStoreTracker: Likely a simpler module focusing on tracking, possibly demonstrating plain POJO usage and time tracking.
– RestWithProduce: A web module exposing REST functionality (with a standard webapp directory, web.xml, and JSP) that uses CDI to produce REST responses.
Analyzing the File Structure
• Each module follows a Maven standard layout (pom.xml, src/main/java, and src/main/resources).
• In the BookStore module, you observe further subdivisions:
• Entities (e.g., Author, Book, BookPrice, Category, StoreDetails)
• Services (e.g., BookService)
• Producers (e.g., DynamicProducer, InjectionProducer)
• Decorators (e.g., EbookPriceDecorator, PaperBackPriceDecorator)
• Interceptors (logging and constructor interceptors)
• CDI qualifiers and extension classes, which indicate advanced usage of CDI features.
• Event handlers (both synchronous and asynchronous)
• The RestWithProduce module shows a similar package structure but is tailored for building a REST web application with its own producers, selectors and entity definitions (e.g., FictionBook, SuspenseBook) that are exposed via REST endpoints.
• The BookStoreTracker module includes plain POJOs (such as a TimeTracker), probably to illustrate lightweight component design and tracking functionality.
a. Main Components:
• BookStore Module:
• BookService as the business service layer
• Entity layer including Book, Author, etc.
• Producer components (DynamicProducer, InjectionProducer) that instantiate beans dynamically based on qualifiers.
• Decorator components (EbookPriceDecorator, PaperBackPriceDecorator) to modify behavior.
• Interceptor stack (LoggingInterceptor, MethodInterceptor, ConstructorInterceptor) for cross-cutting concerns.
• Event handling components (SyncEventHandler and AsyncEventHandler)
• Qualifiers and extensions (PropertyLoaderExtension and associated qualifier classes)
• RestWithProduce Module:
• REST Controller/Resource: BookService under the “rest” package.
• Supporting components: Entities (Book, FictionBook, SuspenseBook), ProducerFactory, and BookSelector.
• Web layer including JSP view and web.xml for configuration.
• BookStoreTracker Module:
• A simple tracker component (TimeTracker) and any POJO-based logic.
• Supporting Infrastructure:
• The CDI container acting as the underlying dependency injection framework.
• External configuration files (beans.xml, WEB-INF/web.xml) that govern component discovery and configuration.
b. Relationships & Interactions:
• How the CDI container injects producers into services.
• Interaction between BookService and underlying entities.
• How decorators and interceptors wrap or modify calls to the service or method invocations.
• Event flow between source components and the synchronous/asynchronous handlers.
• REST module interactions: the REST controller routes calls to business services and in turn interacts with producers/selectors.
• The plain POJO-based tracker consuming time events or being updated by certain processes.
c. Key Architectural Patterns & Design Principles:
• Dependency Injection via CDI: Illustrate the container responsible for injecting beans produced by factories and producers.
• Decorator Pattern: Show decorator classes modifying behavior of price computation.
• Interceptor Pattern: Represent interceptors intercepting method calls for logging or security.
• Event-driven Architecture: Represent asynchronous and synchronous events being fired and handled.
d. Relevant Technologies, Frameworks & Libraries:
• Java EE environment (with JEE 7 specifics)
• CDI 2.x for dependency injection and bean management.
• The use of standard configuration files (beans.xml under META-INF) that control CDI behavior.
• For the web module, include REST (JAX-RS likely), and JSP/servlet container elements for the web aspect.