use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project carbon-business-process by wso2.
the class IfImpl method isSimpleLayout.
/**
* @return false- if the subActivities are instances of ElseIf or Else
* true - otherwise
*/
private boolean isSimpleLayout() {
boolean simple = true;
ActivityInterface activity = null;
// Iterates through the subActivities
Iterator<ActivityInterface> itr = getSubActivities().iterator();
while (itr.hasNext()) {
activity = itr.next();
// if the activity is an instance of ElseIf or Else, break the if condition
if (activity instanceof ElseIfImpl || activity instanceof ElseImpl) {
simple = false;
break;
}
}
return simple;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project ballerina by ballerina-lang.
the class CodeGenerator method generateURILookupInstructions.
private void generateURILookupInstructions(Map<Name, BXMLNSSymbol> namespaces, RegIndex localNameRegIndex, RegIndex uriRegIndex, RegIndex targetQNameRegIndex, DiagnosticPos pos, SymbolEnv symbolEnv) {
if (namespaces.isEmpty()) {
createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
return;
}
Stack<Operand> endJumpInstrStack = new Stack<>();
String prefix;
for (Entry<Name, BXMLNSSymbol> keyValues : namespaces.entrySet()) {
prefix = keyValues.getKey().getValue();
// skip the default namespace
if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
continue;
}
// Below section creates the condition to compare the namespace URIs
// store the comparing uri as string
BXMLNSSymbol nsSymbol = keyValues.getValue();
int opcode = getOpcode(TypeTags.STRING, InstructionCodes.IEQ);
RegIndex conditionExprIndex = getRegIndex(TypeTags.BOOLEAN);
emit(opcode, uriRegIndex, getNamespaceURIIndex(nsSymbol, symbolEnv), conditionExprIndex);
Operand ifCondJumpAddr = getOperand(-1);
emit(InstructionCodes.BR_FALSE, conditionExprIndex, ifCondJumpAddr);
// Below section creates instructions to be executed, if the above condition succeeds (then body)
// create the prefix literal
RegIndex prefixIndex = createStringLiteral(prefix, null, env);
// create a qname
emit(InstructionCodes.NEWQNAME, localNameRegIndex, uriRegIndex, prefixIndex, targetQNameRegIndex);
Operand endJumpAddr = getOperand(-1);
emit(InstructionCodes.GOTO, endJumpAddr);
endJumpInstrStack.add(endJumpAddr);
ifCondJumpAddr.value = nextIP();
}
// else part. create a qname with empty prefix
createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
while (!endJumpInstrStack.isEmpty()) {
endJumpInstrStack.pop().value = nextIP();
}
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangIf ifNode) {
addLineNumberInfo(ifNode.pos);
// Generate code for the if condition evaluation
genNode(ifNode.expr, this.env);
Operand ifCondJumpAddr = getOperand(-1);
emit(InstructionCodes.BR_FALSE, ifNode.expr.regIndex, ifCondJumpAddr);
// Generate code for the then body
genNode(ifNode.body, this.env);
Operand endJumpAddr = getOperand(-1);
emit(InstructionCodes.GOTO, endJumpAddr);
ifCondJumpAddr.value = nextIP();
// Visit else statement if any
if (ifNode.elseStmt != null) {
genNode(ifNode.elseStmt, this.env);
}
endJumpAddr.value = nextIP();
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project ballerina by ballerina-lang.
the class ParserRuleTypeNameContextResolver method resolveItems.
@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
ArrayList<CompletionItem> completionItems = new ArrayList<>();
TokenStream tokenStream = completionContext.get(DocumentServiceKeys.TOKEN_STREAM_KEY);
ParserRuleContext parserRuleContext = completionContext.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY);
CompletionItemSorter itemSorter = ItemSorters.getSorterByClass(DefaultItemSorter.class);
if (parserRuleContext.getParent() instanceof BallerinaParser.CatchClauseContext && CommonUtil.isWithinBrackets(completionContext, Collections.singletonList(CATCH_KEY_WORD))) {
this.populateCompletionItemList(filterCatchConditionSymbolInfo(completionContext), completionItems);
} else if (tokenStream.get(completionContext.get(DocumentServiceKeys.TOKEN_INDEX_KEY)).getText().equals(":")) {
/*
TODO: ATM, this particular condition becomes true only when try to access packages' items in the
endpoint definition context
*/
this.populateCompletionItemList(filterEndpointContextSymbolInfo(completionContext), completionItems);
} else {
StatementTemplateFilter statementTemplateFilter = new StatementTemplateFilter();
// Add the statement templates
completionItems.addAll(statementTemplateFilter.filterItems(completionContext));
this.populateBasicTypes(completionItems, completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY));
itemSorter = ItemSorters.getSorterByClass(completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY).getClass());
}
itemSorter.sortItems(completionContext, completionItems);
return completionItems;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project carbon-apimgt by wso2.
the class PolicyDAOImpl method isBlockConditionExist.
/**
* Check if a blocking condition already exists.
*
* @param blockConditions BlockConditions object to be added
* @return true/false depending on the success
* @throws APIMgtDAOException If failed to check if block condition exist
*/
private boolean isBlockConditionExist(BlockConditions blockConditions) throws APIMgtDAOException {
boolean status = false;
if (blockConditions.getConditionType().equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE)) {
String isExistQuery = "SELECT STARTING_IP, ENDING_IP FROM AM_IP_RANGE_CONDITION WHERE STARTING_IP =? " + "AND ENDING_IP =?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement checkIsExistPreparedStatement = connection.prepareStatement(isExistQuery)) {
checkIsExistPreparedStatement.setString(1, blockConditions.getStartingIP());
checkIsExistPreparedStatement.setString(2, blockConditions.getEndingIP());
try (ResultSet checkIsResultSet = checkIsExistPreparedStatement.executeQuery()) {
if (checkIsResultSet.next()) {
status = true;
}
}
} catch (SQLException e) {
String msg = DAOUtil.DAO_ERROR_PREFIX + "checking if the IP range blacklist condition exists with starting IP: " + blockConditions.getStartingIP() + ", ending IP: " + blockConditions.getEndingIP();
throw new APIMgtDAOException(msg, e);
}
} else {
String isExistQuery = "SELECT CONDITION_ID,TYPE,VALUE,ENABLED,UUID FROM AM_BLOCK_CONDITIONS WHERE TYPE =? " + "AND VALUE =?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement checkIsExistPreparedStatement = connection.prepareStatement(isExistQuery)) {
connection.setAutoCommit(false);
checkIsExistPreparedStatement.setString(1, blockConditions.getConditionType());
checkIsExistPreparedStatement.setString(2, blockConditions.getConditionValue());
try (ResultSet checkIsResultSet = checkIsExistPreparedStatement.executeQuery()) {
if (checkIsResultSet.next()) {
status = true;
}
}
} catch (SQLException e) {
String msg = DAOUtil.DAO_ERROR_PREFIX + "checking if the Block Condition Exist with condition type: " + blockConditions.getConditionType() + ", condition value: " + blockConditions.getConditionValue();
throw new APIMgtDAOException(msg, e);
}
}
return status;
}
Aggregations