Hi, today i started to create my first uno singleton ;-)
idlc, regmerge & javamaker seem to work, regview shows me for example:
/ LogService
Value: Type = RG_VALUETYPE_BINARY
Size = 110
Data = version: 1
documentation: ""
file name: ""
type class: singleton
type name: "logging/LogService"
super type count: 1
super type name 0: "logging/XLogAccess"
field count: 0
method count: 0
reference count: 0
the extension is deployable an i can get an instance, for example:
oContext =
createUnoService("com.sun.star.configuration.bootstrap.BootstrapContext")
oA = oContext.getValueByName("/singletons/logging.LogService")
oB = oContext.getValueByName("/singletons/logging.LogService")
msgbox EqualUnoObjects(oA, oB)
-> return's TRUE
Now i see two problems:
1. oA = CreateUnoService("logging.LogService")
oB = CreateUnoService("logging.LogService")
msgbox EqualUnoObjects(oA, oB)
-> return's FALSE - do i have 2 instances here ???
2. How can i use the static get(xComponentContext) to obtain the instance,
described here:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/ProUNO/C%2B%2B/Mapping_of_Singletons
changing "LogServiceImpl.java" to a java singleton
private static LogServiceImpl instance = null;
private LogServiceImpl(final XComponentContext xComponentContext) {
}
public static XLogAccess get(final XComponentContext xComponentContext)
{
if (LogServiceImpl.instance == null)
LogServiceImpl.instance = new
LogServiceImpl(xComponentContext);
return LogServiceImpl.instance;
}
will cause an error message: "Can not activate the factory for
logging.LogServiceImpl beacause
FactoryHelper can not find a useable constructor "
any hints ?
Oliver
code snippet's:
LogService.idl
[...] module logging {
interface XLogAccess;
singleton LogService : XLogAccess;
};
XLogAccess.idl
[...] module logging {
interface XLogAccess : com::sun::star::uno:: XInterface
{
string getLoggerName();
long getLevel();
[...]
};
};
LogServiceImpl.java
public class LogServiceImpl extends ComponentBase implements XServiceInfo,
XLogAccess {
static final String _serviceName = "logging.LogService";
public LogServiceImpl(final XComponentContext xComponentContext) {
}
public String getImplementationName() {
return getClass().getName();
}
public boolean supportsService(final String name) {
if (name.equals(LogServiceImpl._serviceName))
return true;
return false;
}
public String[] getSupportedServiceNames() {
return new String[] { LogServiceImpl._serviceName };
}
// XLogAccess
public String getLoggerName() {
return Log.getName();
}
public int getLevel() {
return Log.getLevel();
}
}
ServiceProvider.java
public class ServiceProvider {
public static XSingleServiceFactory __getServiceFactory(
final String sImplName, final XMultiServiceFactory
xMultiFactory,
final XRegistryKey xRegistryKey) {
XSingleServiceFactory xSingleServiceFactory = null;
if (sImplName.equals(LogServiceImpl.class.getName()))
xSingleServiceFactory = FactoryHelper.getServiceFactory(
LogServiceImpl.class,
LogServiceImpl._serviceName,
xMultiFactory, xRegistryKey);
return xSingleServiceFactory;
}
public static boolean __writeRegistryServiceInfo(
final XRegistryKey xRegistryKey) {
try {
XRegistryKey newKey =
xRegistryKey.createKey(LogServiceImpl.class
.getName()
+ "/UNO/SINGLETONS/" +
LogServiceImpl._serviceName);
newKey.setStringValue(LogServiceImpl._serviceName);
} catch (InvalidRegistryException e) {
return false;
}
return FactoryHelper.writeRegistryServiceInfo(
LogServiceImpl.class.getName(),
LogServiceImpl._serviceName,
xRegistryKey);
}
}
--
GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45
signature.asc
Description: OpenPGP digital signature
