You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Bassi Suk <ba...@mellon.com> on 2000/12/14 18:36:41 UTC
RE: Xalan Extensions: using a single instance rather than new in
stantiation
Gary,
You are exactly right, but just to explain the question to others l will
redefine the question.
To redefine the question, I am trying to call methods on a "singleton"
class.
public class mySingleton {
private static instance = new mySingleton();
private mySingleton() {
}
public static mySingleton getInstance() {
return instance;
}
public String myMethod() {
return "We are humbled";
}
}
Therefore, in the XSLT stylesheet we want to call the
mySingleton.getInstance() and get an instance of mySingleton and then be
able to use the mySingleton.myMethod().
The QUESTION is, what should the XSLT syntax be for the above to occur.
At present, we have only been using Xalan extensions to obtain an instance
of the java class, and we have done it like so:
<?xml version="1.0" ?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lxslt="http://xml.apache.org/xslt"
xmlns:xyzExt="mySingleton"
extension-element-prefixes="xyzExt"
version="1.0">
<lxslt:component
prefix="xyzExt"
functions="getInstance">
<lxslt:script lang="javaclass" src="mySingleton"/>
</lxslt:component>
<xsl:variable name="value" select="xyzExt:myMethod()"/>
We are a bit stuck as how to incorporate the singleton.
Any help would be gratefully appreciated.
Suk.
> -----Original Message-----
> From: Gary L Peskin [SMTP:garyp@firstech.com]
> Sent: Thursday, December 14, 2000 4:22 PM
> To: xalan-dev@xml.apache.org
> Subject: Re: Xalan Extensions: using a single instance rather than
> new instantiation
>
> Bassi Suk wrote:
> >
> > I have a JAVA class which is acting as a database factory. I only want
> to
> > use one instance of this.
> >
> > Is there a way in Xalan xslt java extensions to use this factory as i
> would
> > through normal java calls.
> > ie.
> >
> > myDBFactory dbFac = myDBFactory.getInstance();
> >
> > dbFac.getOrder(int orderID)
> > dbFac.getDept(int depID)
> >
> > etc...
> >
> > At present, when l reference a java class, Xalan creates a new instance
> of
> > that class each time a new stylesheet references it.
> >
> > I would like it so that each time a stylesheet references the code,
> Xalan
> > refers to the same myDBFactory instance.
>
> Suk --
>
> I'm a little confused as to what you're trying to do. I assume that
> getInstance() is a static method in myDBFactory. When you call it, it
> returns an object of type myDBFactory called dbFac. Is it this dbFac
> that you want to use everywhere? Are you passing a reference to dbFac
> to your various stylesheets or what?
>
> If I understand you correctly, perhaps you want to have a "default
> instance" of myDBFactory. In this case, you'd just store the instance
> as a static field in myDBFactory and get it with either getInstance() or
> a new getDefaultInstance() method.
>
> Not sure what you're trying to do. If my explanation doesn't help,
> perhaps you could explain further and we can go from there.
>
> Gary
*****************************************************************
DISCLAIMER: The information contained in this e-mail may be confidential
and is intended solely for the use of the named addressee. Access, copying
or re-use of the e-mail or any information contained therein by any other
person is not authorized. If you are not the intended recipient please
notify us immediately by returning the e-mail to the originator.