001: /**********************************************************************
002: Copyright (c) 2006 Erik Bengtson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015:
016: Contributors:
017: ...
018: **********************************************************************/package org.jpox.store.expression;
019:
020: import java.lang.reflect.Array;
021:
022: import org.jpox.exceptions.JPOXUserException;
023: import org.jpox.store.DatastoreAdapter;
024: import org.jpox.store.mapping.JavaTypeMapping;
025:
026: /**
027: * Representation of array expression. Either backed
028: * by ScalarExpressions, or by an array field
029: * @version $Revision: 1.2 $
030: */
031: public class ArrayLiteral extends ArrayExpression implements Literal {
032: /** value of the array **/
033: Object value;
034:
035: /**
036: * Constructor
037: * @param qs The query statement
038: */
039: protected ArrayLiteral(QueryExpression qs) {
040: super (qs);
041: }
042:
043: /**
044: * Constructor
045: * @param qs The query statement
046: * @param expr the array of expressions
047: */
048: public ArrayLiteral(QueryExpression qs, ScalarExpression[] expr) {
049: super (qs);
050: this .exprs = expr;
051: }
052:
053: /**
054: * Constructor
055: * @param qs The query statement
056: * @param mapping the {@link JavaTypeMapping}
057: * @param literal the array value
058: */
059: public ArrayLiteral(QueryExpression qs, JavaTypeMapping mapping,
060: Object literal) {
061: super (qs);
062: this .mapping = mapping;
063: this .value = literal;
064: if (value == null || !value.getClass().isArray()) {
065: throw new JPOXUserException("Invalid argument literal : "
066: + value);
067: }
068: DatastoreAdapter dba = qs.getStoreManager()
069: .getDatastoreAdapter();
070: this .exprs = new ScalarExpression[Array.getLength(value)];
071: for (int i = 0; i < Array.getLength(value); i++) {
072: JavaTypeMapping m = dba.getMapping(Array.get(value, i)
073: .getClass(), qs.getStoreManager(), qs
074: .getClassLoaderResolver());
075: this .exprs[i] = m.newLiteral(qs, Array.get(value, i));
076: }
077: }
078:
079: public Object getValue() {
080: return value;
081: }
082:
083: /**
084: * Method to save a "raw" value that this literal represents.
085: * This value differs from the literal value since that is of the same type as this literal.
086: * @param val The raw value
087: */
088: public void setRawValue(Object val) {
089: // Dont support raw value for binary literals
090: }
091:
092: /**
093: * Accessor for the "raw" value that this literal represents.
094: * This value differs from the literal value since that is of the same type as this literal.
095: * @return The raw value
096: */
097: public Object getRawValue() {
098: return null; // Dont support raw value for binary literals
099: }
100: }
|