コード例 #1
0
  @Override
  public Sample read() throws CommonException, SampleModelSizeException {
    Sample result = null;
    this.checkSize();

    try {
      result = reader.read();
    } catch (CMException e) {
      throw new CommonException(e.getMessage());
    } catch (DataTypeUnsupportedException de) {
      throw new CommonException(de.getMessage());
    }
    if (result != null) {
      boolean added;
      if (structDetail != null) {
        added = this.addSample(result, structDetail);
      } else {
        added = this.addSample(result);
      }

      if (added && (result != null)) {
        this.notifyListeners("data_read");
      }
    } else {
      this.notifyListeners("no_data_available");
    }
    return result;
  }
コード例 #2
0
  protected Topic getTopic() throws CommonException {
    Topic result = null;
    Entity[] entities;
    Entity tmp = null;
    Reader r = reader;
    boolean found = false;

    if (reader instanceof Query) {
      try {
        entities = reader.getDependantEntities(EntityFilter.READER);
      } catch (CMException e) {
        throw new CommonException(e.getMessage());
      }
      if (entities.length == 0) {
        throw new CommonException("Query reader has no source.");
      }
      r = (Reader) entities[0];

      for (int i = 1; i < entities.length; i++) {
        entities[i].free();
      }
    }

    try {
      entities = r.getOwnedEntities(EntityFilter.ENTITY);

      if (reader instanceof Query) {
        r.free();
      }

      for (int i = 0; i < entities.length && !found; i++) {
        tmp = entities[i];

        if (tmp instanceof Topic) {
          found = true;
        }
      }
      for (int i = 0; i < entities.length; i++) {
        if (entities[i] != tmp) {
          entities[i].free();
        }
      }
      if (tmp != null) {
        result = (Topic) tmp;

      } else {
        throw new CommonException("Topic could not be retrieved.");
      }

    } catch (CMException e) {
      throw new CommonException(e.getMessage());
    }

    return result;
  }
コード例 #3
0
ファイル: JniCommunicator.java プロジェクト: xrl/opensplice
  public Sample snapshotTake(Snapshot snapshot)
      throws CommunicationException, DataTypeUnsupportedException {
    Sample s = null;
    this.checkConnection();

    try {
      String xmlSnapshot = snapshotSerializer.serializeSnapshot(snapshot);
      String xmlSample = this.jniSnapshotTake(xmlSnapshot);
      this.checkConnection();
      s = untypedSampleDeserializer.deserializeSample(xmlSample, snapshot.getUserDataType());
    } catch (TransformationException e) {
      throw new CommunicationException("Could not take from snapshot.");
    } catch (CMException ce) {
      throw new CommunicationException(ce.getMessage());
    }
    return s;
  }
コード例 #4
0
ファイル: JniCommunicator.java プロジェクト: xrl/opensplice
  public Sample readerTake(Reader reader)
      throws CommunicationException, DataTypeUnsupportedException {
    Sample result = null;
    this.checkConnection();

    try {
      String xmlEntity = entitySerializer.serializeEntity(reader);
      String xmlSample = this.jniReaderTake(xmlEntity);
      this.checkConnection();
      result = untypedSampleDeserializer.deserializeSample(xmlSample, reader.getDataType());
    } catch (CMException e) {
      throw new CommunicationException(e.getMessage());
    } catch (TransformationException e) {
      throw new CommunicationException("Could not take sample.");
    }
    return result;
  }
コード例 #5
0
  public ReaderSampleModel(Reader _reader, String struct) throws CommonException {
    super();

    structDetail = struct;
    if (_reader == null) {
      throw new CommonException("Supplied reader == null.");
    }
    reader = _reader;
    try {
      userDataModel = new UserDataTableModel(reader.getDataType(), struct);
      singleUserDataModel = new UserDataSingleTableModel(reader.getDataType(), false, struct);
    } catch (CMException e) {
      throw new CommonException(e.getMessage());
    } catch (DataTypeUnsupportedException de) {
      throw new CommonException(de.getMessage());
    }
  }
コード例 #6
0
  /**
   * Constructs the model for the supplied Reader.
   *
   * @param _reader The Reader where data is read/taken from.
   * @throws CMException Thrown when the reader is no longer available or the data type of its
   *     contents cannot be found.
   */
  public ReaderSampleModel(Reader _reader) throws CommonException {
    super();

    if (_reader == null) {
      throw new CommonException("Supplied reader == null.");
    }
    reader = _reader;
    try {
      userDataModel = new UserDataTableModel(reader.getDataType());
      singleUserDataModel = new UserDataSingleTableModel(reader.getDataType(), false);
      this.initiateToBeWrittenUserData(new UserData(reader.getDataType()));
    } catch (CMException e) {
      throw new CommonException(e.getMessage());
    } catch (DataTypeUnsupportedException de) {
      throw new CommonException(de.getMessage());
    }
  }
コード例 #7
0
ファイル: JniCommunicator.java プロジェクト: xrl/opensplice
  public Sample readerReadNext(Reader reader, GID instanceGID)
      throws CommunicationException, DataTypeUnsupportedException {
    Sample result = null;
    this.checkConnection();

    try {
      String xmlEntity = entitySerializer.serializeEntity(reader);
      String xmlSample =
          this.jniReaderReadNext(
              xmlEntity,
              Long.toString(instanceGID.getLocalId()),
              Long.toString(instanceGID.getSystemId()));
      this.checkConnection();
      result = untypedSampleDeserializer.deserializeSample(xmlSample, reader.getDataType());
    } catch (CMException e) {
      throw new CommunicationException(e.getMessage());
    } catch (TransformationException e) {
      throw new CommunicationException("Could not read next sample.");
    }
    return result;
  }
コード例 #8
0
  @Override
  public synchronized int export(File file) throws CommonException {
    Topic top;
    TopicQoS qos;
    QoSSerializer ser;
    OutputStreamWriter fw = null;
    String xmlQos;
    Sample sample;
    SampleSerializer sampleSer;
    int i = 0;

    if (!file.exists()) {
      try {
        file.createNewFile();
      } catch (IOException e1) {
        throw new CommonException("Cannot create file.");
      }
    }
    if ((!file.canRead()) || !(file.canWrite())) {
      throw new CommonException("Cannot open file (insufficient rights).");
    }

    try {
      ser = DataTransformerFactory.getQoSSerializer(DataTransformerFactory.XML);
      sampleSer = DataTransformerFactory.getSampleSerializer(DataTransformerFactory.XML);

      fw = new OutputStreamWriter(new FileOutputStream(file, false), "UTF-8");
      top = this.getTopic();

      qos = (TopicQoS) top.getQoS();
      xmlQos = ser.serializeQoS(qos);

      fw.write("<splice_data><partitions>");
      String parts = this.getPartitions(reader);

      if (parts != null) {
        fw.write(parts);
      }
      fw.write("</partitions><topic><name>");
      fw.write(top.getName());
      fw.write("</name><typeName>");
      fw.write(top.getTypeName());
      fw.write("</typeName><keyList>");

      if (top.getKeyList() != null) {
        fw.write(top.getKeyList());
      }
      fw.write("</keyList><qos>");
      fw.write(xmlQos);
      fw.write("</qos><metadata>");
      fw.write(this.userDataModel.getUserDataType().toXML());
      fw.write("</metadata></topic><data>");

      do {
        sample = userDataModel.getDataAt(i);

        if (sample != null) {
          fw.write(sampleSer.serializeSample(sample));
        }
        i++;
      } while (sample != null);

      fw.write("</data></splice_data>");
      fw.flush();
      fw.close();
    } catch (FileNotFoundException e) {
      throw new CommonException(e.getMessage());
    } catch (IOException ie) {
      throw new CommonException(ie.getMessage());
    } catch (CMException ce) {
      throw new CommonException(ce.getMessage());
    } catch (TransformationException te) {
      throw new CommonException(te.getMessage());
    } finally {
      if (fw != null) {
        try {
          fw.close();
        } catch (IOException ie) {
          throw new CommonException(ie.getMessage());
        }
      }
    }
    return i - 1;
  }