<commit_before>/*****************************************************************************
 * $Id$
 *
 * Copyright 2008, The Rules Framework Development Team, and individual
 * contributors as indicated by the @authors tag. See the copyright.txt
 * in the distribution for a full listing of individual contributors.
 *
 * 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 net.sourceforge.rules.service;

import java.rmi.RemoteException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.rules.InvalidRuleSessionException;
import javax.rules.ObjectFilter;
import javax.rules.RuleExecutionSetNotFoundException;
import javax.rules.RuleRuntime;
import javax.rules.RuleSession;
import javax.rules.RuleSessionCreateException;
import javax.rules.RuleSessionTypeUnsupportedException;
import javax.rules.StatelessRuleSession;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * TODO
 *
 * @version $Revision$ $Date$
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
@Local({StatelessDecisionService.class})
@Remote({StatelessDecisionServiceRemote.class})
@Stateless(name="StatelessDecisionService")
//@WebService(serviceName="StatelessDecisionService")
public class StatelessDecisionServiceBean implements StatelessDecisionServiceRemote
{
	// Constants -------------------------------------------------------------

	/**
	 * The <code>Log</code> instance for this class.
	 */
	private static final Log log = LogFactory.getLog(
			StatelessDecisionServiceBean.class);

	/**
	 * TODO
	 */
	private static final long serialVersionUID = 1L;

	// Attributes ------------------------------------------------------------

	/**
	 * TODO
	 */
	private RuleRuntime ruleRuntime;

	// Static ----------------------------------------------------------------

	// Constructors ----------------------------------------------------------

	// StatelessDecisionService implementation -------------------------------

	/* (non-Javadoc)
	 * @see net.sourceforge.rules.service.StatelessDecisionService#decide(java.lang.String, java.util.Map, java.util.List)
	 */
	//@WebMethod()
	//@WebResult(name="outputObjects")
	public List<?> decide(
			//@WebParam(name="bindUri")
			String bindUri,
			//@WebParam(name="properties")
			//@XmlJavaTypeAdapter(MapAdapter.class)
			Map<?, ?> properties,
			//@WebParam(name="inputObjects")
			List<?> inputObjects)
	throws DecisionServiceException {

		if (log.isDebugEnabled()) {
			StringBuilder sb = new StringBuilder("Executing RuleExecutionSet"); //$NON-NLS-1$
			sb.append("\n\tBindURI     : ").append(bindUri); //$NON-NLS-1$
			sb.append("\n\tProperties  : ").append(properties); //$NON-NLS-1$
			sb.append("\n\tInputObjects: ").append(inputObjects); //$NON-NLS-1$
			log.debug(sb.toString());
		}

		int sessionType = RuleRuntime.STATELESS_SESSION_TYPE;
		StatelessRuleSession ruleSession = null;
		ObjectFilter objectFilter = null;
		List<?> outputObjects = null;

		try {
			ruleSession = (StatelessRuleSession)
			ruleRuntime.createRuleSession(bindUri, properties, sessionType);

			objectFilter = createObjectFilter(inputObjects, properties);
			outputObjects = ruleSession.executeRules(
					inputObjects,
					objectFilter
			);

			ruleSession.release();
			ruleSession = null;

		} catch (RuleSessionTypeUnsupportedException e) {<commit_msg>initial revision<commit_after>/*****************************************************************************
 * $Id$
 *
 * Copyright 2008, The Rules Framework Development Team, and individual
 * contributors as indicated by the @authors tag. See the copyright.txt
 * in the distribution for a full listing of individual contributors.
 *
 * 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 net.sourceforge.rules.service;

import java.rmi.RemoteException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.rules.InvalidRuleSessionException;
import javax.rules.ObjectFilter;
import javax.rules.RuleExecutionSetNotFoundException;
import javax.rules.RuleRuntime;
import javax.rules.RuleSession;
import javax.rules.RuleSessionCreateException;
import javax.rules.RuleSessionTypeUnsupportedException;
import javax.rules.StatelessRuleSession;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * TODO
 *
 * @version $Revision$ $Date$
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
@Local({StatelessDecisionService.class})
@Remote({StatelessDecisionServiceRemote.class})
@Stateless(name="StatelessDecisionService")
//@WebService(serviceName="StatelessDecisionService")
public class StatelessDecisionServiceBean implements StatelessDecisionServiceRemote
{
	// Constants -------------------------------------------------------------

	/**
	 * The <code>Log</code> instance for this class.
	 */
	private static final Log log = LogFactory.getLog(
			StatelessDecisionServiceBean.class);

	/**
	 * TODO
	 */
	private static final long serialVersionUID = 1L;

	// Attributes ------------------------------------------------------------

	/**
	 * TODO
	 */
	private RuleRuntime ruleRuntime;

	// Static ----------------------------------------------------------------

	// Constructors ----------------------------------------------------------

	// StatelessDecisionService implementation -------------------------------

	/* (non-Javadoc)
	 * @see net.sourceforge.rules.service.StatelessDecisionService#decide(java.lang.String, java.util.Map, java.util.List)
	 */
	@WebMethod()
	@WebResult(name="outputObjects")
	public List<?> decide(
			@WebParam(name="bindUri")
			String bindUri,
			@WebParam(name="properties")
			@XmlJavaTypeAdapter(MapAdapter.class)
			Map<?, ?> properties,
			@WebParam(name="inputObjects")
			List<?> inputObjects)
	throws DecisionServiceException {

		if (log.isDebugEnabled()) {
			StringBuilder sb = new StringBuilder("Executing RuleExecutionSet"); //$NON-NLS-1$
			sb.append("\n\tBindURI     : ").append(bindUri); //$NON-NLS-1$
			sb.append("\n\tProperties  : ").append(properties); //$NON-NLS-1$
			sb.append("\n\tInputObjects: ").append(inputObjects); //$NON-NLS-1$
			log.debug(sb.toString());
		}

		int sessionType = RuleRuntime.STATELESS_SESSION_TYPE;
		StatelessRuleSession ruleSession = null;
		ObjectFilter objectFilter = null;
		List<?> outputObjects = null;

		try {
			ruleSession = (StatelessRuleSession)
			ruleRuntime.createRuleSession(bindUri, properties, sessionType);

			objectFilter = createObjectFilter(inputObjects, properties);
			outputObjects = ruleSession.executeRules(
					inputObjects,
					objectFilter
			);

			ruleSession.release();
			ruleSession = null;

		} catch (RuleSessionTypeUnsupportedException e) {
{'fraction_non_alphanumeric': 0.2043203246210765, 'fraction_numerical': 0.0031029955841985917, 'mean_word_length': 3.481283422459893, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2503745', 'n_tokens_mistral': 2386, 'n_tokens_neox': 2193, 'n_words': 545}