3
votes

I'm using cxf-codegen-plugin (maven) with wsdl2java goal to generate the java code from my wsdl.

The problem is that it generates protected attributes when I want private attributes:

My wsdl element:

<element name="productCode" type="string"/>

Expected:

@XmlElement(required = true)
private String productCode;

Result:

@XmlElement(required = true)
protected String productCode;

Is there anything to add in my wsdl or in the plugin configuration to generate privates fields ?

Thanks !

1

1 Answers

2
votes

I think this is because of jaxb than cxf .You need to develop your own xjc plugin to do it.

https://jaxb.java.net/nonav/2.0.2/docs/developPlugins.html

Also google about developing and plugging your own xjc Creating a plugin was the right way to go.Resusing the code in this forum

public class PrivateMemberPlugin
    extends Plugin
{

    @Override
    public String getOptionName()
    {
        return "Xpm";
    }

    @Override
    public String getUsage()
    {
        return "  -Xpm    : Change members visibility to private";
    }

    @Override
    public boolean run(Outline model, Options opt, ErrorHandler errorHandler)
        throws SAXException
    {
        for (ClassOutline co : model.getClasses())
        {

            JDefinedClass jdc = co.implClass;
            // avoid concurrent modification by copying the fields in a new list
            List<JFieldVar> fields = new ArrayList<JFieldVar>(jdc.fields().values());
            for (JFieldVar field : fields)
            {
                // never do something with serialVersionUID if it exists.
                if (!field.name().equalsIgnoreCase("serialVersionuid"))
                {
                    // only try to change members that are not private
                    if (field.mods().getValue() != JMod.PRIVATE)
                    {
                        // since there is no way to change the visibilty, remove the field an recreate it
                        jdc.removeField(field);
                        jdc.field(JMod.PRIVATE, field.type(), field.name());

                    }
                }
            }

        }
        return true;
    }

}