using System; using System.Collections; using unoidl.com.sun.star.uno; using unoidl.com.sun.star.lang;
namespace uno.util
{
/** This class can be used as a base class for UNO objects. Itimplementsthecapabilitytobekeptweakly (unoidl.com.sun.star.uno.XWeak)anditimplements unoidl.com.sun.star.lang.XTypeProviderwhichisnecessaryfor usingtheobjectfromStarBasic.
*/ publicclass WeakBase : XWeak, XTypeProvider
{ // Contains all WeakAdapter which have been created in this class // They have to be notified when this object dies private WeakAdapter m_adapter = null;
protectedstatic Hashtable s_types = new Hashtable(); protectedstatic Hashtable s_impl_ids = new Hashtable();
// XWeak impl /** The returned XAdapter implementation can be used to keep a weakreferencetothisobject. @returnaweakadapter
*/ public XAdapter queryAdapter()
{ if (null == m_adapter)
{ lock (this)
{ if (null == m_adapter)
m_adapter = new WeakAdapter( this );
}
} return m_adapter;
}
/** Overrides of Object.Finalize method. Whentherearenoreferencestothisobjectanymore,thenthe garbagecollectorcallsthismethod,therebycausingtheadapter objecttobenotified.Theadapter,inturn,notifiesall listeners(unoidl.com.sun.star.uno.XReference).
*/
~WeakBase()
{ if (null != m_adapter)
m_adapter.referentDying();
}
// XTypeProvider impl
/** Returns an array of Type objects which represent all implemented UNOinterfacesofthisobject. @returnTypeobjectsofallimplementedinterfaces.
*/ public Type [] getTypes()
{
Type [] types;
Type type = GetType(); lock (s_types)
{
types = (Type []) s_types[ type ]; if (null == types)
{
Type [] interfaces = type.GetInterfaces();
ArrayList list = new ArrayList( interfaces.Length ); for ( Int32 pos = 0; pos < interfaces.Length; ++pos )
{
Type iface = interfaces[ pos ]; // xxx todo: as long as the bridge cannot introduce // native CTS types into UNO on the fly if (iface.FullName.StartsWith( "unoidl." ))
{
list.Add( iface );
}
}
Int32 len = list.Count;
Type [] ar = new Type [ len ]; for ( Int32 pos = 0; pos < len; ++pos )
ar[ pos ] = (Type) list[ pos ];
s_types[ type ] = ar;
types = ar;
}
} return types;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.