DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16205>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16205 org.apache.naming.factory.BeanFactory bugs Summary: org.apache.naming.factory.BeanFactory bugs Product: Tomcat 4 Version: 4.1.18 Platform: All OS/Version: All Status: NEW Severity: Major Priority: Other Component: Catalina:Modules AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] 1) The howto examples used the newer <resource-env-ref> inplace of <resource- ref>. Problem is that BeanFactory does not work with <resource-env-ref>. It just returns null. 2) BeanFactory checks for instances of a ResourceRef object, if the object passed isn't one BeanFactory just returns null. No error is logged or exception thrown. This made debugging more difficult than it should have been. It later casts the object to a Reference not a ResourceRef. 3) BeanFactory tries to put the value from <description> element into the object as a parameter. If it can't find a setDescription method it throws a NamingException. Fixed BeanFactory.getObjectInstance() below ===================================================================== public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws NamingException { if (!(obj instanceof Reference)) throw new NamingException("Object must be instanceof javax.naming.Reference"); try { Reference ref = (Reference) obj; String beanClassName = ref.getClassName(); Class beanClass = null; ClassLoader tcl = Thread.currentThread().getContextClassLoader(); if (tcl != null) { try { beanClass = tcl.loadClass(beanClassName); } catch(ClassNotFoundException e) { } } else { try { beanClass = Class.forName(beanClassName); } catch(ClassNotFoundException e) { e.printStackTrace(); } } if (beanClass == null) { throw new NamingException ("Class not found: " + beanClassName); } BeanInfo bi = Introspector.getBeanInfo(beanClass); PropertyDescriptor[] pda = bi.getPropertyDescriptors(); Object bean = beanClass.newInstance(); Enumeration e = ref.getAll(); while (e.hasMoreElements()) { RefAddr ra = (RefAddr) e.nextElement(); String propName = ra.getType(); if (propName.equals(Constants.FACTORY) || propName.equals("scope") || propName.equals("auth") || propName.equals("description")) { continue; } String value = (String)ra.getContent(); Object[] valueArray = new Object[1]; int i = 0; for (i = 0; i<pda.length; i++) { if (pda[i].getName().equals(propName)) { Class propType = pda[i].getPropertyType(); if (propType.equals(String.class)) { valueArray[0] = value; } else if (propType.equals(Character.class) || propType.equals(char.class)) { valueArray[0] = new Character(value.charAt(0)); } else if (propType.equals(Byte.class) || propType.equals(byte.class)) { valueArray[0] = new Byte(value); } else if (propType.equals(Short.class) || propType.equals(short.class)) { valueArray[0] = new Short(value); } else if (propType.equals(Integer.class) || propType.equals(int.class)) { valueArray[0] = new Integer(value); } else if (propType.equals(Long.class) || propType.equals(long.class)) { valueArray[0] = new Long(value); } else if (propType.equals(Float.class) || propType.equals(float.class)) { valueArray[0] = new Float(value); } else if (propType.equals(Double.class) || propType.equals(double.class)) { valueArray[0] = new Double(value); } else { throw new NamingException ("String conversion for property type '" + propType.getName() + "' not available"); } Method setProp = pda[i].getWriteMethod(); if (setProp != null) { setProp.invoke(bean, valueArray); } else { throw new NamingException ("Write not allowed for property: " + propName); } break; } } if (i == pda.length) { throw new NamingException ("No set method found for property: " + propName); } } return bean; } catch (java.beans.IntrospectionException ie) { throw new NamingException(ie.getMessage()); } catch (java.lang.IllegalAccessException iae) { throw new NamingException(iae.getMessage()); } catch (java.lang.InstantiationException ie2) { throw new NamingException(ie2.getMessage()); } catch (java.lang.reflect.InvocationTargetException ite) { throw new NamingException(ite.getMessage()); } } } -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>