<commit_before>/**
 * Copyright (c) 2010-2013, openHAB.org and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.freeswitch.internal;

import java.util.HashSet;
import java.util.Set;

import org.openhab.binding.freeswitch.FreeswitchBindingProvider;
import org.openhab.core.items.Item;
import org.openhab.core.library.items.StringItem;
import org.openhab.core.library.items.SwitchItem;
import org.openhab.library.tel.items.CallItem;
import org.openhab.model.item.binding.AbstractGenericBindingProvider;
import org.openhab.model.item.binding.BindingConfigParseException;


/**
 * This class is responsible for parsing the binding configuration.
 * 
 * @author <NAME>
 * @since 1.4.0
 */
public class FreeswitchGenericBindingProvider extends AbstractGenericBindingProvider implements FreeswitchBindingProvider {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getBindingType() {
		return "freeswitch";
	}

	/**
	 * @{inheritDoc}
	 */
	@Override
	public void validateItemType(Item item, String bindingConfig) throws BindingConfigParseException {
		if (!(item instanceof StringItem || item instanceof CallItem || item instanceof SwitchItem)) {
			throw new BindingConfigParseException("item '" + item.getName()
					+ "' is of type '" + item.getClass().getSimpleName()
					+ "', only String, Call and SwitchItems are allowed");
		}
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
		super.processBindingConfiguration(context, item, bindingConfig);
		
		String[] configParts = bindingConfig.trim().split(":", 2);
		
		String command = configParts[0];
		
		String argument = null;
		
		if(configParts.length > 1)
			argument  = configParts[1];
		
		FreeswitchBindingType type = FreeswitchBindingType.fromString(command);
		
		if(type == null)
			throw new BindingConfigParseException("Unknown item type " + configParts[0] );
		
		FreeswitchBindingConfig config = new FreeswitchBindingConfig(item.getName(),item.getClass(), type, argument);
		<commit_msg>added number type to validation<commit_after>/**
 * Copyright (c) 2010-2013, openHAB.org and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.freeswitch.internal;

import java.util.HashSet;
import java.util.Set;

import org.openhab.binding.freeswitch.FreeswitchBindingProvider;
import org.openhab.core.items.Item;
import org.openhab.core.library.items.NumberItem;
import org.openhab.core.library.items.StringItem;
import org.openhab.core.library.items.SwitchItem;
import org.openhab.library.tel.items.CallItem;
import org.openhab.model.item.binding.AbstractGenericBindingProvider;
import org.openhab.model.item.binding.BindingConfigParseException;


/**
 * This class is responsible for parsing the binding configuration.
 * 
 * @author <NAME>
 * @since 1.4.0
 */
public class FreeswitchGenericBindingProvider extends AbstractGenericBindingProvider implements FreeswitchBindingProvider {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getBindingType() {
		return "freeswitch";
	}

	/**
	 * @{inheritDoc}
	 */
	@Override
	public void validateItemType(Item item, String bindingConfig) throws BindingConfigParseException {
		if (!(item instanceof StringItem || item instanceof CallItem || item instanceof SwitchItem ||
				item instanceof NumberItem)) {
			throw new BindingConfigParseException("item '" + item.getName()
					+ "' is of type '" + item.getClass().getSimpleName()
					+ "', only String, Number, Call and Switch Items are allowed");
		}
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
		super.processBindingConfiguration(context, item, bindingConfig);
		
		String[] configParts = bindingConfig.trim().split(":", 2);
		
		String command = configParts[0];
		
		String argument = null;
		
		if(configParts.length > 1)
			argument  = configParts[1];
		
		FreeswitchBindingType type = FreeswitchBindingType.fromString(command);
		
		if(type == null)
			throw new BindingConfigParseException("Unknown item type " + configParts[0] );
		
		FreeswitchBindingConfig config = new FreeswitchBindingConfig(item.getName(),item.getClass(), type, argument);
		
{'fraction_non_alphanumeric': 0.10731604469744888, 'fraction_numerical': 0.00843348091924942, 'mean_word_length': 4.743341404358354, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6967479', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1312, 'n_words': 341}