Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 31193DEFF for ; Thu, 19 Jul 2012 08:56:57 +0000 (UTC) Received: (qmail 1243 invoked by uid 500); 19 Jul 2012 08:56:57 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 1155 invoked by uid 500); 19 Jul 2012 08:56:55 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 1129 invoked by uid 99); 19 Jul 2012 08:56:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jul 2012 08:56:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jul 2012 08:56:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6AE5A2388860 for ; Thu, 19 Jul 2012 08:56:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1363265 - in /commons/proper/chain/trunk: ./ core/src/main/java/org/apache/commons/chain2/ core/src/test/java/org/apache/commons/chain2/impl/ src/changes/ Date: Thu, 19 Jul 2012 08:56:33 -0000 To: commits@commons.apache.org From: simonetripodi@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120719085633.6AE5A2388860@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: simonetripodi Date: Thu Jul 19 08:56:32 2012 New Revision: 1363265 URL: http://svn.apache.org/viewvc?rev=1363265&view=rev Log: [CHAIN-70] Add a small EDSL to simplify Chain setup and execution Added: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainExecutor.java (with props) commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java (with props) commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java (with props) commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ToExecutorCommandSetter.java (with props) commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/FluentInterfacesTestCase.java (with props) Modified: commons/proper/chain/trunk/RELEASE-NOTES.txt commons/proper/chain/trunk/src/changes/changes.xml Modified: commons/proper/chain/trunk/RELEASE-NOTES.txt URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/RELEASE-NOTES.txt?rev=1363265&r1=1363264&r2=1363265&view=diff ============================================================================== --- commons/proper/chain/trunk/RELEASE-NOTES.txt (original) +++ commons/proper/chain/trunk/RELEASE-NOTES.txt Thu Jul 19 08:56:32 2012 @@ -58,6 +58,7 @@ The Recommended Dependency Set for Chain NEW FEATURES ============= + * [CHAIN-70] Add a small EDSL to simplify Chain setup and execution * [CHAIN-58] Update Chain Context interface to use K,V generics * [CHAIN-56] clever Context with generic type "auto-cast" feature. * [CHAIN-55] split the huge project in submodules. Added: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainExecutor.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainExecutor.java?rev=1363265&view=auto ============================================================================== --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainExecutor.java (added) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainExecutor.java Thu Jul 19 08:56:32 2012 @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.commons.chain2; + +import java.util.Map; + +/** + * Builder that allows continue adding a command in the target chain and execute it. + * + * @param Context key type + * @param Context value type + * @param Type of the context associated with this chain executor + * @since 2.0 + */ +public interface ChainExecutor> extends CommandSetter> { + + /** + * Execute the processing represented by the target chain. + * + * @param context the context processed by the target chain + * @return true, if the processing of the target chain has been completed, + * false otherwise + * @see Chain#execute(Map) + */ + boolean execute(C context); + +} Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainExecutor.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainExecutor.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainExecutor.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java?rev=1363265&view=auto ============================================================================== --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java (added) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java Thu Jul 19 08:56:32 2012 @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.commons.chain2; + +import java.util.Map; + +/** + * Simple fluent chain EDSL to simplify {@link Chain} instances invocation. + * + * @since 2.0 + */ +public final class Chains { + + /** + * Defines the target chain has to be invoked. + * + * @param Context key type + * @param Context value type + * @param Type of the context associated with this command + * @param Type of the {@link Chain} to execute + * @param chain the chain instance reference to execute + * @return next chain builder + */ + public static , CH extends Chain> ToExecutorCommandSetter on(CH chain) { + return new DefaultCommandSetter(checkNotNullArgument(chain, "Null Chain can not be executed")); + } + + /** + * Private constructor, this class cannot be instantiated directly. + */ + private Chains() { + // do nothing + } + + private static class DefaultCommandSetter> implements ToExecutorCommandSetter { + + private final Chain chain; + + public DefaultCommandSetter(Chain chain) { + this.chain = chain; + } + + public > ChainExecutor addCommand(CMD command) { + chain.addCommand(checkNotNullArgument(command, "Chain does not accept null Command instances")); + return new DefaultChainExecutor(chain); + } + + } + + private static final class DefaultChainExecutor> implements ChainExecutor { + + private final Chain chain; + + public DefaultChainExecutor(Chain chain) { + this.chain = chain; + } + + public > ChainExecutor addCommand(CMD command) { + chain.addCommand(checkNotNullArgument(command, "Chain does not accept null Command instances")); + return this; + } + + public boolean execute(C context) { + return chain.execute(checkNotNullArgument(context, "Chain cannot be applied to a null context.")); + } + + } + + private static T checkNotNullArgument(T reference, String message) { + if (reference == null) { + throw new IllegalArgumentException(message); + } + return reference; + } + +} Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chains.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java?rev=1363265&view=auto ============================================================================== --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java (added) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java Thu Jul 19 08:56:32 2012 @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.commons.chain2; + +import java.util.Map; + +/** + * Generic builder that allows adding commands to the target {@link Chain} has to be executed. + * + * @param Context key type + * @param Context value type + * @param Type of the context associated with this command setter + * @param Type of the next chain builder + * @since 2.0 + */ +public interface CommandSetter, CS extends CommandSetter> { + + /** + * Add the given command to the target {@link Chain} has to be executed. + * + * @param Type of the command has to be added + * @param command the command has to be added in the target chain + * @return next chain builder + * @see Chain#addCommand(Command) + */ + > CS addCommand(CMD command); + +} Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/CommandSetter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ToExecutorCommandSetter.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ToExecutorCommandSetter.java?rev=1363265&view=auto ============================================================================== --- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ToExecutorCommandSetter.java (added) +++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ToExecutorCommandSetter.java Thu Jul 19 08:56:32 2012 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.commons.chain2; + +import java.util.Map; + +/** + * First builder that allows adding a command in the target chain. + * + * @param Context key type + * @param Context value type + * @param Type of the context associated with this chain executor + * @since 2.0 + */ +public interface ToExecutorCommandSetter> + extends CommandSetter> { + +} Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ToExecutorCommandSetter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ToExecutorCommandSetter.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ToExecutorCommandSetter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/FluentInterfacesTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/FluentInterfacesTestCase.java?rev=1363265&view=auto ============================================================================== --- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/FluentInterfacesTestCase.java (added) +++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/FluentInterfacesTestCase.java Thu Jul 19 08:56:32 2012 @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.commons.chain2.impl; + +import static org.junit.Assert.assertTrue; +import static org.apache.commons.chain2.Chains.on; + +import org.apache.commons.chain2.Context; +import org.junit.Test; + +import org.apache.commons.chain2.Chain; + +public final class FluentInterfacesTestCase { + + @Test(expected = IllegalArgumentException.class) + public void doesNotAcceptNullChain() { + on((Chain>) null); + } + + @Test(expected = IllegalArgumentException.class) + public void doesNotAcceptNullCommand() { + on(new ChainBase>()) + .addCommand(null); + } + + @Test(expected = IllegalArgumentException.class) + public void doesNotAcceptNullContext() { + on(new ChainBase>()) + .addCommand(new NonDelegatingFilter("3", "c")) + .execute(null); + } + + @Test + public void justMakeSureChainIsExecuted() { + ContextBase context = new ContextBase(); + + on(new ChainBase>()) + .addCommand(new DelegatingFilter("1", "a")) + .addCommand(new ExceptionFilter("2", "b")) + .addCommand(new NonDelegatingFilter("3", "c")) + .execute(context); + + assertTrue(context.containsKey("log")); + } + +} Propchange: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/FluentInterfacesTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/FluentInterfacesTestCase.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/FluentInterfacesTestCase.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: commons/proper/chain/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/changes/changes.xml?rev=1363265&r1=1363264&r2=1363265&view=diff ============================================================================== --- commons/proper/chain/trunk/src/changes/changes.xml (original) +++ commons/proper/chain/trunk/src/changes/changes.xml Thu Jul 19 08:56:32 2012 @@ -41,6 +41,9 @@ The type attribute can be add,u + + Add a small EDSL to simplify Chain setup and execution. + Fixed Checkstyle / PMD Warnings