Package com.massfords.jaxb

Source Code of com.massfords.jaxb.CreateTraverserInterface

package com.massfords.jaxb;

import com.sun.codemodel.JClass;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JMod;
import com.sun.codemodel.JPackage;
import com.sun.codemodel.JTypeVar;
import com.sun.tools.xjc.outline.ClassOutline;
import com.sun.tools.xjc.outline.Outline;

import java.util.Set;

/**
* Creates the traverser interface. A traverse method is added for each of the generated beans.
*
* @author markford
*/
public class CreateTraverserInterface extends CodeCreator {
   
    private JDefinedClass visitor;

    public CreateTraverserInterface(JDefinedClass visitor, Outline outline, JPackage jpackage) {
        super(outline, jpackage);
        this.visitor = visitor;
    }

    @Override
    protected void run(Set<ClassOutline> classes) {
        JDefinedClass scratch = getOutline().getClassFactory().createInterface(getPackage(), "_scratch", null);
        JDefinedClass _interface = getOutline().getClassFactory().createInterface(getPackage(), "Traverser", null);
    setOutput(_interface);
        final JTypeVar retType = scratch.generify("?");
        final JTypeVar exceptionType = _interface.generify("E", Throwable.class);
        final JClass narrowedVisitor = visitor.narrow(retType).narrow(exceptionType);
        for (ClassOutline classOutline : classes) {
            if (!classOutline.target.isAbstract()) {
                // add the bean to the traverser
                JMethod traverseMethod = getOutput().method(JMod.PUBLIC, void.class, "traverse");
                traverseMethod._throws(exceptionType);
                traverseMethod.param(classOutline.implClass, "aBean");
                traverseMethod.param(narrowedVisitor, "aVisitor");
            }
        }
        jpackage.remove(scratch);
    }
}
TOP

Related Classes of com.massfords.jaxb.CreateTraverserInterface

TOP
Copyright © 2018 www.massapi.com. 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.