The content of the invention
The technical assignment of the present invention be for above weak point there is provided a kind of light weight AOP frameworks based on assembly type andIts application method.
A kind of light weight AOP frameworks based on assembly type, are placed between client and service end, and the AOP frameworks include interceptingInterface, interception object handles class and interception list object, wherein,
Intercepting interface is used to receive request and completes interception action;
Intercepting object handles class is used to transmit interception intention and returns to accordingly result;
Intercept list object and then preserve some interception objects.
The interception interface is used to receive client request, and triggering generation intercepts object handles class;
Object handles class is intercepted to pass to interception object for intention will will to be intercepted, call all interceptions intercepted in object queueObject, call service end service;
Intercept list object then by parsing to intercept to be intended to, judge whether to handle interception object therein.
When client sends interception request to service end, service end calls interception object handles class, will intercept anticipate successivelyFigure passes to each interception object intercepted in list object, intercepts object by matching interception intention to decide whether that execution is blockedThe task of cutting, when it is determined that performing, then is completed to intercept by interception interface.
When the interception interface is called realization and intercepted, the unified call by way of reflection, unified call interface isBy obtaining analysis service and interception parameter, whether the interception to judge framework is acted triggers.
A kind of light weight AOP framework application methods based on assembly type, its implementation process is,
An AOP frameworks are configured, are placed between client and service end, the AOP frameworks include intercepting interface, intercept object handles classWith intercept list object, wherein, intercepting interface is used to receive client request, and triggering generation intercepts object handles class;Interception pairAs processing class be used for will will intercept be intended to pass to intercept object, call intercept object queue in all interception objects, callService end is serviced;Intercepting list object then includes some interception objects;
Client sends interception request to service end;
Service end calls interception object handles class, will intercept each interception pair for being intended to pass to and intercepting in list object successivelyAs, object is intercepted by matching interception intention to decide whether to perform interception task, it is when it is determined that performing, then complete by interception interfaceInto interception.
The interception object configures realizations by server end defines a configuration file, and the configuration file is that script is literaryPart, configuration file is operationally registered all interception objects.
The server end is provided with the configuration file based on component, when being intercepted interception object in configuration fileConfigured, interception object when after framework operation in identification configuration file, and object registration will be intercepted in system, the systemRefer to the system that client, service end and AOP unified frames are used;When client call service end, service end is being passed toParameter in dish out one and intercept intention, intercepting object automatic identification and will intercept when order is called and is intended to be intercepted, fromAnd complete interception task.
The configuration file includes intercepting the position that procedure set assembly, class class and needs of object are intercepted,The position is intercepted or rear interception before referring to.
When the interception interface is called realization and intercepted, the unified call by way of reflection, unified call interface isBy obtaining analysis service and interception parameter, whether the interception to judge framework is acted triggers.
The object that intercepts provides the configurable modes of XML to set.
The present invention a kind of light weight AOP frameworks and its application method based on assembly type compared to the prior art, withLower beneficial effect:
A kind of the light weight AOP frameworks and its application method based on assembly type of the present invention, by operationally to the method calledOne dynamic agency is provided, the purpose that interference method is performed is reached for capturing the action of this method needs interception, so thatBusiness core code and non-traffic common code are peeled off, the degree of coupling is reduced, increases durability;And noted during supporting frame operationVolume intercepts the mode of object, and intercepting object can be configured in server end by XML file, when interception object changes,Only need to change configuration file, have no effect on business core code, it is practical, it is applied widely, with good popularizationApplication value.
Embodiment
Below in conjunction with the accompanying drawings and specific embodiment the invention will be further described.
As shown in Figure 1, a kind of light weight AOP frameworks based on assembly type, including following content:
Intercept interface:The interface that tangent plane is intercepted is realized, the interception task of different demands can be according to circumstances realized;When user needs, it is necessary to realize the interception interface that framework is provided during progress tangent plane interception.
Based on component configurable type:Framework defines a configuration file to configure the object to be intercepted in server end, canFlexibly change.All interception objects can operationally be registered, when client call service end method, it is only necessary toDished out in the parameter for passing to service end one and intercept intention, meaning will be intercepted by intercepting object meeting automatic identification when order is calledFigure is intercepted.
Need interception object to be configured in configuration file when being intercepted, configuration file is recognized when after framework operationIn interception object, and object registration will be intercepted in system.During method call, if object needs to intercept, client existsCall during service end by intercept intent information follow parameter to be delivered to service end together.The dynamic proxy of service end calls interception to graspClass is dealt with, each interception object for being intended to pass to and intercepting in queue will be intercepted successively, intercepts object and intercept meaning by matchingFigure come decide whether perform interception task.
This framework is placed between client and service end, and the AOP frameworks include intercepting interface, intercept object handles class and blockList object is cut, wherein,
Intercepting interface is used to receive request and completes interception action;
Intercepting object handles class is used to transmit interception intention and returns to accordingly result;
Intercept list object and then preserve some interception objects.
The interception interface is used to receive client request, and triggering generation intercepts object handles class;
Object handles class is intercepted to pass to interception object for intention will will to be intercepted, call all interceptions intercepted in object queueObject, call service end service;
Intercept list object then by parsing to intercept to be intended to, judge whether to handle interception object therein.
When client sends interception request to service end, service end calls interception object handles class, will intercept anticipate successivelyFigure passes to each interception object intercepted in list object, intercepts object by matching interception intention to decide whether that execution is blockedThe task of cutting, when it is determined that performing, then is completed to intercept by interception interface.
When the interception interface is called realization and intercepted, the unified call by way of reflection, unified call interface isBy obtaining analysis service and interception parameter, whether the interception to judge framework is acted triggers.
A kind of light weight AOP framework application methods based on assembly type, for system core logic code and common component code etc.The problem of adulterating together significantly reduces logical code and public generation there is provided a kind of developing mechanism based on towards tangent planeThe code degree of coupling, improves the durability of this part common component.
Its implementation process is,
An AOP frameworks are configured, are placed between client and service end, the AOP frameworks include intercepting interface, intercept object handles classWith intercept list object, wherein, intercepting interface is used to receive client request, and triggering generation intercepts object handles class;Interception pairAs processing class be used for will will intercept be intended to pass to intercept object, call intercept object queue in all interception objects, callService end is serviced;Intercepting list object then includes some interception objects;
Client sends interception request to service end;
Service end calls interception object handles class, will intercept each interception pair for being intended to pass to and intercepting in list object successivelyAs, object is intercepted by matching interception intention to decide whether to perform interception task, it is when it is determined that performing, then complete by interception interfaceInto interception.
The interception object configures realizations by server end defines a configuration file, and the configuration file is that script is literaryPart, configuration file is operationally registered all interception objects.
The server end is provided with the configuration file based on component, when being intercepted interception object in configuration fileConfigured, interception object when after framework operation in identification configuration file, and object registration will be intercepted in system, the systemRefer to the system that client, service end and AOP unified frames are used;When client call service end, service end is being passed toParameter in dish out one and intercept intention, intercepting object automatic identification and will intercept when order is called and is intended to be intercepted, fromAnd complete interception task.
The configuration file includes intercepting the position that procedure set assembly, class class and needs of object are intercepted,The position is intercepted or rear interception before referring to.
When the interception interface is called realization and intercepted, the unified call by way of reflection, unified call interface isBy obtaining analysis service and interception parameter, whether the interception to judge framework is acted triggers.
The object that intercepts provides the configurable modes of XML to set.
The present invention includes following characteristics:
Public uncore logic code is extracted as interception object.
The interface that uniform service end is called by way of reflection.
The configurable modes of XML are provided flexibly interception object is set.
By the form of interception parameter tell framework which need intercept.
Based on proxy mode.
Public uncore logic code is extracted as object is intercepted, configuration file, which mainly includes, intercepts objectAssembly, class and the position for needing interception(It is front or rear).
The interface that uniform service end is called by way of reflection, unified call interface is for Standard Service and interception pairAs the parameter of intention, unified interface obtains analysis service and interception parameter, and then judges whether the interception action of framework triggers.
There is provided XML configurable modes that interception object is flexibly set, intercept object can change at any time according to demand andCore logic code is not influenceed.
By the form of interception parameter tell framework those need intercept, intercept intent parameter can accurately tell frameworkThose action need intercept, and do not influence core code, it is necessary to when add the parameter, it is not necessary to when without the parameter.
The registration XML configuration examples for intercepting object are as follows:
<xml version="1.0" encoding="utf-8">
<configuration>
<AOPExtend>
<--AOPLocation="Before/After/All"-->
<AOPAttribute AOPAssembly="Genersoft.ZJGL.AOPProxy" AOPClass="Genersoft.ZJGL.AOPProxy.Proxy.Extends.AOPCompDataLockProxy" AOPLocation="All"/>
<AOPAttribute AOPAssembly="Genersoft.ZJGL.Web.ZJGX.SPI" AOPClass="Genersoft.ZJGL.Web.ZJGX.SPI.AOPExtend.AOPFundCenterAuthority" AOPLocation="Before"/>
<AOPAttribute AOPAssembly="Genersoft.ZJGL.Web.ZJGX.SPI" AOPClass="Genersoft.ZJGL.Web.ZJGX.SPI.AOPExtend.AOPBillLading" AOPLocation="Before"/>
</AOPExtend>
</configuration>
Triggering is intercepted, example is as shown in Figure 2.
As shown in figure 3, the unified entrance of service end can lead to automatically when having parsed parameter call InvokeMethod hereCross dynamic proxy to go to call intercept process class, intercept process class goes back to process by demand the interception object of configuration.
By embodiment above, the those skilled in the art can readily realize the present invention.But shouldWork as understanding, the present invention is not limited to above-mentioned embodiment.On the basis of disclosed embodiment, the technical fieldTechnical staff can be combined different technical characteristics, so as to realize different technical schemes.
It is the known technology of those skilled in the art in addition to the technical characteristic described in specification.