001 /*
002 // $Id: PropertyValueNode.java 243 2009-05-22 07:21:37Z jhyde $
003 // This software is subject to the terms of the Eclipse Public License v1.0
004 // Agreement, available at the following URL:
005 // http://www.eclipse.org/legal/epl-v10.html.
006 // Copyright (C) 2007-2008 Julian Hyde
007 // All Rights Reserved.
008 // You must accept the terms of that agreement to use this software.
009 */
010 package org.olap4j.mdx;
011
012 import org.olap4j.type.Type;
013
014 /**
015 * Parse tree node representing a property-value pair.
016 *
017 * <p>Property-value pairs are used to define properties of calculated members.
018 * For example, in
019 *
020 * <blockquote>
021 * <code>WITH MEMBER [Measures].[Foo] AS ' [Measures].[Unit Sales] ',<br/>
022 * FORMAT_STRING = 'Bold',<br/>
023 * SOLVE_ORDER = 2<br/>
024 * SELECT ...</code>
025 * </blockquote>
026 *
027 * there are two property-value pairs FORMAT_STRING and SOLVE_ORDER.
028 *
029 * @version $Id: PropertyValueNode.java 243 2009-05-22 07:21:37Z jhyde $
030 * @author jhyde
031 */
032 public class PropertyValueNode implements ParseTreeNode {
033
034 private final ParseRegion region;
035 private final String name;
036 private ParseTreeNode expression;
037
038 /**
039 * Creates a PropertyValueNode.
040 *
041 * @param region Region of source code
042 * @param name Name of property
043 * @param expression Expression for value of property (often a literal)
044 */
045 public PropertyValueNode(
046 ParseRegion region,
047 String name,
048 ParseTreeNode expression)
049 {
050 this.region = region;
051 this.name = name;
052 this.expression = expression;
053 }
054
055 public ParseRegion getRegion() {
056 return region;
057 }
058
059 public Type getType() {
060 return expression.getType();
061 }
062
063 /**
064 * Returns the expression by which the value of the property is derived.
065 *
066 * @return the expression by which the value of the property is derived
067 */
068 public ParseTreeNode getExpression() {
069 return expression;
070 }
071
072 /**
073 * Returns the name of the property
074 *
075 * @return name of the property
076 */
077 public String getName() {
078 return name;
079 }
080
081 public <T> T accept(ParseTreeVisitor<T> visitor) {
082 return visitor.visit(this);
083 }
084
085 public void unparse(ParseTreeWriter writer) {
086 writer.getPrintWriter().print(name + " = ");
087 expression.unparse(writer);
088 }
089
090 public PropertyValueNode deepCopy() {
091 return new PropertyValueNode(
092 this.region,
093 this.name,
094 this.expression.deepCopy());
095 }
096 }
097
098 // End PropertyValueNode.java