Re: [dev] How to create a uno singleton component ?

2009-10-18 Thread Oliver Brinzing
Hi,

i think i finally did it :-)
the trick is to implement your own SingletonFactory ...

public class SingletonFactory implements XSingleComponentFactory {

private transient LogServiceImpl instance = null;

public Object createInstanceWithArgumentsAndContext(final Object[] args,
final XComponentContext xComponentContext) throws 
Exception {
return createInstanceWithContext(xComponentContext);
}

public Object createInstanceWithContext(
final XComponentContext xComponentContext) throws 
Exception {
if (this.instance == null)
this.instance = new LogServiceImpl(xComponentContext);
return this.instance;
}

and changing ServiceProvider class:

public class ServiceProvider {

public static XSingleComponentFactory __getComponentFactory(final 
String sImplName) {
XSingleComponentFactory xSingleComponentFactory = null;
if (sImplName.equals(LogServiceImpl.class.getName()))
xSingleComponentFactory = new SingletonFactory();
return xSingleComponentFactory;
}

public static boolean __writeRegistryServiceInfo(final XRegistryKey 
xRegistryKey) {
try {
final XRegistryKey newKey = xRegistryKey

.createKey(LogServiceImpl.class.getName()
+ /UNO/SINGLETONS/ + 
LogServiceImpl._serviceName);
newKey.setStringValue(LogServiceImpl._serviceName);
} catch (final InvalidRegistryException e) {
return false;
}
return 
Factory.writeRegistryServiceInfo(LogServiceImpl.class.getName(),
new String[] { LogServiceImpl._serviceName }, 
xRegistryKey);
}
}

now  EqualUnoObjects(oA,oB) returns true ...

oA = CreateUnoService(logging.LogService)
oB = CreateUnoService(logging.LogService)

and generated LogService.class has a static method get(xComponentContext)

Oliver

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45



signature.asc
Description: OpenPGP digital signature


Re: [dev] How to create a uno singleton component ?

2009-10-17 Thread Oliver Brinzing
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 

Re: [dev] How to create a uno singleton component ?

2009-10-12 Thread Stephan Bergmann

On 10/11/09 15:02, Oliver Brinzing wrote:

can one give me some hints how to create a real java singleton component like

final XLoggerPool xLoggerPool = LoggerPool.get(xComponentContext); ?

till now i found only
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Singleton

is there a code templete available  ?


Maybe 
http://api.openoffice.org/servlets/ReadMsg?listName=devmsgNo=19649 is 
of help.


-Stephan

-
To unsubscribe, e-mail: dev-unsubscr...@openoffice.org
For additional commands, e-mail: dev-h...@openoffice.org



Re: [dev] How to create a uno singleton component ?

2009-10-12 Thread Giuseppe Castagno

Hi Oliver,

Oliver Brinzing wrote:

Hi,

can one give me some hints how to create a real java singleton component like

final XLoggerPool xLoggerPool = LoggerPool.get(xComponentContext); ?

till now i found only
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Singleton

is there a code templete available  ?


in this project:

https://forge.osor.eu/projects/ooo-xadessig-it/

I wrote a couple of UNO singletons;
- extension variables and
- a dedicated logger.

The svn repo is here:

https://svn.forge.osor.eu/svn/ooo-xadessig-it

the project that can be checked out as example is:

https://svn.forge.osor.eu/svn/ooo-xadessig-it/trunk/oxsit-sing_var_uno

Check out is anonymous enabled.
The project is an Eclipse one.

Full svn path to interesting classes:

https://svn.forge.osor.eu/svn/ooo-xadessig-it/trunk/oxsit-sing_var_uno/src/it/plio/ext/oxsit/comp/GlobalLogger.java

https://svn.forge.osor.eu/svn/ooo-xadessig-it/trunk/oxsit-sing_var_uno/src/it/plio/ext/oxsit/comp/SingletonGlobalVariables.java

Licence is EUPL (GPL 2.0 like) I don't know if that will suit your
application.

Feel free to ask if you have questions.

BeppeC.
--
Kind Regards,
Giuseppe Castagno
Acca Esse http://www.acca-esse.eu
giuseppe.castagno at acca-esse.eu
beppec56 at openoffice.org


-
To unsubscribe, e-mail: dev-unsubscr...@openoffice.org
For additional commands, e-mail: dev-h...@openoffice.org



Re: [dev] How to create a uno singleton component ?

2009-10-12 Thread Giuseppe Castagno

Hi Oliver,

Oliver Brinzing wrote:

Hi,

can one give me some hints how to create a real java singleton component like

final XLoggerPool xLoggerPool = LoggerPool.get(xComponentContext); ?

till now i found only
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Singleton

is there a code templete available  ?


in this project:

https://forge.osor.eu/projects/ooo-xadessig-it/

I wrote a couple of UNO singletons;
- extension variables and
- a dedicated logger.

The svn repo is here:

https://svn.forge.osor.eu/svn/ooo-xadessig-it

the project that can be checked out as example is:

https://svn.forge.osor.eu/svn/ooo-xadessig-it/trunk/oxsit-sing_var_uno

Check out is anonymous enabled.
The project is an Eclipse one.

Full svn path to interesting classes:

https://svn.forge.osor.eu/svn/ooo-xadessig-it/trunk/oxsit-sing_var_uno/src/it/plio/ext/oxsit/comp/GlobalLogger.java

https://svn.forge.osor.eu/svn/ooo-xadessig-it/trunk/oxsit-sing_var_uno/src/it/plio/ext/oxsit/comp/SingletonGlobalVariables.java

Licence is EUPL (GPL 2.0 like) I don't know if that will suit your
application.

Feel free to ask if you have questions.

BeppeC.
--
Kind Regards,

Giuseppe Castagno
beppe...@openoffice.org
giuseppe.castagno at acca-esse.eu
Acca Esse http://www.acca-esse.eu







-
To unsubscribe, e-mail: dev-unsubscr...@openoffice.org
For additional commands, e-mail: dev-h...@openoffice.org



Re: [dev] How to create a uno singleton component ?

2009-10-12 Thread Oliver Brinzing
Hi Giuseppe,

 in this project:

 https://forge.osor.eu/projects/ooo-xadessig-it/

thanks a lot, i will have a look next weekend ;-)

Oliver
-- 

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45



signature.asc
Description: OpenPGP digital signature