Пример #1
0
  private Signature(Object o) throws SignatureException {
    final ObjectFactory factory = GlobalObjectFactory.createElementsObjectFactory();
    this.subject = o;

    if (this.subject instanceof TCancNFe) {
      this.referenceUri = "#" + ((TCancNFe) this.subject).getInfCanc().getId();
      this.document = XmlTransformer.jaxbToDocument(factory.createCancNFe((TCancNFe) this.subject));

    } else if (this.subject instanceof TInutNFe) {
      this.referenceUri = "#" + ((TInutNFe) this.subject).getInfInut().getId();
      this.document = XmlTransformer.jaxbToDocument(factory.createInutNFe((TInutNFe) this.subject));

    } else if (this.subject instanceof TNFe) {
      this.referenceUri = "#" + ((TNFe) this.subject).getInfNFe().getId();
      this.document = XmlTransformer.jaxbToDocument(factory.createNFe((TNFe) this.subject));

    } else {
      throw new SignatureException(
          "Tipo incompat\u00edvel. Esperado um dos seguintes tipos: "
              + TCancNFe.class.getSimpleName()
              + ", "
              + TInutNFe.class.getSimpleName()
              + " ou "
              + TNFe.class.getSimpleName());
    }

    // Verifica se a referencia e valida (nao apenas '#').
    if ("#".equals(this.referenceUri)) {
      throw new SignatureException(
          "A refer\u00eancia est\u00e1 incompleta. Verifique se o ID do objeto possui um valor v\u00e1lido. No caso da NFe, lembre-se de gerar a chave de acesso.");
    }
  }