
org.drools.ide.common.server.util.GuidedDTTemplateDataProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of droolsjbpm-ide-common Show documentation
Show all versions of droolsjbpm-ide-common Show documentation
Common code between Guvnor and the Eclipse plugins
The newest version!
/*
* Copyright 2012 JBoss Inc
*
* Licensed 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.
*/
package org.drools.ide.common.server.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.drools.ide.common.client.modeldriven.dt52.BRLActionVariableColumn;
import org.drools.ide.common.client.modeldriven.dt52.BRLConditionVariableColumn;
import org.drools.ide.common.client.modeldriven.dt52.BaseColumn;
import org.drools.ide.common.client.modeldriven.dt52.DTCellValue52;
/**
* A Template value provider backed by a Decision Table
*/
public class GuidedDTTemplateDataProvider
implements
TemplateDataProvider {
private Map templateKeysToValueMap = new HashMap();
public GuidedDTTemplateDataProvider(List columns,
List rowData) {
if ( columns == null ) {
throw new NullPointerException( "columns cannot be null" );
}
if ( rowData == null ) {
throw new NullPointerException( "rowData cannot be null" );
}
//rowData does not contain the Analysis column, columns does
if ( rowData.size() != columns.size() - 1 ) {
throw new IllegalArgumentException( "rowData contains a different number of columns to those provided" );
}
//Extract keys and values in constructor rather than on demand for speed
for ( int index = 0; index < columns.size(); index++ ) {
BaseColumn column = columns.get( index );
if ( column instanceof BRLConditionVariableColumn ) {
BRLConditionVariableColumn brlCondition = (BRLConditionVariableColumn) column;
templateKeysToValueMap.put( brlCondition.getVarName(),
rowData.get( index ) );
} else if ( column instanceof BRLActionVariableColumn ) {
BRLActionVariableColumn brlAction = (BRLActionVariableColumn) column;
templateKeysToValueMap.put( brlAction.getVarName(),
rowData.get( index ) );
}
}
}
public String getTemplateKeyValue(String key) {
if ( templateKeysToValueMap.containsKey( key ) ) {
return getStringValue( templateKeysToValueMap.get( key ) );
}
return "";
}
private String getStringValue(DTCellValue52 cell) {
if ( !cell.hasValue() ) {
return "";
}
return GuidedDTDRLUtilities.convertDTCellValueToString( cell );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy