You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2006/01/05 09:17:34 UTC

svn commit: r366117 - in /myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el: ./ ActionsMap.java GenericMap.java StringMap.java TestsMap.java

Author: mmarinschek
Date: Thu Jan  5 00:17:26 2006
New Revision: 366117

URL: http://svn.apache.org/viewcvs?rev=366117&view=rev
Log:
added map-utitilites by Sylvain Vieujot. todo: provide an example for the usage.

Added:
    myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/
    myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/ActionsMap.java
    myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/GenericMap.java
    myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/StringMap.java
    myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/TestsMap.java

Added: myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/ActionsMap.java
URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/ActionsMap.java?rev=366117&view=auto
==============================================================================
--- myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/ActionsMap.java (added)
+++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/ActionsMap.java Thu Jan  5 00:17:26 2006
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2004 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.
+ */
+package org.apache.myfaces.util.el;
+
+import java.util.*;
+
+/**
+ * @author Sylvain Vieujot (latest modification by $Author: skitching $)
+ * @version $Revision: 355303 $ $Date: 2005-12-09 02:36:08 +0100 (Fr, 09 Dez 2005) $
+ *
+ * You can use this class to trigger an action when a boolean is set to true.
+ *
+ * Example : in JSF pages, for dataTable, to remove elements :
+ * Backing bean (#{inboxFace}).
+ * public ActionsMap getRemoveEmailUnid(){
+ * 		return new ActionsMap(){
+ *			public void performAction(String unid) {
+ *				InboxMailDAO<TInboxMail> dao = getInboxMailDAO();
+ *				TInboxMail email = dao.getByPrimaryKey( unid );
+ *				dao.remove( email );
+ *			}
+ *		};
+ *	}
+ * JSF page :
+ * &lt;h:selectBooleanCheckbox value="#{inboxFace.removeEmailUnid[email.unid]}"/&gt;
+ */
+public abstract class ActionsMap implements Map {
+
+    private Set keys;
+
+    public ActionsMap(){
+        // NoOp
+    }
+
+    public ActionsMap(Set keys){
+        this.keys = keys;
+    }
+
+    /**
+     * This method should fire the command.
+     */
+    public abstract void performAction(String command);
+
+    public int size() {
+        return keys.size();
+    }
+
+    public boolean isEmpty() {
+        return keys.isEmpty();
+    }
+
+    public boolean containsKey(Object key) {
+        return keys.contains( key );
+    }
+
+    public boolean containsValue(Object value) {
+        if( ! (value instanceof Boolean) )
+            return false;
+        return ((Boolean)value).booleanValue();
+    }
+
+    public Object get( Object key) {
+        return Boolean.FALSE;
+    }
+
+    public Boolean put(String key, Boolean value) {
+        if( value!=null && value.booleanValue() )
+            performAction( key );
+        return Boolean.FALSE;
+    }
+
+    public Object remove(Object key) {
+        if( keys.remove( key ) )
+            return Boolean.FALSE;
+        return null;
+    }
+
+    public void putAll(Map map) {
+        Iterator it = map.entrySet().iterator();
+
+        while (it.hasNext())
+        {
+            Entry entry = (Entry) it.next();
+            Object obj = entry.getValue();
+            if( (obj instanceof Boolean) && ((Boolean) obj).booleanValue() )
+                performAction( (String) entry.getKey() );
+        }
+    }
+
+    public void clear() {
+        keys.clear();
+    }
+
+    public Set keySet() {
+        return keys;
+    }
+
+    public Collection values() {
+        return Collections.nCopies(keys.size(), Boolean.FALSE);
+    }
+
+    public Set entrySet() {
+        Set set = new HashSet( keys.size() );
+
+        Iterator it = keys.iterator();
+
+        while (it.hasNext())
+        {
+            String command = (String) it.next();
+            set.add( new CommandEntry(command) );
+        }
+
+        return set;
+    }
+
+    private class CommandEntry implements Entry{
+
+        private final String command;
+        private boolean commandPerformed = false;
+
+        public CommandEntry(String command){
+            this.command = command;
+        }
+
+        public Object getKey() {
+            return command;
+        }
+
+        public Object getValue() {
+            return Boolean.valueOf(commandPerformed);
+        }
+
+        public Object setValue(Object performCommand) {
+            if( (performCommand instanceof Boolean) && ((Boolean)performCommand).booleanValue() ){
+                performAction( command );
+                commandPerformed = true;
+            }
+            return Boolean.valueOf(commandPerformed);
+        }
+    }
+}
+

Added: myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/GenericMap.java
URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/GenericMap.java?rev=366117&view=auto
==============================================================================
--- myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/GenericMap.java (added)
+++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/GenericMap.java Thu Jan  5 00:17:26 2006
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2004 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.
+ */
+package org.apache.myfaces.util.el;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Collection;
+
+/**
+ * @author Sylvain Vieujot (latest modification by $Author: skitching $)
+ * @version $Revision: 355303 $ $Date: 2005-12-09 02:36:08 +0100 (Fr, 09 Dez 2005) $
+ *
+ */
+public abstract class GenericMap implements Map {
+
+    /**
+     * This method should return the result of the test.
+     */
+    protected abstract Object getValue(Object key);
+
+    public int size() {
+        return 1;
+    }
+
+    public boolean isEmpty() {
+        return false;
+    }
+
+    public boolean containsKey(Object key) {
+        return true;
+    }
+
+    public boolean containsValue(Object value) {
+        return value instanceof Boolean;
+    }
+
+    public Object get(Object key) {
+        return getValue(key);
+    }
+
+    public Object put(Object key, Object value) {
+        return null;
+    }
+
+    public Object remove(Object key) {
+        return null;
+    }
+
+    public void putAll(Map m) {
+        // NoOp
+    }
+
+    public void clear() {
+        // NoOp
+    }
+
+    public Set keySet() {
+        return null;
+    }
+
+    public Collection values() {
+        return null;
+    }
+
+    public Set entrySet() {
+        return null;
+    }
+}
+
+

Added: myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/StringMap.java
URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/StringMap.java?rev=366117&view=auto
==============================================================================
--- myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/StringMap.java (added)
+++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/StringMap.java Thu Jan  5 00:17:26 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004 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.
+ */
+package org.apache.myfaces.util.el;
+
+/**
+ * You can use this class to perform tests.
+ * Use this for example in JSF backing beans, like BaseFace.getUserInRole(String).
+ *
+ * @author Sylvain Vieujot (latest modification by $Author: skitching $)
+ * @version $Revision: 355303 $ $Date: 2005-12-09 02:36:08 +0100 (Fr, 09 Dez 2005) $
+ *
+ */
+public abstract class StringMap extends GenericMap {
+
+	/**
+	 * This method should return the result of the test.
+	 */
+	public abstract String getString(String testKey);
+
+	public Object getValue(Object testKey){
+		return getString( (String) testKey );
+	}
+
+	public Object get(Object key) {
+		if( ! (key instanceof String) )
+			return null;
+		return getString( (String)key );
+	}
+}
+

Added: myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/TestsMap.java
URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/TestsMap.java?rev=366117&view=auto
==============================================================================
--- myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/TestsMap.java (added)
+++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/el/TestsMap.java Thu Jan  5 00:17:26 2006
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2004 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.
+ */
+package org.apache.myfaces.util.el;
+
+/**
+ * You can use this class to perform tests.
+ * Use this for example in JSF backing beans, like BaseFace.getUserInRole(String).
+ *
+ * @author Sylvain Vieujot (latest modification by $Author: skitching $)
+ * @version $Revision: 355303 $ $Date: 2005-12-09 02:36:08 +0100 (Fr, 09 Dez 2005) $
+ */
+public abstract class TestsMap extends GenericMap {
+
+	/**
+	 * This method should return the result of the test.
+	 */
+	public abstract boolean getTest(String testKey);
+
+	protected Object getValue(Object testKey){
+		return Boolean.valueOf(getTest( (String) testKey ));
+	}
+
+    public Object get(Object key) {
+		if( ! (key instanceof String) )
+			return null;
+		return Boolean.valueOf(getTest( (String)key ));
+	}
+
+	public Boolean put(String key, Boolean value) {
+		return Boolean.FALSE;
+	}
+}
+
+