From: René B. <ren...@ch...> - 2011-01-24 20:22:47
|
Am 24.01.2011 um 18:23 schrieb Ray Kiddy: > > On Jan 24, 2011, at 9:12 AM, Anjo Krank wrote: > >> Isn't the JSP stuff there only linked when the JSP framework is linked? >> >> So you can't call the method when it ain't. >> >> Cheers, Anjo >> > > No, you can certainly check for the existence of a method or a class. The existence of what class would you check? Class.forName(contextClassName()) will you always give you a subclass of (ERX)WOContext. Unfortunately, these class definitions don't give you the desired information. On the other hand, even if e.g Class.forName("WOServletContext") won't fail, it doesn't say that this class is really used to instantiate WOContext. It only say, that your app _may_ be deployed as servlet... René > The Introspection API gives you that, and if something is not there, the exception can be caught. If necessary, it is possible to run through the list of all classes loaded by the VM and see if any of them respond to a given method. Obviously, this is not going to be the quickest way to do things. > > But there is going to be a better way to do this that does not involve searching for a substring in a class name. > > - ray > > >> Am 24.01.2011 um 18:05 schrieb Mike Schrag: >> >>> if (WOServletContext.class.isAssignableFrom(Class.forName(contextClassName()))) { ... } maybe .... >>> >>> On Jan 24, 2011, at 11:31 AM, Ray Kiddy wrote: >>> >>>> >>>> On Jan 24, 2011, at 7:55 AM, René Bock wrote: >>>> >>>>> I would suggest to move this functionality to ERXApplication: >>>>> >>>>> public boolean isDeployedAsServlet() { >>>>> return contextClassName().contains("Servlet"); // i.e one of WOServletContext or ERXWOServletContext >>>>> } >>>>> >>>>> >>>> >>>> Relying on the name, as a string, seems like a bad idea. Really. There is no interface that you could check for? There is no method that one could check for callability? Even if there is only an informal protocol, there has to be a method somewhere, no? >>>> >>>> Please think about this. A string comparison of the name cannot capture what a class does better than asking what the class does. >>>> >>>> cheers - ray >>>> >>>>> Am 24.01.2011 um 11:02 schrieb Marius Soutier: >>>>> >>>>>> Hello, >>>>>> >>>>>> I have an application that I want to deploy both as a normal WO app or as a servlet depending on the customer's need. Now I need to check if it is deployed as a servlet (to load a different set of Properties, for example), however isDeployedAsServlet() only checks whether or not JavaWOJSPServlet is on the classpath. >>>>>> >>>>>> Wouldn't it be more reliable to check the context class name? >>>>>> >>>>>> Either this way: >>>>>> >>>>>> if (this.contextClassName().equals(WOServletContext.class.getSimpleName()) || this.contextClassName().equals(WOServletContext.class.getName()) || >>>>>> this.contextClassName().equals(ERXWOServletContext.class.getSimpleName()) || this.contextClassName().equals(ERXWOServletContext.class.getName()) || >>>>>> this.contextClassName().equals(ERXWOServletContext54.class.getSimpleName()) || this.contextClassName().equals(ERXWOServletContext54.class.getName())) >>>>>> >>>>>> Or less static: >>>>>> if (this.contextClassName().contains("Servlet")) >>>>>> >>>>>> >>>>>> - Marius >>>>>> >>>>>> ------------------------------------------------------------------------------ >>>>>> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >>>>>> Finally, a world-class log management solution at an even better price-free! >>>>>> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >>>>>> February 28th, so secure your free ArcSight Logger TODAY! >>>>>> http://p.sf.net/sfu/arcsight-sfd2d_______________________________________________ >>>>>> Wonder-disc mailing list >>>>>> Won...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/wonder-disc >>>>> >>>>> Mit freundlichem Gruß, >>>>> >>>>> René Bock >>>>> Software Engineering >>>>> >>>>> -- >>>>> Salient GmbH - the interactive advantage >>>>> Kontorhaus - Lindleystraße 12, 60314 Frankfurt Main >>>>> >>>>> Fon +49 (0)69 - 650096 -0, Durchwahl: -18, Fax: -70 >>>>> >>>>> http://www.salient.de >>>>> http://www.openforms.de >>>>> http://www.mockabilly.com (http://itunes.apple.com/de/app/mockabilly/id392285046?mt=8) >>>>> >>>>> Geschäftsführer: Peter Biler, Alexander Gerling, Lars Ohlerich >>>>> Amtsgericht Frankfurt Main, HRB 48693 >>>>> >>>>> // Aktuell für Heinze am Start: www.architekturobjekte.de // >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >>>>> Finally, a world-class log management solution at an even better price-free! >>>>> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >>>>> February 28th, so secure your free ArcSight Logger TODAY! >>>>> http://p.sf.net/sfu/arcsight-sfd2d_______________________________________________ >>>>> Wonder-disc mailing list >>>>> Won...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/wonder-disc >>>> >>>> ------------------------------------------------------------------------------ >>>> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >>>> Finally, a world-class log management solution at an even better price-free! >>>> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >>>> February 28th, so secure your free ArcSight Logger TODAY! >>>> http://p.sf.net/sfu/arcsight-sfd2d_______________________________________________ >>>> Wonder-disc mailing list >>>> Won...@li... >>>> https://lists.sourceforge.net/lists/listinfo/wonder-disc >>> >>> ------------------------------------------------------------------------------ >>> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >>> Finally, a world-class log management solution at an even better price-free! >>> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >>> February 28th, so secure your free ArcSight Logger TODAY! >>> http://p.sf.net/sfu/arcsight-sfd2d_______________________________________________ >>> Wonder-disc mailing list >>> Won...@li... >>> https://lists.sourceforge.net/lists/listinfo/wonder-disc >> >> >> ------------------------------------------------------------------------------ >> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >> Finally, a world-class log management solution at an even better price-free! >> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >> February 28th, so secure your free ArcSight Logger TODAY! >> http://p.sf.net/sfu/arcsight-sfd2d >> _______________________________________________ >> Wonder-disc mailing list >> Won...@li... >> https://lists.sourceforge.net/lists/listinfo/wonder-disc >> > > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > Wonder-disc mailing list > Won...@li... > https://lists.sourceforge.net/lists/listinfo/wonder-disc |