示例#1
0
 public ClueminerReader() {
   providers = new LinkedHashMap<String, WorkspacePersistenceProvider>();
   for (WorkspacePersistenceProvider w :
       Lookup.getDefault().lookupAll(WorkspacePersistenceProvider.class)) {
     try {
       String id = w.getIdentifier();
       if (id != null && !id.isEmpty()) {
         providers.put(w.getIdentifier(), w);
       }
     } catch (Exception e) {
     }
   }
 }
示例#2
0
  public Workspace readWorkspace(XMLStreamReader reader) throws Exception {
    WorkspaceImpl workspace =
        project.getLookup().lookup(WorkspaceProviderImpl.class).newWorkspace();
    WorkspaceInformationImpl info = workspace.getLookup().lookup(WorkspaceInformationImpl.class);

    // Name
    info.setName(reader.getAttributeValue(null, "name"));

    // Status
    String workspaceStatus = reader.getAttributeValue(null, "status");
    if (workspaceStatus.equals("open")) {
      info.open();
    } else if (workspaceStatus.equals("closed")) {
      info.close();
    } else {
      info.invalid();
    }

    // Hack to set this workspace active, when readers need to use attributes for instance
    ProjectControllerImpl pc = Lookup.getDefault().lookup(ProjectControllerImpl.class);
    pc.setTemporaryOpeningWorkspace(workspace);

    // WorkspacePersistent
    readWorkspaceChildren(workspace, reader);
    if (currentProvider != null) {
      // One provider not correctly closed
      throw new ClueminerFormatException(
          "The '" + currentProvider.getIdentifier() + "' persistence provider is not ending read.");
    }
    pc.setTemporaryOpeningWorkspace(null);

    return workspace;
  }
示例#3
0
 public void readWorkspaceChildren(Workspace workspace, XMLStreamReader reader) throws Exception {
   boolean end = false;
   while (reader.hasNext() && !end) {
     Integer eventType = reader.next();
     if (eventType.equals(XMLEvent.START_ELEMENT)) {
       String name = reader.getLocalName();
       WorkspacePersistenceProvider pp = providers.get(name);
       if (pp != null) {
         currentProvider = pp;
         try {
           pp.readXML(reader, workspace);
         } catch (UnsupportedOperationException e) {
         }
       }
     } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
       if ("workspace".equalsIgnoreCase(reader.getLocalName())) {
         end = true;
         currentProvider = null;
       }
     }
   }
 }