/*
 * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.

 * Author: Konstantin Krivopustov
 * Created: 13.11.2008 11:13:41
 *
 * $Id$
 */
package com.haulmont.cuba.core.global;

import com.haulmont.cuba.core.entity.BaseEntity;
import com.haulmont.chile.core.model.MetaClass;

import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;

public class BasicInvocationContext implements Serializable
{
    private Object id;

    private MetaClass metaClass;
    private View view;
    private Query query;

    public class Query {
        private Map<String, Object> parameters = new HashMap<String, Object>();
        private String queryString;

        public Query(String queryString) {
            this.queryString = queryString;
        }

        public void addParameter(String name, Object value) {
            parameters.put(name, value);
        }

        public String getQueryString() {
            return queryString;
        }

        public Map<String, Object> getParameters() {
            return parameters;
        }

        public void setParameters(Map<String, Object> parameters) {
            this.parameters.putAll(parameters);
        }
    }

    public MetaClass getMetaClass() {
        return metaClass;
    }

    public BasicInvocationContext setEntityClass(Class<? extends BaseEntity> entityClass) {
        this.metaClass = MetadataProvider.getSession().getClass(entityClass);
        return this;
    }

    public BasicInvocationContext setEntityClass(MetaClass entityClass) {
        this.metaClass = entityClass;
        return this;
    }

    public Object getId() {
        return id;
    }

    public BasicInvocationContext setId(Object id) {
        this.id = id;
        return this;
    }

    public Query getQuery() {
        return query;
    }

    public void setQuery(Query query) {
        this.query = query;
    }

    public Query setQueryString(String queryString) {
        final Query query = new Query(queryString);
        setQuery(query);
        return query;
    }

    public View getView() {
        return view;
    }

    public BasicInvocationContext setView(View view) {
        this.view = view;
        return this;
    }
}

@@ -572,25 +572,22 @@
 private 
-MetaClass
+String
  metaCla
@@ -666,16 +666,40 @@
 s Query 
+implements Serializable 
 %7B%0D%0A     
@@ -1412,16 +1412,55 @@
  return 
+MetadataProvider.getSession().getClass(
 metaClas
@@ -1456,24 +1456,25 @@
 ss(metaClass
+)
 ;%0D%0A    %7D%0D%0A%0D%0A
@@ -1638,24 +1638,34 @@
 entityClass)
+.getName()
 ;%0D%0A        r
@@ -1753,32 +1753,32 @@
 entityClass) %7B%0D%0A
-
         this.met
@@ -1793,24 +1793,34 @@
  entityClass
+.getName()
 ;%0D%0A        r

replace reference to metaclass at BasicInvocationContext by class name