Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kie.remote.services.jaxb;
  
  import java.util.List;
  import java.util.Map;
  
 
 import  org.drools.core.common.DefaultFactHandle;
 import  org.jbpm.process.audit.NodeInstanceLog;
 import  org.jbpm.process.audit.ProcessInstanceLog;
 import  org.jbpm.process.audit.VariableInstanceLog;
 import  org.jbpm.process.audit.event.AuditEvent;
 import  org.jbpm.services.task.commands.GetTaskContentCommand;
 import  org.jbpm.services.task.impl.model.xml.JaxbContent;
 import  org.jbpm.services.task.impl.model.xml.JaxbTask;
 import  org.kie.api.command.Command;
 import  org.kie.api.runtime.process.ProcessInstance;
 import  org.kie.api.runtime.process.WorkItem;
 import  org.kie.api.task.model.TaskSummary;
 import  org.kie.services.client.serialization.jaxb.impl.JaxbCommandResponse;
 import  org.kie.services.client.serialization.jaxb.impl.JaxbLongListResponse;
 import  org.kie.services.client.serialization.jaxb.impl.JaxbOtherResponse;
 import  org.kie.services.client.serialization.jaxb.impl.JaxbPrimitiveResponse;
 import  org.kie.services.client.serialization.jaxb.impl.JaxbRequestStatus;
 import  org.kie.services.client.serialization.jaxb.impl.JaxbStringListResponse;
 import  org.kie.services.client.serialization.jaxb.impl.JaxbVariablesResponse;
 import  org.kie.services.client.serialization.jaxb.impl.audit.JaxbHistoryLogList;
 import  org.kie.services.client.serialization.jaxb.impl.audit.JaxbNodeInstanceLog;
 import  org.kie.services.client.serialization.jaxb.impl.audit.JaxbProcessInstanceLog;
 import  org.kie.services.client.serialization.jaxb.impl.audit.JaxbVariableInstanceLog;
 import  org.kie.services.client.serialization.jaxb.impl.process.JaxbProcessInstanceListResponse;
 import  org.kie.services.client.serialization.jaxb.impl.process.JaxbProcessInstanceResponse;
 import  org.kie.services.client.serialization.jaxb.impl.process.JaxbWorkItemResponse;
 import  org.kie.services.client.serialization.jaxb.impl.task.JaxbTaskContentResponse;
 import  org.kie.services.client.serialization.jaxb.rest.JaxbExceptionResponse;
 
 @XmlRootElement(name = "command-response")
 @SuppressWarnings("rawtypes")
 public class JaxbCommandsResponse {
 
     @XmlElement(name = "deployment-id")
     @XmlSchemaType(name = "string")
     private String deploymentId;
 
     @XmlElement(name = "process-instance-id")
     @XmlSchemaType(name = "long")
     private Long processInstanceId;
 
     @XmlElement(name = "ver")
     @XmlSchemaType(name = "string")
     private String version;
 
     @XmlElements({ 
             @XmlElement(name = "exception", type = JaxbExceptionResponse.class),
             @XmlElement(name = "long-list", type = JaxbLongListResponse.class),
             @XmlElement(name = "string-list", type = JaxbStringListResponse.class),
             @XmlElement(name = "primitive", type = JaxbPrimitiveResponse.class),
             @XmlElement(name = "process-instance", type = JaxbProcessInstanceResponse.class),
             @XmlElement(name = "process-instance-list", type = JaxbProcessInstanceListResponse.class),
             @XmlElement(name = "task-response", type = JaxbTaskResponse.class),
             @XmlElement(name = "content-response", type = JaxbContentResponse.class ),
             @XmlElement(name = "task-content-response", type = JaxbTaskContentResponse.class ),
             @XmlElement(name = "task-summary-list", type = JaxbTaskSummaryListResponse.class),
             @XmlElement(name = "work-item", type = JaxbWorkItemResponse.class),
             @XmlElement(name = "variables", type = JaxbVariablesResponse.class),
             @XmlElement(name = "other", type = JaxbOtherResponse.class),
             @XmlElement(name = "history-log-list", type = JaxbHistoryLogList.class),
             @XmlElement(name = "proc-inst-log", type = JaxbProcessInstanceLog.class),
             @XmlElement(name = "node-inst-log", type = JaxbNodeInstanceLog.class),
             @XmlElement(name = "var-inst-log", type = JaxbVariableInstanceLog.class)
             })
     private List<JaxbCommandResponse<?>> responses;
 
     public JaxbCommandsResponse() {
         // Default constructor
     }
 
     public JaxbCommandsResponse(JaxbCommandsRequest request) {
         super();
         this. = request.getDeploymentId();
         this. = request.getProcessInstanceId();
     }
 
     public String getDeploymentId() {
         return ;
     }
 
     public void setDeploymentId(String deploymentId) {
         this. = deploymentId;
    }
    public Long getProcessInstanceId() {
        return ;
    }
    public void setProcessInstanceId(Long processInstanceId) {
        this. = processInstanceId;
    }
    public String getVersion() {
        return ;
    }
    public void setVersion(String version) {
        this. = version;
    }
    private void lazyInitResponseList() { 
        ifthis. == null ) { 
            this. = new ArrayList<JaxbCommandResponse<?>>();
        }
    }
    public List<JaxbCommandResponse<?>> getResponses() {
        lazyInitResponseList();
        return ;
    }
    public void setResponses(List<JaxbCommandResponse<?>> responses) {
        this. = responses;
    }
    public void addException(Exception exceptionint i, Command<?> cmd, JaxbRequestStatus status) {
        lazyInitResponseList();
        this..add(new JaxbExceptionResponse(exceptionicmdstatus));
    }
    @SuppressWarnings("unchecked")
    public void addResult(Object resultint i, Command<?> cmd) {
        lazyInitResponseList();
        boolean unknownResultType = false;
        
        String className = result.getClass().getName();
        if (result instanceof ProcessInstance) {
            this..add(new JaxbProcessInstanceResponse((ProcessInstance) resulticmd));
        } else if (result instanceof JaxbTask) {
            this..add(new JaxbTaskResponse((JaxbTask) resulticmd));
        } else if (result instanceof JaxbContent) {
            if (((JaxbContent) result).getId() == -1) {
                this..add(new JaxbTaskContentResponse(((JaxbContent) result).getContentMap(), icmd));
            } else {
                this..add(new JaxbContentResponse((JaxbContent) resulticmd));
            }
        } else if (List.class.isInstance(result)) { 
            // Neccessary to determine return type of empty lists
            Class listType = getListType(cmd);
            iflistType == null ) { 
                unknownResultType = true;
            } else iflistType.equals(TaskSummary.class) ) { 
                this..add(new JaxbTaskSummaryListResponse((List<TaskSummary>) resulticmd));
            } else iflistType.equals(Long.class) ) {
                this..add(new JaxbLongListResponse((List<Long>)resulticmd));
            } else iflistType.equals(String.class) ) {
                this..add(new JaxbStringListResponse((List<String>)resulticmd));
            } else iflistType.equals(ProcessInstance.class) ) {
               this..add(new JaxbProcessInstanceListResponse((List<ProcessInstance>) resulticmd));
            } else iflistType.equals(ProcessInstanceLog.class
                    || listType.equals(NodeInstanceLog.class)
                    || listType.equals(VariableInstanceLog.class) ) {
                this..add(new JaxbHistoryLogList((List<AuditEvent>) result));
            } else { 
                throw new IllegalStateException(listType.getSimpleName() + " should be handled but is not in " + this.getClass().getSimpleName() + "!" );
            }
        } else if (result.getClass().isPrimitive() 
        		|| Boolean.class.getName().equals(className)
        		|| Byte.class.getName().equals(className)
        		|| Short.class.getName().equals(className)
        		|| Integer.class.getName().equals(className)
        		|| Character.class.getName().equals(className)
        		|| Long.class.getName().equals(className)
        		|| Float.class.getName().equals(className)
        		|| Double.class.getName().equals(className) ) {
            this..add(new JaxbPrimitiveResponse(resulticmd));
        } else ifresult instanceof WorkItem ) { 
           this..add(new JaxbWorkItemResponse((WorkItem) resulticmd));
        } else ifresult instanceof ProcessInstanceLog ) { 
            this..add(new JaxbProcessInstanceLog((ProcessInstanceLog) result));
        } else ifresult instanceof NodeInstanceLog ) { 
            this..add(new JaxbNodeInstanceLog((NodeInstanceLog) result));
        } else ifresult instanceof VariableInstanceLog ) { 
            this..add(new JaxbVariableInstanceLog((VariableInstanceLog) result));
        } else ifresult instanceof DefaultFactHandle ) { 
           this..add(new JaxbOtherResponse(resulticmd));
        } else ifcmd instanceof GetTaskContentCommand ) { 
           this..add(new JaxbTaskContentResponse((Map<StringObject>) resulticmd));
        }
        // Other
        else ifresult instanceof JaxbExceptionResponse ) { 
           this..add((JaxbExceptionResponse) result);
        } else {
            unknownResultType = true;
        }
        
        if (unknownResultType) {
            ..printlnthis.getClass().getSimpleName() + ": unknown result type " + result.getClass().getSimpleName() 
                    + " from command " + cmd.getClass().getSimpleName() + " added.");
        }
    }
    static Class getListType( Command cmd ) {
        Class cmdClass = cmd.getClass();
        Type genSuper = cmdClass.getGenericSuperclass();
        ifgenSuper != null ) {
            ifgenSuper instanceof ParameterizedType ) {
                return getClassFromParameterizedListCmd(genSupercmdClass);
            }
        }
        Type [] genInts = cmdClass.getGenericInterfaces();
        ifgenInts.length > 0 ) { 
           ifgenInts[0] instanceof ParameterizedType ) { 
                return getClassFromParameterizedListCmd(genInts[0], cmdClass);
           }
        }
        throw new IllegalStateException("No list type could be found for " + cmd.getClass().getSimpleName() );
    }
    
    private static Class getClassFromParameterizedListCmd(Type genericIntOrSuperClass cmdClass) { 
        Type[] listTypes = ((ParameterizedTypegenericIntOrSuper).getActualTypeArguments();
        iflistTypes.length > 0 ) {
            iflistTypes[0] instanceof ParameterizedType ) {
                Type rawType = ((ParameterizedTypelistTypes[0]).getRawType();
                ifCollection.class.isAssignableFrom((ClassrawType) ) { 
                    Type[] returnTypeParamTypes = ((ParameterizedTypelistTypes[0]).getActualTypeArguments();
                    ifreturnTypeParamTypes.length > 0 ) {
                        return (ClassreturnTypeParamTypes[0];
                    }
                } 
            } 
        }
        throw new IllegalStateException("No list type could be found for " + cmdClass.getSimpleName() );
    }
New to GrepCode? Check out our FAQ X