Search in sources :

Example 1 with Processor

use of org.talend.sdk.component.api.processor.Processor in project component-runtime by Talend.

the class ModelVisitorTest method visit.

private List<String> visit(final Class<?> type) {
    final ModelVisitor visitor = new ModelVisitor();
    final List<String> tracker = new ArrayList<>();
    Stream.of(type.getClasses()).sorted(Comparator.comparing(Class::getName)).forEach(nested -> visitor.visit(nested, new ModelListener() {

        @Override
        public void onPartitionMapper(final Class<?> type, final PartitionMapper partitionMapper) {
            tracker.add("@PartitionMapper(" + type.getName() + ")");
        }

        @Override
        public void onEmitter(final Class<?> type, final Emitter emitter) {
            tracker.add("@Emitter(" + type.getName() + ")");
        }

        @Override
        public void onProcessor(final Class<?> type, final Processor processor) {
            tracker.add("@Processor(" + type.getName() + ")");
        }
    }, true));
    return tracker;
}
Also used : PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) Emitter(org.talend.sdk.component.api.input.Emitter) Processor(org.talend.sdk.component.api.processor.Processor) ModelVisitor(org.talend.sdk.component.runtime.visitor.ModelVisitor) ArrayList(java.util.ArrayList) ModelListener(org.talend.sdk.component.runtime.visitor.ModelListener)

Example 2 with Processor

use of org.talend.sdk.component.api.processor.Processor in project component-runtime by Talend.

the class PluginGenerator method createProcessor.

private byte[] createProcessor(final JarOutputStream outputStream, final String packageName) throws IOException {
    final String className = packageName + "/AProcessor.class";
    outputStream.putNextEntry(new ZipEntry(className));
    final ClassWriter writer = new ClassWriter(COMPUTE_FRAMES);
    final AnnotationVisitor processorAnnotation = writer.visitAnnotation(Type.getDescriptor(Processor.class), true);
    processorAnnotation.visit("family", "comp");
    processorAnnotation.visit("name", "proc");
    processorAnnotation.visitEnd();
    writer.visit(V1_8, ACC_PUBLIC + ACC_SUPER, className.substring(0, className.length() - ".class".length()), null, Type.getInternalName(Object.class), new String[] { Serializable.class.getName().replace(".", "/") });
    writer.visitSource(className.replace(".class", ".java"), null);
    addConstructor(writer);
    // generate a processor
    final MethodVisitor emitMethod = writer.visitMethod(ACC_PUBLIC, "emit", "(L" + packageName + "/AModel;)L" + packageName + "/AModel;", null, new String[0]);
    emitMethod.visitAnnotation(Type.getDescriptor(ElementListener.class), true).visitEnd();
    emitMethod.visitCode();
    emitMethod.visitTypeInsn(NEW, packageName + "/AModel");
    emitMethod.visitInsn(DUP);
    emitMethod.visitMethodInsn(INVOKESPECIAL, packageName + "/AModel", "<init>", "()V", false);
    emitMethod.visitInsn(ARETURN);
    emitMethod.visitInsn(ARETURN);
    emitMethod.visitMaxs(1, 1);
    emitMethod.visitEnd();
    writer.visitEnd();
    return writer.toByteArray();
}
Also used : Processor(org.talend.sdk.component.api.processor.Processor) ZipEntry(java.util.zip.ZipEntry) AnnotationVisitor(org.apache.xbean.asm6.AnnotationVisitor) ClassWriter(org.apache.xbean.asm6.ClassWriter) MethodVisitor(org.apache.xbean.asm6.MethodVisitor)

Aggregations

Processor (org.talend.sdk.component.api.processor.Processor)2 ArrayList (java.util.ArrayList)1 ZipEntry (java.util.zip.ZipEntry)1 AnnotationVisitor (org.apache.xbean.asm6.AnnotationVisitor)1 ClassWriter (org.apache.xbean.asm6.ClassWriter)1 MethodVisitor (org.apache.xbean.asm6.MethodVisitor)1 Emitter (org.talend.sdk.component.api.input.Emitter)1 PartitionMapper (org.talend.sdk.component.api.input.PartitionMapper)1 ModelListener (org.talend.sdk.component.runtime.visitor.ModelListener)1 ModelVisitor (org.talend.sdk.component.runtime.visitor.ModelVisitor)1