Index: bdm/userinfo.h
===================================================================
--- bdm/userinfo.h (revision 142)
+++ bdm/userinfo.h (revision 146)
@@ -86,10 +86,21 @@
 class BindingFrame
 {
-public:
+protected:
+	BindingFrame()
+	{
+		// trik, chci jen to, aby se ZAVCAS inicializoval!!
+		// tj pred vsema UI apod.. hlavne pred praci s XMLStringem
+		XercesConnector::instance();
+	}
+
+public:
+	
 	// nacpe na prislusne pointery, kdyztak da NULL
 	virtual void AssemblyBindedData( DOMElement &element ) = 0;
 
 	// uvolneni pameti po slozeni objektu, tj. lze jedine po AssemblyBD
-	virtual void ReleaseUsedMemory() = 0;
+	virtual void ReleaseUsedMemory()
+	{
+	}
 
 	// vrati bool, pokud se povedlo rozebrat a naplnit element
@@ -97,5 +108,38 @@
 	virtual bool DisassemblyBindedData( DOMElement &element ) = 0;		
 };
-
+/*
+class BindedAttribute : public BindingFrame
+{
+private:		
+	const XMLCh* const transcodedAttributeName;
+
+public:
+	BindedAttribute( string attributeName )
+		: transcodedAttributeName( XMLString::transcode attributeName.c_str() ) )
+	{
+	}
+
+	~BindedAttribute()
+	{			
+		XMLString::release( (XMLCh**)&transcodedAttributeName );
+	}
+
+	// TAM JSOU TY HODNOTY
+	string str;
+
+	// nacpe na prislusne pointery, kdyztak da NULL
+	void AssemblyBindedData( DOMElement &element )
+	{
+		const XMLCh* const transcoded_str = element.getAttribute( transcodedAttributeName );
+		str = string( XMLString::transcode( transcoded_str ) );
+	}
+
+	bool DisassemblyBindedData( DOMElement &element )
+	{
+		const XMLCh* transcoded_str = XMLString::transcode(str.c_str());
+		element.setAttribute( transcodedAttributeName, transcoded_str );
+		XMLString::release( (XMLCh**) &transcoded_str );
+	}
+};
 
 /*!
@@ -110,27 +154,31 @@
 private:
 	//! Type definition of mapping which transforms type names to the related user infors
-	typedef map< const string, UserInfo*> MappedName2UI;
+	typedef map< const string, UserInfo*> MappedString2UI;
 	
 	//! Mapped 
-	static MappedName2UI& mappedName2UI()
-	{
-		static MappedName2UI var;
+	static MappedString2UI& userFriendlyNames2UI()
+	{
+		static MappedString2UI var;
 		return var;
 	}
 
-	const string underlyingTypeName;
-
-public:
+	//! Mapped 
+	static MappedString2UI& namesByRTTI2UI()
+	{
+		static MappedString2UI var;
+		return var;
+	}
+
+	const string userFriendlyTypeName;
+public:
+	const string typeNameByRTTI;
 
 	//! The only constructor which fills both the transcodedTypeName and the help attribute
-	UserInfo( const string& underlyingTypeName )
-		: underlyingTypeName ( underlyingTypeName )
+	UserInfo( const string& userFriendlyTypeName, const string& typeNameByRTTI )
+		: userFriendlyTypeName ( userFriendlyTypeName ),
+		typeNameByRTTI( typeNameByRTTI )
 	{	
-		// trik, chci jen to, aby se inicializoval!!
-		XercesConnector::instance();
-
-		cout << underlyingTypeName;
-
-		mappedName2UI().insert( make_pair( underlyingTypeName, this ) );
+		userFriendlyNames2UI().insert( make_pair( userFriendlyTypeName, this ) );
+		namesByRTTI2UI().insert( make_pair( typeNameByRTTI, this ) );
 	}
 
@@ -142,9 +190,11 @@
 	
 	virtual void BuildInternal(void* &pInstance) = 0;
+	
+	virtual void AbsorbInternal(void* &pInstance) = 0;
 
 	//! returns object of templated type filled with data stored in this CompoundUserInfo instance
 	// NULL if error..
 	template<class T>
-	static void Assembly( const string tagName, DOMElement &element, T* &pInstance  )
+	static void Assembly( T* &pInstance, DOMElement &element, const string tagName )
 	{	
 		pInstance = NULL;
@@ -153,33 +203,17 @@
 		XMLString::upperCase( transcodedTagName );
 
-/*/////////////////////////
-		DOMNodeList* nodeListe = element.getChildNodes();
-		if( nodeListe )
-			for( int i = 0; i < nodeListe->getLength(); i++ )
-			{
-				DOMNode* node = nodeListe->item(i);
-				if( node->getNodeType() == DOMNode::ELEMENT_NODE )
-				{
-					DOMElement* childElement = (DOMElement*) node;
-					cout << XercesConnector::instance().XMLCh2str( childElement->getTagName() );
-				}
-			}
-		getchar();
-
-*/////////////////////////////
-
 
 		DOMNodeList* const nodeList = element.getElementsByTagName( transcodedTagName );
 		XMLString::release( (XMLCh**)&transcodedTagName );
 
-		if( nodeList != NULL && nodeList->getLength() != 1 )
+		if( nodeList == NULL || nodeList->getLength() != 1 )
 			return;
 
 		// TAKZE MAME V RUCE ELEMENT SE JMENEM "tagName"
-		DOMElement* childElement = (DOMElement*) nodeList->item(0);
+		DOMElement* selectedElement = (DOMElement*) nodeList->item(0);
 
 		// COZ O TO, UDELAL BYCH TO STATICKOU KONSTANTOU, ALE JAK JI PAK SMAZU??
 		XMLCh* transcodedTypeAttributeName = XMLString::transcode("type");
-		const XMLCh* const transcodedType = childElement->getAttribute( transcodedTypeAttributeName );
+		const XMLCh* const transcodedType = selectedElement->getAttribute( transcodedTypeAttributeName );
 		XMLString::release( (XMLCh**)&transcodedTypeAttributeName );
 
@@ -188,13 +222,13 @@
 
 		// TED MAME V RUCE JMENO TYPU Z ATRIBUTU TYPE
-		string type = XercesConnector::instance().XMLCh2str( transcodedType );
-
-		MappedName2UI::const_iterator iter = mappedName2UI().find( type  );
-		if( iter == mappedName2UI().end())
+		string userFriendlyTypeName = XercesConnector::instance().XMLCh2str( transcodedType );
+	
+		MappedString2UI::const_iterator iter = userFriendlyNames2UI().find( userFriendlyTypeName );
+		if( iter == userFriendlyNames2UI().end())
 			return;
 
 		// A TED PRISLUSNE UI
 		UserInfo *relatedUI = iter->second;
-		relatedUI->AssemblyBindedData( *childElement );		
+		relatedUI->AssemblyBindedData( *selectedElement );		
 		relatedUI->BuildInternal( (void*&)pInstance );
 		relatedUI->ReleaseUsedMemory();
@@ -205,8 +239,7 @@
 		try
 		{
-			// takhle to zkontroluju? name musi byt shodne s name nahore!!
-			// takze mame typ T, ale name bud od jeho potomka.. oki??
-			string resultingType = typeid( *pInstance ).name();
-			if( resultingType != type )
+			// typova kontrola "do it yourself":)
+			string resultingTypeNameByRTTI = typeid( *pInstance ).name();
+			if( resultingTypeNameByRTTI != relatedUI->typeNameByRTTI )
 			{
 				cout << "FATAL ERROR!!" << endl;
@@ -222,6 +255,62 @@
 	}	
 
-	// ? pri destrukci si za ne naopak zodpovida ten, kdo je vytvoril.. protoze 
-	// budou zit v tom objektu!! tak jakapak destrkuce..
+	//! returns object of templated type filled with data stored in this CompoundUserInfo instance
+	// NULL if error..
+	template<class T>
+	static bool Disassembly( T* pInstance, DOMElement &element, const string tagName, const string help)
+	{	
+		if( pInstance == NULL)
+			return false;
+
+		XMLCh* transcodedTagName = XMLString::transcode( tagName.c_str() );		
+		XMLString::upperCase( transcodedTagName );
+
+		// ADD NEW ELEMENT
+		DOMDocument* pDoc = element.getOwnerDocument();
+		DOMElement* selectedElement = pDoc->createElement( transcodedTagName );		
+		element.appendChild( selectedElement );
+		XMLString::release( (XMLCh**)&transcodedTagName );
+
+			
+		// hledame vhodne UI - co ty mapy jeste nejako zapouzdrit?!?! 
+		MappedString2UI::const_iterator iter = namesByRTTI2UI().find( typeid(*pInstance).name() );
+		if( iter == namesByRTTI2UI().end())
+			return false;
+		UserInfo *relatedUI = iter->second;
+
+		// PRIDAM ATRIBUT TYPE - UDELAT NA TO METODU!! NEBO JESTE LEPE SPECIALNI BINDOVACI OBJEKT..
+		// opet obousmernej, jen na stringy.. pouziju i u valuedUI..
+		const XMLCh* transcodedTypeAttributeName = XMLString::transcode("type");
+		const XMLCh* transcodedUserFriendlyTypeName = XMLString::transcode(relatedUI->userFriendlyTypeName.c_str());
+		selectedElement->setAttribute( transcodedTypeAttributeName, transcodedUserFriendlyTypeName );
+		XMLString::release( (XMLCh**)&transcodedTypeAttributeName );
+		XMLString::release( (XMLCh**)&transcodedUserFriendlyTypeName );
+
+		if( help.length() )
+		{
+			// PRIDAM ATRIBUT TYPE
+			const XMLCh* transcodedHelpAttributeName = XMLString::transcode("help");
+			const XMLCh* transcodedHelpString = XMLString::transcode( help.c_str() );
+			selectedElement->setAttribute( transcodedHelpAttributeName, transcodedHelpString );
+			XMLString::release( (XMLCh**)&transcodedHelpAttributeName );
+			XMLString::release( (XMLCh**)&transcodedHelpString );
+		}
+
+
+		// A TED PRISLUSNE UI
+		// NASMERUJE UKAZATELE BindingFrames.. nejak lip pojmenovat
+		// sloz z pointeru, rozloz na pointery.. 
+		relatedUI->AbsorbInternal( (void*&)pInstance );
+		// rozebere soucastky
+		return relatedUI->DisassemblyBindedData( *selectedElement );		
+	}	
+
+	//! returns object of templated type filled with data stored in this CompoundUserInfo instance
+	// NULL if error..
+	template<class T>
+	static bool Disassembly( T* pInstance, DOMElement &element, const string tagName )
+	{
+		return Disassembly( pInstance, element, tagName, "" );
+	}
 };
 
@@ -232,6 +321,6 @@
 
 	//! The only constructor which fills 
-	TypedUserInfo<T>( ) 
-		: UserInfo( typeid(T).name() ) 
+	TypedUserInfo<T>( const string &userFriendlyTypeName) 
+		: UserInfo( userFriendlyTypeName, typeid(T).name() ) 
 	{	
 	};
@@ -251,4 +340,13 @@
 
 	virtual void Build(T* &pTypedInstance) = 0;
+
+	// FRIEND radeji
+	void AbsorbInternal(void* &pInstance)
+	{
+		T* &pTypedInstance = (T*&) pInstance;
+		Absorb( pTypedInstance );
+	}
+
+	virtual void Absorb(T* &pTypedInstance) = 0;
 
 	static const TypedUserInfo<T> &instance;
@@ -308,8 +406,12 @@
 		bool DisassemblyBindedData( DOMElement &element )
 		{
-	//		return factory.Disassembly( (void*&) pInstance, element, name, help );
-			return true;
+			return factory.Disassembly( pInstance, element, name, help );
 		}
 	};
+
+	CompoundUserInfo<T>( string userFriendlyTypeName )
+		: TypedUserInfo<T>( userFriendlyTypeName )
+	{
+	}
 
 
@@ -338,46 +440,4 @@
 
 
-	/*	
-	//! returns object of templated type filled with data stored in this CompoundUserInfo instance
-	bool Disassembly(void * &pInstance, DOMElement &element, string name, char * help = "" )
-	{
-		T* &pTypedInstance = (T*&) pInstance;
-		// do elementu prida vetev se jmenem name a vyplni obsahujici data z instance
-		// zde nemuze vzniknout zadna chyba, ponevadz XML vytvarime 
-
-/*
-		for( MappedElements::const_iterator iter = elements.begin(); iter != elements.end(); iter++)
-		{
-			iter->second->AppendElement( *pHead );
-				{
-		DOMDocument* pDoc = element.getOwnerDocument();
-
-		DOMElement* pHead = pDoc->createElement( transcodedTypeName );		
-		element.appendChild( pHead );
-
-		FillElement( pHead );
-}
-			}
-
-		for( MappedAttributes::iterator iter = attributes.begin(); iter != attributes.end(); iter++)
-		{
-			// we do not create attributes, which are empty
-			if( !strcmp( iter->second->c_str(), "") )
-				continue;
-
-			DOMDocument* pDoc = pHead->getOwnerDocument();
-			DOMAttr* pAttribute = pDoc->createAttribute( iter->first );
-
-			XMLCh* transcodedValue = XMLString::transcode( iter->second->c_str() ); 
-			pAttribute->setValue( transcodedValue );
-			XMLString::release( &transcodedValue );
-
-			pHead->setAttributeNode(pAttribute);			
-		}
-		return true;
-	}
-*/
-
-
 template<typename T> class ValuedUserInfo : public TypedUserInfo<T>
 {
@@ -390,6 +450,7 @@
 	string value;
 
-	ValuedUserInfo<T>()
-		: transcodedValueName( XMLString::transcode( "value" ))
+	ValuedUserInfo<T>( string userFriendlyTypeName )
+		: TypedUserInfo<T>( userFriendlyTypeName ),
+		  transcodedValueName( XMLString::transcode( "value" ))
 	{
 	}
@@ -406,12 +467,12 @@
 	}
 
-	void ReleaseUsedMemory()
-	{			
-	}
-
 	bool DisassemblyBindedData( DOMElement &element )
 	{
-//		if( value.length()==0 )
-//			return false;
+		if( value.length() )
+		{
+			const XMLCh* transcodedValueString = XMLString::transcode( value.c_str() );
+			element.setAttribute( transcodedValueName, transcodedValueString );
+			XMLString::release( (XMLCh**)&transcodedValueString );
+		}
 		return true;
 	}
