From: Charlie G. <cha...@gm...> - 2007-12-01 21:06:52
|
On Dec 1, 2007 11:57 AM, marcel liker <m_...@ya...> wrote: > Hi there, > I ran into an issue with Jython's "convenience" java methods. Consider this example: > > [mliker@jbox1 ~]$ ./rlwrap jython/jython > Jython 2.2.1 on java1.4.2_08 > Type "copyright", "credits" or "license" for more information. > > >>> from weblogic.jndi import Environment > >>> server, user, password = 'server', 'user', 'password' > >>> env = Environment(providerUrl = 't3://' + server + ':80', securityPrincipal = user, securityCredentials = password) > >>> env.getInitialContext().lookup("javax.jms.QueueConnectionFactory") > weblogic.jms.client.JMSXAConnectionFactory@1d226a7 > > however: > > [mliker@box1 ~]$ ./rlwrap jython/jython > > Jython 2.2.1 on java1.4.2_08 > > Type "copyright", "credits" or "license" for more information. > > >>> from weblogic.jndi import Environment > >>> server, user, password = 'server', 'user', 'password' > > >>> env = Environment(providerUrl = 't3://' + server + ':80', securityPrincipal = user, securityCredentials = password) > >>> env.initialContext.lookup("javax.jms.QueueConnectionFactory") > Traceback (innermost last): > File "<console>", line 1, in ? > AttributeError: 'NoneType' object has no attribute 'lookup' It strikes me as odd that this is complaining about NoneType not having lookup on it. If the bean accessors weren't being created, you'd get an AttributeError about the lack of initialContext on env. Is there anything that could be going on here to cause getInitialContext to return null just in this instance? Your console output makes it seem like that's impossible, but it's the first thing I want to be sure of. Would it be hard for me to set this up locally or have you seen this anywhere else? > If somebody could also shed some light on how does jython provide these "convenience" methods as I have come across instances where not all java methods would have a jython "convenience" method It's based off of JavaBean properties: http://jython.org/Project/userguide.html#javabean-properties Essentially, if an object x has a getBlah method that returns a String, it can be accessed as x.blah and if it has a setBlah(String) method, it can be set with x.blah = 'whatever'. If the get method takes an argument, or if the setter returns something, they won't be exposed as a field since they're not JavaBeans. Charlie |