All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jvnet.jaxb2_commons.BooleanGetter.orig Maven / Gradle / Ivy

Go to download

JAXB 2.1.x XJC Boolean-Getter Plugin This plugin causes getter methods for Boolean Objects to be called "getXX" instead of "isXX". Downloaded from http://fisheye5.atlassian.com/browse/~raw,r=1.1/jaxb2-commons/www/boolean-getter/index.html on 18/03/10 Yiannis Paschalidis Sanity4J was created to simplify running multiple static code analysis tools on the Java projects. It provides a single entry point to run all the selected tools and produce a consolidated report, which presents all findings in an easily accessible manner.

The newest version!
package org.jvnet.jaxb2_commons;

import java.util.Collection;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;

import com.sun.codemodel.JMethod;
import com.sun.tools.xjc.Options;
import com.sun.tools.xjc.Plugin;
import com.sun.tools.xjc.outline.Outline;
import com.sun.tools.xjc.outline.ClassOutline;

/**
 * XJC plugin to generate getXX functions instead of isXX functions for boolean values.
 * The motivation is to make using XJC generated classes easier to use with Spring, since 
 * Spring expects accessors to be called getXX.
 * 
 * @author Adam Burnett
 * @version 1.0
 */
public class BooleanGetter extends Plugin{

    protected final String OPTION_NAME = "Xboolean-getter";
    
    @Override
    public String getOptionName() {
        return OPTION_NAME;
    }

    @Override
    public String getUsage() {
        return "-" + OPTION_NAME + "    :   Generate getXX instead of isXX functions for boolean values\n";
    }
    
    @Override
    public boolean run(Outline model, Options opts, ErrorHandler errors) throws SAXException {
        for( ClassOutline co : model.getClasses() ) {
            Collection methods = co.implClass.methods();
            //pretty simple, just look at all our generated methods and rename isXX to getXX
            for(JMethod m : methods) {
                if(m.name().startsWith("is")) {
                    m.name("get" + m.name().substring(2));
                }
            }
        }
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy