2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 using System
.Collections
;
21 using unoidl
.com
.sun
.star
.uno
;
22 using unoidl
.com
.sun
.star
.lang
;
27 /** This class can be used as a base class for UNO objects.
28 It implements the capability to be kept weakly
29 (unoidl.com.sun.star.uno.XWeak) and it implements
30 unoidl.com.sun.star.lang.XTypeProvider which is necessary for
31 using the object from StarBasic.
33 public class WeakBase
: XWeak
, XTypeProvider
35 // Contains all WeakAdapter which have been created in this class
36 // They have to be notified when this object dies
37 private WeakAdapter m_adapter
= null;
39 protected static Hashtable s_types
= new Hashtable();
40 protected static Hashtable s_impl_ids
= new Hashtable();
43 /** The returned XAdapter implementation can be used to keap a
44 weak reference to this object.
46 @return a weak adapter
48 public XAdapter
queryAdapter()
50 if (null == m_adapter
)
54 if (null == m_adapter
)
55 m_adapter
= new WeakAdapter( this );
61 /** Overrides of Object.Finalize method.
62 When there are no references to this object anymore, then the
63 garbage collector calls this method, thereby causing the adapter
64 object to be notified. The adapter, in turn, notifies all
65 listeners (unoidl.com.sun.star.uno.XReference).
69 if (null != m_adapter
)
70 m_adapter
.referentDying();
75 /** Returns an array of Type objects which represent all implemented
76 UNO interfaces of this object.
78 @return Type objects of all implemented interfaces.
80 public Type
[] getTypes()
83 Type type
= GetType();
86 types
= (Type
[]) s_types
[ type
];
89 Type
[] interfaces
= type
.GetInterfaces();
90 ArrayList list
= new ArrayList( interfaces
.Length
);
91 for ( Int32 pos
= 0; pos
< interfaces
.Length
; ++pos
)
93 Type iface
= interfaces
[ pos
];
94 // xxx todo: as long as the bridge cannot introduce
95 // native CTS types into UNO on the fly
96 if (iface
.FullName
.StartsWith( "unoidl." ))
101 Int32 len
= list
.Count
;
102 Type
[] ar
= new Type
[ len
];
103 for ( Int32 pos
= 0; pos
< len
; ++pos
)
104 ar
[ pos
] = (Type
) list
[ pos
];
105 s_types
[ type
] = ar
;
112 public byte [] getImplementationId()
118 public override String
ToString()
120 System
.Text
.StringBuilder buf
=
121 new System
.Text
.StringBuilder( base.ToString(), 256 );
122 buf
.Append( "\nUNO Object Implementation:\n\tInterfaces: " );
123 Type
[] types
= getTypes();
124 for ( Int32 pos
= 0; pos
< types
.Length
; ++pos
)
126 buf
.Append( types
[ pos
].FullName
);
127 if (pos
< (types
.Length
-1))
130 return buf
.ToString();