protected static String getStatusToolTip() { StringBuffer result = new StringBuffer("<html>"); // NOI18N result.append("<table cellspacing=\"0\" border=\"0\">"); // NOI18N final CollabManager manager = CollabManager.getDefault(); if (manager != null) { Set sessions = new TreeSet( new Comparator() { public int compare(Object o1, Object o2) { String s1 = ((CollabSession) o1).getUserPrincipal().getDisplayName(); String s2 = ((CollabSession) o2).getUserPrincipal().getDisplayName(); return s1.compareTo(s2); } }); sessions.addAll(Arrays.asList(manager.getSessions())); if (sessions.size() == 0) { result.append("<tr><td>"); // NOI18N result.append(getStatusDescription(CollabPrincipal.STATUS_OFFLINE)); result.append("</td></tr>"); // NOI18N } else { for (Iterator i = sessions.iterator(); i.hasNext(); ) { CollabPrincipal principal = ((CollabSession) i.next()).getUserPrincipal(); result.append("<tr>"); // NOI18N result.append("<td>"); // NOI18N result.append("<b>"); // NOI18N result.append(principal.getDisplayName()); result.append(": "); // NOI18N result.append("</b>"); // NOI18N result.append("</td>"); // NOI18N result.append("<td>"); // NOI18N result.append(getStatusDescription(principal.getStatus())); result.append("</td>"); // NOI18N result.append("</tr>"); // NOI18N } } } result.append("</table>"); // NOI18N return result.toString(); }
public Reference createReference(Object bean) throws NamingException { try { BeanInfo bi = Introspector.getBeanInfo(bean.getClass()); PropertyDescriptor[] pds = bi.getPropertyDescriptors(); List refAddrs = new ArrayList(); String factoryClassLocation = defaultFactoryClassLocation; boolean using_ref_props = referenceProperties.size() > 0; // we only include this so that on dereference we are not surprised to find some properties // missing if (using_ref_props) refAddrs.add( new BinaryRefAddr(REF_PROPS_KEY, SerializableUtils.toByteArray(referenceProperties))); for (int i = 0, len = pds.length; i < len; ++i) { PropertyDescriptor pd = pds[i]; String propertyName = pd.getName(); // System.err.println("Making Reference: " + propertyName); if (using_ref_props && !referenceProperties.contains(propertyName)) { // System.err.println("Not a ref_prop -- continuing."); continue; } Class propertyType = pd.getPropertyType(); Method getter = pd.getReadMethod(); Method setter = pd.getWriteMethod(); if (getter != null && setter != null) // only use properties that are both readable and writable { Object val = getter.invoke(bean, EMPTY_ARGS); // System.err.println( "val: " + val ); if (propertyName.equals("factoryClassLocation")) { if (String.class != propertyType) throw new NamingException( this.getClass().getName() + " requires a factoryClassLocation property to be a string, " + propertyType.getName() + " is not valid."); factoryClassLocation = (String) val; } if (val == null) { RefAddr addMe = new BinaryRefAddr(propertyName, NULL_TOKEN_BYTES); refAddrs.add(addMe); } else if (Coerce.canCoerce(propertyType)) { RefAddr addMe = new StringRefAddr(propertyName, String.valueOf(val)); refAddrs.add(addMe); } else // other Object properties { RefAddr addMe = null; PropertyEditor pe = BeansUtils.findPropertyEditor(pd); if (pe != null) { pe.setValue(val); String textValue = pe.getAsText(); if (textValue != null) addMe = new StringRefAddr(propertyName, textValue); } if (addMe == null) // property editor approach failed addMe = new BinaryRefAddr( propertyName, SerializableUtils.toByteArray( val, indirector, IndirectPolicy.INDIRECT_ON_EXCEPTION)); refAddrs.add(addMe); } } else { // System.err.println(this.getClass().getName() + // ": Skipping " + propertyName + " because it is " + (setter == null ? // "read-only." : "write-only.")); if (logger.isLoggable(MLevel.WARNING)) logger.warning( this.getClass().getName() + ": Skipping " + propertyName + " because it is " + (setter == null ? "read-only." : "write-only.")); } } Reference out = new Reference(bean.getClass().getName(), factoryClassName, factoryClassLocation); for (Iterator ii = refAddrs.iterator(); ii.hasNext(); ) out.add((RefAddr) ii.next()); return out; } catch (Exception e) { // e.printStackTrace(); if (Debug.DEBUG && logger.isLoggable(MLevel.FINE)) logger.log(MLevel.FINE, "Exception trying to create Reference.", e); throw new NamingException("Could not create reference from bean: " + e.toString()); } }