I am a Indian Citizen and am going to Shanghai (China) via Macau and I am going to Macau through Hong Kong via ferry, then from Macau I will visit Shanghai (China). Is this possible with a single-entry visa for China?
Based on your itinerary home->HK->Macau->Shanghai->home
Your China visa is only needed when you enter the mainland, which does not include Macau or Hong Kong. Although they are both officially part of "China" they are treated almost as separate countries for immigration and customs purposes. The border is called a "boundary" but you will find immigration and customs people there.
So when you land in HK you will be subject to HK immigration law, and will get a stamp in your passport (assuming you don't take one of the ferries that leaves without going through immigration in HK), then you will exit HK (surrendering your departure card) and go through Macau immmigration- another entry card, and another stamp. Then when you leave Macau and enter China, presumably at Zhuhai, you will exit again and only now will your China visa will come into play.
So, in short, your single entry China visa is fine for this itinerary.