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; }
// AsyncPackageDataModelOracle.getFactNameFromType() uses THIS to determine the simple Type from a // FQCN. // Therefore ensure we provide this minimal information for every Type in the DMO to prevent // getFactNameFromType() // needing a callback to the server which makes things more complicated than really needed. private static ModelField[] makeLazyProxyModelField(final ModelField[] modelFields) { for (ModelField modelField : modelFields) { if (DataType.TYPE_THIS.equals(modelField.getName())) { final ModelField[] result = new ModelField[1]; // LazyModelField is a place-holder to tell AsyncPackageDataModelOracle that it needs to // load more information result[0] = new LazyModelField( modelField.getName(), modelField.getClassName(), modelField.getClassType(), modelField.getOrigin(), modelField.getAccessorsAndMutators(), modelField.getType()); return result; } } return null; }
/** * Returns fact's name from type * * @param type for example org.test.Person or Person * @return Shorter type name Person, not org.test.Person */ @Override public String getFactNameFromType(final String type) { if (type == null || type.isEmpty()) { return null; } if (filteredModelFields.containsKey(type)) { return type; } for (Map.Entry<String, ModelField[]> entry : filteredModelFields.entrySet()) { for (ModelField mf : entry.getValue()) { if (DataType.TYPE_THIS.equals(mf.getName()) && type.equals(mf.getClassName())) { return entry.getKey(); } } } final String fgcnByFactName = getFQCNByFactName(type); if (projectModelFields.containsKey(fgcnByFactName)) { return AsyncPackageDataModelOracleUtilities.getTypeName(fgcnByFactName); } return null; }