001/*
002  GRANITE DATA SERVICES
003  Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004
005  This file is part of Granite Data Services.
006
007  Granite Data Services is free software; you can redistribute it and/or modify
008  it under the terms of the GNU Library General Public License as published by
009  the Free Software Foundation; either version 2 of the License, or (at your
010  option) any later version.
011
012  Granite Data Services is distributed in the hope that it will be useful, but
013  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015  for more details.
016
017  You should have received a copy of the GNU Library General Public License
018  along with this library; if not, see <http://www.gnu.org/licenses/>.
019*/
020
021package org.granite.tide.invocation;
022
023import java.io.Serializable;
024
025
026/**
027 * @author William DRAI
028 */
029public class ContextUpdate implements Serializable {
030
031    private static final long serialVersionUID = 1L;
032    
033    
034    private String componentName;
035    private String componentClassName;
036    private String expression;
037    private Object value;
038    private int scope;
039    private boolean restrict;
040    
041    
042    public ContextUpdate() {
043    }
044    
045    public ContextUpdate(String componentName, String expression, Object value, int scope, boolean restrict) {
046        this.componentName = componentName;
047        this.expression = expression;
048        this.value = value;
049        this.scope = scope;
050        this.restrict = restrict;
051    }
052
053    public String getComponentName() {
054        return componentName;
055    }
056    public void setComponentName(String componentName) {
057        this.componentName = componentName;
058    }
059    
060    public String getComponentClassName() {
061        return componentClassName;
062    }
063    public void setComponentClassName(String componentClassName) {
064        this.componentClassName = componentClassName;
065    }
066    
067    private Class<?> componentClass;
068    
069    public Class<?> getComponentClass() {
070        if (componentClassName == null)
071                return null;
072        
073        if (componentClass == null) {
074                try {
075                        componentClass = Thread.currentThread().getContextClassLoader().loadClass(componentClassName);
076                }
077                catch (Exception e) {
078                        throw new RuntimeException("Component class not found", e);
079                }
080        }
081        return componentClass;      
082    }
083    
084    public String getExpression() {
085        return expression;
086    }
087    public void setExpression(String expression) {
088        this.expression = expression;
089    }
090
091    public Object getValue() {
092        return value;
093    }
094    public void setValue(Object value) {
095        this.value = value;
096    }
097    
098    public int getScope() {
099        return scope;
100    }
101    public void setScope(int scope) {
102        this.scope = scope;
103    }
104    
105    public boolean getRestrict() {
106        return restrict;
107    }
108    public void setRestrict(boolean restrict) {
109        this.restrict = restrict;
110    }
111
112    
113    @Override
114    public String toString() {
115        return componentName 
116                + (componentClassName != null ? "(" + componentClassName + ")" : "") 
117                + (expression != null ? "." + expression : "")
118                + (scope == 1 ? " (SESSION)" : (scope == 2 ? " (CONVERSATION)" : "")) 
119                + (restrict ? " (restricted)" :"");
120    }
121}