simon simon - 5 months ago 21
Java Question

Java naming clash between method variable and package names

I have some classes generated from WSDL files by the Axis Framework. In one of these classes, there is a generated method


public com.initechsystems.www.initech7.initechbo.Organization createOrganization(com.initechsystems.www.initech7.initechbo.Organization org) throws java.rmi.RemoteException {

//(... snip ...)
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
//(... snip ...)
}


The variable name org in the method parameter creates a naming clash with package org.apache.axis.client, as the compiler cannot differentiate between the package and variable. I realize I can fix this easily by changing the variable name org in the method, but I would like to avoid this, because it slows down the workflow. Is there some way around this other than either modifying the WSDL file or the generated classes?

Compiler error:


D:\projects\java\initechdir\target\generated-sources\axistools\wsdl2java\com\initechsystems\www\initech7\initechws\OrganizationManagement\OrganizationManagementSoapStub.java:[1678,29] cannot find symbol
symbol : variable apache
location: class com.initechsystems.www.initech7.initechbo.Organization

Answer

Is there a way to cause that generated code to have import statements? That would prevent you from having to have the fully-qualified name of the class.

So, if you could add:

import org.apache.axis.client.Call;

to the file then your method call would just be:

_call.setProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE);

I'm not sure if Axis has an option for that though. If not I'd say renaming the variable (maybe to "organization") would be the best thing. I would recommend avoiding manual edits of auto-generated files, as that makes regenerating them harder.

Comments