Brij Framework Overview

Brijframework is an open source Java platform. It was developed by Ram Kishor in 2015. It is lightweight when it comes to size and transparency. The basic version of Brij framework is around 2MB.

The core features of the Brij Framework can be used in developing any Java application, but there are extensions for building web applications on top of the Java EE platform. Brij framework targets to make J2EE development easier to use and promotes good programming practices by enabling a POJO-based programming model.

Brijframework makes the easy development of JavaEE application. it provides support to various frameworks. can be defined as a structure where we find solution of the various technical problems.

The Brijframework comprises several modules such as

Model
Bean
JDBC
DAO
ORM
WEB MVC
WEB REST

Benefits of Using the Brij Framework

Following is the list of few of the great benefits of using Brij Framework −

  1. Enables developers to develop POJOs class without need to getter setter method. its control by json file or xml file or annotations.
  2. Enables developers to develop enterprise-class applications using POJOs. The benefit of using only POJOs is that you do not need an EJB container product such as an application server but you have the option of using only a robust servlet container such as Tomcat or some commercial product.

BrijFramework - Architecture

BrijFramework - Environment

Step 1 - Setup Java Development Kit (JDK)

You can download the latest version of SDK from Oracle's Java site − Java SE Downloads. You will find instructions for installing JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively. If you are running Windows and have installed the JDK in C:\jdk1.6.0_15

For windows

 set PATH=C:\jdk1.8\bin;%PATH%
 set JAVA_HOME=C:\jdk1.8 
                  

For Unix (Solaris, Linux, etc.)

 setenv PATH /usr/local/jdk1.6.0_15/bin:$PATH
 setenv JAVA_HOME /usr/local/jdk1.6.0_15 
                  

Step 2 - Setup Spring Framework Libraries

You can use by download libraries or mavan or gradle build tool.
By using Mavan or Gradle build tool
<dependency>
 <groupId>io.github.github-brijframework</groupId>
 <artifactId>github-brijframework-boot</artifactId>
 <version>1.1</version>
</dependency>
<dependency>
 <groupId>io.github.github-brijframework</groupId>
 <artifactId>github-brijframework-bean</artifactId>
 <version>1.1</version>
</dependency>
                  

Download libraries

Code libraries brijframework 1.1 version

Download now !
                  

Context

Context is the mechanism of framework which is launch the application and there module. It’s responsible start and stop all the relative container. The interface provides a common protocol for launching container. It provides methods to start and stop in an orderly manner.

There are two type of context

  1. BootStrapContext
  2. ModuleContext

Bootstrap Context

Bootstrap Context responsible to launch all related module context at the application level.

Bootstrap context is there-

Example: Application Context

Module Context

Module Context responsible to launch all related container at the application level.

Module context is there-

Example: Environment Context, Logger Context, Resource Context, Modal Context, Bean Context

Container

Container is a mechanism to cache component in globally for application. It’s responsible to launch all related factories. The interface provides a common protocol for launching the factories. It provides methods to load and build in an orderly manner.

Module Container is there-

Example: EnvironmentContainer, LoggerContainer, ResourceContainer, ModalContainer, BeanContainer

Factory

A factory is a large building where resource are used to make objects.

Module factory is there-

Example: BeanDefinitionFactory, BeanResourceFactory, BeanScopeFactory ModelDiffinationFactory, ModelResourceFactory, ResourceFactory

Model

Model is a mechanism for accessing an object's properties indirectly, using keys to identify properties, rather than through invocation of an accessor method or accessing them directly through instance variables.

The interface provides a common protocol for all objects for implementing key value coding. It provides methods to set and get property values in an orderly manner without getter setter methods of the class explicitly

No Requirement of setter/ getter to access the property of objects

There are 2 type model definition

  1. XML based configuration file.
  2. JSON based configuration file.
  3. Annotation-based configuration
  4. Java-based configuration

XML based configuration file

								   
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE models SYSTEM "../Models.dtd">
<models>
  <model id="Employee_001" name="Employee" type="io.brijframework.dao.Employee" access="READ_WRITE">
    <properties name="id" access="READ_WRITE"></properties>
    <properties name="name" access="READ_WRITE"></properties>
  </model>
  <model id="Employee_002" name="Employee" type="io.brijframework.dao.Employee" access="READ_WRITE">
    <properties>
      <property name="id" access="READ_WRITE"></property>
      <property name="name" access="READ_WRITE"></property>
    </properties>
  </model>
</models>
								
								

XML based configuration file

[
  {
    "id": "Employee_003",
    "type": "io.brijframework.dao.Employee",
    "name": "Employee",
    "access": "READ_WRITE",
    "properties": {
      "id": {
        "access": "READ_WRITE"
      },
      "name": {
        "access": "READ_WRITE"
      }
    }
  },
  {
    "id": "Employee_004",
    "type": "io.brijframework.dao.Employee",
    "name": "Employee",
    "access": "READ_WRITE",
    "properties": {
      "id": {
        "access": "READ_WRITE"
      },
      "name": {
        "access": "READ_WRITE"
      },
      "address": {
        "access": "READ_WRITE"
      }
    }
  }
]
								

Annotation-based configuration

import org.brijframework.support.model.Model;
import org.brijframework.support.model.properties.ModelProperty;

@Model 
public class Employee {
	
	@ModelProperty
	private String id;

	@ModelProperty
	private String name;
	
	@ModelProperty
	private long rollNo;

	@ModelProperty
	private Address address;
	
}								
								

Java-Based configuration

@ModelResource
public TypeModelResource employee005() {
	TypeModelResourceImpl modelResource=new TypeModelResourceImpl();
	modelResource.setId("Employee005");
	modelResource.setName("Employee");
	modelResource.setType(Employee.class.getName());
	
	PropertyModelResourceImpl id= new PropertyModelResourceImpl();
	id.setName("id");
	modelResource.addProperty(id);
	
	PropertyModelResourceImpl name= new PropertyModelResourceImpl();
	id.setName("name");
	modelResource.addProperty(name);
	
	return modelResource;
}								
								

Example of model class

Step 1 : create pojo class with implements ModelControl


import org.brijframework.model.control.ModelControl;

public class Employee implements ModelControl {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String id;

	private String name;
	
	private long rollNo;

	private Address address;
	
}
								

Step 2 : Create JSON-Based model definition

[
	{
		"id": "Employee_003",
		"type": "io.brijframework.dao.Employee",
		"name": "Employee",
		"access": "READ_WRITE",
		"properties": {
			"id": {
				"access": "READ_WRITE"
			},
			"name": {
				"access": "READ_WRITE"
			},
			"address": {
				"access": "READ_WRITE",
				"model":"Address_001"
			}
		}
	}
]							
							

Step 3 : Create application environment file

Default files are application-environment.properties or application-environment.yaml or application-environment.yml or application-environment.xml

If you want to change then @EnvironmentConfig annotation put to the main and set the path of file

logging:
  level:
    error

application:
  profiles:
    active: "dev"
  main:
    banner-mode: "off"

server:
  email: default@mkyong.com

---
application:
  profiles: dev
  resource:
    config:
     location : classpath:resource/
     enable : true
  model:
   config: 
     location : classpath:/resource/models
     packages : org.brijframework.dao
     enable : true
  bean:
   config: 
     location : classpath:/resource/beans
     packages : org.brijframework.dao
     enable : true
  logger:
    config: 
     enable : true
     level : info
---
application:
  profiles: test
  resource:
    config:
     location : classpath:resource/
     enable : true
  model:
   config: 
     location : classpath:/resource/models
     packages : org.brijframework.dao
     enable : true
  bean:
   config: 
     location : classpath:/resource/beans
     packages : org.brijframework.dao
     enable : true
  logger:
    config: 
     enable : true
     level : info								
								

Step 4 : Create Main class


import org.brijframework.model.context.ModelContext;
import org.brijframework.model.context.factories.ModelContextFactory;
import org.brijframework.support.config.EnvironmentConfig;

import io.brijframework.dao.Employee;

@EnvironmentConfig
public class ModelTester {

	public static void main(String[] args) {
		ModelContext modelContext= ModelContextFactory.getFactory().getContext(ModelContext.class);
		Employee employee = modelContext.getModel("Employee_003");
		employee.setProperty("id", "1021");
		employee.setProperty("address.line", "ok");
		employee.setProperty("address.city.name", "noida");
		
		System.out.println("-----------------------------------------------------------------");
		System.out.println("id : " +employee.getProperty("id"));
		System.out.println("address.line : " +employee.getProperty("address.line"));
		System.out.println("address.city.name : " +employee.getProperty("address.city.name"));
		
		System.out.println("---------------------------Properties-------------------------------------");
		System.out.println(employee.getProperties());

		System.out.println("------------------------------GraphObject----------------------------");
		System.out.println(employee.getGraphObject());
		
		System.out.println("------------------------------JsonObject----------------------------------");
		System.out.println(employee.getJsonObject());
		
		System.out.println("------------------------------XmlObject-----------------------------------");
		System.out.println(employee.getXmlObject());
		
	}
}					
								

Output :

-----------------------------------------------------------------
id : 1021
address.line : ok
Jul 28, 2021 5:45:33 PM org.brijframework.model.control.ModelControl getProperty
WARNING: Invalid access (WRITE_ONLY) of property (city) for model (Address_001)
address.city.name : null
---------------------------Properties-------------------------------------
{address=io.brijframework.dao.Address@1727e03a, name=null, id=1021}
------------------------------GraphObject----------------------------
{
   "address"={
      "city"={
         "name"="noida" 
      },
      "line"="ok",
      "employee"=null,
      "landMark"=null 
   },
   "name"=null,
   "id"="1021" 
}
------------------------------JsonObject----------------------------------
{
   "id":"1021",
   "name":null,
   "rollNo":0,
   "address":{
      "line":"ok",
      "city":{
         "name":"noida" 
      },
      "landMark":null,
      "employee":null 
   } 
}
------------------------------XmlObject-----------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<employee>
  <address>
    <city>
      <name>noida</name>
    </city>
    <line>ok</line>
    <employee>null</employee>
    <landMark>null</landMark>
  </address>
  <name>null</name>
  <rollNo>0</rollNo>
  <id>1021</id>
</employee>
				
								

Bean

Bean, the objects that form the backbone of your application and that are managed by the container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a container. Otherwise, a bean is simply one of many objects in your application.

There are 4 type model definition

  1. XML based configuration file.
  2. JSON based configuration file.
  3. Annotation-based configuration
  4. Java-based configuration

XML based configuration file

								   
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans SYSTEM "../beans.dtd">
<beans>
  <bean id="Employee_001" name="Employee" model="Employee_001" scope="prototype">
    <properties name="id" value="012"></properties>
    <properties name="name" value="Ajay"></properties>
  </bean>
  <bean id="Employee_002" name="Employee" model="Employee_002" scope="singleton" >
    <properties>
      <property name="id" value="011"></property>
      <property name="name" value="Ram"></property>
    </properties>
  </bean>
</beans>
								
								

JSON based configuration file

[
  {
    "id": "Employee_003",
    "model": "Employee_003",
    "name": "Employee",
    "scope": "singleton",
    "properties": {
      "id":"001",
      "name": "Ram"
    }
  },
  {
    "id": "Employee_004",
    "model": "Employee_003",
    "name": "Employee",
    "scope": "singleton",
    "properties": {
      "id":"002",
      "name": "Ajay"
    }
  }
]
								

Annotation-based configuration

import org.brijframework.bean.BeanObject;
import org.brijframework.support.bean.Bean;
import org.brijframework.support.bean.properties.BeanProperty;

@Bean(id = "Employee_011" , properties = {
  @BeanProperty(name = "id", value = "101"),
  @BeanProperty(name = "name", value = "ajay")
} , scope = Scope.SINGLETON) 
public class Employee {
	
	private String id;
	private String name;
	private long rollNo;
	private Address address;
	
}								
								

Java-Based configuration

@BeanResource
public TypeBeanResource employee005() {
	TypeBeanResourceImpl modelResource=new TypeBeanResourceImpl();
	modelResource.setId("Employee005");
	modelResource.setName("Employee");
	modelResource.setModel("Employee005");
	modelResource.setScope(Scope.SINGLETON.toString());
	modelResource.setType(Employee.class.getName());
	modelResource.getProperties().put("id", "001");
	modelResource.getProperties().put("name", "Ajay");
	return modelResource;
}