Going from .40 or .357 to 9mm requires a conversion barrel specifically designed to allow the extractor to work properly. You can't go from 9mm to .40 or .357 because the rims are larger, unless you go somewhere like Glockmeister and get a new top-end.
To expand on what Marty said, Glocks have five basic frame sizes (I don't know how the .45 GAP pistols work into this). Large frame is for 10mm (G20) and .45 (G21). You can switch between the two calibers with one frame by swapping out the entire top-end (slide and barrel assembly).
Standard frames are for 9mm (G17, 34, and 17L), .40 (G22, 35, and 24), and .357 (G31). You can swap out top ends, magazines, and/or barrels to switch one frame between all of these models, although certain conversions also require a new ejector. For example, you can convert a Glock 22 to a Glock 17 with either a new top-end, magazines, and a 9mm ejector, or just the conversion barrel, mags, and ejector.
Compact frames are for the 9mm G19, .40 G23, and .357 G31. However, they are not compatible with the compact frames for the G29 10mm or the G30 .45. They are similar in size but not the same. The same rules apply for conversions.
Sub-Compact frames are for the 9mm G26, .40 G27, and .357 G33. The same rules apply for conversions.
On top of that, barrels can be used from larger pistols in their smaller counterparts, as can magazines, so you can put a 4.5" barrel from a Glock 17 into a Glock 19 without a problem, it will just stick out 0.5" from the muzzle. You can also stick a Glock 17 magazine into a Glock 19, but it will not fit flush with the frame.
Furthermore, you can convert a 10mm pistol to .40 with a barrel specifically designed for this, but you can't go the other way without major surgery as the 10mm cartridge is generally too long for 9mm/.40 frames. I've seen it done with a H&K USP, but it wasn't cheap.
Unfortunately, top-end kits from Glockmeister are almost as expensive as a whole pistol, so I personally would just buy another one in the caliber I wanted.