/** * @param className the name of an OMERO model Java class * @return a Sphinx link to that class' documentation */ private static String linkToJavadoc(String className) { final StringBuffer sb = new StringBuffer(); sb.append(":javadoc:"); sb.append('`'); sb.append(getSimpleName(className)); sb.append(' '); sb.append('<'); sb.append(className.replace('.', '/')); sb.append(".html"); sb.append('>'); sb.append('`'); return sb.toString(); }
/** * @param className a class name * @return a Sphinx link to that class */ private static String linkTo(String className) { final StringBuffer sb = new StringBuffer(); sb.append(":ref:"); sb.append('`'); sb.append(className); sb.append(' '); sb.append('<'); sb.append(labelFor(className)); sb.append('>'); sb.append('`'); return sb.toString(); }
final SortedMap<String, String> classNames = new TreeMap<String, String>(); for (final String className : model.getAllClasses()) { classNames.put(getSimpleName(className), className); final String className = classNamePair.getValue(); out.write(".. _" + labelFor(simpleName) + ":\n\n"); out.write(simpleName + "\n"); final char[] underline = new char[simpleName.length()]; superclassOf.add(linkTo(getSimpleName(subclass))); linkerText.add(linkTo(getSimpleName(linker.getKey()), linker.getValue())); final String propertyName = classAndPropertyNames.getValue(); declaredBy.put(propertyName, superclassName); valueText.put(propertyName, linkTo(getSimpleName(valueClassName))); valueText.put(propertyName, reportType(superclassName, propertyName)); out.write(" from " + linkTo(getSimpleName(declarerName))); } else { final String interfaceName = model.getInterfaceImplemented(className, propertyName); if (interfaceName != null) { out.write(", see " + linkToJavadoc(interfaceName));
/** * Generate a Sphinx report of OMERO Hibernate entities. * @param argv the output filename * @throws IOException if the report cannot be written to the file */ public static void main(String[] argv) throws IOException { if (argv.length != 1) { System.err.println("must give output filename as single argument"); System.exit(1); } out = new FileWriter(argv[0]); final OmeroContext context = OmeroContext.getManagedServerContext(); model = context.getBean("graphPathBean", GraphPathBean.class); report(); out.close(); context.getBean("threadPool", ThreadPool.class).getExecutor().shutdown(); context.closeAll(); } }
/** * Find a Sphinx representation for a mapped property value type. * @param type a Hibernate type * @return a reportable representation of that type */ private static String reportType(String className, String propertyName) { final Type type = model.getPropertyType(className, propertyName); final UserType userType; if (type instanceof CustomType) { userType = ((CustomType) type).getUserType(); } else { userType = null; } if (type instanceof EnumType) { return "enumeration"; } else if (userType instanceof GenericEnumType) { @SuppressWarnings({"rawtypes", "unchecked"}) final Class<? extends Unit> unitQuantityClass = ((GenericEnumType) userType).getQuantityClass(); return "enumeration of " + linkToJavadoc(unitQuantityClass.getName()); } else if (type instanceof ListType || userType instanceof ListAsSQLArrayUserType) { return "list"; } else if (type instanceof MapType) { return "map"; } else { return "``" + type.getName() + "``"; } }
/** * @param className a class name * @param propertyName a property name * @return a Sphinx link to that class property */ private static String linkTo(String className, String propertyName) { final StringBuffer sb = new StringBuffer(); sb.append(":ref:"); sb.append('`'); sb.append(className); sb.append('.'); sb.append(propertyName); sb.append(' '); sb.append('<'); sb.append(labelFor(className/*, propertyName*/)); sb.append('>'); sb.append('`'); return sb.toString(); }