/**
  * Loads the named objects from a zip file, using the prepared map from names to zip entries.
  * Returns a map from names to {@link AspectGraph}s.
  *
  * @param file the file to read from
  * @param graphs the mapping from object names to zip entries
  */
 private Map<String, AspectGraph> loadObjects(
     ResourceKind kind, ZipFile file, Map<String, ZipEntry> graphs) throws IOException {
   FileType filter = kind.getFileType();
   Map<String, AspectGraph> result = new HashMap<String, AspectGraph>();
   for (Map.Entry<String, ZipEntry> graphEntry : graphs.entrySet()) {
     String graphName = filter.stripExtension(graphEntry.getKey());
     InputStream in = file.getInputStream(graphEntry.getValue());
     try {
       AttrGraph xmlGraph = GxlIO.instance().loadGraph(in);
       /*
        * For backward compatibility, we set the role and name of the
        * graph.
        */
       xmlGraph.setRole(kind.getGraphRole());
       xmlGraph.setName(createQualName(graphName).toString());
       addLayout(file, graphEntry.getKey(), xmlGraph);
       AspectGraph graph = xmlGraph.toAspectGraph();
       /* Store the graph */
       result.put(graphName, graph);
     } catch (FormatException exc) {
       throw new IOException(
           String.format("Format error while loading '%s':\n%s", graphName, exc.getMessage()),
           exc);
     } catch (IOException exc) {
       throw new IOException(
           String.format("Error while loading '%s':\n%s", graphName, exc.getMessage()), exc);
     }
   }
   return result;
 }
예제 #2
0
 @Override
 public Set<Resource> doImport(File file, FileType fileType, GrammarModel grammar)
     throws PortException {
   Set<Resource> resources;
   try {
     FileInputStream stream = new FileInputStream(file);
     resources = doImport(fileType.stripExtension(file.getName()), stream, fileType, grammar);
     stream.close();
   } catch (IOException e) {
     throw new PortException(e);
   }
   return resources;
 }