2006/unicorn/src/org/w3c/unicorn/tasklisttree MimetypeCond.java,NONE,1.1 ParameterCond.java,NONE,1.1 TLTCond.java,1.3,1.4

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/tasklisttree
In directory hutz:/tmp/cvs-serv31192/src/org/w3c/unicorn/tasklisttree

Modified Files:
	TLTCond.java 
Added Files:
	MimetypeCond.java ParameterCond.java 
Log Message:
new condition classes extending TLTCond

--- NEW FILE: MimetypeCond.java ---
package org.w3c.unicorn.tasklisttree;

import org.w3c.unicorn.UnicornCall;

public class MimetypeCond extends TLTCond {

	@Override
	public boolean check(UnicornCall unicornCall) {
		
		return value.equals(unicornCall.getInputParameter().getMimeType().toString());
		
	}



}

Index: TLTCond.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/tasklisttree/TLTCond.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- TLTCond.java	16 Sep 2009 12:01:18 -0000	1.3
+++ TLTCond.java	21 Sep 2009 12:11:50 -0000	1.4
@@ -2,6 +2,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.w3c.unicorn.UnicornCall;
 import org.w3c.unicorn.contract.Observer;
 
 /**
@@ -11,19 +12,19 @@
  * @author Barouh Jonathan & Batard Florent
  * 
  */
-public class TLTCond {
+public abstract class TLTCond {
 
 	private String id;
 
-	private Observer observer;
+	protected Observer observer;
 
 	private EnumCondType type;
 
 	private boolean result;
 
-	private String value;
+	protected String value;
 	
-	private String parameter;
+	protected String parameter;
 
 	private static final Log logger = LogFactory.getLog(TLTCond.class);
 
@@ -51,6 +52,25 @@
 	public TLTCond() {
 		TLTCond.logger.trace("constructor()");
 	}
+	
+	public abstract boolean check(UnicornCall unicornCall) throws Exception;
+	
+	public static TLTCond createCond(EnumCondType type) {
+		switch (type) {
+		case MIMETYPE:
+			return new MimetypeCond();
+		case PARAMETER:
+			return new ParameterCond();
+		case XPATH:
+			return new XPathCond();
+		default:
+			return null;
+		}
+	}
+	
+	public static TLTCond createCond(String type) {
+		return createCond(EnumCondType.fromValue(type));
+	}
 
 	/**
 	 * 

--- NEW FILE: ParameterCond.java ---
package org.w3c.unicorn.tasklisttree;

import org.w3c.unicorn.UnicornCall;

public class ParameterCond extends TLTCond {

	@Override
	public boolean check(UnicornCall unicornCall) {
		
		if (!unicornCall.getMapOfStringParameter().containsKey(parameter))
			return false;
		
		boolean passed = false;
		String[] parameterValues = unicornCall.getMapOfStringParameter().get(parameter);
		for (int i=0; i<parameterValues.length; i++)
			if (parameterValues[i].equals(value))
				passed = true;
		
		return passed;
	}

}

Received on Monday, 21 September 2009 12:12:01 UTC