Sounds like you are trying to do a factory pattern...As Bryan mentioned, take a look at how the PrinterFactory works..
You have ultimate control over the number of instances which get created and their resource ids.... The main choice you need to make is, is it a singleton? Or is it not a singleton... If it's a singleton, then in the jndi config file you will have no entry for resource key.....and in your home you will always return the same instance.....i.e. printer factory...the printer factory home will interat with the printerport home to "ask" for printer port instances...but the printerfactory is a singleton. If it's not a singleton, then the jndi config has an entry for resource key and in the home you will create resources with whatever id you define....In printerporthome I simply increment a value...simple but it shows you what you can do... Hope that helps... -----Original Message----- From: Shahzad Younas [mailto:[EMAIL PROTECTED] Sent: Friday, March 18, 2005 6:25 AM To: [email protected] Subject: RE: Instance Problem.. I think I may just do that. Thanks for letting me know. If I only want one object to be instantiated, but for me to supply it with a resource ID, and for ONE to be instantiaed and for its Resource class to be stateful, is this easily possible? What steps must I take then? Or will the code be identical to the Printer factory setup, just that I only send a request message once. I hope my question is clear! Regards, Shahzad -----Original Message----- From: Murray, Bryan P. [mailto:[EMAIL PROTECTED] Sent: 18 March 2005 01:40 To: [email protected] Subject: RE: Instance Problem.. If you follow the Printer example in the docs/example directory, you can see how to implement this. There are 2 Web services, one for the factory and one for all of the instances. The factory is setup as a singleton (there is no reference property) and the instance service is set up to require reference properties. You must send a create message to the factory first to create an instance, then you can send messages to the instance as long as you use the correct reference property that was returned by the factory. You might be best off just using the Printer code to start with, then tweeking it to suit your requirements. -----Original Message----- From: Shahzad Younas [mailto:[EMAIL PROTECTED] Sent: Thursday, March 17, 2005 3:56 PM To: [email protected] Subject: RE: Instance Problem.. I've tried the below and was hitting the problem as mentioned in a previous email. Why is it, that in my service class, if I just do XXResource x = (XXResource) getResourceContext().getResource(); Why is this error given? (below). IE why is a resource not found exceptio nthrown? What steps do I have to do to ensure a resource is instantiated? Or created somehow? I am supplying a resource ID in my request message. I have even played around with the "createInstance" method line in the getInstance method of the XXHome class. But it doesn't seem to make a difference. Please help! Thanks! Shahzad --> 03-17-05 23:47:08 DEBUG [http-8080-Processor24] ProjectResourceBundle: org.apache.ws.util.i18n.resource::handleGetObject(RELEASE_LCK) --> 03-17-05 23:47:08 DEBUG [http-8080-Processor24] Lock: Releasing lock. --> 03-17-05 23:47:08 DEBUG [http-8080-Processor24] ProjectResourceBundle: org.apache.ws.util.i18n.resource::handleGetObject(REMOVING_LCK_FOR_KEY) --> 03-17-05 23:47:08 DEBUG [http-8080-Processor24] LockManager: --> Removing Lock for key: {http://ShibbolethBrowserSession}ResourceID=1 (type=java.lang.String) org.apache.ws.resource.ResourceUnknownException at org.apache.ws.resource.impl.AbstractResourceHome.get(AbstractResourceHom e.ja va:548) at org.apache.ws.resource.impl.AbstractResourceHome.find(AbstractResourceHo me.j ava:306) at org.apache.ws.resource.impl.AbstractResourceContext.getResource(Abstract Reso urceContext.java:166) at shibbolethBrowserSession.ShibbolethBrowserSessionService.HSLogin(Shibbol ethB rowserSessionService.java:87) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ws.resource.handler.ResourceHandler.handleRequest(ResourceHan dler .java:157) at org.apache.ws.resource.handler.axis.ResourceProvider.invoke(ResourceProv ider .java:203) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.j ava: 32) at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:450) at org.apache.axis.server.AxisServer.invoke(AxisServer.java:285) -----Original Message----- From: Ian Springer [mailto:[EMAIL PROTECTED] Sent: 17 March 2005 17:35 To: [email protected] Subject: Re: Instance Problem.. Hi Shahzad, Good question. We've had other questions along these lines, so we definitely need to clarify this in the tutorial. The Service is stateless, but for each resource instance, a Resource is created which is stateful. The Resource contains the ResourcePropertySet but may also contain additional state (i.e. member vars). Try the following: Make the XXXAbstractService class that was generated extend AbstractPortType. Then you can do something like: class XXXService { ResponseDocument addOne(RequestDocument) { getResource().incrementCounter(); return new ResponseDocument(getResource().getCounter()) } } class XXXResource { private int m_counter; public void incrementCounter() { m_counter++; } public int getCounter() { return m_counter; } } Shahzad Younas wrote: > Hi, > > I was wondering, lets say I have a method in my service class: > > class Service > { > private int tmp=1; > > ResponseDocument addOne(RequestDocument) > { > tmp++; > return new ResponseDocument(with a field containing "tmp") > } > } > > if i call this method once (for a given resource ID) (by call, i mean > send a SOAP Request containing the RequestDocument) , i will get a > value of 2 returned. > Ifi call it again, with the same resource ID, will i get a value of 3 > returned? IE by state, do we mean that all variables for the service > are preserved for each resource ID? > > I am abit confused. I know ResourceProperties should hold stateful > values, but I need for the service private variables to be maintained too. > > Thanks > Shahzad --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
