Exemplo n.º 1
0
  /**
   * @exception IOException
   * @exception DicomException
   */
  public CEchoRequestCommandMessage() throws DicomException, IOException {

    commandField = MessageServiceElementCommand.C_ECHO_RQ;
    messageID = super.getNextAvailableMessageID();
    int dataSetType = 0x0101; // none

    // NB. The Affected SOP Class UID should have no extra trailing padding, otherwise the
    // SCP may fail and send an A-ABORT :) (Part 5 says one null (not space) is allowed)
    // This is taken care of by the Attribute.write()

    AttributeList list = new AttributeList();
    {
      AttributeTag t = groupLengthTag;
      Attribute a = new UnsignedLongAttribute(t);
      a.addValue(0);
      list.put(t, a);
    }
    {
      AttributeTag t = TagFromName.AffectedSOPClassUID;
      Attribute a = new UniqueIdentifierAttribute(t);
      a.addValue(SOPClass.Verification);
      list.put(t, a);
    }
    {
      AttributeTag t = TagFromName.CommandField;
      Attribute a = new UnsignedShortAttribute(t);
      a.addValue(commandField);
      list.put(t, a);
    }
    {
      AttributeTag t = TagFromName.MessageID;
      Attribute a = new UnsignedShortAttribute(t);
      a.addValue(messageID);
      list.put(t, a);
    }
    {
      AttributeTag t = TagFromName.CommandDataSetType;
      Attribute a = new UnsignedShortAttribute(t);
      a.addValue(dataSetType);
      list.put(t, a);
    }

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    DicomOutputStream dout =
        new DicomOutputStream(
            bout, null /* no meta-header */, TransferSyntax.ImplicitVRLittleEndian);
    list.write(dout);
    bytes = bout.toByteArray();

    groupLength = bytes.length - 12;
    bytes[8] = (byte) groupLength; // little endian
    bytes[9] = (byte) (groupLength >> 8);
    bytes[10] = (byte) (groupLength >> 16);
    bytes[11] = (byte) (groupLength >> 24);
    // System.err.println("CEchoRequestCommandMessage: bytes="+HexDump.dump(bytes));
  }
 CreateCommand(UnicoreInvokeServer is, String requestId) throws Command.Exception {
   super(is);
   this.requestId = requestId;
   String line;
   while ((line = is.readLine()) != null) {
     if (line.trim().equals(CMD_CREATE_END)) {
       terminated = true;
       break;
     } else {
       try {
         StringTokenizer st = new StringTokenizer(line);
         String key = st.nextToken();
         String value = line.substring(key.length());
         list.put(key, value);
       } catch (java.lang.Exception e) {
         Log.printStackTrace(e);
       }
     }
   }
   if (terminated) {
     job = new UnicoreJob(this);
   } else {
     new Command.Exception("the command was not terminated!");
   }
 }
 /**
  * @param list
  * @param parent
  * @exception NumberFormatException
  * @exception DicomException
  */
 void addAttributesFromNodeToList(AttributeList list, Node parent)
     throws NumberFormatException, DicomException {
   if (parent != null) {
     Node node = parent.getFirstChild();
     while (node != null) {
       String elementName = node.getNodeName();
       NamedNodeMap attributes = node.getAttributes();
       if (attributes != null) {
         Node vrNode = attributes.getNamedItem("vr");
         Node groupNode = attributes.getNamedItem("group");
         Node elementNode = attributes.getNamedItem("element");
         if (vrNode != null && groupNode != null && elementNode != null) {
           String vrString = vrNode.getNodeValue();
           String groupString = groupNode.getNodeValue();
           String elementString = elementNode.getNodeValue();
           if (vrString != null && groupString != null && elementString != null) {
             byte[] vr = vrString.getBytes();
             int group = Integer.parseInt(groupString, 16);
             int element = Integer.parseInt(elementString, 16);
             AttributeTag tag = new AttributeTag(group, element);
             if ((group % 2 == 0 && element == 0)
                 || (group == 0x0008 && element == 0x0001)
                 || (group == 0xfffc && element == 0xfffc)) {
               // System.err.println("ignoring group length or length to end or dataset trailing
               // padding "+tag);
             } else {
               if (vrString.equals("SQ")) {
                 SequenceAttribute a = new SequenceAttribute(tag);
                 // System.err.println("Created "+a);
                 if (node.hasChildNodes()) {
                   Node childNode = node.getFirstChild();
                   while (childNode != null) {
                     String childNodeName = childNode.getNodeName();
                     // System.err.println("childNodeName = "+childNodeName);
                     if (childNodeName != null && childNodeName.equals("Item")) {
                       // should check item number, but ignore for now :(
                       // System.err.println("Adding item to sequence");
                       AttributeList itemList = new AttributeList();
                       addAttributesFromNodeToList(itemList, childNode);
                       a.addItem(itemList);
                     }
                     // else may be a #text element in between
                     childNode = childNode.getNextSibling();
                   }
                 }
                 // System.err.println("Sequence Attribute is "+a);
                 list.put(tag, a);
               } else {
                 Attribute a = AttributeFactory.newAttribute(tag, vr);
                 // System.err.println("Created "+a);
                 if (node.hasChildNodes()) {
                   Node childNode = node.getFirstChild();
                   while (childNode != null) {
                     String childNodeName = childNode.getNodeName();
                     // System.err.println("childNodeName = "+childNodeName);
                     if (childNodeName != null && childNodeName.equals("value")) {
                       // should check value number, but ignore for now :(
                       String value = childNode.getTextContent();
                       // System.err.println("Value value = "+value);
                       if (value != null) {
                         value =
                             StringUtilities.removeLeadingOrTrailingWhitespaceOrISOControl(
                                 value); // just in case
                         a.addValue(value);
                       }
                     }
                     // else may be a #text element in between
                     childNode = childNode.getNextSibling();
                   }
                 }
                 // System.err.println("Attribute is "+a);
                 list.put(tag, a);
               }
             }
           }
         }
       }
       node = node.getNextSibling();
     }
   }
 }