Package org.ow2.easybeans.asm

Examples of org.ow2.easybeans.asm.ClassWriter


            } catch (Exception e) {
                this.logger.error("Cannot configure Carol to use CMI", e);
                throw new EZBComponentException("Cannot configure Carol to use CMI", e);
            }

            ClusterViewManagerFactory clusterViewManagerFactory = ClusterViewManagerFactory.getFactory();

            // Start the manager
            try {
                this.clusterViewManager = (ServerClusterViewManager) clusterViewManagerFactory.create();
            } catch (Exception e) {
                this.logger.error("Cannot retrieve the CMI Server", e);
                throw new EZBComponentException("Cannot retrieve the CMI Server", e);
            }
            if (this.clusterViewManager != null
                    && this.clusterViewManager.getState().equals(ClusterViewManager.State.STOPPED)) {
                if (this.eventComponent != null) {
                    List<Component> components =
                        clusterViewManagerFactory.getConfig().getComponents().getComponents();
                    if (components != null) {
                        for (Component cmiEventComponent : components) {
                            if (org.ow2.cmi.component.event.EventComponent.class.isAssignableFrom(cmiEventComponent.getClass())) {
                                ((org.ow2.cmi.component.event.EventComponent) cmiEventComponent).setEventService(
                                        this.eventComponent.getEventService());
View Full Code Here


            return EASYBEANS_ROOT;
        } else if (EZBContainer.class.isAssignableFrom(clazz)) {
            // The object is an EJB container.

            EZBContainer container = (EZBContainer) instance;

            // Get the archive name (remove all character before the last slash/antislash).
            String archiveName = container.getName().replaceAll("(.*[/\\\\])", "");

            // Compute the application id.
            return EASYBEANS_ROOT + "/" + container.getApplicationName() + "/" + archiveName;
        } else if (Factory.class.isAssignableFrom(clazz)) {
            // The object is a bean factory.

            Factory<?, ?> factory = (Factory<?, ?>) instance;
            EZBContainer container = factory.getContainer();

            // Get the archive name (remove all character before the last slash/antislash).
            String archiveName = container.getName().replaceAll("(.*[/\\\\])", "");

            // Get the bean class name (remove all character before the last point).
            String factoryName = factory.getClassName().replaceAll("(.*\\.)", "");

            // Compute the bean id.
            return EASYBEANS_ROOT + "/" + container.getApplicationName() + "/" + archiveName + "/" + factoryName;
        } else {
            throw new java.lang.IllegalArgumentException("Name is not define for argument of type " + instance.getClass());
        }
    }
View Full Code Here

                    throw new EZBComponentException("Cannot start the CMI Server", e);
                }
            }
        }
        // register the listener.
        EZBEventListener eventListener = new CmiEventListener();
        this.eventComponent.registerEventListener(eventListener);

        this.logger.debug("The CMI configuration extension has been added.");
    }
View Full Code Here

            public synchronized void handle(final IEvent event) {
                if (EZBEventBeanInvocationBegin.class.isAssignableFrom(event.getClass())) {
                    EZBEventBeanInvocationBegin e = (EZBEventBeanInvocationBegin) event;
                    MeanCallTimeStatistic.this.pendingCall.put(Long.valueOf(e.getInvocationNumber()), e);
                } else {
                    EZBEventBeanInvocation eventEnd = (EZBEventBeanInvocation) event;
                    EZBEventBeanInvocation eventBegin =
                        MeanCallTimeStatistic.this.pendingCall.remove(Long.valueOf(eventEnd.getInvocationNumber()));

                    MeanCallTimeStatistic.this.count++;
                    MeanCallTimeStatistic.this.total += eventEnd.getTime() - eventBegin.getTime();
                    setLastSampleTime(System.currentTimeMillis());
                }
            }
View Full Code Here

             * Handle the event.
             * @param event The event to handle.
             */
            public synchronized void handle(final IEvent event) {
                if (EZBEventBeanInvocationBegin.class.isAssignableFrom(event.getClass())) {
                    EZBEventBeanInvocationBegin e = (EZBEventBeanInvocationBegin) event;
                    MeanCallTimeStatistic.this.pendingCall.put(Long.valueOf(e.getInvocationNumber()), e);
                } else {
                    EZBEventBeanInvocation eventEnd = (EZBEventBeanInvocation) event;
                    EZBEventBeanInvocation eventBegin =
                        MeanCallTimeStatistic.this.pendingCall.remove(Long.valueOf(eventEnd.getInvocationNumber()));

View Full Code Here

     * @param methodVisitor the given visitor on which annotation are replayed.
     */
    @Override
    public void replay(final MethodVisitor methodVisitor) {
        // Build a new annotation visitor for the given method
        AnnotationVisitor annotationVisitor = methodVisitor.visitParameterAnnotation(this.index, getName(), getVisible());
        getLogger().debug("AnnotationVisitor annotationVisitor = methodVisitor.visitParameterAnnotation({0}, {1}, {2});",
                Integer.valueOf(this.index), getName(), Boolean.valueOf(getVisible()));

        // Replay
        replayInner(annotationVisitor);

        // End of visit
        annotationVisitor.visitEnd();
        getLogger().debug("annotationVisitor.visitEnd();");
    }
View Full Code Here

     * @param generatedClassName the name of the class to generate.
     * @param allInterceptors interceptors that needs to be managed.
     */
    public InterceptorManagerGenerator(final EjbJarArchiveMetadata ejbJarAnnotationMetadata,
            final String generatedClassName, final List<String> allInterceptors) {
        super(new ClassWriter(ClassWriter.COMPUTE_MAXS));
        this.ejbJarAnnotationMetadata = ejbJarAnnotationMetadata;
        this.generatedClassName = generatedClassName;
        this.allInterceptors = allInterceptors;
    }
View Full Code Here

     * @param methodAnnotationMetadata method meta data
     * @param interceptorType the type of invocationContext to generate (AroundInvoke, PostConstruct, etc)
     */
    public EasyBeansInvocationContextGenerator(final EasyBeansEjbJarMethodMetadata methodAnnotationMetadata,
            final InterceptorType interceptorType) {
        super(new ClassWriter(ClassWriter.COMPUTE_MAXS));
        this.methodAnnotationMetadata = methodAnnotationMetadata;
        this.classAnnotationMetadata = methodAnnotationMetadata.getClassMetadata();
        this.jMethod = methodAnnotationMetadata.getJMethod();

        // package name is prefixed
View Full Code Here

     * @return the bytecode
     * @throws Exception if bytecode can't be built
     */
    public static byte[] getByteForClass(final String className, final String helloWorldString) throws Exception {

        ClassWriter cw = new ClassWriter(0);
        MethodVisitor mv;
        cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, className, null, "java/lang/Object", null);

        // Constructor
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();

        // hello method
        mv = cw.visitMethod(ACC_PUBLIC, "hello", "()Ljava/lang/String;", null, null);
        mv.visitCode();
        mv.visitLdcInsn(helloWorldString);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();

        cw.visitEnd();

        return cw.toByteArray();
    }
View Full Code Here

                // And do this only one time.
                enhanceSuperClass(classAnnotationMetadata, null);

                // Create ClassReader/Writer
                ClassReader cr = getClassReader(classAnnotationMetadata);
                ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
                InterceptorClassAdapter cv = new InterceptorClassAdapter(classAnnotationMetadata, cw);
                InjectionClassAdapter cv2 = new InjectionClassAdapter(classAnnotationMetadata, cv, this.map, null, false);
                cr.accept(cv2, 0);
                classAnnotationMetadata.setModified();
                defineClass(this.loader, classAnnotationMetadata.getClassName().replace("/", "."), cw.toByteArray());
            }
        }
        // search all beans
        logger.info("Beans found are {0}", this.ejbJarAnnotationMetadata.getBeanNames());


        List<String> beanNames = this.ejbJarAnnotationMetadata.getBeanNames();
        for (String beanName : beanNames) {
            for (EasyBeansEjbJarClassMetadata classAnnotationMetadata : this.ejbJarAnnotationMetadata
                    .getClassesForBean(beanName)) {
                if (classAnnotationMetadata.isBean()) {

                    // First, enhance all super classes of the bean. (if any)
                    // And do this only one time.
                    enhanceSuperClass(classAnnotationMetadata, classAnnotationMetadata);
                    //logger.info("Enhancement of {0} done !", classAnnotationMetadata);

                    // Create ClassReader/Writer
                    ClassReader cr = getClassReader(classAnnotationMetadata);
                    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
                    BeanClassAdapter cv = new BeanClassAdapter(classAnnotationMetadata, cw);
                    InterceptorClassAdapter itcpClassAdapter = new InterceptorClassAdapter(classAnnotationMetadata, cv);
                    InjectionClassAdapter cv2 = new InjectionClassAdapter(classAnnotationMetadata, itcpClassAdapter, this.map,
                            classAnnotationMetadata, false);

                    ClassVisitor beanVisitor = cv2;
                    // EJb 2.1 view ?
                    if (classAnnotationMetadata.getRemoteHome() != null || classAnnotationMetadata.getLocalHome() != null) {
                        Migration21ClassAdapter ejb21Adapter = new Migration21ClassAdapter(classAnnotationMetadata, cv2);
                        beanVisitor = ejb21Adapter;
                    }


                    cr.accept(beanVisitor, 0);

                    // define subclasses if interceptor enabled
                    loadDefinedClasses(this.loader, itcpClassAdapter.getDefinedClasses());

                    defineClass(this.loader, classAnnotationMetadata.getClassName().replace("/", "."), cw.toByteArray());

                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.ow2.easybeans.asm.ClassWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.