Skip to content

Commit 12b38e9

Browse files
authored
Merge pull request dianpoint#29 from ccoderJava/feature-validator
Feature validator
2 parents e3182dc + 2369b2e commit 12b38e9

File tree

2 files changed

+184
-12
lines changed

2 files changed

+184
-12
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ target/
3838
### fleet
3939
.fleet
4040

41-
.flattened-pom.xml
41+
42+
.flattened-pom.xml
43+

README.md

Lines changed: 181 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ English | [中文](README_cn.md)
1313
<div align="center">
1414
<h3 align="center">Summer</h3>
1515
<p align="center">
16-
Minimized AOP,IoC kernel tools.
16+
Minimized AOP, IoC kernel tools.
1717
</p>
1818
<br>
1919
<a href="https://github.com/dianpoint/summer"><strong>Summer Docs >></strong> </a>
@@ -26,23 +26,33 @@ English | [中文](README_cn.md)
2626
<a href="https://github.com/dianpoint/summer/issues">Request Feature</a>
2727
</div>
2828

29-
3029
<!-- TOC -->
3130

3231
* [Summer](#summer)
33-
* [About The Project](#about-the-project)
34-
* [Getting Started](#getting-started)
35-
* [Prerequisites](#prerequisites)
36-
* [Installation](#installation)
37-
* [Usage](#usage)
38-
* [Roadmap](#roadmap)
39-
* [Contributing](#contributing)
40-
* [License](#license)
41-
* [Contact](#contact)
32+
* [About The Project](#about-the-project)
33+
* [Getting Started](#getting-started)
34+
* [Prerequisites](#prerequisites)
35+
* [Installation](#installation)
36+
* [Usage](#usage)
37+
* [Bean Definition and Injection](#bean-definition-and-injection)
38+
* [AOP Usage](#aop-usage)
39+
* [Validation](#validation)
40+
* [RequestMapping Annotation](#requestmapping-annotation)
41+
* [Autowired Annotation](#autowired-annotation)
42+
* [Project Structure](#project-structure)
43+
* [Roadmap](#roadmap)
44+
* [Contributing](#contributing)
45+
* [License](#license)
46+
* [Contact](#contact)
4247

4348
<!-- TOC -->
4449

4550
## About The Project
51+
Summer is a minimized AOP and IoC kernel toolset. It provides a lightweight and efficient solution for building Java applications, supporting XML-based bean definition and dependency injection, as well as AOP functionality. The project consists of two main modules: `summer-beans` and `summer-validator`.
52+
53+
### Modules
54+
- **summer-beans**: Core module for bean management, including bean definition, creation, and dependency injection. It also supports AOP features such as proxy creation and advice execution.
55+
- **summer-validator**: A validation module that provides various validation rules for collections and objects.
4656

4757
Summer is a minimized AOP (Aspect-Oriented Programming) and IoC (Inversion of Control) kernel tool library. It provides a set of validators and related utility classes to simplify the validation logic of objects and collections. Additionally, it includes some functions for batch task processing.
4858

@@ -71,6 +81,19 @@ the status, progress, and related information of main and sub-tasks.
7181
## Getting Started
7282

7383
### Prerequisites
84+
- Java 8 or higher
85+
- Maven
86+
87+
### Installation
88+
1. Clone the repository:
89+
90+
```shell
91+
git clone https://github.com/dianpoint/summer.git
92+
cd summer
93+
```
94+
95+
2. Build the project using Maven:
96+
```shell
7497
Make sure you have Java and Maven installed in your development environment.
7598

7699
### Installation
@@ -90,6 +113,153 @@ mvn clean install
90113
```
91114

92115

116+
### Usage
117+
118+
#### Bean Definition and Injection
119+
You can define beans in an XML file and use the XmlBeanDefinitionReader to load and register them. Here is an example:
120+
```java
121+
// Create a bean factory
122+
AbstractBeanFactory beanFactory = new DefaultListableBeanFactory();
123+
// Create a resource for the XML file
124+
Resource resource = new ClassPathResource("beans.xml");
125+
// Create a reader to load bean definitions from the resource
126+
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
127+
reader.loadBeanDefinitions(resource);
128+
// Get a bean from the factory
129+
Object bean = beanFactory.getBean("beanName");
130+
```
131+
132+
#### AOP Usage
133+
Summer supports AOP through proxy creation and advice execution. You can use the ProxyFactoryBean to create a proxy for a target object and apply advice before or after method execution.
134+
135+
```java
136+
// Create a proxy factory bean
137+
ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
138+
proxyFactoryBean.setTarget(target);
139+
proxyFactoryBean.setInterceptorName("interceptorBeanName");
140+
proxyFactoryBean.setBeanFactory(beanFactory);
141+
// Get the proxy object
142+
Object proxy = proxyFactoryBean.getSingletonInstance();
143+
```
144+
145+
#### Validation
146+
The summer-validator module provides validation rules for collections and objects. You can use the ValidationRules and Validators classes to perform validation.
147+
148+
```java
149+
// Validate a collection
150+
ValidationRule<Collection<?>> rule = ValidationRules.minsize(5);
151+
ValidationResult result = rule.validate(collection);
152+
if (result.isSuccess()) {
153+
// Collection meets the validation rule
154+
} else {
155+
// Collection does not meet the validation rule
156+
}
157+
158+
// Validate an object using annotations
159+
User user = new User(null, "123@mail.com");
160+
List<ValidationResult> validationResults = Validators.annotated(User.class).validate(user);
161+
```
162+
163+
#### RequestMapping Annotation
164+
The RequestMapping annotation can be used to map HTTP requests to specific methods in a controller.
165+
```java
166+
import com.dianpoint.summer.web.RequestMapping;
167+
168+
public class MyController {
169+
170+
@RequestMapping("/hello")
171+
public String hello() {
172+
return "Hello, World!";
173+
}
174+
}
175+
```
176+
177+
178+
#### Autowired Annotation
179+
The Autowired annotation can be used to automatically inject dependencies into fields.
180+
```java
181+
import com.dianpoint.summer.beans.factory.annotation.Autowired;
182+
183+
public class MyService {
184+
185+
@Autowired
186+
private AnotherService anotherService;
187+
188+
// ...
189+
}
190+
```
191+
192+
193+
### Project Structure
194+
```java
195+
summer/
196+
├── summer-beans/
197+
│ ├── src/
198+
│ │ ├── main/
199+
│ │ │ └── java/
200+
│ │ │ └── com/dianpoint/summer/
201+
│ │ │ ├── beans/
202+
│ │ │ ├── context/
203+
│ │ │ ├── web/
204+
│ │ │ └── ...
205+
│ │ └── test/
206+
│ │ └── java/
207+
│ │ └── com/dianpoint/summer/test/
208+
│ │ ├── xml/
209+
│ │ └── ...
210+
│ └── pom.xml
211+
├── summer-validator/
212+
│ ├── src/
213+
│ │ ├── main/
214+
│ │ │ └── java/
215+
│ │ │ └── com/dianpoint/summer/validator/
216+
│ │ │ ├── annotations/
217+
│ │ │ ├── constraintvalidators/
218+
│ │ │ └── ...
219+
│ │ └── test/
220+
│ │ └── java/
221+
│ │ └── com/dianpoint/summer/validator/test/
222+
│ │ └── ...
223+
│ └── pom.xml
224+
├── docs/
225+
│ └── readme.md
226+
├── .github/
227+
│ └── workflows/
228+
│ └── maven-test.yml
229+
├── .gitignore
230+
├── pom.xml
231+
├── README.md
232+
└── README_cn.md
233+
```
234+
235+
### Roadmap
236+
237+
- [x] Implement basic bean definition and injection
238+
- [x] Add AOP support
239+
- [ ] Improve validation module with more rules
240+
- [ ] Add support for annotation-based configuration
241+
+ [ ] Implement @Autowired and @Component annotations
242+
+ [ ] Provide annotation scanning functionality
243+
244+
See the issues for a full list of proposed features and known issues.
245+
246+
247+
### Contributing
248+
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
249+
250+
1. Fork the Project
251+
2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
252+
3. Commit your Changes (git commit -m 'Add some AmazingFeature')
253+
4. Push to the Branch (git push origin feature/AmazingFeature)
254+
5. Open a Pull Request
255+
256+
257+
### License
258+
Summer is distributed under the Apache License 2.0 License. See License.txt for more information.
259+
260+
### Contact
261+
+ Email: congccoder@gmail.com
262+
+ Github: https://github.com/ccoderJava
93263
## Usage
94264
95265
## Roadmap

0 commit comments

Comments
 (0)