|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
在ruby里才是一切皆对象。当然我不并不是很了解ruby,但是ruby确实是将语法简化得很好。经由过程nanocontainer的nanowar和其struts插件完善的完成了IoC形式的通明,但没法在尺度的nanowar中引进nanoaop不能不说是一种遗憾。看了一下nanocontainer的代码,决意本人下手给nanowar增加aop的撑持。要在组件和实例中撑持AOP,起首要引进interceptorchains。能够思索在XML界说中引进<aspectinterceptor=InterceptorNamepointcuts=Filter/>标签。这个<aspect>标签与组件或实例的<parameter>标签在统一级别上。个中interceptor指出拦阻器的称号。拦阻器的完成能够经由过程尺度组件体例在统一个设置文件中举行注册。pointcuts是拦阻办法的过滤表达式(perl5的正则表达式,和nanoaop预界说几个过滤划定规矩)。在nanowar中完成这个<aspect>标签,必要修正ScopedCotainerComposer,XMLContainerBuilder,ContainerRecorder,ServletContainerListener,DefaultLifecycleContainerBuider类。因为拦阻器没法在IoC容器初始化的过程当中失掉实例。因而,还必要引进一个新的通用拦阻器类(InterceptorDelegate),作为真实的拦阻器实例和需被拦阻的组件的挪用桥梁。因为对源代码修改量较年夜,干脆就在本来类的后面加上Aspectable前缀引进新的类,但除AOP部分,其他的坚持稳定。ScopedCotainerComposer=>AspectableScopedContainerComposer.javapublicAspectableScopedContainerComposer()throwsClassNotFoundException{this(newDynaopAspectablePicoContainerFactory().createContainer());}XMLContainerBuilder=>AspectableXMLContainerBuilder.javaprotectedPicoContainercreateContainerFromScript(....AspectablePicoContainerFactorycontainerFactory=newDynaopAspectablePicoContainerFactory();AspectablePicoContainerchildContainer=containerFactory.createContainer(componentAdapterFactory,parentContainer);cuts=childContainer.getPointcutsFactory();....}privatevoidregisterComponentImplementation(NanoContainercontainer,Elementelement)throwsClassNotFoundException,MalformedURLException{......Mapinterceptors=createInterceptors(element);......if(interceptors!=null){registerComponentInterceptor(container,clazz,interceptors);}}.......privatevoidregisterComponentInterceptor(NanoContainercontainer,Classcomponent,Stringpointcuts,StringinterceptorKey){if(notSet(pointcuts)){pointcuts=ALL_METHODS;}if(container.getPico()instanceofAspectablePicoContainer){AspectablePicoContaineraspectContainer=(AspectablePicoContainer)container.getPico();aspectContainer.registerInterceptor(cuts.instancesOf(component),getMethodPointcut(pointcuts),newInterceptorDelegate(aspectContainer,interceptorKey));}}.......privateMapcreateInterceptors(Elementelement){MapinterceptorMap=newHashMap();NodeListchildren=element.getChildNodes();for(inti=0;i<children.getLength();i++){if(children.item(i)instanceofElement){ElementchildElement=(Element)children.item(i);if(ASPECT.equals(childElement.getNodeName())){Stringinterceptor=childElement.getAttribute(INTERCEPTOR);if(notSet(interceptor))thrownewNanoContainerMarkupException(""+KEY+"attributenotspecifiedfor"+element.getNodeName());Stringpointcuts=childElement.getAttribute(POINTCUTS);interceptorMap.put(interceptor,pointcuts);}}}if(interceptorMap.isEmpty())returnnull;elsereturninterceptorMap;}privateMethodPointcutgetMethodPointcut(Stringpointcuts){if(OBJECT_METHODS.equals(pointcuts))returncuts.objectMethods();if(IS_METHODS.equals(pointcuts))returncuts.isMethods();if(ALL_METHODS.equals(pointcuts))returncuts.allMethods();if(GET_METHODS.equals(pointcuts))returncuts.getMethods();if(SET_METHODS.equals(pointcuts))returncuts.setMethods();returncuts.signature(pointcuts);}ContainerRecorder=>AspectableContainerRecorder.javapublicMutablePicoContainergetContainerProxy(){if(this.containerinstanceofAspectablePicoContainer)return(MutablePicoContainer)Proxy.newProxyInstance(getClass().getClassLoader(),newClass[]{AspectablePicoContainer.class},invocationRecorder);elsereturn(MutablePicoContainer)Proxy.newProxyInstance(getClass().getClassLoader(),newClass[]{MutablePicoContainer.class},invocationRecorder);}DefaultLifecycleContainerBuider=>AspectableLifecycleContainerBuider.javaprotectedPicoContainercreateContainer(PicoContainerparentContainer,ObjectassemblyScope){AspectablePicoContainerFactorycontainerFactory=newDynaopAspectablePicoContainerFactory();returncontainerFactory.createContainer(parentContainer);}ServletContainerListener=>AspectableServletContainerListener.javaprivateContainerBuildercreateBuilder(ServletContextcontext)throwsClassNotFoundException{......if(initParameter.equals(CONTAINER_COMPOSER)){ContainerComposercontainerComposer=createContainerComposer(context);returnnewAspectableLifecycleContainerBuilder(containerComposer);}InterceptorDelegate.javaimportorg.aopalliance.intercept.MethodInterceptor;importorg.aopalliance.intercept.MethodInvocation;importorg.picocontainer.PicoContainer;importdynaop.Interceptor;importdynaop.Invocation;publicclassInterceptorDelegateimplementsInterceptor,MethodInterceptor{privatePicoContainerpico;privateObjectkey;publicInterceptorDelegate(PicoContainerpico,Objectkey){this.pico=pico;this.key=key;}/*(non-Javadoc)*@seedynaop.Interceptor#intercept(dynaop.Invocation)*/publicObjectintercept(Invocationinvocation)throwsThrowable{return((Interceptor)pico.getComponentInstance(key)).intercept(invocation);}/*(non-Javadoc)*@seeorg.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)*/publicObjectinvoke(MethodInvocationinvocation)throwsThrowable{return((MethodInterceptor)pico.getComponentInstance(key)).invoke(invocation);}}
市场分额,java比asp高一点,因为C#是仿照java开发的,所以哦C#能做的java都能做到,但是java能做的,C#不一定都能做到。毕竟是抄袭吗。 |
|