private static String getFactNameFromType( final ProjectDataModelOracle oracle, final String fullyQualifiedClassName) { if (fullyQualifiedClassName == null) { return null; } if (oracle.getProjectModelFields().containsKey(fullyQualifiedClassName)) { return fullyQualifiedClassName; } for (Map.Entry<String, ModelField[]> entry : oracle.getProjectModelFields().entrySet()) { for (ModelField mf : entry.getValue()) { if (DataType.TYPE_THIS.equals(mf.getName()) && fullyQualifiedClassName.equals(mf.getClassName())) { return entry.getKey(); } } } return null; }
/** * Convenience method to get an array of field names for a type in a project * * @param oracle The DMO representing a project * @param fullyQualifiedClassName The FQCN of the type * @return */ public static String[] getFieldNames( final ProjectDataModelOracle oracle, final String fullyQualifiedClassName) { final ModelField[] modelFields = oracle.getProjectModelFields().get(fullyQualifiedClassName); if (modelFields == null) { return new String[0]; } final String[] fieldNames = new String[modelFields.length]; for (int i = 0; i < modelFields.length; i++) { fieldNames[i] = modelFields[i].getName(); } return fieldNames; }
private static ModelField getField( final ProjectDataModelOracle oracle, final String fullyQualifiedClassName, final String fieldName) { final String shortName = getFactNameFromType(oracle, fullyQualifiedClassName); final ModelField[] fields = oracle.getProjectModelFields().get(shortName); if (fields == null) { return null; } for (ModelField modelField : fields) { if (modelField.getName().equals(fieldName)) { return modelField; } } return null; }
/** * Convenience method to get an array of all fully qualified class names available in a project * * @param oracle The DMO representing a project * @return */ public static String[] getFactTypes(final ProjectDataModelOracle oracle) { List<String> packageNames = oracle.getProjectPackageNames(); final Map<String, ModelField[]> modelFields = oracle.getProjectModelFields(); final List<String> types = new ArrayList<String>(); for (String type : modelFields.keySet()) { int beginIndex = type.lastIndexOf('.'); if (beginIndex < 0) { types.add(type); } else { String substring = type.substring(0, beginIndex); if (packageNames.contains(substring)) { types.add(type); } } } Collections.sort(types); return types.toArray(new String[types.size()]); }