How to resolve ObjectFactory Collisions in JAVA

In my previous article I have explained how to generate the web service classes.If you have not already read the topic then I would advise you to do so. Moving on, we can sometimes get an error like below

[ERROR] Two declarations cause a collision in the ObjectFactory cl
  line 1191 of file:/D:/RAMEEZ/Web%20Services/TeamBpl/TeamBpl3.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 981 of file:/D:/RAMEEZ/Web%20Services/TeamBpl/TeamBpl3.xsd

This is a very common issue we face, and the way to resolve this is to simply write a XML file having a JAXB binding configuration.

Simple Steps for Clear Understanding:

Here are a few simple steps with images to help you fix the issue quickly :)


STEP 1:

Analyze the issue.
From the above error log we see line number 1191 and 981 have issues in the
XSD Schema file. Lets look into the XSD file. See below.



STEP 2:

So this is happening because the "name" attribute is somehow causing collision when the WSDL file is getting parsed.


STEP 3:

To solve this simple open a new file in Notepad(or any text editor you use) and name it something like "conflict.xml".

STEP 4:

Copy it from here.

<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">

 <jxb:bindings node="/xs:schema" schemalocation="TeamBpl3.xsd">
  <jxb:bindings schemalocation="TeamBpl3.xsd">
   <jxb:bindings node="./xs:element[@name='MediaUrl']">
    <jxb:factorymethod name="RootMediaElement">
   </jxb:factorymethod></jxb:bindings>
  </jxb:bindings>
 </jxb:bindings> 


</jxb:bindings> 



STEP 5:

Now run the "wsimport" command with the -b switch. This is called the binding (-b).

wsimport [WSDL_FILE.wsdl] -b conflict.xml -keep -verbose


STEP 6:

This will generate the stub classes properly without any issues.




REMEMBER:

When you have multiple collisions then in that case you have to write multiple jxb:bindings for each. Means you have to repeat line number 5 to 11 from STEP 3.

Hope this helps!



Steps to Create Web Service Stub

This document gives instructions on creating web service stubs better knowas proxy classes. We will take an example and proceed with the explanation.

STEP 1:

Copy the URL link in the browser address bar and hit enter.Check if the WSDL is accessible through your network or not.

STEP 2:

Download the WSDL file in a folder and should be saved with the ".wsdl" extension.

STEP 3:

Now start to download the artifacts in a folder in your local drive.This should include the WSDL file and all the associated XSDs. The XSD files can be downloaded from the links found inside the downloaded WSDL file.

STEP 4:

Go into the WSDL file.You will see a section having the schemas.

STEP 5:

Rename the XSD Http links.Point it to the local path of the XML Schemas.

STEP 6:

Open a command prompt and check the "wsimport" tool.

STEP 7:

We will use the wsimport and the associated commands to create the stubs.Please check the snap shot below f the command prompt.The command is like:wsimport -keep -extensionThere are many associated commands. We need to use them as and when required.

STEP 8:

After the previous command we can see folders created in the same destination of the artifact files.

STEP 9:

Copy this folders in the “src” folder of your JAVA project in your IDE.It should look like this ad you are good to go.

 

Java DecimalFormat - For Large Decimal Point Numbers

The Java DecimalFormat class helps us to format numbers in many ways. I was trying to convert
a big number to a 2 decimal point number.Thought of sharing the same with some explaination.

Trying to achieve this:    1,308,207 ---> 1.31


    String number = "1,308,207";
    java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
    number = number.replace(",", ""); 
    Float f = Float.parseFloat(number) / 1000000;
    String result = df.format(f); 
    System.out.println(result);   // result = 1.31

So how does it work??

Well it works like this. DecimalFromat uses java.math.RoundingMode.HALF_EVEN method which
rounds off the number to nearest even i.e when it's 0.05 it becomes 0.1.

1. The number becomes 1308207 at line 3.
2. At line no. 5 it becomes 1.308207.
3. Now the actual formatting starts:-
4. The right hand side(RHS) value is 07,so nearest round off is 10, only 1 taken & RHS discarded.
5. Now the number becomes 1.308201
6. Rightmost 01,the nearest round off id 00, RHS discarded & number becomes 0.
7. Again number becomes smaller 1.30820, in same way becomes 1.3082.
8. Next step : 1.308
9. Finally 1.31(08 becomes 10 with HALF_EVEN method and 0 discarded).


Do you have suggestions or want to improve the solution? Please do feel free to write back to us

List of deprecated Java packages in AEM 6.2


Here is a list of deprecated packages in AEM 6.2 that you should keep handy for your reference.
If you are not sure the new package/API you just Googled out is deprecated or not, then just
do a quick search here.

If it is there in the list , it shouldn't be there in your code!!



com.adobe.aem.formsndocuments.listeners
com.adobe.cq.creativecloud.cloudims
com.adobe.cq.creativecloud.filesync
com.adobe.cq.creativecloud.home
com.adobe.cq.dms.tagmanager
com.adobe.cq.mcm.silverpop
com.adobe.cq.social.blog
com.adobe.cq.social.blog.antispam
com.adobe.cq.social.blog.antispam.process
com.adobe.cq.social.blog.search
com.adobe.cq.social.blog.search.process
com.adobe.cq.social.blog.trackback
com.adobe.cq.social.blueprint.endpoints
com.adobe.cq.social.sc.lucene
com.adobe.cq.social.scoring.util
com.adobe.granite.ocs.api
com.adobe.granite.ocs.api.goals
com.adobe.granite.ocs.api.provider
com.adobe.livecycle.formsmanagement.api
com.adobe.livecycle.formsmanagement.exception
com.day.cq.activitystreams.api
com.day.cq.auth.pin
com.day.cq.dam.html
com.day.cq.jobs.core
com.day.cq.searchpromote.feed
com.day.cq.searchpromote.feed.api
com.day.crx.sc.api
com.day.crx.sc.osgi
com.day.crx.sc.qom
org.apache.aries.subsystem
org.apache.commons.imaging.formats.bmp.pixelparsers
org.apache.commons.imaging.formats.bmp.writers
org.apache.commons.imaging.formats.tga
org.apache.felix.prefs
org.apache.felix.scr
org.apache.jackrabbit.mk.api
org.apache.jackrabbit.oak.commons.mk
org.apache.jackrabbit.oak.kernel
org.apache.jackrabbit.oak.security.authentication.ldap
org.apache.sling.event
org.apache.sling.jcr.compiler
org.eclipse.equinox.region
org.joda.time.tz.data
org.joda.time.tz.data.Africa
org.joda.time.tz.data.America
org.joda.time.tz.data.America.Argentina
org.joda.time.tz.data.America.Indiana
org.joda.time.tz.data.America.Kentucky
org.joda.time.tz.data.America.North_Dakota
org.joda.time.tz.data.Antarctica
org.joda.time.tz.data.Asia
org.joda.time.tz.data.Atlantic
org.joda.time.tz.data.Australia
org.joda.time.tz.data.Etc
org.joda.time.tz.data.Europe
org.joda.time.tz.data.Indian
org.joda.time.tz.data.Pacific
org.osgi.service.prefs
org.osgi.service.repository
org.osgi.service.subsystem

Let me know about any issues. Suggestions are always welcome....

Coder Magnet
CoderMagnet is full of resources from our daily development activities. It has solutions for common problematic scenarios in technologies like Java 8, AEM, JCR and also occasionally gives you tips on Blogger as well.