/*
Get the value of the ReplyReliability field from the message header.

Javadoc description supplied by SIBusMessage interface.
436634
@Override
    public final Reliability getReplyReliability() {
        Byte rType = (Byte) getApi().getField(JsApiAccess.REPLYRELIABILITY_VALUE);
        /* If set, return the corresponding Reliability instance */
        return (rType == null) ? null : Reliability.getReliability(rType);
    }
505884
@Override
	public Object evaluate( Message message ) throws JMSException
    {
        // Standard headers
        if (name.equals("JMSCorrelationID"))
            return message.getJMSCorrelationID();
        if (name.equals("JMSMessageID"))
            return message.getJMSMessageID();
        if (name.equals("JMSType"))
            return message.getJMSType();
        if (name.equals("JMSDeliveryMode"))
            return message.getJMSDeliveryMode() == DeliveryMode.PERSISTENT ? "PERSISTENT" : "NON_PERSISTENT";
        if (name.equals("JMSPriority"))
            return Integer.valueOf(message.getJMSPriority());
        if (name.equals("JMSTimestamp"))
            return Long.valueOf(message.getJMSTimestamp());
                
        return message.getObjectProperty(name);
    }
1370405
private static String getViolationInvalidValue(final Object invalidValue) {
        if (invalidValue == null) {
            return null;
        }

        if (invalidValue.getClass().isArray()) {
            if (invalidValue instanceof Object[]) {
                return Arrays.toString((Object[]) invalidValue);
            } else if (invalidValue instanceof boolean[]) {
                return Arrays.toString((boolean[]) invalidValue);
            } else if (invalidValue instanceof byte[]) {
                return Arrays.toString((byte[]) invalidValue);
            } else if (invalidValue instanceof char[]) {
                return Arrays.toString((char[]) invalidValue);
            } else if (invalidValue instanceof double[]) {
                return Arrays.toString((double[]) invalidValue);
            } else if (invalidValue instanceof float[]) {
                return Arrays.toString((float[]) invalidValue);
            } else if (invalidValue instanceof int[]) {
                return Arrays.toString((int[]) invalidValue);
            } else if (invalidValue instanceof long[]) {
                return Arrays.toString((long[]) invalidValue);
            } else if (invalidValue instanceof short[]) {
                return Arrays.toString((short[]) invalidValue);
            }
        }

        return invalidValue.toString();
    }

    /**
     * Get a path to a field causing constraint violations.
     *
     * @param violation constraint violation.
     * @return path to a property that caused constraint violations.
     */
    private static String getViolationPath(final ConstraintViolation violation) {
        final String rootBeanName = violation.getRootBean().getClass().getSimpleName();
        final String propertyPath = violation.getPropertyPath().toString();

        return rootBeanName + (!"".equals(propertyPath) ? '.' + propertyPath : "");
    }

    /**
     * Determine the response status (400 or 500) from the given BV exception.
     *
     * @param violation BV exception.
     * @return response status (400 or 500).
     */
    public static Response.Status getResponseStatus(final ConstraintViolationException violation) {
        final Iterator<ConstraintViolation<?>> iterator = violation.getConstraintViolations().iterator();

        if (iterator.hasNext()) {
            for (final Path.Node node : iterator.next().getPropertyPath()) {
                final ElementKind kind = node.getKind();

                if (ElementKind.RETURN_VALUE.equals(kind)) {
                    return Response.Status.INTERNAL_SERVER_ERROR;
                }
            }
        }

        return Response.Status.BAD_REQUEST;
    }
}
549286
public Integer getReplyCode() {
        Object replyCode = getHeader(FtpMessageHeaders.FTP_REPLY_CODE);

        if (replyCode != null) {
            if (replyCode instanceof Integer) {
                return (Integer) replyCode;
            } else {
                return Integer.valueOf(replyCode.toString());
            }
        } else if (commandResult != null) {
            return Optional.ofNullable(commandResult.getReplyCode()).map(Integer::valueOf).orElse(FTPReply.COMMAND_OK);
        }

        return null;
    }
155152
private ISFSObject getMessage() {
        if(messageObject != null) {
            MessageParamsClass clazz = context.getMessageParamsClass(messageObject.getClass());
            if(clazz != null) 
                return new ResponseParamSerializer().object2params(clazz.getUnwrapper(), messageObject);
        }
        if(jsonMessage != null)
            return SFSObject.newFromJsonData(jsonMessage);
        if(messageString == null)
            return new SFSObject();
        ISFSObject answer = new SFSObject();
        answer.putUtfString(APIKey.MESSAGE, messageString);
        return answer;
            
    }
266729
static Reliability lookupReliability(String name) throws JMSException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "lookupReliability", name);
    Reliability result;

    // map asSIBDest -> NONE
    if (ApiJmsConstants.MAPPING_AS_SIB_DESTINATION.equals(name)) {
      result = Reliability.NONE;
    }
    else {
      try {
        result = Reliability.getReliabilityByName(name);
      }
      catch (Exception e) {
        // No FFDC code needed
        throw (JMSException) JmsErrorUtils.newThrowable(
          JMSException.class,
          "INVALID_VALUE_CWSIA0301",
          new Object[] { "quality of service", name },
          tc);
      }
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "lookupReliability",  result);
    return result;
  }
496943
@Override
    public final void setReplyReliability(Reliability value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setReplyReliability", value);
        if (value != null) {
            /* Get the int value of the Reliability instance and set it in the field */
            getApi().setField(JsApiAccess.REPLYRELIABILITY_VALUE, value.toByte());
        }
        else {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "setReplyReliability", "NullPointerException");
            throw new NullPointerException();
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setReplyReliability");
    }
1339679
public Reliability getReliability() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "getReliability");
        Reliability r = msg.getReliability();
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "getReliablity", r);
        return r;
    }
833123
private static Optional<String> getMethodReturnValueName(ConstraintViolation<?> violation) {
        int returnValueNames = -1;

        final StringBuilder result = new StringBuilder("server response");
        for (Path.Node node : violation.getPropertyPath()) {
            if (node.getKind().equals(ElementKind.RETURN_VALUE)) {
                returnValueNames = 0;
            } else if (returnValueNames >= 0) {
                result.append(returnValueNames++ == 0 ? " " : ".").append(node);
            }
        }

        return returnValueNames >= 0 ? Optional.of(result.toString()) : Optional.empty();
    }
473382
@Override
    public Object getIdentifierValue(Identifier id,
                                     boolean ignoreType)
                    throws BadMessageFormatMatchingException {
        return getIdentifierValue(id, ignoreType, null, false);
    }
468803
Object getValue(
    MatchSpaceKey msg,
    Object contextValue)
    throws MatchingException, BadMessageFormatMatchingException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      tc.entry(
        cclass,
        "getValue",
        "msg: " + msg + "contextValue: " + contextValue);
    
    // The value which we'll return    
    SetValEvaluationContext xpEval = null;
  
    // May need to call MFP multiple times, if our context has multiple nodes
    if(contextValue != null)
    {
      // Currently this must be a list of nodes
      if (contextValue instanceof SetValEvaluationContext)
      {
        SetValEvaluationContext evalContext = (SetValEvaluationContext)contextValue;

        // Get the node list
        ArrayList wrappedParentList = evalContext.getWrappedNodeList();
        
        // If the list is empty, then we have yet to get the document root
        if(wrappedParentList.isEmpty())
        {
    	    //Set up a root (document) context for evaluation
        	Object docRoot = Matching.getEvaluator().getDocumentRoot(msg);
            
          // Create an object to hold the wrapped node
          WrappedNodeResults wrapper = new WrappedNodeResults(docRoot);
          // Set the root into the evaluation context
          evalContext.addNode(wrapper);
        }
        
        // Iterate over the nodes        
        Iterator iter = wrappedParentList.iterator();

        while(iter.hasNext())
        {
          WrappedNodeResults nextWrappedParentNode = (WrappedNodeResults)iter.next();       
          Object nextParentNode = nextWrappedParentNode.getNode();
          
          String debugString = "";
          if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            tc.debug(this,cclass, "getValue", "Evaluation context node: " + nextWrappedParentNode); 
          
          ArrayList wrappedChildList = nextWrappedParentNode.getEvalListResult(id.getName());
            
          // If not cached we'll need to go to MFP
          if(wrappedChildList == null)
          {
            // Call MFP to get the results for this node
            ArrayList nodeList = 
              (ArrayList) msg.getIdentifierValue(id,
                                                 false,
                                                 nextParentNode, 
                                                 true); // true means return a nodelist
            wrappedChildList = new ArrayList();
            
            if(nodeList != null)
            {
              Iterator iterNode = nodeList.iterator();
              
              while(iterNode.hasNext())
              {
                Object theNode = (Object)iterNode.next();

                // Create an object to hold the wrapped node
                WrappedNodeResults wrapper = new WrappedNodeResults(theNode);
                wrappedChildList.add(wrapper); 
              }              
            }
            // Add result to cache for next time
            nextWrappedParentNode.addEvalListResult(id.getName(), wrappedChildList);
            
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
              debugString = "Result from MFP ";
          }
          else
          {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
              debugString = "Result from Cache ";
          }

          // Useful debug
          if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
          {
            Iterator iterDebug = wrappedChildList.iterator();
            String asString = ", type: List - ";
            while(iterDebug.hasNext())
            {
              WrappedNodeResults wrapper = (WrappedNodeResults)iterDebug.next();
              asString = asString + "<" + wrapper + ">"; 
            }
            tc.debug(this,cclass, "getValue", debugString + "for identifier " + id.getName() + asString);
          }          
          
          if(!wrappedChildList.isEmpty())
          {
            // Build the return value as an XPathEvaluationContext
            if(xpEval == null)
              xpEval = new SetValEvaluationContext();
  
            // Add the wrapped node to the result
            xpEval.addWrappedNodeList(wrappedChildList);                      
          } 
        } // eof while
      } // eof instanceof XPathEvaluationContext
    }
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      tc.exit(this,cclass, "getValue", xpEval);
    
    return xpEval;
  }
532963
public Reliability getReliability()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) 
      SibTr.entry(tc, "getReliability");
    Reliability rel =  _sourceStream.getReliability();
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) 
      SibTr.exit(tc, "getReliability", rel);    
    return rel;
  }
414517
public String getResponseHeaderValue(String name, String defaultVal) {
        if (m_response.containsHeader(name)) {
            return m_response.getFirstHeader(name).getValue();
        } else {
            return defaultVal;
        }
    }
199587
public final Reliability getReliability() {
    /* Get the byte value and get the corresponding Reliability instance       */
    Byte rType = (Byte)jmo.getField(ControlAccess.RELIABILITY);
    return Reliability.getReliability(rType);
  }
238001
@Override
    public Reliability getDefaultReliability()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "getDefaultReliability");

        Reliability rel = _definition.getDefaultReliability();

        // A reliability of NONE signals use target value.
        if (rel.equals(Reliability.NONE))
        {
            rel = getTarget().getDefaultReliability();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "getDefaultReliability", rel);

        return rel;
    }
998699
public void setReliability(Reliability value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setReliability", value);
        /* Set the cached value */
        cachedReliability = value;
        /* Get the int value of the Reliability instance and set it in the field */
        getHdr2().setField(JsHdr2Access.RELIABILITY, value.toByte());
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setReliability");
    }
34157
@Override
    public final byte[] getApiMessageIdAsBytes() {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "getApiMessageIdAsBytes");

        byte[] value = (byte[]) getApi().getField(JsApiAccess.MESSAGEID);
        if (value != null) {
            byte[] copy = new byte[value.length];
            System.arraycopy(value, 0, copy, 0, value.length);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "getApiMessageIdAsBytes", copy);
            return copy;
        }
        else {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "getApiMessageIdAsBytes", null);
            return null;
        }
    }