Java Code Examples for org.eclipse.birt.core.data.DataTypeUtil#convert()
The following examples show how to use
org.eclipse.birt.core.data.DataTypeUtil#convert() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSetIterator.java From birt with Eclipse Public License 1.0 | 6 votes |
public Object getValue( int fieldIndex ) throws BirtException { Object value = it.getValue( this.metadata.getFieldName( fieldIndex ) ); if ( value == null ) { return this.metadata.getNullValueReplacer( fieldIndex ); } if( byte[].class.equals( value.getClass( ) ) ) { return value; } Object convertedValue = this.metadata.getDataProcessor( fieldIndex ) .process( value ); return convertedValue.getClass().isAssignableFrom( value.getClass()) ? convertedValue : DataTypeUtil.convert( convertedValue, value.getClass( ) ); }
Example 2
Source File: PreparedDummyQuery.java From birt with Eclipse Public License 1.0 | 6 votes |
public Object getValue( String name ) throws BirtException { checkOpened( ); if ( exprManager.getExpr( name ) == null ) throw new DataException( ResourceConstants.INVALID_BOUND_COLUMN_NAME, name ); Object o = exprValueMap.get( name ); IBinding b = exprManager.getBinding( name ); if ( o != null && b != null ) { o = DataTypeUtil.convert( o, b.getDataType( ) ); } return o; }
Example 3
Source File: DataSourceQuery.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * convert the String value to Object according to its data type. * * @param inputValue * @param type * @return * @throws DataException */ private static Object convertToValue( Object inputValue, Class typeClass ) throws DataException { try { return DataTypeUtil.convert( inputValue, typeClass); } catch ( Exception ex ) { throw new DataException( ResourceConstants.CANNOT_CONVERT_PARAMETER_TYPE, ex, new Object[]{ inputValue, typeClass } ); } }
Example 4
Source File: DataUtil.java From birt with Eclipse Public License 1.0 | 6 votes |
public static <T> T convertType( Object tempValue, Class<T> type ) throws BirtException { T value = null; if ( tempValue == null || type.isAssignableFrom( tempValue.getClass( ) ) ) { value = (T) tempValue; } else if ( type == DimensionType.class ) { // todo } else { value = (T) DataTypeUtil.convert( tempValue, type ); } return value; }
Example 5
Source File: DataRow.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @see org.eclipse.birt.data.engine.api.script.IDataRow#setColumnValue(int, java.lang.Object) */ public void setColumnValue(int index, Object value) throws BirtException { if ( ! dataSet.allowUpdateRowData() ) throw new DataException( ResourceConstants.NO_ROW_UPDATE); IResultObject obj = getAndCheckResultObject( ); // Observe the type restriction on the column Class fieldClass = obj.getResultClass().getFieldValueClass( index ); if ( fieldClass != DataType.AnyType.class ) { try { value = DataTypeUtil.convert( value, fieldClass ); } catch ( BirtException e ) { if ( obj.getResultClass( ) instanceof ResultClass ) { if ( obj.getResultClass( ).wasAnyType( index )) throw new IllegalArgumentException( DataResourceHandle.getInstance( ) .getMessage( ResourceConstants.POSSIBLE_MIXED_DATA_TYPE_IN_COLUMN ) ); } else { throw e; } } } obj.setCustomFieldValue( index, value ); }
Example 6
Source File: DataRow.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @see org.eclipse.birt.data.engine.api.script.IDataRow#setColumnValue(int, java.lang.Object) */ public void setColumnValue(String name, Object value) throws BirtException { if ( ! dataSet.allowUpdateRowData() ) throw new DataException( ResourceConstants.NO_ROW_UPDATE); IResultObject obj = getAndCheckResultObject( ); // Observe the type restriction on the column Class fieldClass = obj.getResultClass().getFieldValueClass( name ); if ( fieldClass != DataType.AnyType.class ) { try { value = DataTypeUtil.convert( value, fieldClass ); } catch ( BirtException e ) { if ( obj.getResultClass( ) instanceof ResultClass ) { if( obj.getResultClass( ).wasAnyType( name )) throw new IllegalArgumentException( DataResourceHandle.getInstance( ) .getMessage( ResourceConstants.POSSIBLE_MIXED_DATA_TYPE_IN_COLUMN ) ); } else { throw e; } } } obj.setCustomFieldValue( name, value ); }
Example 7
Source File: ColumnReferenceExpression.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @see org.eclipse.birt.data.engine.expression.CompiledExpression#evaluate(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable) */ public Object evaluate(ScriptContext context, Scriptable scope) throws DataException { // This method should not normally be called. // Assume the JS "row" variable has been correctly set up in scope. // Evaluate the expression row[index] or row["name"] StringBuffer expr = new StringBuffer( this.rowIndicator+"["); if ( isIndexed() ) { expr.append(m_columnIndex); } else { expr.append('"'); expr.append( JavascriptEvalUtil.transformToJsConstants( m_columnName ) ); expr.append('"'); } expr.append(']'); try { return DataTypeUtil.convert( ScriptEvalUtil.evaluateJSAsExpr( context, scope, expr.toString( ), ScriptExpression.defaultID, 0 ), this.dataType ); } catch (BirtException e) { throw DataException.wrap(e); } }
Example 8
Source File: ResultIterator.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @param groupKeyValues * @param columnExprs * @param i * @return * @throws BirtException */ private boolean groupKeyValuesEqual( org.eclipse.birt.data.engine.odi.IResultIterator odiResult, Object[] groupKeyValues, String[] columnExprs, int i ) throws BirtException { Object fieldValue = null; fieldValue = ScriptEvalUtil.evalExpr( new ScriptExpression( columnExprs[i] ), resultService.getSession( ) .getEngineContext( ) .getScriptContext( ) .newContext( ResultIterator.this.scope ), org.eclipse.birt.core.script.ScriptExpression.defaultID, 0 ); boolean retValue = false; if ( fieldValue == groupKeyValues[i] ) { retValue = true; } else if ( fieldValue != null && groupKeyValues[i] != null ) { if ( fieldValue.getClass( ) .equals( groupKeyValues[i].getClass( ) ) ) { retValue = equal( fieldValue, groupKeyValues[i] ); } else { Object convertedOb = DataTypeUtil.convert( groupKeyValues[i], fieldValue.getClass( ) ); retValue = equal( fieldValue, convertedOb ); } } return retValue; }
Example 9
Source File: BindingColumnsEvalUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @param baseExpr * @param exprType * @param valueMap * @throws DataException */ private Object evaluateValue( BindingColumn bindingColumn, int exprType ) throws DataException { Object exprValue = null; try { if ( exprType == MANUAL_BINDING ) { if ( bindingColumn.isAggregation ) exprValue = this.odiResult.getAggrValue( bindingColumn.columnName ); else exprValue = ExprEvaluateUtil.evaluateExpression( bindingColumn.baseExpr, odiResult, scope, cx ); } else exprValue = ExprEvaluateUtil.evaluateRawExpression( bindingColumn.baseExpr, scope, cx ); if ( exprValue != null && !( exprValue instanceof Exception ) ) exprValue = DataTypeUtil.convert( JavascriptEvalUtil.convertJavascriptValue( exprValue ), bindingColumn.type ); } catch ( BirtException e ) { throw DataException.wrap( e ); } return exprValue; }
Example 10
Source File: ResultObjectUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
private static Object convert( Object o, int type ) throws DataException { try { return DataTypeUtil.convert( o, type ); } catch ( BirtException e ) { throw DataException.wrap( e ); } }
Example 11
Source File: OdiAdapter.java From birt with Eclipse Public License 1.0 | 5 votes |
private IResultObject getConvertedResultObject( IResultObject resultObject ) throws DataException { if ( resultObject == null ) return null; if ( columnIndexListForTypeConvert == null ) return resultObject; Object[] obj = new Object[resultClass.getFieldCount( )]; for ( int i = 1; i <= resultClass.getFieldCount( ); i++ ) { if ( columnIndexListForTypeConvert.contains( i ) ) { try { obj[i - 1] = DataTypeUtil.convert( resultObject.getFieldValue( i ), DataTypeUtil.toApiDataType( resultClass.getFieldMetaData( i ) .getDataType( ) ) ); } catch ( BirtException e ) { throw DataException.wrap( e ); } } else { obj[i - 1] = resultObject.getFieldValue( i ); } } IResultObject result = new ResultObject( resultClass, obj ); return result; }
Example 12
Source File: Expression.java From birt with Eclipse Public License 1.0 | 5 votes |
public Object getValue( ) { if ( value == NOT_EVALUATED ) { try { value = DataTypeUtil.convert( scriptText, valueType ); } catch ( BirtException ex ) { value = null; } } return value; }
Example 13
Source File: CubeQueryUtil.java From birt with Eclipse Public License 1.0 | 4 votes |
public Object next( ) { try { if( !this.hasNext ) return null; Object result = this.currentValue; boolean accept = false; while( this.dataSetIterator.next( ) ) { accept = true; Iterator it = this.levelValueMap.keySet( ).iterator( ); while( it.hasNext()) { String key = it.next( ).toString( ); Object value = this.levelValueMap.get( key ); if( ScriptEvalUtil.compare( value, this.dataSetIterator.getValue( this.dataSetIterator.getFieldIndex( key ) ) ) != 0) { accept = false; break; } } if( accept ) { this.currentValue = this.dataSetIterator.getValue( this.dataSetIterator.getFieldIndex( this.attribute == null ? this.targetLevelName : OlapExpressionUtil.getAttributeColumnName( this.targetLevelName, this.attribute ) ) ); break; } } this.hasNext = accept; return DataTypeUtil.convert( result, targetDateType ); } catch ( BirtException e ) { return null; } }
Example 14
Source File: PreparedDummyQuery.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * @param queryResults * @param queryScope * @throws BirtException */ private ResultIterator( QueryResults queryResults, ExprManager exprManager, Scriptable queryScope, Scriptable parentScope ) throws BirtException { this.queryResults = queryResults; this.exprManager = exprManager; this.queryScope = queryScope; this.jsDummyRowObject = new JSDummyRowObject(exprManager, queryScope, parentScope, session.getEngineContext( ).getScriptContext( )); queryScope.put( "row", queryScope, jsDummyRowObject ); this.getRdSaveUtil( ).doSaveStart( ); exprValueMap = new HashMap( ); Map exprMap = getBindingMap( exprManager.getBindingExprs( ) ); Iterator it = exprMap.entrySet( ).iterator( ); while ( it.hasNext( ) ) { Map.Entry entry = (Entry) it.next( ); String exprName = (String) entry.getKey( ); IBaseExpression baseExpr = (IBaseExpression) entry.getValue( ); Object exprValue = ExprEvaluateUtil.evaluateRawExpression( baseExpr, queryScope, session.getEngineContext( ).getScriptContext( ) ); IBinding binding = exprManager.getBinding( exprName ); if ( baseExpr != null && binding.getDataType( ) != baseExpr.getDataType( ) ) exprValue = DataTypeUtil.convert( exprValue, binding.getDataType( ) ); exprValueMap.put( exprName, exprValue ); } this.getRdSaveUtil( ).doSaveExpr( exprValueMap ); if( needCache() ) { try { createCacheOutputStream( ); saveMetaData( ); IOUtil.writeInt(this.rowOutputStream, 1 ); cacheRow( ); } catch (IOException e) { throw new DataException( ResourceConstants.CREATE_CACHE_TEMPFILE_ERROR ); } } }