Upload
afonsobrandao
View
419
Download
7
Tags:
Embed Size (px)
Citation preview
Brutos Application Brutos Application FrameworkFramework
A MVC controller.A MVC controller.
www.brutosframework.com.brwww.brutosframework.com.br
SummarySummary
►What is it?What is it?►What are the advantages in using Brutos?What are the advantages in using Brutos?►How to get the Brutos?How to get the Brutos?►How to configure?How to configure?► Building controllers.Building controllers.► Building actions.Building actions.► Building interceptors.Building interceptors.►Handling exceptions.Handling exceptions.►Mapping beans.Mapping beans.
What is it?What is it?
The Brutos Application Framework is MVC controller The Brutos Application Framework is MVC controller developed in Java. Designed to reduce the complexity of web developed in Java. Designed to reduce the complexity of web development, with configurable mapping, view resolution as development, with configurable mapping, view resolution as well as support for uploading and downloading files. Can be well as support for uploading and downloading files. Can be configured using XML, annotations and CoC.configured using XML, annotations and CoC.
The framework follows the below principles:The framework follows the below principles:• flexibility;flexibility;• loose coupling andloose coupling and• productivity.productivity.
What are the advantages in using What are the advantages in using Brutos?Brutos?
►Loose couplingLoose coupling. . ►Allows creating testable components.Allows creating testable components.►Advanced bean mapping support.Advanced bean mapping support.►Easy learning.Easy learning.
How to get the Brutos?How to get the Brutos?
The Brutos team provides release bundles hosted on the The Brutos team provides release bundles hosted on the SourceForge File Release System, in ZIP. Each release bundle SourceForge File Release System, in ZIP. Each release bundle contains JARs, documentation, source code, and other information.contains JARs, documentation, source code, and other information.You can download releases of Brutos, from the list at You can download releases of Brutos, from the list at http://sourceforge.net/projects/brutos/files/brutos/.http://sourceforge.net/projects/brutos/files/brutos/.
Release Bundle DownloadsRelease Bundle Downloads
Maven Repository ArtifactsMaven Repository ArtifactsThey are produced a number of artifacts. All under the org.brandao They are produced a number of artifacts. All under the org.brandao groupIdgroupIdbrutos-core: brutos-core: The main artifact, it is needed to build applications The main artifact, it is needed to build applications using the Brutos native APIs.using the Brutos native APIs.brutos-annotation: brutos-annotation: Optional artifact that allows building Optional artifact that allows building applications using annotations. This artifact depends on the brutos-applications using annotations. This artifact depends on the brutos-core.core.brutos-web: brutos-web: Optional artifact that allows building web applications.Optional artifact that allows building web applications.This artifact depends on the brutos-core.This artifact depends on the brutos-core.The official repository is The official repository is http://www.brutosframework.com.br/maven/2http://www.brutosframework.com.br/maven/2..
How to configure?How to configure?
<listener><listener> <listener-class>org.brandao.brutos.web.ContextLoaderListener</listener-class><listener-class>org.brandao.brutos.web.ContextLoaderListener</listener-class></listener></listener>
Register the listener in web.xmlRegister the listener in web.xml
Register the filter in web.xmlRegister the filter in web.xml<filter><filter> <filter-name>Brutos Framework Filter</filter-name><filter-name>Brutos Framework Filter</filter-name> <filter-class>org.brandao.brutos.web.http.BrutosRequestFilter</filter-class><filter-class>org.brandao.brutos.web.http.BrutosRequestFilter</filter-class> </filter></filter> <filter-mapping><filter-mapping> <filter-name>Brutos Framework Filter</filter-name><filter-name>Brutos Framework Filter</filter-name> <url-pattern>*</url-pattern><url-pattern>*</url-pattern> <dispatcher>REQUEST</dispatcher><dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher><dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher><dispatcher>INCLUDE</dispatcher> <dispatcher>ERROR</dispatcher><dispatcher>ERROR</dispatcher> </filter-mapping></filter-mapping>
Attention: If you are using a container that supports the Servlet 3.0 specification, the registration of ContextLoadListener and DispatcherServlet or BrutosRequestFilter are not necessary. They will be automatically registered.
Building controllersBuilding controllers
public class SampleController {
...
}
A controller can be built in three different ways:A controller can be built in three different ways:• the class name follows the format the class name follows the format <controller-name>Controller;<controller-name>Controller;• using the annotation @Controller orusing the annotation @Controller or• using the element <controller/> of schema brutos-controllers.xsd.using the element <controller/> of schema brutos-controllers.xsd.
• viewview: /WEB-INF/samplecontroller/index.jsp: /WEB-INF/samplecontroller/index.jsp• URIURI: /sample: /sample
Building controllersBuilding controllers@Controllerpublic class Sample {
...
}
• viewview: /WEB-INF/samplecontroller/index.jsp: /WEB-INF/samplecontroller/index.jsp• URIURI: /sample: /sample
Building controllersBuilding controllers
<controller id=“/controller” class=“Sample”> ...</controller>
• viewview: /WEB-INF/sample/index.jsp: /WEB-INF/sample/index.jsp• URIURI: /controller: /controller
public class Sample {
...
}
Building actionsBuilding actions
public class SampleController {
public void testAction() { ... }
}
A action can be built in three different ways:A action can be built in three different ways:• the class name follows the format <action-name>Action;the class name follows the format <action-name>Action;• using the annotation @Action orusing the annotation @Action or• using the element <action/> of schema brutos-controllers.xsd.using the element <action/> of schema brutos-controllers.xsd.
• viewview: /WEB-INF/samplecontroller/testAction/index.jsp: /WEB-INF/samplecontroller/testAction/index.jsp• URIURI: /sample/test: /sample/test
Building actionsBuilding actionspublic class SampleController {
@Action public void test() { ... }
}
• viewview: /WEB-INF/samplecontroller/testAction/index.jsp: /WEB-INF/samplecontroller/testAction/index.jsp• URIURI: /sample/test: /sample/test
Building actionsBuilding actions
• viewview: /WEB-INF/samplecontroller/test.jsp: /WEB-INF/samplecontroller/test.jsp• URIURI: /controller/test: /controller/test
@Action(value=“/test”, view=@View(“test”))public class SampleController {
}
Building actionsBuilding actions
<controller id=“/controller” class=“Sample”> <action id=“/test” executor=“test”/></controller>
• viewview: /WEB-INF/sample/testAction/index.jsp: /WEB-INF/sample/testAction/index.jsp• URIURI: /controller/test: /controller/test
public class Sample {
public void test() { ... }
}
Building interceptorsBuilding interceptors
public class SampleInterceptorInterceptorController extends AbstractInterceptor {
public void intercepted(InterceptorStack stack, InterceptorHandler handler) throws InterceptedException {
...
}
}
A interceptor can be built in three different ways:A interceptor can be built in three different ways:• the class name follows the format <interceptor-name>InterceptorController;the class name follows the format <interceptor-name>InterceptorController;• using the annotation @Intercepts orusing the annotation @Intercepts or• using the element <interceptor/> of schema brutos-controllers.xsd.using the element <interceptor/> of schema brutos-controllers.xsd.Note:Note:An interceptor must implement InterceptorController interface.An interceptor must implement InterceptorController interface.To intercept the execution of a controller, use the annotation @InterceptedBy or use the To intercept the execution of a controller, use the annotation @InterceptedBy or use the <interceptor-ref /> of brutos-controllers.xsd schema.<interceptor-ref /> of brutos-controllers.xsd schema.
Building interceptorsBuilding interceptors
@Interceptspublic class SampleInterceptor extends AbstractInterceptor {
public void intercepted(InterceptorStack stack, InterceptorHandler handler) throws InterceptedException {
...
}
}
Building interceptorsBuilding interceptors
<interceptors> <interceptor name=“sample” class=“SampleInterceptor”/></interceptors>
public class SampleInterceptor extends AbstractInterceptor {
public void intercepted(InterceptorStack stack, InterceptorHandler handler) throws InterceptedException {
...
}
}
Handling exceptionsHandling exceptionsAn exception can be intercepted and manipulated in three different ways:An exception can be intercepted and manipulated in three different ways:• declaring in the method;declaring in the method;• using the annotation @TrowSafe or;using the annotation @TrowSafe or;• using the element <throw-safe/> of schema brutos-controllers.xsd.using the element <throw-safe/> of schema brutos-controllers.xsd.
public class SampleController {
public void testAction() throws NullPointerException{ ... }
}
• action viewaction view: /WEB-INF/samplecontroller/testAction/index.jsp: /WEB-INF/samplecontroller/testAction/index.jsp• URIURI: /sample/test: /sample/test• exception viewexception view: /WEB-INF/samplecontroller/testAction/nullpointerexception.jsp: /WEB-INF/samplecontroller/testAction/nullpointerexception.jsp
Handling exceptionsHandling exceptionspublic class SampleController {
@ThrowSafe(target=NullPointerException.class, view=“npe”) public void testAction() { ... }
}
• action viewaction view: /WEB-INF/samplecontroller/testAction/index.jsp: /WEB-INF/samplecontroller/testAction/index.jsp• URIURI: /sample/test: /sample/test• exception viewexception view: /WEB-INF/samplecontroller/testAction/npe.jsp: /WEB-INF/samplecontroller/testAction/npe.jsp
Handling exceptionsHandling exceptions@ThrowSafe(target=NullPointerException.class, view=“npeController”)public class SampleController {
public void testAction() { ... }
}
• action viewaction view: /WEB-INF/samplecontroller/testAction/index.jsp: /WEB-INF/samplecontroller/testAction/index.jsp• URIURI: /sample/test: /sample/test• exception viewexception view: /WEB-INF/samplecontroller/npeController.jsp: /WEB-INF/samplecontroller/npeController.jsp
Handling exceptionsHandling exceptionspublic class SampleController {
public void testAction() { ... }
}
• action viewaction view: /WEB-INF/samplecontroller/testAction/index.jsp: /WEB-INF/samplecontroller/testAction/index.jsp• URIURI: /sample/test: /sample/test• exception viewexception view: /WEB-INF/samplecontroller/testAction/nullpointerexception.jsp: /WEB-INF/samplecontroller/testAction/nullpointerexception.jsp
<controller id=“/controller” class=“Sample”> <action id=“/test” executor=“test”/></controller>
Mapping of beansMapping of beans
►Mapping of property. Mapping of property. ►Mapping of constructors.Mapping of constructors.►Mapping of action parameters.Mapping of action parameters.►Mapping of enum.Mapping of enum.►Mapping of Date and Calendar.Mapping of Date and Calendar.►Mapping of collections.Mapping of collections.►Mapping of maps.Mapping of maps.►Mapping of files.Mapping of files.►Mapping of polymorphism.Mapping of polymorphism.
Mapping of propertyMapping of propertypublic class SampleController {
private Integer property;
}
JavaJava ParameterParameter
SampleController.property property
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property”></form>
ViewView
MappingMapping
Mapping of propertyMapping of propertypublic class SampleController {
@Basic(bean=“prop1”) private Integer property;
}
JavaJava ParameterParameter
SampleController.property prop1
ControllerController
<form action=“/sample” method=“post”> <input type=“text” name=“prop1”></form>
ViewView
MappingMapping
Mapping of propertyMapping of propertypublic class SampleController {
private Integer property;
@Basic(bean=“prop1”) public Integer getProperty(){ return this.property; }
}
JavaJava ParameterParameter
SampleController.property prop1
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“prop1”></form>
ViewView
MappingMapping
Mapping of constructorsMapping of constructorspublic class SampleBean {
@Transient private Integer property;
public SampleBean(@Basic(bean=“prop1”) Integer property){ this.property = property; }
}
BeanBean
public class SampleController {
private SampleBean property;
}
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property.prop1”></form>
ViewView
JavaJava ParameterParameter
SampleController.property.property property.prop1
MappingMapping
Mapping of action Mapping of action parametersparameters
public class SampleController {
public void testAction(@Basic(bean=“prop1”) Integer property){ ... }
}
JavaJava ParameterParameter
SampleController.testAction[property] prop1
ControllerController
<form action=“/sample/test” method=“post”> <input type=“text” name=“prop1”></form>
ViewView
MappingMapping
Mapping of action Mapping of action parametersparameters
public class SampleBean {
@Basic(bean=“prop1”) private Integer property1;
}
BeanBean
public class SampleController {
public void testAction(@Basic(bean=“property”) SampleBean property){ ... }}
ControllerController
<form target=“/sample/test” method=“post”> <input type=“text” name=“property.prop1”></form>
ViewView
JavaJava ParameterParameter
SampleController.testAction[property.property1]
property.prop1
MappingMapping
Mapping of enumMapping of enumpublic enum SampleEnum { VALUE1, VALUE2;}
EnumEnum
public class SampleController {
private SampleEnum property;
}
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property”></form>
ViewView
JavaJava ParameterParameter ValueValue ObjectObject
SampleController.property
property 0 SimpleEnum.VALUE1
SampleController.property
Property VALUE2 SimpleEnum.VALUE2
MappingMapping
Mapping of enumMapping of enumpublic enum SampleEnum { VALUE1, VALUE2;}
EnumEnum
public class SampleController {
@Enumerated(EnumerationType.ORDINAL) private SampleEnum property;
}
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property” value=“0”></form>
ViewView
JavaJava ParameterParameter ValueValue ObjectObject
SampleController.property
property 0 SimpleEnum.VALUE1
MappingMapping
Mapping of enumMapping of enumpublic enum SampleEnum { VALUE1, VALUE2;}
EnumEnum
public class SampleController {
@Enumerated(EnumerationType.STRING) private SampleEnum property;
}
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property” value=“VALUE1”></form>
ViewView
JavaJava ParameterParameter ValueValue ObjectObject
SampleController.property
property VALUE1 SimpleEnum.VALUE1
MappingMapping
Mapping of Date and Mapping of Date and CalendarCalendar
public class SampleController {
private Date property;
}
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property” value=“29/08/1984”></form>
ViewView
JavaJava ParameterParameter ValueValue ObjectObject
SampleController.property
property 29/08/1984 Date (29 August 1984)
MappingMapping
Mapping of Date and Mapping of Date and CalendarCalendar
public class SampleController {
@Temporal(“yyyy-MM-dd”) private Date property;
}
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property” value=“1984-08-29”></form>
ViewView
JavaJava ParameterParameter ValueValue ObjectObject
SampleController.property
property 1984-08-29 Date (29 August 1984)
MappingMapping
Mapping of collectionsMapping of collectionspublic class SampleController {
private List<Integer> property;
}
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property.element[0]” value=“1”> <input type=“text” name=“property.element[1]” value=“7”> <input type=“text” name=“property.element[2]” value=“5”></form>
ViewView
JavaJava ParameterParameter valuevalue ObjectObject
SampleController.property
property.element[0] 1
ArrayList(1,7,5)property.element[1] 7
property.element[2] 5
MappingMapping
Mapping of collectionsMapping of collections
public class SampleController {
private List<SampleBean> property;
}
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property.element[0].intList.element[0]” value=“1”> <input type=“text” name=“property.element[1].intList.element[0]” value=“7”> <input type=“text” name=“property.element[1].intList.element[1]” value=“5”></form>
ViewView
JavaJava ParameterParameter ValueValue ObjectObject
SampleController.property
property.element[0].intList.element[0]
1 ArrayList[SampleBean(intList=ArrayList[1]),SampleBean(intList=ArrayList[7,5])]
property.element[1].intList.element[0]
7
property.element[1].intList.element[1]
5
MappingMapping
public class SampleBean {
private List<Integer> intList;
}
BeanBean
Mapping of mapsMapping of mapspublic class SampleController {
private Map<String,Integer> property;
}
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property.key[0]” value=“x1”> <input type=“text” name=“property.element[0]” value=“1”> <input type=“text” name=“property.key[1]” value=“x2”> <input type=“text” name=“property.element[1]” value=“7”></form>
ViewView
JavaJava ParameterParameter ValueValue ObjectObject
SampleController.property
property.key[0] x1HashMap( “x1”=>1, “x2”=>7)
property.element[0] 1
property.key[1] x2
property.element[1] 7
MappingMapping
Mapping of mapsMapping of maps
public class SampleController {
private Map<SampleBean,String> property;}
ControllerController
<form target=“/sample” method=“post”> <input type=“text” name=“property.key[0].intList.element[0]” value=“1”> <input type=“text” name=“property.element[0] value=“x1”> <input type=“text” name=“property.key[1].intList.element[0]” value=“5”> <input type=“text” name=“property.element[1]” value=“x2”></form>
ViewView
JavaJava ParameterParameter ValuValuee
ObjectObject
SampleController.property
property.key[0].intList.element[0]
1HashMap[SampleBean(intList=ArrayList[1])=>”x1”,SampleBean(intList=ArrayList[5])=>”x2”]
property.element[0] x1
property.key[1].intList.element[0]
5
property.element[1] x2
MappingMapping
public class SampleBean {
private List<Integer> intList;}
BeanBean
Mapping of filesMapping of filespublic class SampleController {
private File property;
}
ControllerController
<form target=“/sample” method=“post” enctype="multipart/form-data"> <input type=“file” name=“property” ></form>
ViewView
JavaJava ParameteParameterr
ValueValue ObjectObject
SampleController.property
property <binary-data> File
MappingMapping
Mapping of filesMapping of filespublic class SampleController {
private List<File> property;
}
ControllerController
<form target=“/sample” method=“post” enctype="multipart/form-data"> <input type=“file” name=“property[0]” > <input type=“file” name=“property[1]” ></form>
ViewView
JavaJava ParameteParameterr
ValueValue ObjectObject
SampleController.property
property[0] <binary-data>ArrayList[File,File]
property[1] <binary-data>
MappingMapping
Mapping of filesMapping of filespublic class SampleController {
@Type(ListType.class) private List<File> property;
}
ControllerController
<form target=“/sample” method=“post” enctype="multipart/form-data"> <input type=“file” name=“property” > <input type=“file” name=“property” ></form>
ViewView
JavaJava ParameteParameterr
ValueValue ObjectObject
SampleController.property
property <binary-data>ArrayList[File,File]
Property <binary-data>
MappingMapping
Mapping of filesMapping of filespublic class SampleController {
private UploadedFile property;
}
ControllerController
<form target=“/sample” method=“post” enctype="multipart/form-data"> <input type=“file” name=“property” ></form>
ViewView
JavaJava ParameteParameterr
ValueValue ObjectObject
SampleController.property
property <binary-data> UploadedFile
MappingMapping
Mapping of filesMapping of filespublic class SampleController {
private File property;
private String description;
}
ControllerController
<form target=“/sample” method=“post” enctype="multipart/form-data"> <input type=“file” name=“property”> <input type=“text” name=“description” value=“desc”></form>
ViewView
JavaJava ParameterParameter ValueValue ObjectObject
SampleController.property property <binary-data> File
SampleController.description description desc String(“desc”)
MappingMapping
Mapping of polymorphismMapping of polymorphismBeansBeanspublic interface Property {
String getName();
}
public abstract class AbstractProperty {
private String name;
public String getName(){ return this.name }
}
public class DecimalProperty extends AbstractProperty{
private Integer length; private Integer decimals; ...}
public class SetProperty extends AbstractProperty{
private List<String> values; ...}
Mapping of polymorphismMapping of polymorphismControllerController
public class SampleController {
@Any( metaBean=@Basic(bean=“propertyType”), metaType=String.class, metaValues={ @MetaValue(value=“decimal”, target=DecimalProperty.class), @MetaValue(value=“set”, target=SetProperty.class) } ) private Property property;
}
Mapping of polymorphismMapping of polymorphism
JavaJava ParameterParameter ValueValue ObjectObject
SampleController.property
property.propertyType
decimalDecimalProperty( length=10, decimals=2, name=“prop1”)
property.length 10
property.decimals 2
property.name prop1
MappingMapping
<form target=“/sample” method=“post” > <input type=“hidden” name=“property.propertyType” value=“decimal”> <input type=“text” name=“property.length” value=“10”> <input type=“text” name=“property.decimals” value=“2”> <input type=“text” name=“property.name” value=“prop1”></form>
ViewView
Mapping of polymorphismMapping of polymorphism
JavaJava ParameterParameter ValueValue ObjectObject
SampleController.property
property.propertyType
setSetProperty( values=ArrayList(“V1”, “V2”) name=“prop1”)
property.values[0] V1
property.values[1] V2
property.name prop1
MappingMapping
<form target=“/sample” method=“post” > <input type=“hidden” name=“property.propertyType” value=“set”> <input type=“text” name=“property.values[0]” value=“V1”> <input type=“text” name=“property.values[1]” value=“V2”> <input type=“text” name=“property.name” value=“prop1”></form>
ViewView
ReferencesReferences
► http://www.brutosframework.com.br/http://www.brutosframework.com.br/►http://www.amazon.com.br/Brutos-Frahttp://www.amazon.com.br/Brutos-Fra
mework-framework-para-aplica%C3%Amework-framework-para-aplica%C3%A7%C3%B5es-ebook/dp/B00VD3JDOM/r7%C3%B5es-ebook/dp/B00VD3JDOM/ref=sr_1_1?ie=UTF8&qid=1435879104ef=sr_1_1?ie=UTF8&qid=1435879104&sr=8-1&keywords=java+mvc&sr=8-1&keywords=java+mvc
►https://en.wikipedia.org/wiki/Brutos_Frhttps://en.wikipedia.org/wiki/Brutos_Frameworkamework