Author: saminda Date: Wed Nov 2 22:05:18 2005 New Revision: 330477 URL: http://svn.apache.org/viewcvs?rev=330477&view=rev Log: 1. Added AbstractMediator. 2. Updated RuleSelectorImpl to handle the rule condition with "xpath" 3. Some changes to SynapseDeployerTest. Note: This is not an standard test case. It was there to check the basics. Once done with infrastructure, proper test cases will be added.
Added: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/mediator/AbstractMediator.java Modified: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelectorImpl.java incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/AdminMediator.java incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/LogMediator.java incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/SynapseDeployerTest.java Added: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/mediator/AbstractMediator.java URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/mediator/AbstractMediator.java?rev=330477&view=auto ============================================================================== --- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/mediator/AbstractMediator.java (added) +++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/mediator/AbstractMediator.java Wed Nov 2 22:05:18 2005 @@ -0,0 +1,35 @@ +package org.apache.synapse.mediator; + +import java.util.HashMap; +/* +* Copyright 2004,2005 The Apache Software Foundation. +* +* 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. +* +*/ + +public abstract class AbstractMediator implements Mediator{ + protected final HashMap mediatorActionList; + public AbstractMediator() { + mediatorActionList = new HashMap(); + } + public void addParameter(String key, Object value) { + if ( value != null ) { + mediatorActionList.put(key,value); + } + } + + public Object getParameter(String key) { + return mediatorActionList.get(key); + } +} Modified: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelectorImpl.java URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelectorImpl.java?rev=330477&r1=330476&r2=330477&view=diff ============================================================================== --- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelectorImpl.java (original) +++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/rule/RuleSelectorImpl.java Wed Nov 2 22:05:18 2005 @@ -1,20 +1,18 @@ package org.apache.synapse.rule; import org.apache.axis2.context.MessageContext; -import org.apache.axis2.om.OMElement; import org.apache.axis2.om.OMAttribute; -import org.apache.synapse.rule.Rule; -import org.apache.synapse.rule.RuleSelector; -import org.apache.synapse.mediator.Mediator; +import org.apache.axis2.om.OMElement; import org.apache.synapse.SynapseException; +import org.apache.synapse.mediator.Mediator; import javax.xml.namespace.QName; -import java.util.Iterator; import java.util.ArrayList; +import java.util.Iterator; public class RuleSelectorImpl implements RuleSelector { - private Rule rules []; + private Rule rules []; /** @@ -29,32 +27,53 @@ Iterator itsruls = ruleSet.getChildrenWithName(new QName("rule")); while (itsruls.hasNext()) { OMElement ruleElement = (OMElement) itsruls.next(); - OMAttribute attributeName = ruleElement.getAttribute(new QName("name")); - if(attributeName != null){ + OMAttribute attributeName = ruleElement + .getAttribute(new QName("name")); + if (attributeName != null) { String rulename = attributeName.getAttributeValue(); Rule rule = new Rule(); - Iterator mediatoes = ruleElement.getChildrenWithName(new QName("mediator")); + Iterator mediatoes = ruleElement + .getChildrenWithName(new QName("mediator")); ArrayList mediatorList = new ArrayList(); while (mediatoes.hasNext()) { OMElement mediatorElement = (OMElement) mediatoes.next(); - OMAttribute mediatorName = mediatorElement.getAttribute(new QName("name")); //what is the use of this - OMAttribute mediatorImplClass = mediatorElement.getAttribute(new QName("class")); - + OMAttribute mediatorName = mediatorElement.getAttribute( + new QName("name")); //what is the use of this + OMAttribute mediatorImplClass = mediatorElement + .getAttribute(new QName("class")); + Mediator mediator; try { - Mediator mediator = (Mediator) Class.forName(mediatorImplClass.getAttributeValue()).newInstance(); + mediator = (Mediator) Class + .forName(mediatorImplClass.getAttributeValue()) + .newInstance(); mediatorList.add(mediator); - } catch (Exception e){ + } catch (Exception e) { throw new SynapseException(e); } + Iterator iteParam = ruleElement.getChildrenWithName(new QName("parameter")); + if (iteParam != null) { + // mediator.addParameter(); + //todo : adding mediator action paramenters + } + //todo: Deepal mediator has to create and add the rule } - rule.setMediators((Mediator[])mediatorList.toArray(new Mediator[mediatorList.size()])); + Iterator iteXpath = ruleElement + .getChildrenWithName(new QName("xpath")); + if (iteXpath != null) { + while (iteXpath.hasNext()) { + OMElement xpathElement = (OMElement) iteXpath.next(); + rule.setXpath(xpathElement.getText()); + } + } + rule.setMediators((Mediator[]) mediatorList + .toArray(new Mediator[mediatorList.size()])); rule.setName(rulename); ruleslist.add(rule); } } - rules = (Rule[])ruleslist.toArray(new Rule[ruleslist.size()]); + rules = (Rule[]) ruleslist.toArray(new Rule[ruleslist.size()]); } public Rule [] getRules() { Modified: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/AdminMediator.java URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/AdminMediator.java?rev=330477&r1=330476&r2=330477&view=diff ============================================================================== --- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/AdminMediator.java (original) +++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/AdminMediator.java Wed Nov 2 22:05:18 2005 @@ -1,6 +1,7 @@ package org.apache.synapse.samples.mediators; import org.apache.synapse.mediator.Mediator; +import org.apache.synapse.mediator.AbstractMediator; import org.apache.axis2.context.MessageContext; /* * Copyright 2004,2005 The Apache Software Foundation. @@ -19,16 +20,9 @@ * */ -public class AdminMediator implements Mediator { - public boolean mediate(MessageContext messageContext) { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - public void addParameter(String key, Object value) { - //To change body of implemented methods use File | Settings | File Templates. - } +public class AdminMediator extends AbstractMediator implements Mediator{ - public Object getParameter(String key) { - return null; //To change body of implemented methods use File | Settings | File Templates. + public boolean mediate(MessageContext messageContext) { + return false; } } Modified: incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/LogMediator.java URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/LogMediator.java?rev=330477&r1=330476&r2=330477&view=diff ============================================================================== --- incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/LogMediator.java (original) +++ incubator/synapse/trunk/scratch/prototype1/src/org/apache/synapse/samples/mediators/LogMediator.java Wed Nov 2 22:05:18 2005 @@ -1,6 +1,7 @@ package org.apache.synapse.samples.mediators; import org.apache.synapse.mediator.Mediator; +import org.apache.synapse.mediator.AbstractMediator; import org.apache.axis2.context.MessageContext; /* * Copyright 2004,2005 The Apache Software Foundation. @@ -19,16 +20,9 @@ * */ -public class LogMediator implements Mediator { - public boolean mediate(MessageContext messageContext) { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - public void addParameter(String key, Object value) { - //To change body of implemented methods use File | Settings | File Templates. - } +public class LogMediator extends AbstractMediator implements Mediator { - public Object getParameter(String key) { - return null; //To change body of implemented methods use File | Settings | File Templates. + public boolean mediate(MessageContext messageContext) { + return false; } } Modified: incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/SynapseDeployerTest.java URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/SynapseDeployerTest.java?rev=330477&r1=330476&r2=330477&view=diff ============================================================================== --- incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/SynapseDeployerTest.java (original) +++ incubator/synapse/trunk/scratch/prototype1/test/org/apache/synapse/engine/SynapseDeployerTest.java Wed Nov 2 22:05:18 2005 @@ -33,21 +33,24 @@ SynapseConfiguration config = deployer.populteConfig(); System.out.println(config.getIncomingPreStageRuleSet()); - System.out.println(config.getIncomingProcessingStageRuleSet().toString()); - System.out.println(config.getIncomingPostStageRuleSet().toString()); - System.out.println(config.getOutgoingPreStageRuleSet().toString()); - System.out.println(config.getOutgoingProcessingStageRuleSet()); - System.out.println(config.getOutgoingPostStageRuleSet()); +// System.out.println(config.getIncomingProcessingStageRuleSet().toString()); +// System.out.println(config.getIncomingPostStageRuleSet().toString()); +// +// System.out.println(config.getOutgoingPreStageRuleSet().toString()); +// System.out.println(config.getOutgoingProcessingStageRuleSet()); +// System.out.println(config.getOutgoingPostStageRuleSet()); RuleSelectorImpl selectorImpl = new RuleSelectorImpl(); - selectorImpl.init(config.getIncomingPreStageRuleSet()); + selectorImpl.init(config.getIncomingPostStageRuleSet()); Rule[] rules = selectorImpl.getRules(); for (int i = 0 ; i < rules.length ; i++) { Rule pertRule = rules[i]; System.out.println(pertRule.getName()); System.out.println(pertRule.getMediators()); + System.out.println(); + System.out.println(pertRule.getXpath()); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]