/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
//
/**
*
* @author Xiping Change Log: 3/9/07: Neeraj Joshi: Changed signature to take a
* list of expressions and boolean This will help in reflection
*
*/
package org.apache.imperius.spl.parser.expressions.impl;
import java.util.List;
import java.util.logging.Logger;
import org.apache.imperius.spl.core.Expression;
import org.apache.imperius.spl.core.TypeInfo;
import org.apache.imperius.spl.parser.exceptions.SPLException;
import org.apache.imperius.spl.parser.exceptions.TypesNotAssignableException;
import org.apache.imperius.spl.parser.expressions.DoubleArgumentExpression;
import org.apache.imperius.spl.parser.util.TypeResolver;
import org.apache.imperius.util.Messages;
import org.apache.imperius.util.SPLLogger;
public class AssignmentExpression extends DoubleArgumentExpression
{
private static Logger logger = SPLLogger.getSPLLogger().getLogger();
private static final String sourceClass="AssignmentExpression";
public AssignmentExpression(List exprList, boolean evaluateExpression)
throws SPLException
{
super(exprList);
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "AssignmentExpression");
validate();
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AssignmentExpression");
}
public Object evaluate() throws SPLException
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
Object rhsResult = _rhsExp.evaluate();
// code to insert rhs into the symbol table
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
return rhsResult;
}
// @Override
public TypeInfo getType()
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
return _dataType;
}
// @Override
public boolean validate() throws SPLException
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
TypeInfo lType = _lhsExp.getType();
TypeInfo rType = _rhsExp.getType();
if (!TypeResolver.isTypeAssignableForEquality(lType, rType))
{
logger.severe(Thread.currentThread().getName()+" "+"Types not compatible");
throw new TypesNotAssignableException(Messages.getString(
"SPL_TYPE_NOT_COMPATIBLE_EXCEPTION_MSG", new Object[] {
lType, rType }));
}
_dataType.copy(rType);
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
return true;
}
public Expression getLHSExpression() throws SPLException
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getLHSExpression");
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getLHSExpression");
return this._lhsExp;
}
public Expression getRHSExpression() throws SPLException
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getRHSExpression");
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getRHSExpression");
return this._rhsExp;
}
public String toString()
{
logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
String str = this._lhsExp.toString() + " = " + this._rhsExp.toString();
logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
return str;
}
}