Author: lfryc(a)redhat.com
Date: 2011-03-09 04:27:32 -0500 (Wed, 09 Mar 2011)
New Revision: 22093
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/AbstractNode.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadable.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNodeImpl.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNodeImpl.java
modules/tests/metamer/trunk/application/src/test/java/org/richfaces/tests/metamer/TestRichTreeModelRecursiveAdaptorBeanSerialization.java
Removed:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadingListener.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Reference.java
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/KeyConverter.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadingChecker.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNode.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Node.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNode.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTreeModelAdaptor/TestTreeModelAdaptorSelection.java
Log:
refactored tree to support serialization (needed for MyFaces) (RF-1224)
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java 2011-03-09
09:26:00 UTC (rev 22092)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -30,15 +30,15 @@
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.PostConstruct;
+import javax.el.ELContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
+import javax.faces.context.FacesContext;
import org.richfaces.component.UITreeModelRecursiveAdaptor;
import org.richfaces.tests.metamer.Attributes;
-import org.richfaces.tests.metamer.model.treeAdaptor.LazyLoadingListener;
-import org.richfaces.tests.metamer.model.treeAdaptor.Node;
import org.richfaces.tests.metamer.model.treeAdaptor.RecursiveNode;
-import org.richfaces.tests.metamer.model.treeAdaptor.Reference;
+import org.richfaces.tests.metamer.model.treeAdaptor.RecursiveNodeImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +51,7 @@
public class RichTreeModelRecursiveAdaptorBean implements Serializable {
- private static final long serialVersionUID = 4008175400649809L;
+ private static final long serialVersionUID = 1L;
private static Logger logger;
private static List<RecursiveNode> rootNodes;
@@ -64,17 +64,9 @@
/*
* Nodes which was loaded lazily in the current request
*/
- private Set<Node> lazyInitializedNodes = new LinkedHashSet<Node>();
+ private Set<String> lazyInitializedNodes = new LinkedHashSet<String>();
- private LazyLoadingListener<Node> nodeLazyLoadingListener = new
LazyLoadingListener<Node>() {
- private static final long serialVersionUID = 1L;
-
- public void notify(Node node) {
- lazyInitializedNodes.add(node);
- };
- };
-
- public Set<Node> getLazyInitializedNodes() {
+ public Set<String> getLazyInitializedNodes() {
return lazyInitializedNodes;
}
@@ -101,16 +93,7 @@
public List<RecursiveNode> getRootNodes() {
if (!rootNodesInitialized) {
- rootNodes = RecursiveNode.createChildren(null, leafChildrenNullable,
- new Reference<LazyLoadingListener<Node>>() {
- private static final long serialVersionUID = 1L;
-
- @Override
- public LazyLoadingListener<Node> get() {
- return nodeLazyLoadingListener;
- }
- });
- rootNodesInitialized = true;
+ rootNodes = RecursiveNodeImpl.createChildren(true, "", 1, false);
}
return rootNodes;
}
@@ -138,4 +121,9 @@
public static List<RecursiveNode> getRootNodesStatically() {
return rootNodes;
}
+
+ public static RichTreeModelRecursiveAdaptorBean getFacesContext() {
+ ELContext elContext = FacesContext.getCurrentInstance().getELContext();
+ return (RichTreeModelRecursiveAdaptorBean)
elContext.getELResolver().getValue(elContext, null,
"richTreeModelRecursiveAdaptorBean");
+ }
}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/AbstractNode.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/AbstractNode.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/AbstractNode.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.model.treeAdaptor;
+
+import java.io.Serializable;
+
+import org.richfaces.tests.metamer.bean.RichTreeModelRecursiveAdaptorBean;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public abstract class AbstractNode implements Serializable, LazyLoadable, Node {
+
+ private static final long serialVersionUID = 1L;
+
+ private boolean isRoot;
+ private int number;
+ private String parentLabel;
+
+ protected AbstractNode(boolean isRoot, int number, String parentLabel) {
+ this.number = number;
+ this.parentLabel = parentLabel;
+ this.isRoot = isRoot;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.INode#isRoot()
+ */
+ @Override
+ public boolean isRoot() {
+ return isRoot;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.INode#getNumber()
+ */
+ @Override
+ public int getNumber() {
+ return number;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.INode#getParentLabel()
+ */
+ @Override
+ public String getParentLabel() {
+ return parentLabel;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.INode#getLabel()
+ */
+ @Override
+ public abstract String getLabel();
+
+ @Override
+ public void notifyLoaded() {
+ RichTreeModelRecursiveAdaptorBean bean =
RichTreeModelRecursiveAdaptorBean.getFacesContext();
+ bean.getLazyInitializedNodes().add(this.getLabel());
+ }
+}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/KeyConverter.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/KeyConverter.java 2011-03-09
09:26:00 UTC (rev 22092)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/KeyConverter.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -66,7 +66,7 @@
break;
case 'K':
- for (ModelNode.K key : model.getMap().keySet()) {
+ for (ModelNodeImpl.K key : model.getMap().keySet()) {
if (key.number == num) {
return key;
}
@@ -85,8 +85,8 @@
}
public String getAsString(FacesContext context, UIComponent component, Object value)
{
- if (value instanceof ModelNode.K) {
- ModelNode.K k = (ModelNode.K) value;
+ if (value instanceof ModelNodeImpl.K) {
+ ModelNodeImpl.K k = (ModelNodeImpl.K) value;
return k.getLabel();
}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadable.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadable.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadable.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.model.treeAdaptor;
+
+/**
+ * <p>
+ * Marks that given object can be checked for lazy loading.
+ * </p>
+ *
+ * <p>
+ * Needs to implement {@link #notifyLoaded()} which performs notification about accessing
object by external entity.
+ * </p>
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public interface LazyLoadable {
+ void notifyLoaded();
+}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadingChecker.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadingChecker.java 2011-03-09
09:26:00 UTC (rev 22092)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadingChecker.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -1,3 +1,24 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
package org.richfaces.tests.metamer.model.treeAdaptor;
import static java.lang.reflect.Modifier.isStatic;
@@ -3,52 +24,36 @@
import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
-import javassist.util.proxy.MethodHandler;
-import javassist.util.proxy.ProxyFactory;
-import javassist.util.proxy.ProxyObject;
+/**
+ * <p>
+ * Wraps {@link LazyLoadable} entity with proxy which performs notification by {@link
LazyLoadable#notifyLoaded()} to
+ * let know about accessing methods of that wrapped instance.
+ * </p>
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public final class LazyLoadingChecker<T extends Serializable & LazyLoadable>
implements InvocationHandler, Serializable {
+ private static final long serialVersionUID = 1L;
-import org.apache.commons.lang.Validate;
-
-public final class LazyLoadingChecker<T> implements MethodHandler, Serializable {
- private static final long serialVersionUID = 1L;
-
T instance;
- Reference<LazyLoadingListener<T>> listenerReference = null;
- private LazyLoadingChecker(T instance, Reference<LazyLoadingListener<T>>
listenerReference) {
+ private LazyLoadingChecker(T instance) {
this.instance = instance;
- this.listenerReference = listenerReference;
}
@SuppressWarnings("unchecked")
- public static <T> T wrapInstance(T instance,
Reference<LazyLoadingListener<T>> listenerReference) {
- Validate.notNull(listenerReference);
- ProxyFactory f = new ProxyFactory();
- f.setSuperclass(instance.getClass());
- Class<?> c = f.createClass();
-
- T proxy;
- try {
- proxy = (T) c.newInstance();
- } catch (InstantiationException e) {
- throw new IllegalStateException(e);
- } catch (IllegalAccessException e) {
- throw new IllegalStateException(e);
- }
-
- ((ProxyObject) proxy).setHandler(new LazyLoadingChecker<T>(instance,
listenerReference));
- return proxy;
+ public static <T extends Serializable & LazyLoadable> T wrapInstance(T
instance) {
+ return (T) Proxy.newProxyInstance(instance.getClass().getClassLoader(),
instance.getClass().getInterfaces(),
+ new LazyLoadingChecker<T>(instance));
}
@Override
- public Object invoke(Object self, Method m, Method proceed, Object[] args) throws
Throwable {
+ public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
if (!isStatic(m.getModifiers())) {
- LazyLoadingListener<T> listener = listenerReference.get();
- if (listener != null) {
- listener.notify(instance);
- } else {
- throw new IllegalStateException();
- }
+ instance.notifyLoaded();
}
Object result = m.invoke(instance, args);
Deleted:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadingListener.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadingListener.java 2011-03-09
09:26:00 UTC (rev 22092)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/LazyLoadingListener.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -1,7 +0,0 @@
-package org.richfaces.tests.metamer.model.treeAdaptor;
-
-import java.io.Serializable;
-
-public interface LazyLoadingListener<T> extends Serializable {
- void notify(T instance);
-}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNode.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNode.java 2011-03-09
09:26:00 UTC (rev 22092)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNode.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -21,137 +21,24 @@
*******************************************************************************/
package org.richfaces.tests.metamer.model.treeAdaptor;
-import java.io.Serializable;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.atomic.AtomicReference;
+import org.richfaces.tests.metamer.model.treeAdaptor.ModelNodeImpl.A;
+import org.richfaces.tests.metamer.model.treeAdaptor.ModelNodeImpl.B;
+import org.richfaces.tests.metamer.model.treeAdaptor.ModelNodeImpl.K;
+import org.richfaces.tests.metamer.model.treeAdaptor.ModelNodeImpl.V;
+
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
-public class ModelNode extends Node {
- private static final long serialVersionUID = 1L;
+public interface ModelNode extends Node {
+ A getValue();
- private static final int BS = 3;
- private static final int KS = 4;
- List<B> bs;
- Map<K, V> map;
- List<RecursiveNode> rs;
+ List<B> getList();
- public ModelNode() {
- super(null, null, null);
- }
+ Map<K, V> getMap();
- protected ModelNode(Node parent, AtomicReference<Boolean> nullable,
- Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
- super(parent, nullable, lazyLoadingListenerReference);
- }
-
- public static ModelNode getInstance(Node parent, AtomicReference<Boolean>
nullable,
- Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
- return lazyLoadingChecker(new ModelNode(parent, nullable,
lazyLoadingListenerReference));
- }
-
- public String getLabel() {
- return isRoot() ? "M" : getParent().getLabel() + "-M";
- }
-
- public A getValue() {
- return new A();
- }
-
- public List<B> getList() {
- if (bs == null) {
- bs = new LinkedList<B>();
- for (int i = 0; i < BS; i++) {
- bs.add(new B(i));
- }
- }
- return bs;
- }
-
- public Map<K, V> getMap() {
- if (map == null) {
- map = new LinkedHashMap<K, V>();
- for (int i = 0; i < KS; i++) {
- map.put(new K(i), new V(i));
- }
- }
- return map;
- }
-
- public List<RecursiveNode> getRecursive() {
- if (rs == null) {
- rs = RecursiveNode.createChildren(this, getNullable(), null);
- }
- return rs;
- }
-
- public class A implements Serializable {
- private static final long serialVersionUID = 1L;
-
- public String getLabel() {
- return ModelNode.this.getLabel() + "-A";
- }
- }
-
- public class B implements Serializable {
- private static final long serialVersionUID = 1L;
-
- int number;
-
- public B(int number) {
- this.number = number;
- }
-
- public String getLabel() {
- return ModelNode.this.getLabel() + "-B-" + number;
- }
- }
-
- public class K implements Serializable, Comparable<K> {
- private static final long serialVersionUID = 1L;
-
- int number;
-
- public K(int number) {
- this.number = number;
- }
-
- public String getLabel() {
- return ModelNode.this.getLabel() + "-K-" + number;
- }
-
- @Override
- public int compareTo(K o) {
- return this.number - o.number;
- }
-
- @Override
- public String toString() {
- return Integer.toString(number);
- }
- }
-
- public class V implements Serializable {
- private static final long serialVersionUID = 1L;
-
- int number;
-
- public V(int number) {
- this.number = number;
- }
-
- public String getLabel() {
- return ModelNode.this.getLabel() + "-V-" + number;
- }
- }
-
- @Override
- public String toString() {
- return getLabel();
- }
-}
\ No newline at end of file
+ List<RecursiveNode> getRecursive();
+}
Copied:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNodeImpl.java
(from rev 22092,
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNode.java)
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNodeImpl.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/ModelNodeImpl.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -0,0 +1,217 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.model.treeAdaptor;
+
+import java.io.Serializable;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class ModelNodeImpl extends AbstractNode implements ModelNode {
+ private static final long serialVersionUID = 1L;
+
+ private static final int BS = 3;
+ private static final int KS = 4;
+ List<B> bs;
+ Map<K, V> map;
+ List<RecursiveNode> rs;
+
+ protected ModelNodeImpl(boolean isRoot, int number, String parentLabel) {
+ super(isRoot, number, parentLabel);
+ }
+
+ public static ModelNode getInstance(boolean isRoot, int number, String parentLabel)
{
+ ModelNodeImpl modelNode = new ModelNodeImpl(isRoot, number, parentLabel);
+ return LazyLoadingChecker.wrapInstance(modelNode);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.IModelNode#getLabel()
+ */
+ @Override
+ public String getLabel() {
+ return isRoot() ? "M" : getParentLabel() + "-M";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.IModelNode#getValue()
+ */
+ @Override
+ public A getValue() {
+ return new A(getLabel());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.IModelNode#getList()
+ */
+ @Override
+ public List<B> getList() {
+ if (bs == null) {
+ bs = new LinkedList<B>();
+ for (int i = 0; i < BS; i++) {
+ bs.add(new B(getLabel(), i));
+ }
+ }
+ return bs;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.IModelNode#getMap()
+ */
+ @Override
+ public Map<K, V> getMap() {
+ if (map == null) {
+ map = new LinkedHashMap<K, V>();
+ for (int i = 0; i < KS; i++) {
+ map.put(new K(getLabel(), i), new V(getLabel(), i));
+ }
+ }
+ return map;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.IModelNode#getRecursive()
+ */
+ @Override
+ public List<RecursiveNode> getRecursive() {
+ if (rs == null) {
+ rs = RecursiveNodeImpl.createChildren(false, getLabel(), 1, true);
+ }
+ return rs;
+ }
+
+ public static class A implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ String parentLabel;
+
+ public A(String parentLabel) {
+ this.parentLabel = parentLabel;
+ }
+
+ public String getLabel() {
+ return parentLabel + "-A";
+ }
+ }
+
+ public static class B implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ int number;
+ String parentLabel;
+
+ public B(String parentLabel, int number) {
+ this.parentLabel = parentLabel;
+ this.number = number;
+ }
+
+ public String getLabel() {
+ return parentLabel + "-B-" + number;
+ }
+ }
+
+ public static class K implements Serializable, Comparable<K> {
+ private static final long serialVersionUID = 1L;
+
+ int number;
+ String parentLabel;
+
+ public K(String parentLabel, int number) {
+ this.parentLabel = parentLabel;
+ this.number = number;
+ }
+
+ public String getLabel() {
+ return parentLabel + "-K-" + number;
+ }
+
+ @Override
+ public int compareTo(K o) {
+ return this.getLabel().compareTo(o.getLabel());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj == this) {
+ return true;
+ }
+ if (obj.getClass() != getClass()) {
+ return false;
+ }
+ K rhs = (K) obj;
+ return new EqualsBuilder().append(getLabel(), rhs.getLabel()).isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder(17, 37).append(getLabel()).toHashCode();
+
+ }
+
+ @Override
+ public String toString() {
+ return Integer.toString(number);
+ }
+ }
+
+ public static class V implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ int number;
+ String parentLabel;
+
+ public V(String parentLabel, int number) {
+ this.parentLabel = parentLabel;
+ this.number = number;
+ }
+
+ public String getLabel() {
+ return parentLabel + "-V-" + number;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return getLabel();
+ }
+}
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Node.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Node.java 2011-03-09
09:26:00 UTC (rev 22092)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Node.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -21,85 +21,18 @@
*******************************************************************************/
package org.richfaces.tests.metamer.model.treeAdaptor;
-import java.io.Serializable;
-import java.util.Deque;
-import java.util.LinkedList;
-import java.util.concurrent.atomic.AtomicReference;
-
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
-public abstract class Node implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private Node parent;
- private AtomicReference<Boolean> nullable;
- private Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference
= new NodeReference();
+public interface Node {
- protected Node(Node parent, AtomicReference<Boolean> nullable,
- Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
- this.parent = parent;
- this.nullable = nullable;
- if (lazyLoadingListenerReference != null) {
- this.lazyLoadingListenerReference = lazyLoadingListenerReference;
- }
- }
+ public abstract boolean isRoot();
- public static <T extends Node> T lazyLoadingChecker(T node) {
- return (T) LazyLoadingChecker.wrapInstance(node,
node.getLazyLoadingListenerReference());
- }
+ public abstract int getNumber();
- public Node getParent() {
- return parent;
- }
+ public abstract String getParentLabel();
- public boolean isRoot() {
- return parent == null;
- }
-
- public AtomicReference<Boolean> getNullable() {
- return nullable;
- }
-
- public int getLevel() {
- return isRoot() ? 1 : parent.getLevel() + 1;
- }
-
- public Node getRoot() {
- return isRoot() ? this : parent.getRoot();
- }
-
- public Iterable<Node> getPredecessorsFromRoot() {
- Deque<Node> list = new LinkedList<Node>();
- list.addFirst(this);
-
- while (list.getFirst().parent != null) {
- list.addFirst(list.getFirst().parent);
- }
-
- return list;
- }
-
public abstract String getLabel();
- public Reference<LazyLoadingListener<Node>>
getLazyLoadingListenerReference() {
- return lazyLoadingListenerReference;
- }
-
- public void setLazyLoadingListener(Reference<LazyLoadingListener<Node>>
lazyLoadingListener) {
- this.lazyLoadingListenerReference = lazyLoadingListener;
- }
-
- public class NodeReference implements
Reference<LazyLoadingListener<Node>> {
- @Override
- public LazyLoadingListener<Node> get() {
- Node root = getRoot();
- if (root == Node.this) {
- return null;
- }
- return getRoot().getLazyLoadingListenerReference().get();
- }
- }
-}
+}
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNode.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNode.java 2011-03-09
09:26:00 UTC (rev 22092)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNode.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -21,244 +21,23 @@
*******************************************************************************/
package org.richfaces.tests.metamer.model.treeAdaptor;
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicReference;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
-public class RecursiveNode extends Node {
- private static final long serialVersionUID = 1L;
-
- private static final int CHILDREN = 4;
- private static final int LEVELS = 2;
- private static final List<RecursiveNode> EMPTY_LIST = new
LinkedList<RecursiveNode>();
- private static final Map<Integer, RecursiveNode> EMPTY_MAP = new
HashMap<Integer, RecursiveNode>();
+public interface RecursiveNode extends Node {
- int number;
- List<RecursiveNode> children = null;
- NodeMap nodeMap = new NodeMap();
- ModelNode model;
+ public abstract ModelNode getModel();
- public RecursiveNode() {
- super(null, null, null);
- }
+ public abstract boolean isLeaf();
- protected RecursiveNode(Node parent, AtomicReference<Boolean> nullable, int
number,
- Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
- super(parent, nullable, lazyLoadingListenerReference);
- this.number = number;
- }
+ public abstract List<RecursiveNode> getRecursiveList();
- public static RecursiveNode getInstance(Node parent, AtomicReference<Boolean>
nullable, int number,
- Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
- return lazyLoadingChecker(new RecursiveNode(parent, nullable, number,
lazyLoadingListenerReference));
- }
+ public abstract Map<Integer, RecursiveNode> getRecursiveMap();
- public int getNumber() {
- return number;
- }
+ public abstract int getRecursionLevel();
- public boolean isLeaf() {
- return getRecursionLevel() >= LEVELS + (isOddBranch() ? 0 : 1);
- }
-
- public List<RecursiveNode> getRecursiveList() {
- if (isLeaf()) {
- return getEmptyList();
- }
- if (children == null) {
- children = createChildren(this, getNullable(), null);
- }
- return children;
- }
-
- public Map<Integer, RecursiveNode> getRecursiveMap() {
- if (isLeaf()) {
- return getEmptyMap();
- }
- return nodeMap;
- }
-
- private List<RecursiveNode> getEmptyList() {
- return getNullable().get() ? null : EMPTY_LIST;
- }
-
- private Map<Integer, RecursiveNode> getEmptyMap() {
- return getNullable().get() ? null : EMPTY_MAP;
- }
-
- public String getLabel() {
- String parentLabel = (isRoot() ? "" : getParent().getLabel() +
"-") + "R-";
- String recursionLabel = (isRecursionRoot() ? parentLabel : getParent().getLabel()
+ ".") + number;
- return recursionLabel;
- }
-
- public ModelNode getModel() {
- if (isLeaf() && !isPreceededByModel()) {
- if (model == null) {
- model = ModelNode.getInstance(this, getNullable(), null);
- }
- return model;
- }
- return null;
- }
-
- public int getRecursionLevel() {
- return isRecursionRoot() ? 1 : 1 + ((RecursiveNode)
getParent()).getRecursionLevel();
- }
-
- private boolean isRecursionRoot() {
- if (isRoot()) {
- return true;
- } else {
- return !(getParent() instanceof RecursiveNode);
- }
- }
-
- public static List<RecursiveNode> createChildren(Node parent,
AtomicReference<Boolean> nullable,
- Reference<LazyLoadingListener<Node>> lazyLoadingListenerReference) {
- List<RecursiveNode> children = new LinkedList<RecursiveNode>();
- for (int i = 0; i < CHILDREN; i++) {
- RecursiveNode node = RecursiveNode.getInstance(parent, nullable, i,
lazyLoadingListenerReference);
- children.add(node);
- }
- return children;
- }
-
- private boolean isPreceededByModel() {
- for (Node predecessor : getPredecessorsFromRoot()) {
- if (predecessor instanceof ModelNode) {
- return true;
- }
- }
- return false;
- }
-
- private boolean isOddBranch() {
- for (Node predecessor : getPredecessorsFromRoot()) {
- if (predecessor instanceof RecursiveNode) {
- return ((RecursiveNode) predecessor).number % 2 == 1;
- }
- }
- return this.number % 2 == 1;
- }
-
- @Override
- public String toString() {
- return getLabel();
- }
-
- public class NodeMap implements Map<Integer, RecursiveNode>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public int size() {
- return getRecursiveList().size();
- }
-
- @Override
- public boolean isEmpty() {
- return getRecursiveList().isEmpty();
- }
-
- @Override
- public boolean containsKey(Object key) {
- throw new UnsupportedOperationException("not implemented");
- }
-
- @Override
- public boolean containsValue(Object value) {
- throw new UnsupportedOperationException("not implemented");
- }
-
- @Override
- public RecursiveNode get(Object key) {
- if (key instanceof Integer) {
- return getRecursiveList().get((Integer) key);
- }
- throw new IllegalStateException("there is no value for the key
'" + key + "' (type "
- + key.getClass().getName() + ")");
- }
-
- @Override
- public RecursiveNode put(Integer key, RecursiveNode value) {
- throw new UnsupportedOperationException("not supported");
- }
-
- @Override
- public RecursiveNode remove(Object key) {
- throw new UnsupportedOperationException("not supported");
- }
-
- @Override
- public void putAll(Map<? extends Integer, ? extends RecursiveNode> m) {
- throw new UnsupportedOperationException("not supported");
- }
-
- @Override
- public void clear() {
- throw new UnsupportedOperationException("not supported");
- }
-
- @Override
- public Set<Integer> keySet() {
- HashSet<Integer> set = new HashSet<Integer>();
- for (int i = 0; i < getRecursiveList().size(); i++) {
- set.add(i);
- }
- return set;
- }
-
- @Override
- public Collection<RecursiveNode> values() {
- return getRecursiveList();
- }
-
- @Override
- public Set<java.util.Map.Entry<Integer, RecursiveNode>> entrySet() {
- HashSet<Map.Entry<Integer, RecursiveNode>> set = new
HashSet<Map.Entry<Integer, RecursiveNode>>();
- int i = 0;
- for (RecursiveNode node : getRecursiveList()) {
- set.add(new MapEntry(i++, node));
- }
- return set;
- }
-
- }
-
- public class MapEntry implements Map.Entry<Integer, RecursiveNode> {
-
- int key;
- RecursiveNode node;
-
- public MapEntry(int key, RecursiveNode node) {
- this.key = key;
- this.node = node;
- }
-
- @Override
- public Integer getKey() {
- return key;
- }
-
- @Override
- public RecursiveNode getValue() {
- return node;
- }
-
- @Override
- public RecursiveNode setValue(RecursiveNode value) {
- throw new UnsupportedOperationException("not supported");
- }
- }
}
\ No newline at end of file
Copied:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNodeImpl.java
(from rev 22092,
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNode.java)
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNodeImpl.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/RecursiveNodeImpl.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -0,0 +1,264 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.model.treeAdaptor;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.richfaces.tests.metamer.bean.RichTreeModelRecursiveAdaptorBean;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class RecursiveNodeImpl extends AbstractNode implements RecursiveNode {
+ private static final long serialVersionUID = 1L;
+
+ private static final int CHILDREN = 4;
+ private static final int LEVELS = 2;
+ private static final List<RecursiveNode> EMPTY_LIST = new
LinkedList<RecursiveNode>();
+ private static final Map<Integer, RecursiveNode> EMPTY_MAP = new
HashMap<Integer, RecursiveNode>();
+
+ int recursionLevel;
+ boolean oddBranch;
+ List<RecursiveNode> children = null;
+ NodeMap nodeMap = new NodeMap();
+ ModelNode model;
+
+ protected RecursiveNodeImpl(boolean isRoot, int number, String parentLabel, int
recursionLevel, boolean oddBranch) {
+ super(isRoot, number, parentLabel);
+ this.recursionLevel = recursionLevel;
+ this.oddBranch = oddBranch;
+ }
+
+ public static RecursiveNode getInstance(boolean isRoot, int number, String
parentLabel, int recursionLevel, boolean oddBranch) {
+ RecursiveNodeImpl recursiveNode = new RecursiveNodeImpl(isRoot, number,
parentLabel, recursionLevel, oddBranch);
+ return LazyLoadingChecker.wrapInstance(recursiveNode);
+ }
+
+ public static List<RecursiveNode> createChildren(boolean createRoots, String
parentLabel, int recursionLevel, boolean preferedOddBranch) {
+ List<RecursiveNode> children = new LinkedList<RecursiveNode>();
+ for (int i = 0; i < CHILDREN; i++) {
+ boolean oddBranch = preferedOddBranch;
+ if (createRoots) {
+ oddBranch = i % 2 == 1;
+ }
+ RecursiveNode node = RecursiveNodeImpl.getInstance(createRoots, i,
parentLabel, recursionLevel, oddBranch);
+ children.add(node);
+ }
+ return children;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.IRecursiveNode#getModel()
+ */
+ @Override
+ public ModelNode getModel() {
+ if (isLeaf() && model == null) {
+ model = ModelNodeImpl.getInstance(false, 1, getLabel());
+ }
+ return model;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.IRecursiveNode#isLeaf()
+ */
+ @Override
+ public boolean isLeaf() {
+ return getRecursionLevel() >= LEVELS + (oddBranch ? 0 : 1);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.tests.metamer.model.treeAdaptor.IRecursiveNode#getRecursiveList()
+ */
+ @Override
+ public List<RecursiveNode> getRecursiveList() {
+ if (isLeaf()) {
+ return getEmptyList();
+ }
+ if (children == null) {
+ children = createChildren(false, getLabel(), recursionLevel + 1,
this.oddBranch);
+ }
+ return children;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.tests.metamer.model.treeAdaptor.IRecursiveNode#getRecursiveMap()
+ */
+ @Override
+ public Map<Integer, RecursiveNode> getRecursiveMap() {
+ if (isLeaf()) {
+ return getEmptyMap();
+ }
+ return nodeMap;
+ }
+
+ private List<RecursiveNode> getEmptyList() {
+ return isNullable() ? null : EMPTY_LIST;
+ }
+
+ private Map<Integer, RecursiveNode> getEmptyMap() {
+ return isNullable() ? null : EMPTY_MAP;
+ }
+
+ private boolean isNullable() {
+ return
RichTreeModelRecursiveAdaptorBean.getFacesContext().isLeafChildrenNullable();
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.tests.metamer.model.treeAdaptor.IRecursiveNode#getLabel()
+ */
+ @Override
+ public String getLabel() {
+ String parentLabel = (isRoot() ? "" : getParentLabel() + "-")
+ "R-";
+ String recursionLabel = (isRecursionRoot() ? parentLabel : getParentLabel() +
".") + getNumber();
+ return recursionLabel;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.tests.metamer.model.treeAdaptor.IRecursiveNode#getRecursionLevel()
+ */
+ @Override
+ public int getRecursionLevel() {
+ return recursionLevel;
+ }
+
+ private boolean isRecursionRoot() {
+ return recursionLevel == 1;
+ }
+
+ @Override
+ public String toString() {
+ return getLabel();
+ }
+
+ public class NodeMap implements Map<Integer, RecursiveNode>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public int size() {
+ return getRecursiveList().size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return getRecursiveList().isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(Object key) {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public RecursiveNode get(Object key) {
+ if (key instanceof Integer) {
+ return getRecursiveList().get((Integer) key);
+ }
+ throw new IllegalStateException("there is no value for the key
'" + key + "' (type "
+ + key.getClass().getName() + ")");
+ }
+
+ @Override
+ public RecursiveNode put(Integer key, RecursiveNode value) {
+ throw new UnsupportedOperationException("not supported");
+ }
+
+ @Override
+ public RecursiveNode remove(Object key) {
+ throw new UnsupportedOperationException("not supported");
+ }
+
+ @Override
+ public void putAll(Map<? extends Integer, ? extends RecursiveNode> m) {
+ throw new UnsupportedOperationException("not supported");
+ }
+
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException("not supported");
+ }
+
+ @Override
+ public Set<Integer> keySet() {
+ HashSet<Integer> set = new HashSet<Integer>();
+ for (int i = 0; i < getRecursiveList().size(); i++) {
+ set.add(i);
+ }
+ return set;
+ }
+
+ @Override
+ public Collection<RecursiveNode> values() {
+ return getRecursiveList();
+ }
+
+ @Override
+ public Set<java.util.Map.Entry<Integer, RecursiveNode>> entrySet() {
+ HashSet<Map.Entry<Integer, RecursiveNode>> set = new
HashSet<Map.Entry<Integer, RecursiveNode>>();
+ int i = 0;
+ for (RecursiveNode node : getRecursiveList()) {
+ set.add(new MapEntry(i++, node));
+ }
+ return set;
+ }
+
+ }
+
+ public class MapEntry implements Map.Entry<Integer, RecursiveNode> {
+
+ int key;
+ RecursiveNode node;
+
+ public MapEntry(int key, RecursiveNode node) {
+ this.key = key;
+ this.node = node;
+ }
+
+ @Override
+ public Integer getKey() {
+ return key;
+ }
+
+ @Override
+ public RecursiveNode getValue() {
+ return node;
+ }
+
+ @Override
+ public RecursiveNode setValue(RecursiveNode value) {
+ throw new UnsupportedOperationException("not supported");
+ }
+ }
+}
\ No newline at end of file
Deleted:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Reference.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Reference.java 2011-03-09
09:26:00 UTC (rev 22092)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/model/treeAdaptor/Reference.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -1,8 +0,0 @@
-package org.richfaces.tests.metamer.model.treeAdaptor;
-
-import java.io.Serializable;
-
-public interface Reference<T> extends Serializable {
-
- public T get();
-}
Added:
modules/tests/metamer/trunk/application/src/test/java/org/richfaces/tests/metamer/TestRichTreeModelRecursiveAdaptorBeanSerialization.java
===================================================================
---
modules/tests/metamer/trunk/application/src/test/java/org/richfaces/tests/metamer/TestRichTreeModelRecursiveAdaptorBeanSerialization.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/test/java/org/richfaces/tests/metamer/TestRichTreeModelRecursiveAdaptorBeanSerialization.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.richfaces.tests.metamer.bean.RichTreeModelRecursiveAdaptorBean;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.io.NullOutputStream;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestRichTreeModelRecursiveAdaptorBeanSerialization {
+
+ private Set<Integer> notEquals = new TreeSet<Integer>();
+
+ PrintStream sysout;
+
+ @BeforeClass
+ public void redirectOut() {
+ sysout = System.out;
+ System.setOut(new PrintStream(new NullOutputStream()));
+ }
+
+ @AfterClass(alwaysRun = true)
+ public void returnOut() {
+ System.setOut(sysout);
+ }
+
+ @Test
+ public void testBeanSerialization() throws IOException, ClassNotFoundException,
IllegalArgumentException,
+ IllegalAccessException {
+
+ RichTreeModelRecursiveAdaptorBean bean = new
RichTreeModelRecursiveAdaptorBean();
+ bean.init();
+
+ Object obj1 = bean;
+
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ ObjectOutputStream outputStream = new ObjectOutputStream(byteArrayOutputStream);
+ outputStream.writeObject(obj1);
+
+ byte[] bytes = byteArrayOutputStream.toByteArray();
+
+ ObjectInputStream inputStream = new ObjectInputStream(new
ByteArrayInputStream(bytes));
+ Object obj2 = inputStream.readObject();
+
+ verifyEqualsDeeply(obj1, obj2);
+ }
+
+ public void verifyEqualsDeeply(Object obj1, Object obj2) throws
IllegalArgumentException, IllegalAccessException {
+
+ if (obj1 == null) {
+ if (obj2 == null) {
+ return;
+ }
+ throw new AssertionError("obj1 is null, but obj2 is not null");
+ }
+
+ Class<?> classO = obj1.getClass();
+ assertEquals(obj2.getClass(), classO, "Both objects should be instances of
the same class");
+
+ if (obj1.equals(obj2)) {
+ return;
+ }
+
+ int hash = cohash(obj1, obj2);
+ if (notEquals.contains(hash)) {
+ return;
+ }
+
+ notEquals.add(hash);
+
+ if (Collection.class.isAssignableFrom(classO)) {
+ Collection<?> col1 = (Collection<?>) obj1;
+ Collection<?> col2 = (Collection<?>) obj2;
+ assertEquals(col1.toArray(new Object[col1.size()]), col2.toArray(new
Object[col2.size()]));
+ } else if (Map.class.isAssignableFrom(classO)) {
+ Map map1 = (Map) obj1;
+ Map map2 = (Map) obj2;
+
+ Object[] array1 = map1.keySet().toArray(new Object[map1.size()]);
+ Arrays.sort(array1, new HashCodeComparator());
+
+ Object[] array2 = map2.keySet().toArray(new Object[map2.size()]);
+ Arrays.sort(array2, new HashCodeComparator());
+
+ assertEquals(array1, array2);
+
+ array1 = map1.values().toArray(new Object[map1.size()]);
+ Arrays.sort(array1, new HashCodeComparator());
+
+ array2 = map2.values().toArray(new Object[map2.size()]);
+ Arrays.sort(array2, new HashCodeComparator());
+
+ assertEquals(array1, array2);
+ } else {
+ for (Field field : classO.getDeclaredFields()) {
+
+ if (Modifier.isStatic(field.getModifiers())) {
+ continue;
+ }
+ if (Modifier.isTransient(field.getModifiers())) {
+ continue;
+ }
+
+ boolean accessible = field.isAccessible();
+ if (!accessible) {
+ field.setAccessible(true);
+ }
+ Object nObj1 = field.get(obj1);
+ Object nObj2 = field.get(obj2);
+ if (!accessible) {
+ field.setAccessible(false);
+ }
+ verifyEqualsDeeply(nObj1, nObj2);
+ }
+ }
+ }
+
+ public int cohash(Object obj1, Object obj2) {
+ return 17 * obj1.hashCode() * obj2.hashCode() + obj2.hashCode() + 11;
+ }
+
+ public class HashCodeComparator implements Comparator<Object> {
+ @Override
+ public int compare(Object o1, Object o2) {
+ return o1.hashCode() - o2.hashCode();
+ }
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTreeModelAdaptor/TestTreeModelAdaptorSelection.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTreeModelAdaptor/TestTreeModelAdaptorSelection.java 2011-03-09
09:26:00 UTC (rev 22092)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTreeModelAdaptor/TestTreeModelAdaptorSelection.java 2011-03-09
09:27:32 UTC (rev 22093)
@@ -51,7 +51,7 @@
PathsCrate pathsForListModel = new PathsCrate("listModel", new Integer[][]
{ { 2, 1, 3 }, { 3, 3, 2, 2 } });
PathsCrate pathsForMapModel = new PathsCrate("mapModel", new Integer[][] {
{ 2, 1, 5 }, { 3, 3, 2, 6 } });
PathsCrate pathsForRecursiveModel = new PathsCrate("recursiveModel", new
Integer[][] { { 4, 1, 10, 2 },
- { 1, 4, 3, 11, 4, 1 } });
+ { 1, 4, 3, 11, 4 } });
@Inject
@Use(enumeration = true)