use of com.linkedin.restli.restspec.RestSpecCodec in project rest.li by linkedin.
the class ResourceSchemaCollection method createFromIdls.
/**
* Create {@link ResourceSchemaCollection} from idl files.
*
* @param restspecSearchPaths file system paths to search for idl files
* @return constructed ResourceSchemaCollection
*/
public static ResourceSchemaCollection createFromIdls(String[] restspecSearchPaths) {
final RestSpecCodec codec = new RestSpecCodec();
final Map<String, ResourceSchema> resourceSchemaMap = new HashMap<String, ResourceSchema>();
for (String path : restspecSearchPaths) {
final File dir = new File(path);
if (!dir.isDirectory()) {
throw new IllegalArgumentException(String.format("path '%s' is not a directory", dir.getAbsolutePath()));
}
final File[] idlFiles = dir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.getName().endsWith(RestConstants.RESOURCE_MODEL_FILENAME_EXTENSION);
}
});
for (File idlFile : idlFiles) {
try {
final FileInputStream is = new FileInputStream(idlFile);
final ResourceSchema resourceSchema = codec.readResourceSchema(is);
resourceSchemaMap.put(resourceSchema.getName(), resourceSchema);
} catch (IOException e) {
throw new RestLiInternalException(String.format("Error loading restspec IDL file '%s'", idlFile.getName()), e);
}
}
}
return new ResourceSchemaCollection(resourceSchemaMap);
}
Aggregations