Ideas needed, some kind of connection system

Well I have a design problem, and I can’t find any aceptable solution yet, so if anyone has any ideas it would really help.

Imagine a series of tubes, that can be straight,T-formed,X-formed, ect.

Now I now for every object were are possible connections to other objects.

I know the localrotation of the connection and the localposition.



My problem now is to calculate the positions:



Now if i know that tube B is at the world position 0,0,0 with identity rotation

And i know that tube A is connected at Connection 1 to tube B Connection 2, how can I calculate the position and rotation from tube A in world space?