JBoss Portal SVN: r9367 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model/event and 4 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-18 17:57:38 -0500 (Tue, 18 Dec 2007)
New Revision: 9367
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChangeEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateModification.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/navigational/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChange.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChangeEvent.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateModification.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/navigational/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/structural/
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/navigational/NavigationalStateModification.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
create a state package in the event package
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18 22:47:00 UTC (rev 9366)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -25,10 +25,10 @@
import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.presentation.model.StateScopeType;
import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.event.StateChange;
-import org.jboss.portal.presentation.model.event.StateChangeEvent;
-import org.jboss.portal.presentation.model.event.navigational.NavigationalStateModification;
-import org.jboss.portal.presentation.model.event.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.event.state.StateChange;
+import org.jboss.portal.presentation.model.event.state.StateChangeEvent;
+import org.jboss.portal.presentation.model.event.state.navigational.NavigationalStateModification;
+import org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChange.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChange.java 2007-12-18 22:47:00 UTC (rev 9366)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChange.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -1,79 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated 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.jboss.portal.presentation.model.event;
-
-import org.jboss.portal.presentation.model.event.StateModification;
-
-/**
- * A change in the state of the model. The change is the association of a target id and a modification.
- * The target id refers to an object in the structural state context and the modification is a modification
- * of its state. Note that the modification could also modify the state of other objects.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public final class StateChange<M extends StateModification>
-{
-
- /** . */
- private final String targetId;
-
- /** . */
- private final M modification;
-
- public StateChange(String targetId, M modification)
- {
- if (targetId == null)
- {
- throw new IllegalArgumentException();
- }
- if (modification == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.targetId = targetId;
- this.modification = modification;
- }
-
- /**
- * Returns the target id of the change.
- *
- * @return the target id
- */
- public String getTargetId()
- {
- return targetId;
- }
-
- /**
- * Returns the modification operated on the target id.
- *
- * @return the modification
- */
- public M getModification()
- {
- return modification;
- }
-}
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChangeEvent.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChangeEvent.java 2007-12-18 22:47:00 UTC (rev 9366)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChangeEvent.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -1,60 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated 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.jboss.portal.presentation.model.event;
-
-import org.jboss.portal.presentation.model.ModelEvent;
-import org.jboss.portal.presentation.model.event.StateChange;
-
-/**
- * Signals a state change occured.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public final class StateChangeEvent extends ModelEvent
-{
-
- /** . */
- private final StateChange change;
-
- public StateChangeEvent(StateChange change)
- {
- if (change == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.change = change;
- }
-
- /**
- * Returns the state change that occured.
- *
- * @return the state change
- */
- public StateChange getChange()
- {
- return change;
- }
-}
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateModification.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateModification.java 2007-12-18 22:47:00 UTC (rev 9366)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateModification.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -1,33 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated 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.jboss.portal.presentation.model.event;
-
-/**
- * An abstract class for the modification of state.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public abstract class StateModification
-{
-}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java (from rev 9366, branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChange.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -0,0 +1,79 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.model.event.state;
+
+import org.jboss.portal.presentation.model.event.state.StateModification;
+
+/**
+ * A change in the state of the model. The change is the association of a target id and a modification.
+ * The target id refers to an object in the structural state context and the modification is a modification
+ * of its state. Note that the modification could also modify the state of other objects.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public final class StateChange<M extends StateModification>
+{
+
+ /** . */
+ private final String targetId;
+
+ /** . */
+ private final M modification;
+
+ public StateChange(String targetId, M modification)
+ {
+ if (targetId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (modification == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.targetId = targetId;
+ this.modification = modification;
+ }
+
+ /**
+ * Returns the target id of the change.
+ *
+ * @return the target id
+ */
+ public String getTargetId()
+ {
+ return targetId;
+ }
+
+ /**
+ * Returns the modification operated on the target id.
+ *
+ * @return the modification
+ */
+ public M getModification()
+ {
+ return modification;
+ }
+}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChangeEvent.java (from rev 9366, branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateChangeEvent.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChangeEvent.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChangeEvent.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.model.event.state;
+
+import org.jboss.portal.presentation.model.ModelEvent;
+import org.jboss.portal.presentation.model.event.state.StateChange;
+
+/**
+ * Signals a state change occured.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public final class StateChangeEvent extends ModelEvent
+{
+
+ /** . */
+ private final StateChange change;
+
+ public StateChangeEvent(StateChange change)
+ {
+ if (change == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.change = change;
+ }
+
+ /**
+ * Returns the state change that occured.
+ *
+ * @return the state change
+ */
+ public StateChange getChange()
+ {
+ return change;
+ }
+}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateModification.java (from rev 9366, branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/StateModification.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateModification.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateModification.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.model.event.state;
+
+/**
+ * An abstract class for the modification of state.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public abstract class StateModification
+{
+}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/navigational (from rev 9366, branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/navigational)
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/navigational/NavigationalStateModification.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/navigational/NavigationalStateModification.java 2007-12-18 22:47:00 UTC (rev 9366)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/navigational/NavigationalStateModification.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -20,9 +20,9 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
******************************************************************************/
-package org.jboss.portal.presentation.model.event.navigational;
+package org.jboss.portal.presentation.model.event.state.navigational;
-import org.jboss.portal.presentation.model.event.StateModification;
+import org.jboss.portal.presentation.model.event.state.StateModification;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural (from rev 9366, branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/structural)
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/structural/StructuralStateModification.java 2007-12-18 22:47:00 UTC (rev 9366)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -20,9 +20,9 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
******************************************************************************/
-package org.jboss.portal.presentation.model.event.structural;
+package org.jboss.portal.presentation.model.event.state.structural;
-import org.jboss.portal.presentation.model.event.StateModification;
+import org.jboss.portal.presentation.model.event.state.StateModification;
import org.jboss.portal.presentation.model.UIObject;
import java.util.Map;
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java 2007-12-18 22:47:00 UTC (rev 9366)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -25,10 +25,10 @@
import junit.framework.Assert;
import org.jboss.portal.presentation.model.ModelEvent;
import org.jboss.portal.presentation.model.ModelListener;
-import org.jboss.portal.presentation.model.event.StateChange;
-import org.jboss.portal.presentation.model.event.StateChangeEvent;
-import org.jboss.portal.presentation.model.event.navigational.NavigationalStateModification;
-import org.jboss.portal.presentation.model.event.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.event.state.StateChange;
+import org.jboss.portal.presentation.model.event.state.StateChangeEvent;
+import org.jboss.portal.presentation.model.event.state.navigational.NavigationalStateModification;
+import org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
import java.util.ArrayList;
import java.util.List;
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 22:47:00 UTC (rev 9366)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 22:57:38 UTC (rev 9367)
@@ -31,7 +31,7 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIPortal;
-import org.jboss.portal.presentation.model.event.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.StaleStateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
18 years, 4 months
JBoss Portal SVN: r9366 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model and 3 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-18 17:47:00 -0500 (Tue, 18 Dec 2007)
New Revision: 9366
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
Log:
- finish move implementation + basic test of the feature
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18 22:04:33 UTC (rev 9365)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18 22:47:00 UTC (rev 9366)
@@ -382,6 +382,29 @@
context.container.update(destruction);
}
+ public void move(UIObject destination) throws IllegalArgumentException, StateException
+ {
+ if (destination == null)
+ {
+ throw new IllegalArgumentException("No null object accepted");
+ }
+ if (destination instanceof AbstractUIObject)
+ {
+ //
+ AbstractUIObject tmp = (AbstractUIObject)destination;
+
+ // Perform the move operation
+ StructuralObject.Move move = context.container.structuralStateContext.move(context.structuralObject, tmp.context.structuralObject);
+
+ //
+ context.container.update(move);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Object not of right type");
+ }
+ }
+
protected abstract <T extends UIObject> boolean isAllowedAsChild(Class<T> type);
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18 22:04:33 UTC (rev 9365)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18 22:47:00 UTC (rev 9366)
@@ -94,12 +94,18 @@
if (change instanceof StructuralObject.Update)
{
StructuralObject.Update update = (StructuralObject.Update)change;
+
+ //
update(update.getObject());
}
else if (change instanceof StructuralObject.Creation)
{
StructuralObject.Creation creation = (StructuralObject.Creation)change;
+
+ //
update(creation.getParent());
+
+ //
update(creation.getChild());
}
else if (change instanceof StructuralObject.Destruction)
@@ -121,6 +127,19 @@
}
}
}
+ else if (change instanceof StructuralObject.Move)
+ {
+ StructuralObject.Move move = (StructuralObject.Move)change;
+
+ //
+ update(move.getParent());
+
+ //
+ update(move.getSource());
+
+ //
+ update(move.getDestination());
+ }
else
{
throw new AssertionError();
@@ -235,6 +254,13 @@
// Private **********************************************************************************************************
+ /**
+ * Update the state of an object if it is present. It will also reset the parent and children
+ * relationships in order to force a implicit refresh.
+ *
+ * @param structuralObject the structural object to update
+ * @return the object API implementation
+ */
private AbstractUIObject update(StructuralObject structuralObject)
{
AbstractUIObject object = universe.get(structuralObject.getId());
@@ -250,8 +276,6 @@
else
{
object.context.structuralObject = structuralObject;
-
- //
object.parent.reset();
object.children.reset();
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-18 22:04:33 UTC (rev 9365)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-18 22:47:00 UTC (rev 9366)
@@ -161,4 +161,7 @@
*/
void destroyChild(String name) throws IllegalArgumentException, StateException;
+
+ void move(UIObject destination) throws IllegalArgumentException, StateException;
+
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-18 22:04:33 UTC (rev 9365)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-18 22:47:00 UTC (rev 9366)
@@ -66,13 +66,23 @@
{
/** . */
+ private final StructuralObject parent;
+
+ /** . */
private final StructuralObject source;
/** . */
private final StructuralObject destination;
- public Move(StructuralObject source, StructuralObject destination)
+ public Move(
+ StructuralObject parent,
+ StructuralObject source,
+ StructuralObject destination)
{
+ if (parent == null)
+ {
+ throw new IllegalArgumentException();
+ }
if (source == null)
{
throw new IllegalArgumentException();
@@ -83,10 +93,16 @@
}
//
+ this.parent = parent;
this.source = source;
this.destination = destination;
}
+ public StructuralObject getParent()
+ {
+ return parent;
+ }
+
public StructuralObject getSource()
{
return source;
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 22:04:33 UTC (rev 9365)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 22:47:00 UTC (rev 9366)
@@ -39,10 +39,12 @@
import org.jboss.portal.presentation.test.model.state.structural.MockObject;
import org.jboss.portal.presentation.test.model.state.structural.MockException;
import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
+import org.jboss.portal.common.util.Tools;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.HashSet;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -537,4 +539,36 @@
assertEquals(null, context.getObject(daaId));
}
+ public void testMove() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PORTAL);
+
+ MockObject mockFooJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ MockObject mockFooDaa = mockFoo.addChild("daa", MockObject.Type.PAGE);
+
+ MockObject mockBarDaa = mockBar.addChild("daa", MockObject.Type.PAGE);
+
+ //
+ UIContext context = createContext();
+
+ //
+ UIObject foo = context.getChild("foo");
+ List<? extends UIObject> fooChildren = foo.getChildren();
+ UIObject fooJuu = foo.getChild("juu");
+ UIObject fooDaa = foo.getChild("daa");
+ UIObject bar = context.getChild("bar");
+ UIObject barDaa = bar.getChild("daa");
+ List<? extends UIObject> barChildren = bar.getChildren();
+
+ //
+ fooJuu.move(bar);
+
+ //
+ assertEquals(bar, fooJuu.getParent());
+ assertEquals(Collections.singleton(fooDaa), new HashSet<UIObject>(fooChildren));
+ assertEquals(Tools.toSet(barDaa, fooJuu), new HashSet<UIObject>(barChildren));
+ }
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-18 22:04:33 UTC (rev 9365)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-18 22:47:00 UTC (rev 9366)
@@ -227,6 +227,7 @@
{
MockObject mockSource = getValidMockObject(source);
MockObject mockDestination = getValidMockObject(destination);
+ MockObject mockParent = mockSource.getParent();
//
try
@@ -234,7 +235,7 @@
mockSource.move(mockDestination);
//
- return new StructuralObject.Move(mockSource.takeSnapshot(), mockSource.takeSnapshot());
+ return new StructuralObject.Move(mockParent.takeSnapshot(), mockSource.takeSnapshot(), mockSource.takeSnapshot());
}
catch (MockException e)
{
18 years, 4 months
JBoss Portal SVN: r9365 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-18 17:04:33 -0500 (Tue, 18 Dec 2007)
New Revision: 9365
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
remove unused logger
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 22:03:28 UTC (rev 9364)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 22:04:33 UTC (rev 9365)
@@ -24,7 +24,6 @@
import junit.framework.Assert;
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
import org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
import org.jboss.portal.presentation.model.StateScopeType;
@@ -53,9 +52,6 @@
{
/** . */
- private Logger logger = Logger.getLogger(this.getClass());
-
- /** . */
private MockModel model;
public ModelTestCase()
18 years, 4 months
JBoss Portal SVN: r9364 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: model and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-18 17:03:28 -0500 (Tue, 18 Dec 2007)
New Revision: 9364
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
more complete test case for destruction
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18 21:20:11 UTC (rev 9363)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18 22:03:28 UTC (rev 9364)
@@ -126,7 +126,7 @@
}
}
- public void resolveConflicts()
+ public void refresh()
{
switch (context.status)
{
@@ -144,6 +144,10 @@
public <T> T getProperty(StateScopeType scopeType, String propertyName, Class<T> propertyType)
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
if (scopeType == null)
{
throw new IllegalArgumentException();
@@ -178,6 +182,10 @@
public <T> void setProperty(StateScopeType scopeType, String propertyName, T propertyValue) throws StateChangeVetoException
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
if (scopeType == null)
{
throw new IllegalArgumentException();
@@ -248,6 +256,16 @@
public AbstractUIObject getChild(String name)
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException("No null name accepted");
+ }
+
+ //
for (AbstractUIObject child : getChildren())
{
if (child.getName().equals(name))
@@ -255,16 +273,30 @@
return child;
}
}
+
+ //
return null;
}
public String getName()
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
return context.structuralObject.getState().getName();
}
public final UIObject getParent()
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
if (!parent.loaded)
{
parent.object = context.container.getParent(context.structuralObject);
@@ -277,11 +309,23 @@
public final List<AbstractUIObject> getChildren()
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
return children;
}
public <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
+
+ //
StructuralObject.Creation creation;
try
{
@@ -313,6 +357,10 @@
public void destroyChild(String name) throws IllegalArgumentException, StateException
{
+ if (!context.isValid())
+ {
+ throw new IllegalStateException();
+ }
if (name == null)
{
throw new IllegalArgumentException();
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18 21:20:11 UTC (rev 9363)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18 22:03:28 UTC (rev 9364)
@@ -184,7 +184,14 @@
StructuralObject structuralObject = this.structuralStateContext.load(id);
//
- return update(structuralObject);
+ if (structuralObject != null)
+ {
+ return update(structuralObject);
+ }
+ else
+ {
+ return null;
+ }
}
else
{
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-18 21:20:11 UTC (rev 9363)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-18 22:03:28 UTC (rev 9364)
@@ -82,6 +82,16 @@
container.addModelListener(listener);
}
+ public UIObject.Status getStatus()
+ {
+ return status;
+ }
+
+ public boolean isValid()
+ {
+ return status == UIObject.Status.VALID;
+ }
+
// Package protected ************************************************************************************************
void updateStatus(StateException e)
@@ -100,4 +110,9 @@
}
}
+ void invalidate()
+ {
+ status = UIObject.Status.INVALID;
+ }
+
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java 2007-12-18 21:20:11 UTC (rev 9363)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java 2007-12-18 22:03:28 UTC (rev 9364)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model.container;
+import org.jboss.portal.presentation.model.UIObject;
+
import java.util.AbstractList;
import java.util.List;
@@ -46,6 +48,10 @@
public AbstractUIObject get(int i)
{
+ if (!object.context.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
if (content == null)
{
content = object.context.container.getChildren(object.context.structuralObject);
@@ -55,6 +61,10 @@
public int size()
{
+ if (!object.context.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
if (content == null)
{
content = object.context.container.getChildren(object.context.structuralObject);
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-18 21:20:11 UTC (rev 9363)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-18 22:03:28 UTC (rev 9364)
@@ -70,7 +70,7 @@
* <li><code>INVALID</code> status leads to throw an <code>IllegalStateException</code></li>
* </ul>
*/
- void resolveConflicts();
+ void refresh();
/**
* Return the current status.
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 21:20:11 UTC (rev 9363)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 22:03:28 UTC (rev 9364)
@@ -456,22 +456,89 @@
eventAssert.next(portal.getId(), new StructuralStateModification.Creation(UIPortal.class, "foo", new HashMap<String, String>()));
}
- public void testDestroyChild() throws Exception
+ public void testDestroyChildUpdatesLoadedDescendant() throws Exception
{
- MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
- MockObject mockBar = model.getRoot().addChild("bar", MockObject.Type.PORTAL);
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ MockObject mockDaa = mockJuu.addChild("daa", MockObject.Type.PAGE);
+ //
+ String daaId = mockDaa.getId();
+
+ //
UIContext context = createContext();
- UIPortal foo = (UIPortal)context.getChild("foo");
- UIPage juu = (UIPage)foo.getChild("juu");
+ // Load only the descendant
+ UIObject daa = context.getObject(daaId);
+ List<? extends UIObject> daaChildren = daa.getChildren();
+ // Destroy foo
context.destroyChild("foo");
- List<? extends UIObject> rootChildren = context.getChildren();
+ // Check daa state
+ assertEquals(UIObject.Status.INVALID, daa.getStatus());
+ assertEquals(null, context.getObject(daaId));
+ try
+ {
+ daaChildren.size();
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+ }
+ public void testDestroyChildUpdatesLoadedSubtree() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ MockObject mockDaa = mockJuu.addChild("daa", MockObject.Type.PAGE);
+ //
+ String fooId = mockFoo.getId();
+ String juuId = mockJuu.getId();
+ String daaId = mockDaa.getId();
+ //
+ UIContext context = createContext();
+
+ // Load subtree entirely
+ UIObject foo = context.getChild("foo");
+ UIObject juu = foo.getChild("juu");
+ UIObject daa = juu.getChild("daa");
+ List<? extends UIObject> fooChildren = foo.getChildren();
+ List<? extends UIObject> juuChildren = juu.getChildren();
+ List<? extends UIObject> daaChildren = daa.getChildren();
+
+ //
+ foo.destroyChild("juu");
+
+ //
+ try
+ {
+ juuChildren.size();
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+ try
+ {
+ daaChildren.size();
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+ assertEquals(0, fooChildren.size());
+ assertEquals(UIObject.Status.VALID, foo.getStatus());
+ assertEquals(UIObject.Status.INVALID, juu.getStatus());
+ assertEquals(UIObject.Status.INVALID, daa.getStatus());
+ assertSame(foo, context.getObject(fooId));
+ assertEquals(null, context.getObject(juuId));
+ assertEquals(null, context.getObject(daaId));
}
+
}
18 years, 4 months
JBoss Portal SVN: r9363 - branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-18 16:20:11 -0500 (Tue, 18 Dec 2007)
New Revision: 9363
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
remove dead code
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-18 18:34:40 UTC (rev 9362)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-18 21:20:11 UTC (rev 9363)
@@ -173,23 +173,6 @@
assertEquals(Collections.singletonMap("foo", "bar2"), rootState2_1.getProperties());
}
- private void assertStale(StructuralObject object)
- {
- try
- {
- ssc.validate(object);
- fail();
- }
- catch (StateException ignore)
- {
- }
- }
-
- private void assertNotStale(StructuralObject object)
- {
- ssc.validate(object);
- }
-
public void testAddChild() throws MockException
{
MockObject mockRoot = model.getRoot();
@@ -420,4 +403,20 @@
}
}
+ private void assertStale(StructuralObject object)
+ {
+ try
+ {
+ ssc.validate(object);
+ fail();
+ }
+ catch (StateException ignore)
+ {
+ }
+ }
+
+ private void assertNotStale(StructuralObject object)
+ {
+ ssc.validate(object);
+ }
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 18:34:40 UTC (rev 9362)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 21:20:11 UTC (rev 9363)
@@ -83,71 +83,6 @@
this.model = null;
}
- /**
- *
- * @throws Exception
- */
- /*public void testCreateChild() throws Exception
- {
- //Adding a UIContext...this should result in an IllegalArgumentException
- try
- {
- this.uiContext.createChild("duplicateRoot", UIContext.class);
- }
- catch(Exception e)
- {
- this.assertEquals(e.getClass(), IllegalArgumentException.class);
- }
-
- //Assert the state of UIPortal added to the UIObject tree
- UIPortal portal = this.uiContext.createChild("defaultPortal", UIPortal.class);
- assertEquals(portal.getName(), "defaultPortal");
- assertEquals(portal.getId(), "/defaultPortal");
- assertTrue(portal.getParent() instanceof UIContext);
-
- //Add a UIPage to the UIPortal
- UIPage page = portal.createChild("defaultPage", UIPage.class);
- assertEquals(page.getName(), "defaultPage");
- assertEquals(page.getId(), "/defaultPortal/defaultPage");
- assertTrue(page.getParent() instanceof UIPortal);
-
- //Add a UIPage to the UIContainer
- UIContainer container = page.createChild("defaultContainer", UIContainer.class);
- assertEquals(container.getName(), "defaultContainer");
- assertEquals(container.getId(), "/defaultPortal/defaultPage/defaultContainer");
- assertTrue(container.getParent() instanceof UIPage);
-
- //Add a UIWindow to UIPage
- UIWindow window = container.createChild("defaultWindow", UIWindow.class);
- assertEquals(window.getName(), "defaultWindow");
- assertEquals(window.getId(), "/defaultPortal/defaultPage/defaultContainer/defaultWindow");
- assertTrue(window.getParent() instanceof UIContainer);
- }*/
-
- /**
- *
- * @throws Exception
- */
- /*public void testDestroyChild() throws Exception
- {
- //Assert the state of UIPortal added to the UIObject tree
- UIPortal portal = this.uiContext.createChild("defaultPortal", UIPortal.class);
-
- //Add a UIPage to the UIPortal
- UIPage page = portal.createChild("defaultPage", UIPage.class);
-
- //Add a UIPage to the UIContainer
- UIContainer container = page.createChild("defaultContainer", UIContainer.class);
-
- //Add a UIWindow to UIPage
- UIWindow window = container.createChild("defaultWindow", UIWindow.class);
-
- //Destroy the container. When this is done, both container and window must be destroyed from the UIObject tree
- page.removeChild(container.getName());
- List<UIObject> pageChildren = page.getChildren();
- assertTrue(pageChildren == null || pageChildren.size() == 0);
- }*/
-
public void testUIContextParentIsNull()
{
UIContext context = createContext();
18 years, 4 months
JBoss Portal SVN: r9362 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model: container and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-18 13:34:40 -0500 (Tue, 18 Dec 2007)
New Revision: 9362
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java
Log:
- refactor a bit
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java 2007-12-18 18:34:40 UTC (rev 9362)
@@ -25,9 +25,8 @@
import org.jboss.portal.presentation.model.UIContainer;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -36,9 +35,9 @@
public class UIContainerImpl extends AbstractUIObject implements UIContainer
{
- public UIContainerImpl(UIObjectContainer context, StructuralObject object)
+ public UIContainerImpl(UIObjectContext context)
{
- super(context, object);
+ super(context);
}
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-18 18:34:40 UTC (rev 9362)
@@ -23,12 +23,11 @@
package org.jboss.portal.presentation.impl.model;
import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.ModelListener;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -37,9 +36,9 @@
public class UIContextImpl extends AbstractUIObject implements UIContext
{
- public UIContextImpl(UIObjectContainer context, StructuralObject object)
+ public UIContextImpl(UIObjectContext context)
{
- super(context, object);
+ super(context);
}
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
@@ -49,11 +48,11 @@
public UIObject getObject(String id)
{
- return container.getObject(id);
+ return context.getObject(id);
}
public void addModelListener(ModelListener listener)
{
- container.addModelListener(listener);
+ context.addModelListener(listener);
}
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java 2007-12-18 18:34:40 UTC (rev 9362)
@@ -26,9 +26,8 @@
import org.jboss.portal.presentation.model.UIContainer;
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -37,9 +36,9 @@
public class UIPageImpl extends AbstractUIObject implements UIPage
{
- public UIPageImpl(UIObjectContainer context, StructuralObject object)
+ public UIPageImpl(UIObjectContext context)
{
- super(context, object);
+ super(context);
}
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java 2007-12-18 18:34:40 UTC (rev 9362)
@@ -25,9 +25,8 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -36,9 +35,9 @@
public class UIPortalImpl extends AbstractUIObject implements UIPortal
{
- public UIPortalImpl(UIObjectContainer context, StructuralObject object)
+ public UIPortalImpl(UIObjectContext context)
{
- super(context, object);
+ super(context);
}
protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-18 18:34:40 UTC (rev 9362)
@@ -27,9 +27,8 @@
import org.jboss.portal.presentation.model.StateScopeType;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContext;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -38,9 +37,9 @@
public class UIWindowImpl extends AbstractUIObject implements UIWindow
{
- public UIWindowImpl(UIObjectContainer context, StructuralObject object)
+ public UIWindowImpl(UIObjectContext context)
{
- super(context, object);
+ super(context);
}
/**
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18 17:34:47 UTC (rev 9361)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18 18:34:40 UTC (rev 9362)
@@ -29,13 +29,9 @@
import org.jboss.portal.presentation.model.event.StateChangeEvent;
import org.jboss.portal.presentation.model.event.navigational.NavigationalStateModification;
import org.jboss.portal.presentation.model.event.structural.StructuralStateModification;
-import org.jboss.portal.presentation.model.state.NoSuchStateException;
-import org.jboss.portal.presentation.model.state.StaleStateException;
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
-import org.jboss.portal.presentation.impl.model.container.UIObjectList;
import java.io.Serializable;
import java.util.Collections;
@@ -44,9 +40,10 @@
import java.util.Map;
/**
+ * Implement base fonctionnality of the <code>UIObject</code> interface.
+ *
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- *
*/
public abstract class AbstractUIObject implements UIObject, Serializable
{
@@ -54,8 +51,8 @@
/** . */
private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
- /** . */
- protected final UIObjectContainer container;
+ /** The context. */
+ protected final UIObjectContext context;
/** . */
final UIObjectList children;
@@ -63,34 +60,24 @@
/** . */
final UIObjectRef parent;
- /** This is used to assist with data needed during lazy loading, other state related data etc... */
- StructuralObject structuralObject;
-
- /** . */
- Status status;
-
- public AbstractUIObject(UIObjectContainer container, StructuralObject object)
+ public AbstractUIObject(UIObjectContext context)
{
- this.structuralObject = object;
- this.container = container;
+ if (context == null)
+ {
+ throw new IllegalArgumentException("No null context accepted");
+ }
+
+ //
+ this.context = context;
this.children = new UIObjectList(this);
this.parent = new UIObjectRef();
- this.status = Status.VALID;
}
- protected final StructuralObject getStructuralObject()
- {
- return structuralObject;
- }
-
// UIObject interface implementation-----------------------------------------------------------------------------------------------------------------------------
- /**
- *
- */
public String getId()
{
- return structuralObject.getId();
+ return context.structuralObject.getId();
}
/**
@@ -124,40 +111,24 @@
public Status getStatus()
{
- return status;
+ return context.status;
}
- void updateStatus(StateException e)
- {
- if (e instanceof NoSuchStateException)
- {
- status = Status.INVALID;
- }
- else if (e instanceof StaleStateException)
- {
- status = Status.STALE;
- }
- else
- {
- throw new AssertionError(e);
- }
- }
-
public void validate()
{
try
{
- container.structuralStateContext.validate(structuralObject);
+ context.container.structuralStateContext.validate(context.structuralObject);
}
catch (StateException e)
{
- updateStatus(e);
+ context.updateStatus(e);
}
}
public void resolveConflicts()
{
- switch (status)
+ switch (context.status)
{
case STALE:
// Todo :-)
@@ -189,10 +160,10 @@
switch (scopeType)
{
case NAVIGATIONAL:
- value = container.navigationalStateContext.get(getId(), propertyName);
+ value = context.container.navigationalStateContext.get(getId(), propertyName);
break;
case STRUCTURAL:
- value = structuralObject.getState().getProperties().get(propertyName);
+ value = context.structuralObject.getState().getProperties().get(propertyName);
break;
default:
throw new AssertionError();
@@ -225,13 +196,13 @@
case NAVIGATIONAL:
{
// Have context process the change
- container.navigationalStateContext.set(id, propertyName, propertyValue);
+ context.container.navigationalStateContext.set(id, propertyName, propertyValue);
// Broadcast event
NavigationalStateModification mod = new NavigationalStateModification(propertyName, propertyValue);
StateChange<NavigationalStateModification> change = new StateChange<NavigationalStateModification>(id, mod);
StateChangeEvent event = new StateChangeEvent(change);
- container.fireEvent(event);
+ context.container.fireEvent(event);
break;
}
case STRUCTURAL:
@@ -245,7 +216,7 @@
StructuralObject.Update update;
try
{
- update = container.structuralStateContext.update(structuralObject, changes);
+ update = context.container.structuralStateContext.update(context.structuralObject, changes);
}
catch (StateException e)
{
@@ -256,13 +227,13 @@
}
//
- container.update(update);
+ context.container.update(update);
// Broadcast event
StructuralStateModification mod = new StructuralStateModification.Update(changes);
StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(id, mod);
StateChangeEvent event = new StateChangeEvent(change);
- container.fireEvent(event);
+ context.container.fireEvent(event);
}
else
{
@@ -287,22 +258,16 @@
return null;
}
- /**
- *
- */
public String getName()
{
- return structuralObject.getState().getName();
+ return context.structuralObject.getState().getName();
}
- /**
- *
- */
public final UIObject getParent()
{
if (!parent.loaded)
{
- parent.object = container.getParent(structuralObject);
+ parent.object = context.container.getParent(context.structuralObject);
parent.loaded = true;
}
@@ -310,9 +275,6 @@
return parent.object;
}
- /**
- *
- */
public final List<AbstractUIObject> getChildren()
{
return children;
@@ -323,18 +285,18 @@
StructuralObject.Creation creation;
try
{
- creation = container.structuralStateContext.create(structuralObject, type, name, EMPTY_STATE);
+ creation = context.container.structuralStateContext.create(context.structuralObject, type, name, EMPTY_STATE);
}
catch (StateException e)
{
- updateStatus(e);
+ context.updateStatus(e);
//
throw e;
}
//
- container.update(creation);
+ context.container.update(creation);
//
StructuralObject child = creation.getChild();
@@ -343,10 +305,10 @@
StructuralStateModification mod = new StructuralStateModification.Creation(type, name, EMPTY_STATE);
StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(child.getId(), mod);
StateChangeEvent event = new StateChangeEvent(change);
- container.fireEvent(event);
+ context.container.fireEvent(event);
//
- return type.cast(container.getObject(child.getId()));
+ return type.cast(context.getObject(child.getId()));
}
public void destroyChild(String name) throws IllegalArgumentException, StateException
@@ -366,10 +328,10 @@
}
// Destroy the child
- StructuralObject.Destruction destruction = container.structuralStateContext.destroy(namedChild.structuralObject);
+ StructuralObject.Destruction destruction = context.container.structuralStateContext.destroy(namedChild.context.structuralObject);
//
- container.update(destruction);
+ context.container.update(destruction);
}
protected abstract <T extends UIObject> boolean isAllowedAsChild(Class<T> type);
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18 17:34:47 UTC (rev 9361)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18 18:34:40 UTC (rev 9362)
@@ -55,16 +55,16 @@
private final Map<String, AbstractUIObject> universe = new HashMap<String, AbstractUIObject>();
/** . */
- protected final StructuralStateContext structuralStateContext;
+ private final List<ModelListener> listeners;
/** . */
- protected final NavigationalStateContext navigationalStateContext;
+ final UIContext root;
/** . */
- protected final List<ModelListener> listeners;
+ final StructuralStateContext structuralStateContext;
/** . */
- protected final UIContext root;
+ final NavigationalStateContext navigationalStateContext;
public UIObjectContainer(StructuralStateContext structuralStateContext, NavigationalStateContext navigationalStateContext)
{
@@ -80,15 +80,14 @@
this.root = root;
}
+ // Public ***********************************************************************************************************
+
public UIContext getRoot()
{
return root;
}
- public UIObject getObject(String id)
- {
- return getObject(id, true);
- }
+ // Package protected ************************************************************************************************
void update(StructuralObject.Change change)
{
@@ -118,7 +117,7 @@
//
if (o != null)
{
- o.status = UIObject.Status.INVALID;
+ o.context.status = UIObject.Status.INVALID;
}
}
}
@@ -166,7 +165,7 @@
* @param loadIfAbsent load the object from the structural state context if it is not present
* @return the loaded object
*/
- private AbstractUIObject getObject(String id, boolean loadIfAbsent)
+ AbstractUIObject getObject(String id, boolean loadIfAbsent)
{
try
{
@@ -198,29 +197,60 @@
}
}
+ void addModelListener(ModelListener listener)
+ {
+ if (listener == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ if (!listeners.contains(listener))
+ {
+ listeners.add(listener);
+ }
+ }
+
+ void fireEvent(ModelEvent event)
+ {
+ for (ModelListener listener : listeners)
+ {
+ try
+ {
+ listener.onEvent(event);
+ }
+ catch (Exception ignore)
+ {
+ System.out.println("ignore = " + ignore);
+ }
+ }
+ }
+
+ // Private **********************************************************************************************************
+
private AbstractUIObject update(StructuralObject structuralObject)
{
- AbstractUIObject context = universe.get(structuralObject.getId());
+ AbstractUIObject object = universe.get(structuralObject.getId());
//
- if (context == null)
+ if (object == null)
{
- context = createObject(structuralObject);
+ object = createObject(structuralObject);
//
- universe.put(structuralObject.getId(), context);
+ universe.put(structuralObject.getId(), object);
}
else
{
- context.structuralObject = structuralObject;
+ object.context.structuralObject = structuralObject;
//
- context.parent.invalidate();
- context.children.invalidate();
+ object.parent.reset();
+ object.children.reset();
}
//
- return context;
+ return object;
}
private AbstractUIObject createObject(StructuralObject state)
@@ -228,58 +258,32 @@
Class type = state.getState().getType();
//
+ UIObjectContext context = new UIObjectContext(this, state);
+
+ //
if(type == UIContext.class)
{
- return new UIContextImpl(this, state);
+ return new UIContextImpl(context);
}
else if(type == UIPortal.class)
{
- return new UIPortalImpl(this, state);
+ return new UIPortalImpl(context);
}
else if(type == UIPage.class)
{
- return new UIPageImpl(this, state);
+ return new UIPageImpl(context);
}
else if(type == UIContainer.class)
{
- return new UIContainerImpl(this, state);
+ return new UIContainerImpl(context);
}
else if(type == UIWindow.class)
{
- return new UIWindowImpl(this, state);
+ return new UIWindowImpl(context);
}
else
{
throw new AssertionError();
}
}
-
- public void addModelListener(ModelListener listener)
- {
- if (listener == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- if (!listeners.contains(listener))
- {
- listeners.add(listener);
- }
- }
-
- protected void fireEvent(ModelEvent event)
- {
- for (ModelListener listener : listeners)
- {
- try
- {
- listener.onEvent(event);
- }
- catch (Exception ignore)
- {
- System.out.println("ignore = " + ignore);
- }
- }
- }
}
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-18 18:34:40 UTC (rev 9362)
@@ -0,0 +1,103 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.impl.model.container;
+
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StaleStateException;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.ModelListener;
+
+/**
+ * Encapsulate internal of an object.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public final class UIObjectContext
+{
+
+ /** . */
+ UIObjectContainer container;
+
+ /** . */
+ StructuralObject structuralObject;
+
+ /** . */
+ UIObject.Status status;
+
+ public UIObjectContext(UIObjectContainer container, StructuralObject structuralObject)
+ {
+ if (container == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (structuralObject == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.container = container;
+ this.structuralObject = structuralObject;
+ this.status = UIObject.Status.VALID;
+ }
+
+ // Public ***********************************************************************************************************
+
+ public UIContext getRoot()
+ {
+ return container.root;
+ }
+
+ public UIObject getObject(String id)
+ {
+ return container.getObject(id, true);
+ }
+
+ public void addModelListener(ModelListener listener)
+ {
+ container.addModelListener(listener);
+ }
+
+ // Package protected ************************************************************************************************
+
+ void updateStatus(StateException e)
+ {
+ if (e instanceof NoSuchStateException)
+ {
+ status = UIObject.Status.INVALID;
+ }
+ else if (e instanceof StaleStateException)
+ {
+ status = UIObject.Status.STALE;
+ }
+ else
+ {
+ throw new AssertionError(e);
+ }
+ }
+
+}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java 2007-12-18 17:34:47 UTC (rev 9361)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java 2007-12-18 18:34:40 UTC (rev 9362)
@@ -29,18 +29,18 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class UIObjectList extends AbstractList<AbstractUIObject>
+final class UIObjectList extends AbstractList<AbstractUIObject>
{
/** . */
private List<AbstractUIObject> content;
/** . */
- private final AbstractUIObject context;
+ private final AbstractUIObject object;
- public UIObjectList(AbstractUIObject context)
+ UIObjectList(AbstractUIObject object)
{
- this.context = context;
+ this.object = object;
this.content = null;
}
@@ -48,7 +48,7 @@
{
if (content == null)
{
- content = context.container.getChildren(context.structuralObject);
+ content = object.context.container.getChildren(object.context.structuralObject);
}
return content.get(i);
}
@@ -57,12 +57,12 @@
{
if (content == null)
{
- content = context.container.getChildren(context.structuralObject);
+ content = object.context.container.getChildren(object.context.structuralObject);
}
return content.size();
}
- void invalidate()
+ void reset()
{
content = null;
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java 2007-12-18 17:34:47 UTC (rev 9361)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java 2007-12-18 18:34:40 UTC (rev 9362)
@@ -23,10 +23,12 @@
package org.jboss.portal.presentation.impl.model.container;
/**
+ * A lazy reference.
+ *
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class UIObjectRef
+final class UIObjectRef
{
/** . */
@@ -35,13 +37,13 @@
/** . */
boolean loaded;
- public UIObjectRef()
+ UIObjectRef()
{
object = null;
loaded = false;
}
- void invalidate()
+ void reset()
{
loaded = false;
object = null;
18 years, 4 months
JBoss Portal SVN: r9361 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: impl and 6 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-12-18 12:34:47 -0500 (Tue, 18 Dec 2007)
New Revision: 9361
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/ConstraintViolationException.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockException.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/DuplicateStateException.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/NoSuchStateException.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateException.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
Log:
- isolate model state management in a package
- implement destroy and move (partially)
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -150,7 +150,7 @@
//TODO: set proper status
//TODO: set proper parent reference
- List<UIObject> windows = page.getChildren();
+ List<? extends UIObject> windows = page.getChildren();
List clientWindows = new ArrayList();
for(int i=0; i<windows.size(); i++)
{
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -336,7 +336,7 @@
if(uiObject instanceof UIPage)
{
UIPage page = (UIPage)uiObject;
- List<UIObject> windows = page.getChildren();
+ List<? extends UIObject> windows = page.getChildren();
for(int i=0; i<windows.size(); i++)
{
UIObject cour = windows.get(i);
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -23,7 +23,7 @@
package org.jboss.portal.presentation.impl;
import org.jboss.portal.presentation.client.PresentationContext;
-import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
import org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIObject;
@@ -57,7 +57,7 @@
private PresentationServer presentationServer = null;
/** . */
- private UIContextImpl root;
+ private UIObjectContainer container;
public PresentationContextImpl(PresentationServer presentationServer, ServerInvocation invocation)
{
@@ -67,7 +67,7 @@
public UIContext getUIContext()
{
- if (root == null)
+ if (container == null)
{
HttpSession session = this.invocation.getServerContext().getClientRequest().getSession();
@@ -80,11 +80,11 @@
}
//
- root = new UIContextImpl(presentationServer.getStructuralStateManager(), nsc);
+ container = new UIObjectContainer(presentationServer.getStructuralStateManager(), nsc);
}
//
- return root;
+ return container.getRoot();
}
/**
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContainerImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -25,17 +25,18 @@
import org.jboss.portal.presentation.model.UIContainer;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIContainerImpl extends UIObjectImpl implements UIContainer
+public class UIContainerImpl extends AbstractUIObject implements UIContainer
{
- public UIContainerImpl(UIContextImpl context, StructuralObject object)
+ public UIContainerImpl(UIObjectContainer context, StructuralObject object)
{
super(context, object);
}
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -1,245 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated 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.jboss.portal.presentation.impl.model;
-
-import org.jboss.portal.presentation.model.ModelEvent;
-import org.jboss.portal.presentation.model.ModelListener;
-import org.jboss.portal.presentation.model.UIContainer;
-import org.jboss.portal.presentation.model.UIContext;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.UIPortal;
-import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- *
- */
-public final class UIContextImpl extends UIObjectImpl implements UIContext
-{
-
- /** . */
- private final Map<String, UIObjectImpl> universe = new HashMap<String, UIObjectImpl>();
-
- /** . */
- protected final StructuralStateContext structuralStateContext;
-
- /** . */
- protected final NavigationalStateContext navigationalStateContext;
-
- /** . */
- protected final List<ModelListener> listeners;
-
- private static StructuralObject getRootState(StructuralStateContext loader)
- {
- return loader.load(loader.getRootId());
- }
-
- public UIContextImpl(StructuralStateContext structuralStateContext, NavigationalStateContext navigationalStateContext)
- {
- super(getRootState(structuralStateContext));
-
- //
- this.structuralStateContext = structuralStateContext;
- this.navigationalStateContext = navigationalStateContext;
- this.listeners = new ArrayList<ModelListener>();
-
- // Put our self in the universe
- universe.put(getId(), this);
- }
-
- /**
- *
- */
- public UIObject getObject(String id)
- {
- return getObject(id, true);
- }
-
- void update(StructuralObject.Change change)
- {
- if (change instanceof StructuralObject.Update)
- {
- StructuralObject.Update update = (StructuralObject.Update)change;
- context.updateUniverse(update.getObject());
- }
- else if (change instanceof StructuralObject.Creation)
- {
- StructuralObject.Creation creation = (StructuralObject.Creation)change;
- context.updateUniverse(creation.getParent());
- context.updateUniverse(creation.getChild());
- }
- else
- {
- throw new AssertionError();
- }
- }
-
- UIObjectImpl getParent(StructuralObject structuralObject)
- {
- StructuralObject parentStructuralState = context.structuralStateContext.loadParent(structuralObject);
- return context.updateUniverse(parentStructuralState);
- }
-
- List<UIObject> getChildren(StructuralObject structuralObject)
- {
- ArrayList<UIObject> children = new ArrayList<UIObject>();
- for (StructuralObject structuralChild : context.structuralStateContext.loadChildren(structuralObject))
- {
- UIObjectImpl child = context.updateUniverse(structuralChild);
- children.add(child);
- }
- return children;
- }
-
- /**
- * Get an object from the universe. If the parameter <code>loadIfAbsent</code> has the value <code>false</code>
- * and the object is not in the universe it will throw an <code>AssertionError</code> otherwise it will return
- * the object.
- *
- * @param id the id of the object to obtain
- * @param loadIfAbsent load the object from the structural state context if it is not present
- * @return the loaded object
- */
- private UIObjectImpl getObject(String id, boolean loadIfAbsent)
- {
- try
- {
- UIObjectImpl object = universe.get(id);
-
- //
- if (object != null)
- {
- return object;
- }
-
- //
- if (loadIfAbsent)
- {
- // Fetch the state of the UIObject in question
- StructuralObject structuralObject = this.structuralStateContext.load(id);
-
- //
- return updateUniverse(structuralObject);
- }
- else
- {
- throw new AssertionError("Should not be here");
- }
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- private UIObjectImpl updateUniverse(StructuralObject structuralObject)
- {
- UIObjectImpl object = universe.get(structuralObject.getId());
-
- //
- if (object == null)
- {
- object = createObject(structuralObject);
-
- //
- universe.put(structuralObject.getId(), object);
- }
- else
- {
- object.update(structuralObject);
- }
-
- //
- return object;
- }
-
- private UIObjectImpl createObject(StructuralObject state)
- {
- Class type = state.getState().getType();
-
- //
- if(type == UIPortal.class)
- {
- return new UIPortalImpl(this, state);
- }
- else if(type == UIPage.class)
- {
- return new UIPageImpl(this, state);
- }
- else if(type == UIContainer.class)
- {
- return new UIContainerImpl(this, state);
- }
- else if(type == UIWindow.class)
- {
- return new UIWindowImpl(this, state);
- }
- else
- {
- throw new AssertionError();
- }
- }
-
- public void addModelListener(ModelListener listener)
- {
- if (listener == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- if (!listeners.contains(listener))
- {
- listeners.add(listener);
- }
- }
-
- protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
- {
- return type == UIPortal.class;
- }
-
- protected void fireEvent(ModelEvent event)
- {
- for (ModelListener listener : listeners)
- {
- try
- {
- listener.onEvent(event);
- }
- catch (Exception ignore)
- {
- System.out.println("ignore = " + ignore);
- }
- }
- }
-}
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -0,0 +1,59 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.impl.model;
+
+import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.ModelListener;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIContextImpl extends AbstractUIObject implements UIContext
+{
+
+ public UIContextImpl(UIObjectContainer context, StructuralObject object)
+ {
+ super(context, object);
+ }
+
+ protected <T extends UIObject> boolean isAllowedAsChild(Class<T> type)
+ {
+ return type == UIPortal.class;
+ }
+
+ public UIObject getObject(String id)
+ {
+ return container.getObject(id);
+ }
+
+ public void addModelListener(ModelListener listener)
+ {
+ container.addModelListener(listener);
+ }
+}
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -1,583 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated 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.jboss.portal.presentation.impl.model;
-
-import org.jboss.portal.common.NotYetImplemented;
-import org.jboss.portal.presentation.model.StateScopeType;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.event.StateChange;
-import org.jboss.portal.presentation.model.event.StateChangeEvent;
-import org.jboss.portal.presentation.model.event.navigational.NavigationalStateModification;
-import org.jboss.portal.presentation.model.event.structural.StructuralStateModification;
-import org.jboss.portal.presentation.model.state.NoSuchStateException;
-import org.jboss.portal.presentation.model.state.StaleStateException;
-import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.model.state.StateException;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- *
- */
-public abstract class UIObjectImpl implements UIObject, Serializable
-{
-
- /** . */
- private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
-
- /** . */
- protected final UIContextImpl context;
-
- /** . */
- private List<UIObject> children;
-
- /** . */
- private UIObjectImpl parent;
-
- /** This is used to assist with data needed during lazy loading, other state related data etc... */
- private StructuralObject structuralObject;
-
- /** . */
- private Status status;
-
- public UIObjectImpl(UIContextImpl context, StructuralObject object)
- {
- this.structuralObject = object;
- this.context = context;
- this.children = null;
- this.parent = null;
- this.status = Status.VALID;
- }
-
- public UIObjectImpl(StructuralObject object)
- {
- this.structuralObject = object;
- this.context = (UIContextImpl)this;
- this.children = null;
- this.parent = null;
- this.status = Status.VALID;
- }
-
- protected final StructuralObject getStructuralObject()
- {
- return structuralObject;
- }
-
- //UIObject interface implementation-----------------------------------------------------------------------------------------------------------------------------
-
- /**
- *
- */
- public String getId()
- {
- return structuralObject.getId();
- }
-
- /**
- * Attempt to cast the value argument to the provided type argument. If the value argument type is assignable
- * to the provided type, the value is returned, otherwise if it is not or the value is null, null is returned.
- *
- * todo: Move that to common package.
- *
- * @param value the value to cast
- * @param type the type to downcast
- * @return the casted value or null
- */
- private <T> T safeCast(Object value, Class<T> type)
- {
- if (value == null)
- {
- return null;
- }
- else
- {
- if (type.isAssignableFrom(value.getClass()))
- {
- return type.cast(value);
- }
- else
- {
- return null;
- }
- }
- }
-
- public Status getStatus()
- {
- return status;
- }
-
- void updateStatus(StateException e)
- {
- if (e instanceof NoSuchStateException)
- {
- status = Status.INVALID;
- }
- else if (e instanceof StaleStateException)
- {
- status = Status.STALE;
- }
- else
- {
- throw new AssertionError(e);
- }
- }
-
- public void validate()
- {
- try
- {
- context.structuralStateContext.validate(structuralObject);
- }
- catch (StateException e)
- {
- updateStatus(e);
- }
- }
-
- public void resolveConflicts()
- {
- switch (status)
- {
- case STALE:
- // Todo :-)
- throw new NotYetImplemented();
- case INVALID:
- // Cannot be resolved
- throw new IllegalStateException();
- case VALID:
- // Nothing to do
- break;
- }
- }
-
- public <T> T getProperty(StateScopeType scopeType, String propertyName, Class<T> propertyType)
- {
- if (scopeType == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyType == null)
- {
- throw new IllegalArgumentException();
- }
- Object value;
- switch (scopeType)
- {
- case NAVIGATIONAL:
- value = context.navigationalStateContext.get(getId(), propertyName);
- break;
- case STRUCTURAL:
- value = structuralObject.getState().getProperties().get(propertyName);
- break;
- default:
- throw new AssertionError();
- }
- return safeCast(value, propertyType);
- }
-
- public Object getProperty(StateScopeType scopeType, String propertyName)
- {
- return getProperty(scopeType, propertyName, Object.class);
- }
-
- public <T> void setProperty(StateScopeType scopeType, String propertyName, T propertyValue) throws StateChangeVetoException
- {
- if (scopeType == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- String id = getId();
-
- //
- switch (scopeType)
- {
- case NAVIGATIONAL:
- {
- // Have context process the change
- context.navigationalStateContext.set(id, propertyName, propertyValue);
-
- // Broadcast event
- NavigationalStateModification mod = new NavigationalStateModification(propertyName, propertyValue);
- StateChange<NavigationalStateModification> change = new StateChange<NavigationalStateModification>(id, mod);
- StateChangeEvent event = new StateChangeEvent(change);
- context.fireEvent(event);
- break;
- }
- case STRUCTURAL:
- {
- if (propertyValue instanceof String)
- {
- Map<String, String> changes = new HashMap<String, String>();
- changes.put(propertyName, (String)propertyValue);
-
- // Have context process change
- StructuralObject.Update update;
- try
- {
- update = context.structuralStateContext.update(structuralObject, changes);
- }
- catch (StateException e)
- {
- validate();
-
- //
- throw e;
- }
-
- //
- context.update(update);
-
- // Broadcast event
- StructuralStateModification mod = new StructuralStateModification.Update(changes);
- StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(id, mod);
- StateChangeEvent event = new StateChangeEvent(change);
- context.fireEvent(event);
- }
- else
- {
- throw new StateChangeVetoException("Structural property value must be string value");
- }
- break;
- }
- default:
- throw new AssertionError();
- }
- }
-
- public UIObject getChild(String name)
- {
- for (UIObject child : getChildren())
- {
- if (child.getName().equals(name))
- {
- return child;
- }
- }
- return null;
- }
-
- /**
- *
- */
- public String getName()
- {
- return structuralObject.getState().getName();
- }
-
- /**
- *
- */
- public final UIObject getParent()
- {
- if (this instanceof UIContextImpl)
- {
- return null;
- }
-
- //
- if (parent == null)
- {
- parent = context.getParent(structuralObject);
- }
-
- //
- return parent;
- }
-
- /**
- *
- */
- public final List<UIObject> getChildren()
- {
- if (children == null)
- {
- children = context.getChildren(structuralObject);
- }
- return children;
- }
-
- public <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException
- {
- StructuralObject.Creation creation;
- try
- {
- creation = context.structuralStateContext.create(structuralObject, type, name, EMPTY_STATE);
- }
- catch (StateException e)
- {
- updateStatus(e);
-
- //
- throw e;
- }
-
- //
- context.update(creation);
-
- //
- StructuralObject child = creation.getChild();
-
- // Eventing
- StructuralStateModification mod = new StructuralStateModification.Creation(type, name, EMPTY_STATE);
- StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(child.getId(), mod);
- StateChangeEvent event = new StateChangeEvent(change);
- context.fireEvent(event);
-
- //
- return type.cast(context.getObject(child.getId()));
- }
-
- void update(StructuralObject object)
- {
- structuralObject = object;
- parent = null;
- children = null;
- }
-
- protected abstract <T extends UIObject> boolean isAllowedAsChild(Class<T> type);
-
- /**
- *
- */
-// public <T extends UIObject> List<T> getChildren(Class<T> type)
-// {
-// try
-// {
-// List<T> filteredList = new ArrayList<T>();
-//
-// //Making sure all children are fully loaded
-// List<UIObject> allChildren = this.getChildren();
-//
-// Class<T> implementationClass = this.getImplementationClass(type);
-// if(allChildren != null)
-// {
-// for(int i=0; i<allChildren.size(); i++)
-// {
-// UIObject child = allChildren.get(i);
-// if(implementationClass == child.getClass())
-// {
-// filteredList.add((T)child);
-// }
-// }
-// }
-// return filteredList;
-// }
-// catch(Exception e)
-// {
-// throw new RuntimeException(e);
-// }
-// throw new UnsupportedOperationException("todo");
-// }
-
-
-
- /**
- *
- */
-// public <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException
-// {
-// if(!this.isAllowedAsChild(type))
-// {
-// throw new IllegalArgumentException(type.getName()+" cannot be added as a child to this parent");
-// }
-// try
-// {
-// T child = this.getImplementationClass(type).newInstance();
-//
-// //Name
-// ((UIObjectImpl)child).name = name;
-//
-// //Id
-// ((UIObjectImpl)child).id = this.generateChildId(name);
-//
-// //State
-// ((UIObjectImpl)child).state = this.getUIContext().getStructuralStateManager().load(((UIObjectImpl)child).id);
-//
-// this.children.add(child);
-//
-// return child;
-// }
-// catch(Exception e)
-// {
-// throw new RuntimeException(e);
-// }
-// }
-//
-// /**
-// *
-// */
-// public void removeChild(String name)
-// {
-// //Make sure all children are loaded
-// this.getChildren();
-// if(this.children != null)
-// {
-// for(int i=0; i<this.children.size(); i++)
-// {
-// UIObject child = this.children.get(i);
-// if(child.getName().equals(name))
-// {
-// this.children.remove(child);
-// break;
-// }
-// }
-// }
-// }
-
- //-----UIObjectImpl implementation specific methods------------------------------------------------------------------------------------------------------------
-// protected void setState(UIContext uiContext, ObjectState state, boolean loadParent)
-// {
-// //Name
-// this.name = state.getName();
-//
-// //Parent..load using parentId from state being used
-// if(loadParent && state.getParentId() != null && state.getParentId().trim().length()>0)
-// {
-// ObjectState parentState = uiContext.getStructuralStateManager().load(state.getParentId());
-// this.parent = uiContext.getObject(state.getParentId(), parentState.getType());
-// }
-//
-// //Id
-// this.id = this.generateId();
-//
-// //State
-// this.state = state;
-// }
- //--------------------------------------------------------------------------------------------------------------------------------------------------------------
-
-// /**
-// *
-// * @return
-// */
-// private String generateId()
-// {
-// String newId = null;
-//
-// String myName = "";
-// if(this.getName() != null && this.getName().trim().length()>0)
-// {
-// myName = this.getName();
-// }
-//
-// //Generate a new id concatenating its entire path in the UIObject tree
-// StringBuffer buffer = new StringBuffer();
-// if(this.getParent() != null && !(this.getParent() instanceof UIContext))
-// {
-// buffer.append("/"+this.getParent().getId().substring(1)+"/");
-// if(myName.trim().length()>0)
-// {
-// buffer.append(myName);
-// }
-// newId = buffer.toString();
-// }
-// else
-// {
-// buffer.append("/");
-// if(myName.trim().length()>0)
-// {
-// buffer.append(myName);
-// }
-// newId = buffer.toString();
-// }
-//
-// return newId;
-// }
-
-/*
- private String generateChildId(String childName)
- {
- String newId = null;
- String myName = "";
- if(this.getName() != null && this.getName().trim().length()>0)
- {
- myName = this.getName();
- }
-
- //Generate a new id concatenating its entire path in the UIObject tree
- StringBuffer buffer = new StringBuffer();
- if(this.getParent() != null && !(this.getParent() instanceof UIContext))
- {
- buffer.append("/"+this.getParent().getId().substring(1)+"/");
- if(myName.trim().length()>0)
- {
- buffer.append(myName+"/");
- }
- buffer.append(childName);
- newId = buffer.toString();
- }
- else
- {
- buffer.append("/");
- if(myName.trim().length()>0)
- {
- buffer.append(myName+"/");
- }
- buffer.append(childName);
- newId = buffer.toString();
- }
-
- return newId;
- }
-*/
-
-/*
- private UIContext getUIContext()
- {
- UIContext uiContext = null;
-
- //Make sure this UIObject is not the root UIContext object
- if(this.getParent() == null)
- {
- return (UIContext)this;
- }
-
- //Move up the tree to the UIContext and get the ModelLoader
- UIObject parent = this.getParent();
- while(!(parent instanceof UIContext))
- {
- parent = parent.getParent();
- }
- uiContext = (UIContext)parent;
-
- return uiContext;
- }
-*/
-}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPageImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -26,17 +26,18 @@
import org.jboss.portal.presentation.model.UIContainer;
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIPageImpl extends UIObjectImpl implements UIPage
+public class UIPageImpl extends AbstractUIObject implements UIPage
{
- public UIPageImpl(UIContextImpl context, StructuralObject object)
+ public UIPageImpl(UIObjectContainer context, StructuralObject object)
{
super(context, object);
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIPortalImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -25,17 +25,18 @@
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIPortalImpl extends UIObjectImpl implements UIPortal
+public class UIPortalImpl extends AbstractUIObject implements UIPortal
{
- public UIPortalImpl(UIContextImpl context, StructuralObject object)
+ public UIPortalImpl(UIObjectContainer context, StructuralObject object)
{
super(context, object);
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIWindowImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -27,17 +27,18 @@
import org.jboss.portal.presentation.model.StateScopeType;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.impl.model.container.AbstractUIObject;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public class UIWindowImpl extends UIObjectImpl implements UIWindow
+public class UIWindowImpl extends AbstractUIObject implements UIWindow
{
- public UIWindowImpl(UIContextImpl context, StructuralObject object)
+ public UIWindowImpl(UIObjectContainer context, StructuralObject object)
{
super(context, object);
}
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -0,0 +1,377 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.impl.model.container;
+
+import org.jboss.portal.common.NotYetImplemented;
+import org.jboss.portal.presentation.model.StateScopeType;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.event.StateChange;
+import org.jboss.portal.presentation.model.event.StateChangeEvent;
+import org.jboss.portal.presentation.model.event.navigational.NavigationalStateModification;
+import org.jboss.portal.presentation.model.event.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StaleStateException;
+import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
+import org.jboss.portal.presentation.impl.model.container.UIObjectList;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ *
+ */
+public abstract class AbstractUIObject implements UIObject, Serializable
+{
+
+ /** . */
+ private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
+
+ /** . */
+ protected final UIObjectContainer container;
+
+ /** . */
+ final UIObjectList children;
+
+ /** . */
+ final UIObjectRef parent;
+
+ /** This is used to assist with data needed during lazy loading, other state related data etc... */
+ StructuralObject structuralObject;
+
+ /** . */
+ Status status;
+
+ public AbstractUIObject(UIObjectContainer container, StructuralObject object)
+ {
+ this.structuralObject = object;
+ this.container = container;
+ this.children = new UIObjectList(this);
+ this.parent = new UIObjectRef();
+ this.status = Status.VALID;
+ }
+
+ protected final StructuralObject getStructuralObject()
+ {
+ return structuralObject;
+ }
+
+ // UIObject interface implementation-----------------------------------------------------------------------------------------------------------------------------
+
+ /**
+ *
+ */
+ public String getId()
+ {
+ return structuralObject.getId();
+ }
+
+ /**
+ * Attempt to cast the value argument to the provided type argument. If the value argument type is assignable
+ * to the provided type, the value is returned, otherwise if it is not or the value is null, null is returned.
+ *
+ * todo: Move that to common package.
+ *
+ * @param value the value to cast
+ * @param type the type to downcast
+ * @return the casted value or null
+ */
+ private <T> T safeCast(Object value, Class<T> type)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+ else
+ {
+ if (type.isAssignableFrom(value.getClass()))
+ {
+ return type.cast(value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+
+ public Status getStatus()
+ {
+ return status;
+ }
+
+ void updateStatus(StateException e)
+ {
+ if (e instanceof NoSuchStateException)
+ {
+ status = Status.INVALID;
+ }
+ else if (e instanceof StaleStateException)
+ {
+ status = Status.STALE;
+ }
+ else
+ {
+ throw new AssertionError(e);
+ }
+ }
+
+ public void validate()
+ {
+ try
+ {
+ container.structuralStateContext.validate(structuralObject);
+ }
+ catch (StateException e)
+ {
+ updateStatus(e);
+ }
+ }
+
+ public void resolveConflicts()
+ {
+ switch (status)
+ {
+ case STALE:
+ // Todo :-)
+ throw new NotYetImplemented();
+ case INVALID:
+ // Cannot be resolved
+ throw new IllegalStateException();
+ case VALID:
+ // Nothing to do
+ break;
+ }
+ }
+
+ public <T> T getProperty(StateScopeType scopeType, String propertyName, Class<T> propertyType)
+ {
+ if (scopeType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ Object value;
+ switch (scopeType)
+ {
+ case NAVIGATIONAL:
+ value = container.navigationalStateContext.get(getId(), propertyName);
+ break;
+ case STRUCTURAL:
+ value = structuralObject.getState().getProperties().get(propertyName);
+ break;
+ default:
+ throw new AssertionError();
+ }
+ return safeCast(value, propertyType);
+ }
+
+ public Object getProperty(StateScopeType scopeType, String propertyName)
+ {
+ return getProperty(scopeType, propertyName, Object.class);
+ }
+
+ public <T> void setProperty(StateScopeType scopeType, String propertyName, T propertyValue) throws StateChangeVetoException
+ {
+ if (scopeType == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ String id = getId();
+
+ //
+ switch (scopeType)
+ {
+ case NAVIGATIONAL:
+ {
+ // Have context process the change
+ container.navigationalStateContext.set(id, propertyName, propertyValue);
+
+ // Broadcast event
+ NavigationalStateModification mod = new NavigationalStateModification(propertyName, propertyValue);
+ StateChange<NavigationalStateModification> change = new StateChange<NavigationalStateModification>(id, mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ container.fireEvent(event);
+ break;
+ }
+ case STRUCTURAL:
+ {
+ if (propertyValue instanceof String)
+ {
+ Map<String, String> changes = new HashMap<String, String>();
+ changes.put(propertyName, (String)propertyValue);
+
+ // Have context process change
+ StructuralObject.Update update;
+ try
+ {
+ update = container.structuralStateContext.update(structuralObject, changes);
+ }
+ catch (StateException e)
+ {
+ validate();
+
+ //
+ throw e;
+ }
+
+ //
+ container.update(update);
+
+ // Broadcast event
+ StructuralStateModification mod = new StructuralStateModification.Update(changes);
+ StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(id, mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ container.fireEvent(event);
+ }
+ else
+ {
+ throw new StateChangeVetoException("Structural property value must be string value");
+ }
+ break;
+ }
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ public AbstractUIObject getChild(String name)
+ {
+ for (AbstractUIObject child : getChildren())
+ {
+ if (child.getName().equals(name))
+ {
+ return child;
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ */
+ public String getName()
+ {
+ return structuralObject.getState().getName();
+ }
+
+ /**
+ *
+ */
+ public final UIObject getParent()
+ {
+ if (!parent.loaded)
+ {
+ parent.object = container.getParent(structuralObject);
+ parent.loaded = true;
+ }
+
+ //
+ return parent.object;
+ }
+
+ /**
+ *
+ */
+ public final List<AbstractUIObject> getChildren()
+ {
+ return children;
+ }
+
+ public <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException
+ {
+ StructuralObject.Creation creation;
+ try
+ {
+ creation = container.structuralStateContext.create(structuralObject, type, name, EMPTY_STATE);
+ }
+ catch (StateException e)
+ {
+ updateStatus(e);
+
+ //
+ throw e;
+ }
+
+ //
+ container.update(creation);
+
+ //
+ StructuralObject child = creation.getChild();
+
+ // Eventing
+ StructuralStateModification mod = new StructuralStateModification.Creation(type, name, EMPTY_STATE);
+ StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(child.getId(), mod);
+ StateChangeEvent event = new StateChangeEvent(change);
+ container.fireEvent(event);
+
+ //
+ return type.cast(container.getObject(child.getId()));
+ }
+
+ public void destroyChild(String name) throws IllegalArgumentException, StateException
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ // Get the named child
+ AbstractUIObject namedChild = getChild(name);
+
+ //
+ if (namedChild == null)
+ {
+ throw new IllegalArgumentException("No such child with name " + name);
+ }
+
+ // Destroy the child
+ StructuralObject.Destruction destruction = container.structuralStateContext.destroy(namedChild.structuralObject);
+
+ //
+ container.update(destruction);
+ }
+
+ protected abstract <T extends UIObject> boolean isAllowedAsChild(Class<T> type);
+
+}
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -0,0 +1,285 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.impl.model.container;
+
+import org.jboss.portal.presentation.model.ModelEvent;
+import org.jboss.portal.presentation.model.ModelListener;
+import org.jboss.portal.presentation.model.UIContainer;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIPage;
+import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.UIWindow;
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.impl.model.UIPortalImpl;
+import org.jboss.portal.presentation.impl.model.UIPageImpl;
+import org.jboss.portal.presentation.impl.model.UIContainerImpl;
+import org.jboss.portal.presentation.impl.model.UIWindowImpl;
+import org.jboss.portal.presentation.impl.model.UIContextImpl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public final class UIObjectContainer
+{
+
+ /** . */
+ private final Map<String, AbstractUIObject> universe = new HashMap<String, AbstractUIObject>();
+
+ /** . */
+ protected final StructuralStateContext structuralStateContext;
+
+ /** . */
+ protected final NavigationalStateContext navigationalStateContext;
+
+ /** . */
+ protected final List<ModelListener> listeners;
+
+ /** . */
+ protected final UIContext root;
+
+ public UIObjectContainer(StructuralStateContext structuralStateContext, NavigationalStateContext navigationalStateContext)
+ {
+ // Put our self in the universe
+ String rootId = structuralStateContext.getRootId();
+ StructuralObject rootObject = structuralStateContext.load(rootId);
+ UIContextImpl root = (UIContextImpl)update(rootObject);
+
+ //
+ this.structuralStateContext = structuralStateContext;
+ this.navigationalStateContext = navigationalStateContext;
+ this.listeners = new ArrayList<ModelListener>();
+ this.root = root;
+ }
+
+ public UIContext getRoot()
+ {
+ return root;
+ }
+
+ public UIObject getObject(String id)
+ {
+ return getObject(id, true);
+ }
+
+ void update(StructuralObject.Change change)
+ {
+ if (change instanceof StructuralObject.Update)
+ {
+ StructuralObject.Update update = (StructuralObject.Update)change;
+ update(update.getObject());
+ }
+ else if (change instanceof StructuralObject.Creation)
+ {
+ StructuralObject.Creation creation = (StructuralObject.Creation)change;
+ update(creation.getParent());
+ update(creation.getChild());
+ }
+ else if (change instanceof StructuralObject.Destruction)
+ {
+ StructuralObject.Destruction destruction = (StructuralObject.Destruction)change;
+
+ //
+ update(destruction.getParent());
+
+ //
+ for (String id : destruction.getIds())
+ {
+ AbstractUIObject o = universe.remove(id);
+
+ //
+ if (o != null)
+ {
+ o.status = UIObject.Status.INVALID;
+ }
+ }
+ }
+ else
+ {
+ throw new AssertionError();
+ }
+ }
+
+ AbstractUIObject getParent(StructuralObject structuralObject)
+ {
+ StructuralObject parentStructuralState = structuralStateContext.loadParent(structuralObject);
+
+ //
+ if (parentStructuralState == null)
+ {
+ return null;
+ }
+
+ //
+ return update(parentStructuralState);
+ }
+
+ List<AbstractUIObject> getChildren(StructuralObject structuralObject)
+ {
+ ArrayList<AbstractUIObject> children = new ArrayList<AbstractUIObject>();
+
+ //
+ for (StructuralObject structuralChild : structuralStateContext.loadChildren(structuralObject))
+ {
+ AbstractUIObject child = update(structuralChild);
+ children.add(child);
+ }
+
+ //
+ return children;
+ }
+
+ /**
+ * Get an object from the universe. If the parameter <code>loadIfAbsent</code> has the value <code>false</code>
+ * and the object is not in the universe it will throw an <code>AssertionError</code> otherwise it will return
+ * the object.
+ *
+ * @param id the id of the object to obtain
+ * @param loadIfAbsent load the object from the structural state context if it is not present
+ * @return the loaded object
+ */
+ private AbstractUIObject getObject(String id, boolean loadIfAbsent)
+ {
+ try
+ {
+ AbstractUIObject context = universe.get(id);
+
+ //
+ if (context != null)
+ {
+ return context;
+ }
+
+ //
+ if (loadIfAbsent)
+ {
+ // Fetch the state of the UIObject in question
+ StructuralObject structuralObject = this.structuralStateContext.load(id);
+
+ //
+ return update(structuralObject);
+ }
+ else
+ {
+ throw new AssertionError("Should not be here");
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private AbstractUIObject update(StructuralObject structuralObject)
+ {
+ AbstractUIObject context = universe.get(structuralObject.getId());
+
+ //
+ if (context == null)
+ {
+ context = createObject(structuralObject);
+
+ //
+ universe.put(structuralObject.getId(), context);
+ }
+ else
+ {
+ context.structuralObject = structuralObject;
+
+ //
+ context.parent.invalidate();
+ context.children.invalidate();
+ }
+
+ //
+ return context;
+ }
+
+ private AbstractUIObject createObject(StructuralObject state)
+ {
+ Class type = state.getState().getType();
+
+ //
+ if(type == UIContext.class)
+ {
+ return new UIContextImpl(this, state);
+ }
+ else if(type == UIPortal.class)
+ {
+ return new UIPortalImpl(this, state);
+ }
+ else if(type == UIPage.class)
+ {
+ return new UIPageImpl(this, state);
+ }
+ else if(type == UIContainer.class)
+ {
+ return new UIContainerImpl(this, state);
+ }
+ else if(type == UIWindow.class)
+ {
+ return new UIWindowImpl(this, state);
+ }
+ else
+ {
+ throw new AssertionError();
+ }
+ }
+
+ public void addModelListener(ModelListener listener)
+ {
+ if (listener == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ if (!listeners.contains(listener))
+ {
+ listeners.add(listener);
+ }
+ }
+
+ protected void fireEvent(ModelEvent event)
+ {
+ for (ModelListener listener : listeners)
+ {
+ try
+ {
+ listener.onEvent(event);
+ }
+ catch (Exception ignore)
+ {
+ System.out.println("ignore = " + ignore);
+ }
+ }
+ }
+}
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectList.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.impl.model.container;
+
+import java.util.AbstractList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIObjectList extends AbstractList<AbstractUIObject>
+{
+
+ /** . */
+ private List<AbstractUIObject> content;
+
+ /** . */
+ private final AbstractUIObject context;
+
+ public UIObjectList(AbstractUIObject context)
+ {
+ this.context = context;
+ this.content = null;
+ }
+
+ public AbstractUIObject get(int i)
+ {
+ if (content == null)
+ {
+ content = context.container.getChildren(context.structuralObject);
+ }
+ return content.get(i);
+ }
+
+ public int size()
+ {
+ if (content == null)
+ {
+ content = context.container.getChildren(context.structuralObject);
+ }
+ return content.size();
+ }
+
+ void invalidate()
+ {
+ content = null;
+ }
+}
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRef.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.impl.model.container;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UIObjectRef
+{
+
+ /** . */
+ AbstractUIObject object;
+
+ /** . */
+ boolean loaded;
+
+ public UIObjectRef()
+ {
+ object = null;
+ loaded = false;
+ }
+
+ void invalidate()
+ {
+ loaded = false;
+ object = null;
+ }
+}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -143,26 +143,22 @@
* @throws IllegalArgumentException if the name is null, already exists or this kind of object does not accept children of the specified type
* @throws StateException any state exception
*/
- public <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException, StateException;
+ <T extends UIObject> T createChild(String name, Class<T> type) throws IllegalArgumentException, StateException;
/**
* Returns the children of this object.
*
* @return the list of children
*/
- List<UIObject> getChildren();
+ List<? extends UIObject> getChildren();
/**
+ * Destroy a named child.
*
- * @param name
+ * @param name the name of the child to destroy
+ * @throws IllegalArgumentException if the name is null or the child does not exist
+ * @throws StateException any state exception
*/
-// public void removeChild(String name);
+ void destroyChild(String name) throws IllegalArgumentException, StateException;
- /**
- *
- * @param <T>
- * @param type
- * @return
- */
-// <T extends UIObject> List<T> getChildren(Class<T> type);
}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/ConstraintViolationException.java (from rev 9357, branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/DuplicateStateException.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/ConstraintViolationException.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/ConstraintViolationException.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.model.state;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ConstraintViolationException extends StateException
+{
+ public ConstraintViolationException()
+ {
+ }
+
+ public ConstraintViolationException(String s)
+ {
+ super(s);
+ }
+
+ public ConstraintViolationException(String s, Throwable throwable)
+ {
+ super(s, throwable);
+ }
+
+ public ConstraintViolationException(Throwable throwable)
+ {
+ super(throwable);
+ }
+}
\ No newline at end of file
Deleted: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/DuplicateStateException.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/DuplicateStateException.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/DuplicateStateException.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -1,31 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated 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.jboss.portal.presentation.model.state;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class DuplicateStateException extends StateException
-{
-}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/NoSuchStateException.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/NoSuchStateException.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/NoSuchStateException.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -28,4 +28,22 @@
*/
public class NoSuchStateException extends StateException
{
+ public NoSuchStateException()
+ {
+ }
+
+ public NoSuchStateException(String s)
+ {
+ super(s);
+ }
+
+ public NoSuchStateException(String s, Throwable throwable)
+ {
+ super(s, throwable);
+ }
+
+ public NoSuchStateException(Throwable throwable)
+ {
+ super(throwable);
+ }
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateException.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateException.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/StateException.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public abstract class StateException extends RuntimeException
+public class StateException extends RuntimeException
{
public StateException()
{
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -26,16 +26,17 @@
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIPortal;
import org.jboss.portal.presentation.model.state.StaleStateException;
+import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.test.model.state.structural.MockModel;
import org.jboss.portal.presentation.test.model.state.structural.MockObject;
+import org.jboss.portal.presentation.test.model.state.structural.MockException;
+import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
/**
* Test that the mock model we are using behaves in an expected manner
@@ -54,7 +55,7 @@
protected void setUp() throws Exception
{
- model = new MockModel();
+ model = new MockModelImpl();
ssc = model.getStructuralStateContext();
}
@@ -120,7 +121,7 @@
assertEquals(Collections.singletonMap("foo", "bar"), rootState1_1.getProperties());
}
- public void testUpdateProperty()
+ public void testUpdateProperty() throws MockException
{
MockObject mockRoot = model.getRoot();
String rootId = mockRoot.getId();
@@ -176,29 +177,20 @@
{
try
{
- ssc.loadParent(object);
+ ssc.validate(object);
fail();
}
- catch (StaleStateException ignore)
+ catch (StateException ignore)
{
}
- try
- {
- ssc.loadChildren(object);
- fail();
- }
- catch (StaleStateException ignore)
- {
- }
}
private void assertNotStale(StructuralObject object)
{
- ssc.loadParent(object);
- ssc.loadChildren(object);
+ ssc.validate(object);
}
- public void testAddChild()
+ public void testAddChild() throws MockException
{
MockObject mockRoot = model.getRoot();
int rootV0 = mockRoot.getVersion();
@@ -261,4 +253,171 @@
assertEquals(rootId, root.getId());
}
+ public void testDestroy() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockFoo.addChild("bar", MockObject.Type.PAGE);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ int rootV0 = mockRoot.getVersion();
+ int fooV0 = mockFoo.getVersion();
+ int barV0 = mockBar.getVersion();
+ String fooId = mockFoo.getId();
+ String barId = mockBar.getId();
+ String juuId = mockJuu.getId();
+ StructuralObject foo0 = ssc.load(fooId);
+ StructuralObject bar0 = ssc.load(barId);
+ StructuralObject juu0 = ssc.load(juuId);
+
+ //
+ model.destroy(mockJuu);
+
+ //
+ StructuralObject foo1 = ssc.load(fooId);
+ StructuralObject bar1 = ssc.load(barId);
+ StructuralObject juu1 = ssc.load(juuId);
+ int rootV1 = mockRoot.getVersion();
+ int fooV1 = mockFoo.getVersion();
+ int barV1 = mockBar.getVersion();
+
+ //
+ assertStale(juu0);
+ assertStale(foo0);
+ assertNotStale(bar0);
+ assertNull(juu1);
+ assertNotStale(foo1);
+ assertNotStale(bar1);
+ assertEquals(Collections.singletonList(mockFoo), mockRoot.getChildren());
+ assertEquals(Collections.singletonList(mockBar), mockFoo.getChildren());
+ assertTrue(mockFoo.isValid());
+ assertTrue(mockBar.isValid());
+ assertFalse(mockJuu.isValid());
+ assertTrue(rootV1 == rootV0);
+ assertTrue(fooV1 > fooV0);
+ assertTrue(barV1 == barV0);
+
+ //
+ model.destroy(mockFoo);
+
+ int rootV2 = mockRoot.getVersion();
+ StructuralObject foo2 = ssc.load(fooId);
+ StructuralObject bar2 = ssc.load(barId);
+ StructuralObject juu2 = ssc.load(juuId);
+
+ //
+ assertStale(juu0);
+ assertStale(foo0);
+ assertStale(bar0);
+ assertNull(juu1);
+ assertStale(foo1);
+ assertStale(bar1);
+ assertNull(foo2);
+ assertNull(bar2);
+ assertNull(juu2);
+ assertEquals(Collections.emptyList(), mockRoot.getChildren());
+ assertFalse(mockFoo.isValid());
+ assertFalse(mockBar.isValid());
+ assertFalse(mockJuu.isValid());
+ assertTrue(rootV2 > rootV1);
+ }
+
+ public void testDestroyInvalidates() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+
+ //
+ model.destroy(mockFoo);
+
+ //
+ assertEquals(false, mockFoo.isValid());
+ try
+ {
+ mockFoo.addChild("juu", MockObject.Type.PAGE);
+ }
+ catch (MockException e)
+ {
+ assertEquals(MockException.ErrorCode.INVALID_OBJECT, e.getCode());
+ }
+ try
+ {
+ model.destroy(mockFoo);
+ }
+ catch (MockException e)
+ {
+ assertEquals(MockException.ErrorCode.INVALID_OBJECT, e.getCode());
+ }
+ try
+ {
+ mockFoo.setPropertyValue("blah", "bluh");
+ }
+ catch (MockException e)
+ {
+ assertEquals(MockException.ErrorCode.INVALID_OBJECT, e.getCode());
+ }
+ }
+
+ public void testMove() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PAGE);
+
+ mockFoo.move(mockBar);
+
+ assertSame(mockBar, mockFoo.getParent());
+ assertEquals(Collections.singletonList(mockFoo), mockBar.getChildren());
+ assertEquals(Collections.singletonList(mockBar), mockRoot.getChildren());
+ }
+
+ public void testMoveViolatesConstraint() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PAGE);
+ MockObject mockJuu = mockBar.addChild("juu", MockObject.Type.PAGE);
+
+ //
+ try
+ {
+ mockRoot.move(mockRoot);
+ }
+ catch (MockException e)
+ {
+ assertEquals(MockException.ErrorCode.CONSTRAINT_VIOLATION, e.getCode());
+ }
+
+ //
+ try
+ {
+ mockRoot.move(mockFoo);
+ }
+ catch (MockException e)
+ {
+ assertEquals(MockException.ErrorCode.CONSTRAINT_VIOLATION, e.getCode());
+ }
+
+ //
+ try
+ {
+ mockBar.move(mockBar);
+ }
+ catch (MockException e)
+ {
+ assertEquals(MockException.ErrorCode.CONSTRAINT_VIOLATION, e.getCode());
+ }
+
+ //
+ try
+ {
+ mockBar.move(mockJuu);
+ }
+ catch (MockException e)
+ {
+ assertEquals(MockException.ErrorCode.CONSTRAINT_VIOLATION, e.getCode());
+ }
+ }
+
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -25,7 +25,7 @@
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.log4j.Logger;
-import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
import org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
import org.jboss.portal.presentation.model.StateScopeType;
import org.jboss.portal.presentation.model.UIContext;
@@ -38,6 +38,8 @@
import org.jboss.portal.presentation.model.state.StateChangeVetoException;
import org.jboss.portal.presentation.test.model.state.structural.MockModel;
import org.jboss.portal.presentation.test.model.state.structural.MockObject;
+import org.jboss.portal.presentation.test.model.state.structural.MockException;
+import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
import java.util.Collections;
import java.util.HashMap;
@@ -70,7 +72,7 @@
*/
protected void setUp() throws Exception
{
- this.model = new MockModel();
+ this.model = new MockModelImpl();
}
/**
@@ -179,7 +181,7 @@
private UIContext createContext()
{
- return new UIContextImpl(model.getStructuralStateContext(), new NavigationalStateContextImpl());
+ return new UIObjectContainer(model.getStructuralStateContext(), new NavigationalStateContextImpl()).getRoot();
}
public void testGetPropertyThrowsIAE()
@@ -214,7 +216,7 @@
UIContext context = createContext();
//
- List<UIObject> children = context.getChildren();
+ List<? extends UIObject> children = context.getChildren();
assertNotNull(children);
assertEquals(2, children.size());
@@ -288,12 +290,12 @@
Assert.assertEquals(null, object.getProperty(scopeType, propertyName, Blah.class)); }
}
- public void testUpdatePropertyNonExistingObject()
+ public void testUpdatePropertyNonExistingObject() throws MockException
{
UIContext context = createContext();
MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());
- model.destroy(mockFoo.getId());
+ model.destroy(mockFoo);
//
try
@@ -306,7 +308,7 @@
}
}
- public void testUpdateExistingMutableStructuralProperty()
+ public void testUpdateExistingMutableStructuralProperty() throws MockException
{
MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
String fooId = mockFoo.getId();
@@ -338,7 +340,7 @@
eventAssert.assertEmpty();
}
- public void testUpdateExistingNonMutableStructuralProperty()
+ public void testUpdateExistingNonMutableStructuralProperty() throws MockException
{
MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
String fooId = mockFoo.getId();
@@ -377,7 +379,7 @@
eventAssert.assertEmpty();
}
- public void testUpdateNonExistingMutableStructuralProperty()
+ public void testUpdateNonExistingMutableStructuralProperty() throws MockException
{
MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
String fooId = mockFoo.getId();
@@ -408,7 +410,7 @@
eventAssert.assertEmpty();
}
- public void testUpdateNonExistingNonMutableStructuralProperty()
+ public void testUpdateNonExistingNonMutableStructuralProperty() throws MockException
{
MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
mockFoo.setPropertyBehavior("foo", MockObject.Failure.veto());
@@ -446,7 +448,7 @@
eventAssert.assertEmpty();
}
- public void testUpdateNavigationalProperty()
+ public void testUpdateNavigationalProperty() throws MockException
{
MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
UIContext context = createContext();
@@ -476,7 +478,7 @@
context.setProperty(StateScopeType.STRUCTURAL, "foo", "bar2");
}
- public void testConcurrentStructuralPropertyDetection()
+ public void testConcurrentStructuralPropertyDetection() throws MockException
{
UIContext context = createContext();
@@ -503,23 +505,38 @@
EventAssert eventAssert = new EventAssert();
context.addModelListener(eventAssert);
+ //
+ List<? extends UIObject> rootChildren = context.getChildren();
+ assertNotNull(rootChildren);
+ assertEquals(0, rootChildren.size());
assertNull(context.getChild("foo"));
+ //
UIPortal portal = context.createChild("foo", UIPortal.class);
-
assertNotNull(portal);
-
assertSame(context, portal.getParent());
-
assertSame(portal, context.getChild("foo"));
-
+ assertEquals(1, rootChildren.size());
+ assertSame(portal, rootChildren.iterator().next());
eventAssert.next(portal.getId(), new StructuralStateModification.Creation(UIPortal.class, "foo", new HashMap<String, String>()));
}
- public void testBlah()
+ public void testDestroyChild() throws Exception
{
+ MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = model.getRoot().addChild("bar", MockObject.Type.PORTAL);
+ MockObject mockJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ UIContext context = createContext();
+ UIPortal foo = (UIPortal)context.getChild("foo");
+ UIPage juu = (UIPage)foo.getChild("juu");
+ context.destroyChild("foo");
+
+ List<? extends UIObject> rootChildren = context.getChildren();
+
+
+
}
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -24,10 +24,10 @@
import junit.framework.TestCase;
import org.apache.log4j.Logger;
-import org.jboss.portal.presentation.impl.model.UIContextImpl;
+import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
import org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
import org.jboss.portal.presentation.model.UIContext;
-import org.jboss.portal.presentation.test.model.state.structural.MockModel;
+import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -43,7 +43,7 @@
*/
protected void setUp() throws Exception
{
- this.uiContext = new UIContextImpl(new MockModel().getStructuralStateContext(), new NavigationalStateContextImpl());
+ this.uiContext = new UIObjectContainer(new MockModelImpl().getStructuralStateContext(), new NavigationalStateContextImpl()).getRoot();
}
/**
Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockException.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockException.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockException.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.test.model.state.structural;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MockException extends Exception
+{
+
+ /** . */
+ private ErrorCode code;
+
+ public MockException(ErrorCode code)
+ {
+ this.code = code;
+ }
+
+ public MockException(String s, ErrorCode code)
+ {
+ super(s);
+ this.code = code;
+ }
+
+ public enum ErrorCode
+ {
+ INVALID_OBJECT,
+ CONSTRAINT_VIOLATION
+ }
+
+ public ErrorCode getCode()
+ {
+ return code;
+ }
+}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -22,196 +22,19 @@
******************************************************************************/
package org.jboss.portal.presentation.test.model.state.structural;
-import org.jboss.portal.presentation.model.UIContext;
-import org.jboss.portal.presentation.model.UIObject;
-import org.jboss.portal.presentation.model.UIPage;
-import org.jboss.portal.presentation.model.UIPortal;
-import org.jboss.portal.presentation.model.UIWindow;
-import org.jboss.portal.presentation.model.state.NoSuchStateException;
-import org.jboss.portal.presentation.model.state.StaleStateException;
-import org.jboss.portal.presentation.model.state.StateChangeVetoException;
-import org.jboss.portal.presentation.model.state.StateException;
-import org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class MockModel
+public interface MockModel
{
- /** . */
- private int generator = 0;
+ StructuralStateContext getStructuralStateContext();
- /** . */
- private final Map<String, MockObjectImpl> universe = new HashMap<String, MockObjectImpl>();
+ MockObject getRoot();
- /** . */
- private final MockObjectImpl root = createObject(MockObject.Type.CONTEXT, "");
+ void destroy(MockObject object) throws MockException;
- /** . */
- private static final Map<Class<? extends UIObject>, MockObject.Type> map;
-
- static
- {
- map = new HashMap<Class<? extends UIObject>, MockObject.Type>();
- map.put(UIContext.class, MockObject.Type.CONTEXT);
- map.put(UIPage.class, MockObject.Type.PAGE);
- map.put(UIPortal.class, MockObject.Type.PORTAL);
- map.put(UIWindow.class, MockObject.Type.WINDOW);
- }
-
- public StructuralStateContext getStructuralStateContext()
- {
- return structuralStateContext;
- }
-
- public MockObject getRoot()
- {
- return root;
- }
-
- public void destroy(String objectId)
- {
- MockObjectImpl object = universe.remove(objectId);
-
- //
- object.destroy();
- }
-
- MockObjectImpl createObject(MockObject.Type type, String name)
- {
- MockObjectImpl mockObject = new MockObjectImpl(this, name, type, "" + generator++);
- universe.put(mockObject.getId(), mockObject);
- return mockObject;
- }
-
- private final StructuralStateContext structuralStateContext = new AbstractStructuralStateContext()
- {
- public StructuralObject load(String objectId) throws IllegalArgumentException
- {
- if (objectId == null)
- {
- throw new IllegalArgumentException();
- }
- MockObjectImpl object = universe.get(objectId);
- return object != null ? object.takeSnapshot() : null;
- }
-
- public String getRootId()
- {
- return root.getId();
- }
-
- public void validate(StructuralObject object) throws StateException
- {
- getValidMockObject(object);
- }
-
- public StructuralObject.Update update(StructuralObject object, Map<String, String> changes) throws StateChangeVetoException
- {
- MockObject mockObject = getValidMockObject(object);
-
- //
- for (Map.Entry<String, String> entry : changes.entrySet())
- {
- String propertyName = entry.getKey();
- MockObject.UpdateBehavior behavior = mockObject.getPropertyBehavior(propertyName);
- if (behavior instanceof MockObject.Veto)
- {
- throw new StateChangeVetoException("Cannot modify non behavior property");
- }
- else if (behavior instanceof MockObject.Failure)
- {
- MockObject.Failure failure = (MockObject.Failure)behavior;
- failure.throwAs(IllegalArgumentException.class).
- throwAs(StateChangeVetoException.class).
- throwAs(StateException.class);
- }
- else
- {
- mockObject.setPropertyValue(propertyName, entry.getValue());
- }
- }
-
- //
- return new StructuralObject.Update(mockObject.takeSnapshot());
- }
-
- public StructuralObject.Creation create(StructuralObject parent, Class<? extends UIObject> classType, String name, Map<String, String> properties) throws StateException, IllegalArgumentException
- {
- MockObject mockParent = getValidMockObject(parent);
-
- //
- MockObject.Type type = map.get(classType);
-
- //
- MockObject mockChild = mockParent.addChild(name, type, properties);
-
- //
- return new StructuralObject.Creation(mockParent.takeSnapshot(), mockChild.takeSnapshot());
- }
-
- public List<StructuralObject> loadChildren(StructuralObject parent)
- {
- MockObject mockParent = getValidMockObject(parent);
-
- //
- List<StructuralObject> tmp = new ArrayList<StructuralObject>();
- for (MockObject mockChild : mockParent.getChildren())
- {
- tmp.add(mockChild.takeSnapshot());
- }
- return tmp;
- }
-
- public StructuralObject loadParent(StructuralObject child)
- {
- MockObject mockchild = getValidMockObject(child);
- MockObject mockParent = mockchild.getParent();
- return mockParent != null ? mockParent.takeSnapshot() : null;
- }
-
- private MockObject getValidMockObject(StructuralObject object)
- {
- if (object == null)
- {
- throw new IllegalArgumentException("No null object accepted");
- }
-
- //
- StructuralObjectImpl structuralObject = (StructuralObjectImpl)object;
-
- //
- MockObjectImpl mockObject = universe.get(structuralObject.getId());
-
- //
- if (mockObject == null)
- {
- throw new NoSuchStateException();
- }
-
- //
- if (!mockObject.isValid())
- {
- throw new StaleStateException();
- }
-
- //
- if (mockObject.getVersion() != structuralObject.version)
- {
- throw new StaleStateException("Version has changed obtained=" + mockObject.getVersion() + " wanted=" + structuralObject.version);
- }
-
- //
- return mockObject;
- }
- };
}
Copied: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java (from rev 9357, branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java)
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -0,0 +1,306 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.test.model.state.structural;
+
+import org.jboss.portal.presentation.model.UIContext;
+import org.jboss.portal.presentation.model.UIObject;
+import org.jboss.portal.presentation.model.UIPage;
+import org.jboss.portal.presentation.model.UIPortal;
+import org.jboss.portal.presentation.model.UIWindow;
+import org.jboss.portal.presentation.model.state.NoSuchStateException;
+import org.jboss.portal.presentation.model.state.StaleStateException;
+import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.ConstraintViolationException;
+import org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class MockModelImpl implements MockModel
+{
+
+ /** . */
+ private int generator = 0;
+
+ /** . */
+ private final Map<String, MockObjectImpl> universe = new HashMap<String, MockObjectImpl>();
+
+ /** . */
+ private final MockObjectImpl root = createObject(MockObject.Type.CONTEXT, "");
+
+ /** . */
+ private static final Map<Class<? extends UIObject>, MockObject.Type> map;
+
+ static
+ {
+ map = new HashMap<Class<? extends UIObject>, MockObject.Type>();
+ map.put(UIContext.class, MockObject.Type.CONTEXT);
+ map.put(UIPage.class, MockObject.Type.PAGE);
+ map.put(UIPortal.class, MockObject.Type.PORTAL);
+ map.put(UIWindow.class, MockObject.Type.WINDOW);
+ }
+
+ public StructuralStateContext getStructuralStateContext()
+ {
+ return structuralStateContext;
+ }
+
+ public MockObject getRoot()
+ {
+ return root;
+ }
+
+ public void destroy(MockObject object) throws MockException
+ {
+ destroy((MockObjectImpl)object, new ArrayList<String>());
+ }
+
+ void destroy(MockObjectImpl object, List<String> ids) throws MockException
+ {
+ universe.remove(object.getId());
+
+ // Remove children recursively
+ for (MockObjectImpl child : object.getChildren())
+ {
+ destroy(child, ids);
+ }
+
+ //
+ object.destroy();
+
+ //
+ ids.add(object.getId());
+ }
+
+ MockObjectImpl createObject(MockObject.Type type, String name)
+ {
+ MockObjectImpl mockObject = new MockObjectImpl(this, name, type, "" + generator++);
+ universe.put(mockObject.getId(), mockObject);
+ return mockObject;
+ }
+
+ private final StructuralStateContext structuralStateContext = new AbstractStructuralStateContext()
+ {
+ public StructuralObject load(String objectId) throws IllegalArgumentException
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ MockObjectImpl object = universe.get(objectId);
+
+ //
+ return object != null ? object.takeSnapshot() : null;
+ }
+
+ public String getRootId()
+ {
+ return root.getId();
+ }
+
+ public void validate(StructuralObject object) throws StateException
+ {
+ getValidMockObject(object);
+ }
+
+ public StructuralObject.Update update(StructuralObject object, Map<String, String> changes) throws StateChangeVetoException
+ {
+ MockObject mockObject = getValidMockObject(object);
+
+ //
+ for (Map.Entry<String, String> entry : changes.entrySet())
+ {
+ String propertyName = entry.getKey();
+ MockObject.UpdateBehavior behavior = mockObject.getPropertyBehavior(propertyName);
+ if (behavior instanceof MockObject.Veto)
+ {
+ throw new StateChangeVetoException("Cannot modify non behavior property");
+ }
+ else if (behavior instanceof MockObject.Failure)
+ {
+ MockObject.Failure failure = (MockObject.Failure)behavior;
+ failure.throwAs(IllegalArgumentException.class).
+ throwAs(StateChangeVetoException.class).
+ throwAs(StateException.class);
+ }
+ else
+ {
+ try
+ {
+ mockObject.setPropertyValue(propertyName, entry.getValue());
+ }
+ catch (MockException e)
+ {
+ throw new AssertionError();
+ }
+ }
+ }
+
+ //
+ return new StructuralObject.Update(mockObject.takeSnapshot());
+ }
+
+ public StructuralObject.Creation create(StructuralObject parent, Class<? extends UIObject> classType, String name, Map<String, String> properties) throws StateException, IllegalArgumentException
+ {
+ MockObject mockParent = getValidMockObject(parent);
+
+ //
+ MockObject.Type type = map.get(classType);
+
+ //
+ try
+ {
+ MockObject mockChild = mockParent.addChild(name, type, properties);
+
+ //
+ return new StructuralObject.Creation(mockParent.takeSnapshot(), mockChild.takeSnapshot());
+ }
+ catch (MockException e)
+ {
+ switch (e.getCode())
+ {
+ case CONSTRAINT_VIOLATION:
+ throw new ConstraintViolationException();
+ default:
+ throw new AssertionError();
+ }
+ }
+ }
+
+ public StructuralObject.Destruction destroy(StructuralObject object) throws StateException, IllegalArgumentException
+ {
+ MockObjectImpl mockObject = getValidMockObject(object);
+
+ //
+ MockObjectImpl parent = mockObject.getParent();
+
+ //
+ List<String> ids = new ArrayList<String>();
+
+ //
+ try
+ {
+ MockModelImpl.this.destroy(mockObject, ids);
+ }
+ catch (MockException e)
+ {
+ // It is kind of unexpected since we are destroying something valid
+ throw new StateException(e);
+ }
+
+ //
+ return new StructuralObject.Destruction(parent.takeSnapshot(), ids);
+ }
+
+ public StructuralObject.Move move(StructuralObject source, StructuralObject destination) throws StateException, IllegalArgumentException
+ {
+ MockObject mockSource = getValidMockObject(source);
+ MockObject mockDestination = getValidMockObject(destination);
+
+ //
+ try
+ {
+ mockSource.move(mockDestination);
+
+ //
+ return new StructuralObject.Move(mockSource.takeSnapshot(), mockSource.takeSnapshot());
+ }
+ catch (MockException e)
+ {
+ switch (e.getCode())
+ {
+ default:
+ throw new AssertionError();
+ case CONSTRAINT_VIOLATION:
+ throw new ConstraintViolationException();
+ }
+ }
+ }
+
+ public List<StructuralObject> loadChildren(StructuralObject parent)
+ {
+ MockObject mockParent = getValidMockObject(parent);
+
+ //
+ List<StructuralObject> tmp = new ArrayList<StructuralObject>();
+ for (MockObject mockChild : mockParent.getChildren())
+ {
+ tmp.add(mockChild.takeSnapshot());
+ }
+ return tmp;
+ }
+
+ public StructuralObject loadParent(StructuralObject child) throws StateException
+ {
+ MockObject mockchild = getValidMockObject(child);
+ MockObject mockParent = mockchild.getParent();
+ return mockParent != null ? mockParent.takeSnapshot() : null;
+ }
+
+ private MockObjectImpl getValidMockObject(StructuralObject object) throws StateException
+ {
+ if (object == null)
+ {
+ throw new IllegalArgumentException("No null object accepted");
+ }
+
+ //
+ StructuralObjectImpl structuralObject = (StructuralObjectImpl)object;
+
+ //
+ MockObjectImpl mockObject = universe.get(structuralObject.getId());
+
+ //
+ if (mockObject == null)
+ {
+ throw new NoSuchStateException();
+ }
+
+ //
+ if (!mockObject.isValid())
+ {
+ throw new StaleStateException();
+ }
+
+ //
+ if (mockObject.getVersion() != structuralObject.version)
+ {
+ throw new StaleStateException("Version has changed obtained=" + mockObject.getVersion() + " wanted=" + structuralObject.version);
+ }
+
+ //
+ return mockObject;
+ }
+ };
+}
\ No newline at end of file
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObject.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -102,25 +102,27 @@
int getVersion();
- String getPropertyValue(String propertyName);
+ String getPropertyValue(String propertyName) throws IllegalArgumentException;
- void setPropertyBehavior(String propertyName, UpdateBehavior propertyBehavior);
+ void setPropertyBehavior(String propertyName, UpdateBehavior propertyBehavior) throws IllegalArgumentException;
- UpdateBehavior getPropertyBehavior(String propertyName);
+ UpdateBehavior getPropertyBehavior(String propertyName) throws IllegalArgumentException;
- void setPropertyValue(String propertyName, String propertyValue);
+ void setPropertyValue(String propertyName, String propertyValue) throws MockException;
Set<String> getPropertyNames();
- MockObject addChild(String name, Type type, Map<String, String> state);
+ MockObject addChild(String name, Type type, Map<String, String> state) throws IllegalArgumentException, MockException;
- MockObject addChild(String name, Type type);
+ MockObject addChild(String name, Type type) throws IllegalArgumentException, MockException;
MockObject getParent();
- List<MockObject> getChildren();
+ List<? extends MockObject> getChildren();
boolean isValid();
StructuralObject takeSnapshot();
+
+ void move(MockObject destination) throws IllegalArgumentException, MockException;
}
Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockObjectImpl.java 2007-12-18 17:34:47 UTC (rev 9361)
@@ -23,6 +23,7 @@
package org.jboss.portal.presentation.test.model.state.structural;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
+import org.jboss.portal.presentation.model.state.ConstraintViolationException;
import java.util.ArrayList;
import java.util.Collections;
@@ -61,7 +62,7 @@
private final LinkedHashMap<String, MockObjectImpl> children;
/** . */
- private final MockModel model;
+ private final MockModelImpl model;
/** . */
private MockObjectImpl parent;
@@ -72,7 +73,7 @@
/** The version id. */
int version;
- MockObjectImpl(MockModel model, String name, MockObject.Type type, String id)
+ MockObjectImpl(MockModelImpl model, String name, MockObject.Type type, String id)
{
this.model = model;
this.name = name;
@@ -107,40 +108,46 @@
public String getPropertyValue(String propertyName)
{
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
return propertyValues.get(propertyName);
}
- public MockObject getParent()
+ public MockObjectImpl getParent()
{
return parent;
}
- public List<MockObject> getChildren()
+ public List<MockObjectImpl> getChildren()
{
- return Collections.unmodifiableList(new ArrayList<MockObject>(children.values()));
+ return Collections.unmodifiableList(new ArrayList<MockObjectImpl>(children.values()));
}
- public MockObject addChild(String name, MockObject.Type type)
+ public MockObjectImpl addChild(String name, MockObject.Type type) throws MockException
{
return addChild(name, type, EMPTY_STATE);
}
public Set<String> getPropertyNames()
{
- return propertyValues.keySet();
+ return Collections.unmodifiableSet(propertyValues.keySet());
}
- public MockObject addChild(String name, Type type, Map<String, String> state)
+ public MockObjectImpl addChild(String name, Type type, Map<String, String> state) throws MockException
{
+ if (!valid)
+ {
+ throw new MockException(MockException.ErrorCode.INVALID_OBJECT);
+ }
if (name == null)
{
throw new IllegalArgumentException();
}
-
- //
if (children.containsKey(name))
{
- throw new IllegalArgumentException();
+ throw new MockException(MockException.ErrorCode.CONSTRAINT_VIOLATION);
}
//
@@ -183,11 +190,19 @@
public UpdateBehavior getPropertyBehavior(String propertyName)
{
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException();
+ }
return propertyBehaviors.get(propertyName);
}
- public void setPropertyValue(String propertyName, String propertyValue)
+ public void setPropertyValue(String propertyName, String propertyValue) throws MockException
{
+ if (!valid)
+ {
+ throw new MockException(MockException.ErrorCode.INVALID_OBJECT);
+ }
if (propertyName == null)
{
throw new IllegalArgumentException();
@@ -215,14 +230,55 @@
return new StructuralObjectImpl(id, version, new StructuralStateImpl(type.clazz, name, new HashMap<String, String>(propertyValues)));
}
- void destroy()
+ public void move(MockObject destination) throws IllegalStateException, MockException
{
- // Remove children recursively
- for (String childId : new ArrayList<String>(children.keySet()))
+ move((MockObjectImpl)destination);
+ }
+
+ private void move(MockObjectImpl destination) throws MockException
+ {
+ if (!valid)
{
- model.destroy(childId);
+ throw new MockException(MockException.ErrorCode.INVALID_OBJECT);
}
+ if (destination == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ // The source cannot an ancestor of the destination
+ for (MockObject current = destination;current != null;current = current.getParent())
+ {
+ if (current == this)
+ {
+ throw new MockException(MockException.ErrorCode.CONSTRAINT_VIOLATION);
+ }
+ }
+
+ // No duplicate child name
+ for (MockObjectImpl child : destination.children.values())
+ {
+ if (name.equals(child.name))
+ {
+ throw new MockException(MockException.ErrorCode.CONSTRAINT_VIOLATION);
+ }
+ }
+
+ //
+ parent.children.remove(id);
+ destination.children.put(id, this);
+ parent = destination;
+ version++;
+ destination.version++;
+ }
+
+ public void destroy() throws MockException
+ {
+ if (!valid)
+ {
+ throw new MockException(MockException.ErrorCode.INVALID_OBJECT);
+ }
+
// Detach from parent
if (parent != null)
{
18 years, 4 months
JBoss Portal SVN: r9360 - in branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal: test/wsrp/framework/support and 7 other directories.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-12-17 20:32:23 -0500 (Mon, 17 Dec 2007)
New Revision: 9360
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/BehaviorRegistry.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/MarkupBehavior.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/ServiceObjectFactory.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/ResponseDebugFactory.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPExceptionFactory.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ActionHandler.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/deployment/WSRPDeployer.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerConfigurationServiceImpl.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/servlet/UserAccess.java
Log:
- Started migrating to Java 5: replaced for loops with new style syntax, started adding types to collections.
- Allowed me to find a bug in SessionHandler.releaseSessions: was not properly adding the session ids (was adding a List instead of adding the list elements).
- Add private constructor to utility objects accessed only via static methods.
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/BehaviorRegistry.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/BehaviorRegistry.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/BehaviorRegistry.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -27,7 +27,6 @@
import org.jboss.portal.wsrp.core.InvalidHandleFault;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
/**
@@ -37,7 +36,7 @@
*/
public class BehaviorRegistry
{
- private final Map behaviors = new HashMap();
+ private final Map<String, MarkupBehavior> behaviors = new HashMap<String, MarkupBehavior>();
private PortletManagementBehavior portletManagementBehavior;
private ServiceDescriptionBehavior serviceDescriptionBehavior;
private RegistrationBehavior registrationBehavior;
@@ -63,7 +62,7 @@
{
if (behaviors.containsKey(handle))
{
- return (MarkupBehavior)behaviors.get(handle);
+ return behaviors.get(handle);
}
throw WSRPExceptionFactory.throwSOAPFaultException(WSRPExceptionFactory.INVALID_HANDLE,
"There is no registered MarkupBehavior for handle '" + handle + "'", null);
@@ -71,10 +70,9 @@
public void registerMarkupBehavior(MarkupBehavior behavior)
{
- for (Iterator handles = behavior.getSupportedHandles().iterator(); handles.hasNext();)
+ for (String handle : behavior.getSupportedHandles())
{
- String handle = (String)handles.next();
- MarkupBehavior existing = (MarkupBehavior)behaviors.get(handle);
+ MarkupBehavior existing = behaviors.get(handle);
if (existing != null)
{
throw new IllegalArgumentException("Cannot register behavior " + behavior.getClass().getName()
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/MarkupBehavior.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/MarkupBehavior.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/MarkupBehavior.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -67,7 +67,7 @@
*/
public abstract class MarkupBehavior extends TestProducerBehavior implements WSRP_v1_Markup_PortType
{
- private List handles = new ArrayList(3);
+ private List<String> handles = new ArrayList<String>(3);
private BehaviorRegistry registry;
@@ -152,7 +152,7 @@
// default implementation does not nothing
}
- public List getSupportedHandles()
+ public List<String> getSupportedHandles()
{
return handles;
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/ServiceObjectFactory.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/ServiceObjectFactory.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/ServiceObjectFactory.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -43,6 +43,10 @@
public static final String SAMPLE_DISPLAYNAME = "SampleDisplayName";
public static final String SAMPLE_KEYWORD = "keyword";
+ private ServiceObjectFactory()
+ {
+ }
+
/**
* Create the dummiest form of LocalizedString
*
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/ResponseDebugFactory.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/ResponseDebugFactory.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/ResponseDebugFactory.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -34,6 +34,10 @@
*/
public class ResponseDebugFactory
{
+ private ResponseDebugFactory()
+ {
+ }
+
/**
* Extracts information from ServiceDescription and puts into StringBuffer object
*
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -50,6 +50,10 @@
*/
public class UserContextConverter
{
+ private UserContextConverter()
+ {
+ }
+
public static UserContext createPortalUserContextFrom(org.jboss.portal.wsrp.core.UserContext userContext,
String[] desiredLocales, String preferredLocale)
{
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPExceptionFactory.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPExceptionFactory.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPExceptionFactory.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -60,6 +60,10 @@
public static final String UNSUPPORTED_WINDOW_STATE = "UnsupportedWindowState";
private static final String NS_PREFIX = "wsrp";
+ private WSRPExceptionFactory()
+ {
+ }
+
public static void throwMissingParametersFaultIfValueIsMissing(Object valueToCheck, String valueName, String context)
throws SOAPFaultException
{
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -88,6 +88,10 @@
*/
public class WSRPTypeFactory
{
+ private WSRPTypeFactory()
+ {
+ }
+
/** ====== WSRP request objects ====== **/
/**
* registrationContext(RegistrationContext)?, desiredLocales(xsd:string)*
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -85,6 +85,10 @@
WSRP_JSR168_MODES.put(WSRPConstants.VIEW_MODE, Mode.VIEW);
}
+ private WSRPUtils()
+ {
+ }
+
public static WindowState getJSR168WindowStateFromWSRPName(String wsrpWindowStateName)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(wsrpWindowStateName, WSRP_WINDOW_STATE_NAME, null);
@@ -267,9 +271,9 @@
int size = registrationInfo.size();
PropertyDescription[] propertyDescriptions = new PropertyDescription[size];
int i = 0;
- for (Iterator props = registrationInfo.values().iterator(); props.hasNext();)
+ for (Object o : registrationInfo.values())
{
- RegistrationPropertyDescription property = (RegistrationPropertyDescription)props.next();
+ RegistrationPropertyDescription property = (RegistrationPropertyDescription)o;
propertyDescriptions[i++] = convertToPropertyDescription(property);
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ActionHandler.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ActionHandler.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ActionHandler.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -59,7 +59,6 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -75,6 +74,7 @@
super(consumer);
}
+ @SuppressWarnings({"CastToConcreteClass"})
protected Object prepareRequest(RequestPrecursor requestPrecursor, PortletInvocation invocation)
{
PortletContext portletContext = requestPrecursor.getPortletContext();
@@ -172,14 +172,13 @@
{
int capacity = params.size();
List formParameters = new ArrayList(capacity);
- for (Iterator paramEntries = params.entrySet().iterator(); paramEntries.hasNext();)
+ for (Map.Entry param : params.entrySet())
{
- Map.Entry param = (Map.Entry)paramEntries.next();
String name = (String)param.getKey();
String[] values = (String[])param.getValue();
- for (int i = 0; i < values.length; i++)
+ for (String value : values)
{
- formParameters.add(new NamedString(name, values[i]));
+ formParameters.add(new NamedString(name, value));
}
}
interactionParams.setFormParameters((NamedString[])formParameters.toArray(new NamedString[capacity]));
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -52,7 +52,7 @@
/** Gives access to the Portal's portlet invokers */
private FederatingPortletInvoker federatingPortletInvoker;
- private SortedMap consumers;
+ private SortedMap<String, WSRPConsumer> consumers;
private SessionFactory sessionFactory;
@@ -247,7 +247,7 @@
sessionFactory = (SessionFactory)initialContext.lookup(sessionFactoryJNDIName);
// load the configured consumers
- consumers = new TreeMap();
+ consumers = new TreeMap<String, WSRPConsumer>();
Session session = sessionFactory.getCurrentSession();
@@ -285,10 +285,8 @@
{
sessionFactory = null;
- for (Iterator consumersIt = consumers.values().iterator(); consumersIt.hasNext();)
+ for (WSRPConsumer consumer : consumers.values())
{
- WSRPConsumer consumer = (WSRPConsumer)consumersIt.next();
-
// if producer is not active, it shouldn't be registered with the federating portlet invoker, hence do not
// unregister it.
if (consumer.getProducerInfo().isActive())
@@ -318,7 +316,7 @@
public WSRPConsumer getConsumer(String id)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "consumer id", null);
- return (WSRPConsumer)consumers.get(id);
+ return consumers.get(id);
}
public void registerOrDeregisterConsumerWith(String id, boolean register)
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -93,13 +93,13 @@
private CookieProtocol requiresInitCookie;
/** The Producer-Offered Portlets (handle -> WSRPPortlet) */
- private Map popsMap;
+ private Map<String, Portlet> popsMap;
/** A cache for Consumer-Configured Portlets (handle -> WSRPPortlet) */
- private Map ccpsMap;
+ private Map<String, Portlet> ccpsMap;
/** Portlet groups. */
- private Map portletGroups;
+ private Map<String, Set<Portlet>> portletGroups;
/** Time at which the cache expires */
private long expirationTimeMillis;
@@ -177,7 +177,7 @@
}
else
{
- return valid.booleanValue();
+ return valid;
}
}
@@ -404,8 +404,8 @@
{
int length = portletDescriptions.length;
log.debug("Extracting " + length + " portlets.");
- popsMap = new LinkedHashMap(length);
- portletGroups = new HashMap();
+ popsMap = new LinkedHashMap<String, Portlet>(length);
+ portletGroups = new HashMap<String, Set<Portlet>>();
for (int i = 0; i < length; i++)
{
@@ -420,8 +420,8 @@
}
else
{
- popsMap = Collections.EMPTY_MAP;
- portletGroups = Collections.EMPTY_MAP;
+ popsMap = Collections.emptyMap();
+ portletGroups = Collections.emptyMap();
}
//todo: could extract more information here... and rename method more appropriately
@@ -461,10 +461,10 @@
String portletGroupId = portletDescription.getGroupID();
if (portletGroupId != null)
{
- Set groupedPortlets = (Set)portletGroups.get(portletGroupId);
+ Set<Portlet> groupedPortlets = portletGroups.get(portletGroupId);
if (groupedPortlets == null)
{
- groupedPortlets = new HashSet();
+ groupedPortlets = new HashSet<Portlet>();
portletGroups.put(portletGroupId, groupedPortlets);
}
groupedPortlets.add(wsrpPortlet);
@@ -506,7 +506,7 @@
// add the portlet to the CCP cache
if (ccpsMap == null)
{
- ccpsMap = new HashMap();
+ ccpsMap = new HashMap<String, Portlet>();
}
ccpsMap.put(portletHandle, portlet);
@@ -544,24 +544,24 @@
{
log.debug("Trying cached POPs");
- portlet = (Portlet)popsMap.get(portletHandle);
+ portlet = popsMap.get(portletHandle);
if (portlet == null && ccpsMap != null)
{
log.debug("Trying cached CCPs");
- portlet = (Portlet)ccpsMap.get(portletHandle);
+ portlet = ccpsMap.get(portletHandle);
}
}
return portlet;
}
- public Map getPortletGroupMap() throws PortletInvokerException
+ public Map<String, Set<Portlet>> getPortletGroupMap() throws PortletInvokerException
{
refresh(false);
return portletGroups;
}
- public Map getPortletMap() throws PortletInvokerException
+ public Map<String, Portlet> getPortletMap() throws PortletInvokerException
{
refresh(false);
return popsMap;
@@ -571,7 +571,7 @@
private boolean useCache()
{
- return persistentExpirationCacheSeconds != null && persistentExpirationCacheSeconds.intValue() > 0;
+ return persistentExpirationCacheSeconds != null && persistentExpirationCacheSeconds > 0;
}
private void resetCacheTimerIfNeeded()
@@ -579,7 +579,7 @@
if (useCache())
{
// reset expiration time
- expirationTimeMillis = System.currentTimeMillis() + (persistentExpirationCacheSeconds.intValue() * 1000);
+ expirationTimeMillis = System.currentTimeMillis() + (persistentExpirationCacheSeconds * 1000);
}
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -33,7 +33,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -52,13 +51,13 @@
private boolean perGroupCookies = false;
/** group id -> Cookie[] */
- private Map groupCookies;
+ private Map<String, Cookie[]> groupCookies;
/** portlet handle -> SessionInfo */
- private Map portletSessions;
+ private Map<String, SessionInfo> portletSessions;
/** session id -> portlet handle */
- private Map sessionId2PortletHandle;
+ private Map<String, String> sessionId2PortletHandle;
/** Cookies sent by the remote producer */
private Cookie[] userCookie;
@@ -156,7 +155,7 @@
if (groupCookies == null)
{
- groupCookies = new HashMap();
+ groupCookies = new HashMap<String, Cookie[]>();
}
if (groupCookies.containsKey(groupId))
@@ -175,7 +174,7 @@
}
// purge expired cookies
- Cookie[] cookies = (Cookie[])groupCookies.get(groupId);
+ Cookie[] cookies = groupCookies.get(groupId);
cookies = purgeExpiredCookies(cookies);
// if there are no non-expired cookies left, we will need to re-init them
@@ -202,8 +201,8 @@
if (portletSessions == null)
{
- portletSessions = new HashMap();
- sessionId2PortletHandle = new HashMap();
+ portletSessions = new HashMap<String, SessionInfo>();
+ sessionId2PortletHandle = new HashMap<String, String>();
}
portletSessions.put(portletHandle, info);
@@ -254,7 +253,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(sessionId, "session id");
- String portletHandle = (String)sessionId2PortletHandle.get(sessionId);
+ String portletHandle = sessionId2PortletHandle.get(sessionId);
if (portletHandle == null)
{
throw new IllegalArgumentException("No such session id: '" + sessionId + "'");
@@ -267,16 +266,15 @@
* @return a list containing the session ids that were still valid when they were removed and would need to be
* released
*/
- public List removeSessions()
+ public List<String> removeSessions()
{
- List idsToRelease = new ArrayList(getNumberOfSessions());
+ List<String> idsToRelease = new ArrayList<String>(getNumberOfSessions());
// copy to avoid ConcurrentModificationException
- List handlesCopy = new ArrayList(portletSessions.keySet());
+ List<String> handlesCopy = new ArrayList<String>(portletSessions.keySet());
- for (Iterator handles = handlesCopy.iterator(); handles.hasNext();)
+ for (String handle : handlesCopy)
{
- String handle = (String)handles.next();
SessionIdResult result = removeSessionIdForPortlet(handle);
// only release sessions that are still valid
@@ -364,17 +362,16 @@
*/
private Cookie[] purgeExpiredCookies(Cookie[] cookies)
{
- List cleanCookies = Tools.toList(cookies);
+ List<Cookie> cleanCookies = Tools.toList(cookies);
- for (int i = 0; i < cookies.length; i++)
+ for (Cookie cookie : cookies)
{
- Cookie cookie = cookies[i];
if (cookie.isExpired())
{
cleanCookies.remove(cookie);
}
}
- return (Cookie[])cleanCookies.toArray(new Cookie[0]);
+ return cleanCookies.toArray(new Cookie[cleanCookies.size()]);
}
private SessionIdResult internalGetSessionIdForPortlet(String portletHandle)
@@ -410,14 +407,14 @@
return null;
}
- return (SessionInfo)portletSessions.get(portletHandle);
+ return portletSessions.get(portletHandle);
}
/**
- * @return
+ * @return the known session id
* @since 2.6
*/
- Collection getSessionIds()
+ Collection<String> getSessionIds()
{
return sessionId2PortletHandle.keySet();
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -41,7 +41,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -209,7 +208,7 @@
throw new IllegalStateException("Registration status not yet known: call refresh first!");
}
- return requiresRegistration.booleanValue();
+ return requiresRegistration;
}
/**
@@ -227,7 +226,7 @@
throw new IllegalStateException("Registration status not yet known: call refresh first!");
}
- return !requiresRegistration.booleanValue();
+ return !requiresRegistration;
}
public boolean hasLocalInfo()
@@ -241,13 +240,13 @@
{
registrationData = WSRPTypeFactory.createDefaultRegistrationData();
registrationData.setConsumerName(persistentConsumerName);
- List properties = new ArrayList();
+ List<Property> properties = new ArrayList<Property>();
Map regProps = getRegistrationProperties();
if (!regProps.isEmpty())
{
- for (Iterator entries = regProps.values().iterator(); entries.hasNext();)
+ for (Object o : regProps.values())
{
- RegistrationProperty prop = (RegistrationProperty)entries.next();
+ RegistrationProperty prop = (RegistrationProperty)o;
String value = prop.getValue();
if (value != null && !prop.isDeterminedInvalid())
{
@@ -255,7 +254,7 @@
}
}
- registrationData.setRegistrationProperties((Property[])properties.toArray(new Property[regProps.size()]));
+ registrationData.setRegistrationProperties(properties.toArray(new Property[regProps.size()]));
}
}
@@ -416,9 +415,9 @@
checkForExtraProperties(producerId, result, expectedNames, persistentRegistrationProperties, !mergeWithLocalInfo);
// Merge existing properties
- for (Iterator props = descriptionsMap.values().iterator(); props.hasNext();)
+ for (Object o : descriptionsMap.values())
{
- RegistrationProperty prop = (RegistrationProperty)props.next();
+ RegistrationProperty prop = (RegistrationProperty)o;
String name = prop.getName();
RegistrationProperty existing = getRegistrationProperty(name);
if (existing != null)
@@ -473,7 +472,7 @@
}
// if issues have been detected, mark the registration as invalid (but do not reset the data)
- consistentWithProducerExpectations = Boolean.valueOf(!result.hasIssues());
+ consistentWithProducerExpectations = !result.hasIssues();
String msg = "Registration configuration is " + (result.hasIssues() ? "NOT " : "") + "valid";
result.appendToStatus(msg);
@@ -519,7 +518,6 @@
* @param result
* @param expectedNames
* @param properties
- * @return a set of the property names expected by the producer
*/
private void checkForExtraProperties(String producerId, RegistrationRefreshResult result, Set expectedNames, Map properties, boolean keepExtra)
{
@@ -569,10 +567,9 @@
{
if (descriptions != null)
{
- Map result = new HashMap(descriptions.length);
- for (int i = 0; i < descriptions.length; i++)
+ Map<String, RegistrationProperty> result = new HashMap<String, RegistrationProperty>(descriptions.length);
+ for (PropertyDescription description : descriptions)
{
- PropertyDescription description = descriptions[i];
String name = description.getName();
RegistrationPropertyDescription desc = WSRPUtils.convertToRegistrationPropertyDescription(description);
RegistrationProperty prop = new RegistrationProperty(name, null, WSRPUtils.toString(desc.getLang()));
@@ -614,9 +611,9 @@
// mark the registration properties as valid
if (persistentRegistrationProperties != null)
{
- for (Iterator props = persistentRegistrationProperties.values().iterator(); props.hasNext();)
+ for (Object o : persistentRegistrationProperties.values())
{
- RegistrationProperty prop = (RegistrationProperty)props.next();
+ RegistrationProperty prop = (RegistrationProperty)o;
prop.setInvalid(Boolean.FALSE, null);
}
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -30,6 +30,7 @@
import org.jboss.portal.api.session.event.PortalSessionEvent;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.portlet.InvokerUnavailableException;
+import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.wsrp.WSRPTypeFactory;
@@ -46,7 +47,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -70,7 +70,7 @@
private static final String SESSION_ID_PREFIX = "org.jboss.portal.wsrp.session.";
/** session id -> ProducerSessionInformation */
- private Map sessionInfos = new HashMap(); // todo: thread-safe?
+ private Map<String, ProducerSessionInformation> sessionInfos = new HashMap<String, ProducerSessionInformation>(); // todo: thread-safe?
/**
* Constructs a new SessionHandler.
@@ -158,14 +158,12 @@
{
log.debug("Cookie initialization per group requested.");
sessionInformation.setPerGroupCookies(true);
- Map groups = consumer.getPortletGroupMap();
+ Map<String, Set<Portlet>> groups = consumer.getPortletGroupMap();
try
{
- String groupId;
- for (Iterator groupIds = groups.keySet().iterator(); groupIds.hasNext();)
+ for (String groupId : groups.keySet())
{
- groupId = (String)groupIds.next();
RequestHeaderClientHandler.setCurrentGroupId(groupId);
log.debug("Initializing cookie for group '" + groupId + "'.");
initCookie(initCookie, invocation, retryIfFails);
@@ -310,14 +308,13 @@
/** @since 2.6 */
void releaseSessions() throws PortletInvokerException
{
- List idsToRelease = new ArrayList(sessionInfos.size());
+ List<String> idsToRelease = new ArrayList<String>();
- Set uniqueInfos = new HashSet(sessionInfos.values());
+ Set<ProducerSessionInformation> uniqueInfos = new HashSet<ProducerSessionInformation>(sessionInfos.values());
- for (Iterator infos = uniqueInfos.iterator(); infos.hasNext();)
+ for (ProducerSessionInformation info : uniqueInfos)
{
- ProducerSessionInformation info = (ProducerSessionInformation)infos.next();
- idsToRelease.add(info.removeSessions());
+ idsToRelease.addAll(info.removeSessions());
}
internalReleaseSessions(idsToRelease);
@@ -332,12 +329,11 @@
{
if (sessionIds != null)
{
- List idsToRelease = new ArrayList();
+ List<String> idsToRelease = new ArrayList<String>();
- for (int i = 0; i < sessionIds.length; i++)
+ for (String sessionId : sessionIds)
{
- String sessionId = sessionIds[i];
- ProducerSessionInformation info = (ProducerSessionInformation)sessionInfos.get(sessionId);
+ ProducerSessionInformation info = sessionInfos.get(sessionId);
sessionId = info.removeSession(sessionId);
if (sessionId != null)
{
@@ -349,12 +345,12 @@
}
}
- private void internalReleaseSessions(List idsToRelease) throws PortletInvokerException
+ private void internalReleaseSessions(List<String> idsToRelease) throws PortletInvokerException
{
if (idsToRelease != null && !idsToRelease.isEmpty())
{
ReleaseSessions releaseSessions = WSRPTypeFactory.createReleaseSessions(consumer.getRegistrationContext(),
- (String[])idsToRelease.toArray(new String[0]));
+ idsToRelease.toArray(new String[idsToRelease.size()]));
try
{
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -74,7 +74,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
@@ -106,7 +105,7 @@
}
/** The default user scopes as per the specification (6.1.4) */
- private static final Set WSRP_DEFAULT_USER_SCOPE = new HashSet(2);
+ private static final Set<String> WSRP_DEFAULT_USER_SCOPE = new HashSet<String>(2);
static
{
@@ -208,8 +207,7 @@
WSRPUtils.convertToWSRPPortletContext(portletContext), UserAccess.getUserContext());
try
{
- PortletContext newPortletContext = WSRPUtils.convertToPortalPortletContext(getPortletManagementService().clonePortlet(clonePortlet));
- return newPortletContext;
+ return WSRPUtils.convertToPortalPortletContext(getPortletManagementService().clonePortlet(clonePortlet));
}
catch (Exception e)
{
@@ -227,27 +225,27 @@
return Collections.EMPTY_LIST;
}
- List handles = new ArrayList(numberOfClones);
- for (Iterator contexts = portletContexts.iterator(); contexts.hasNext();)
+ List<String> handles = new ArrayList<String>(numberOfClones);
+ for (Object portletContext : portletContexts)
{
- PortletContext context = (PortletContext)contexts.next();
+ PortletContext context = (PortletContext)portletContext;
String id = context.getId();
handles.add(id);
}
log.debug("Attempting to destroy clones: " + handles);
DestroyPortlets destroyPortlets = WSRPTypeFactory.createDestroyPortlets(getRegistrationContext(),
- (String[])handles.toArray(new String[0]));
+ handles.toArray(new String[handles.size()]));
try
{
DestroyPortletsResponse response = getPortletManagementService().destroyPortlets(destroyPortlets);
DestroyFailed[] failures = response.getDestroyFailed();
- List result = Collections.EMPTY_LIST;
+ List<DestroyCloneFailure> result = Collections.emptyList();
if (failures != null)
{
int failureNumbers = failures.length;
- result = new ArrayList(failureNumbers);
+ result = new ArrayList<DestroyCloneFailure>(failureNumbers);
// list all the failures and successes
for (int i = 0; i < failureNumbers; i++)
{
@@ -262,9 +260,9 @@
// update ProducerInfo's caches by removing all the successfully destroyed clones
if (!handles.isEmpty())
{
- for (Iterator destroyed = handles.iterator(); destroyed.hasNext();)
+ for (String handle : handles)
{
- producerInfo.removeHandleFromCaches((String)destroyed.next());
+ producerInfo.removeHandleFromCaches(handle);
}
}
@@ -280,7 +278,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(keys, "Portlet ids");
- return getProperties(portletContext, (String[])keys.toArray(new String[0]));
+ return getProperties(portletContext, (String[])keys.toArray(new String[keys.size()]));
}
private PropertyMap getProperties(PortletContext portletContext, String[] keys) throws PortletInvokerException
@@ -344,8 +342,8 @@
PropertyList propertyList = WSRPTypeFactory.createPropertyList();
int changesNumber = changes.length;
- List updates = new ArrayList(changesNumber);
- List resets = new ArrayList(changesNumber);
+ List<Property> updates = new ArrayList<Property>(changesNumber);
+ List<ResetProperty> resets = new ArrayList<ResetProperty>(changesNumber);
for (int i = 0; i < changesNumber; i++)
{
PropertyChange change = changes[i];
@@ -365,8 +363,8 @@
throw new IllegalArgumentException("Unexpected property change type: " + change.getType());
}
}
- propertyList.setProperties((Property[])updates.toArray(new Property[0]));
- propertyList.setResetProperties((ResetProperty[])resets.toArray(new ResetProperty[0]));
+ propertyList.setProperties(updates.toArray(new Property[updates.size()]));
+ propertyList.setResetProperties(resets.toArray(new ResetProperty[resets.size()]));
SetPortletProperties setPortletProperties =
WSRPTypeFactory.createSetPortletProperties(getRegistrationContext(), WSRPUtils.convertToWSRPPortletContext(portletContext), propertyList);
@@ -396,7 +394,7 @@
// Portlet-related methods ******************************************************************************************
- public Map getPortletGroupMap() throws PortletInvokerException
+ public Map<String, Set<Portlet>> getPortletGroupMap() throws PortletInvokerException
{
return producerInfo.getPortletGroupMap();
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/deployment/WSRPDeployer.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/deployment/WSRPDeployer.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/deployment/WSRPDeployer.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -35,7 +35,6 @@
import org.xml.sax.EntityResolver;
import java.net.URL;
-import java.util.Iterator;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -117,9 +116,9 @@
{
super.start(di);
WSRPDeployment deployment = (WSRPDeployment)di.metaData;
- for (Iterator i = deployment.getConsumers().iterator(); i.hasNext();)
+ for (Object o : deployment.getConsumers())
{
- WSRPConsumer consumer = (WSRPConsumer)i.next();
+ WSRPConsumer consumer = (WSRPConsumer)o;
try
{
consumerRegistry.activateConsumerWith(consumer.getProducerId());
@@ -134,11 +133,11 @@
public void stop(DeploymentInfo di) throws DeploymentException
{
WSRPDeployment deployment = (WSRPDeployment)di.metaData;
- for (Iterator i = deployment.getConsumers().iterator(); i.hasNext();)
+ for (Object o : deployment.getConsumers())
{
try
{
- WSRPConsumer consumer = (WSRPConsumer)i.next();
+ WSRPConsumer consumer = (WSRPConsumer)o;
consumer.stop();
}
catch (Exception e)
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -138,12 +138,14 @@
Set keySet = prefsInfo.getKeys();
descs = new PropertyDescription[keySet.size()];
int index = 0;
- for (Iterator keys = keySet.iterator(); keys.hasNext();)
+ for (Object key : keySet)
{
- PreferenceInfo prefInfo = prefsInfo.getPreference((String)keys.next());
+ PreferenceInfo prefInfo = prefsInfo.getPreference((String)key);
// WSRP Spec 8.7: return only the portion of the Portlet's persistent state the user is allowed to modify
- if (!prefInfo.isReadOnly().booleanValue())
+ // if read only status is not determined, we consider it as being read-only to be safe
+ Boolean readOnly = prefInfo.isReadOnly();
+ if (readOnly != null && !readOnly)
{
//todo: check what we should use key
//todo: right now we only support String properties
@@ -226,9 +228,9 @@
{
destroyFailed = new DestroyFailed[failuresNumber];
int i = 0;
- for (Iterator failures = failuresList.iterator(); failures.hasNext();)
+ for (Object aFailuresList : failuresList)
{
- DestroyCloneFailure failure = (DestroyCloneFailure)failures.next();
+ DestroyCloneFailure failure = (DestroyCloneFailure)aFailuresList;
destroyFailed[i++] = WSRPTypeFactory.createDestroyFailed(failure.getPortletId(), failure.getMessage());
}
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -126,9 +126,9 @@
}
- public Set getOfferedPortletDescriptions(String[] desiredLocales)
+ public Set<PortletDescription> getOfferedPortletDescriptions(String[] desiredLocales)
{
- Set portlets;
+ Set<Portlet> portlets;
try
{
portlets = producer.getRemotablePortlets();
@@ -136,14 +136,13 @@
catch (PortletInvokerException e)
{
log.warn("Could not retrieve portlets. Reason:\n\t" + e.getLocalizedMessage());
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
- Set offeredPortletDescriptions = new HashSet(portlets.size());
+ Set<PortletDescription> offeredPortletDescriptions = new HashSet<PortletDescription>(portlets.size());
- for (Iterator iterator = portlets.iterator(); iterator.hasNext();)
+ for (Portlet portlet : portlets)
{
- Portlet portlet = (Portlet)iterator.next();
PortletDescription desc = getPortletDescription(portlet, desiredLocales);
offeredPortletDescriptions.add(desc);
}
@@ -169,13 +168,14 @@
/**
* @param desiredLocales
- * @param registration here so that we can do filtering of portlets based on registration data.
+ * @param registration here so that we can do filtering of portlets based on registration data (not currently
+ * implemented)
* @return
*/
private PortletDescription[] getPortletDescriptions(String[] desiredLocales, Registration registration)
{
- return (PortletDescription[])getOfferedPortletDescriptions(desiredLocales)
- .toArray(new PortletDescription[]{});
+ Set<PortletDescription> descriptions = getOfferedPortletDescriptions(desiredLocales);
+ return descriptions.toArray(new PortletDescription[descriptions.size()]);
}
/**
@@ -271,9 +271,9 @@
String[] localeNames = new String[locales.size()];
int i = 0;
- for (Iterator iterator = locales.iterator(); iterator.hasNext();)
+ for (Object locale : locales)
{
- localeNames[i++] = WSRPUtils.toString((Locale)iterator.next());
+ localeNames[i++] = WSRPUtils.toString((Locale)locale);
}
return localeNames;
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -82,7 +82,6 @@
import java.rmi.RemoteException;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
/**
@@ -414,14 +413,13 @@
return portlet;
}
- Set getRemotablePortlets() throws PortletInvokerException
+ Set<Portlet> getRemotablePortlets() throws PortletInvokerException
{
log.debug("Retrieving remotable portlets");
- Set allPortlets = invoker.getPortlets();
- Set remotablePortlets = new HashSet(allPortlets.size());
- for (Iterator iterator = allPortlets.iterator(); iterator.hasNext();)
+ Set<Portlet> allPortlets = invoker.getPortlets();
+ Set<Portlet> remotablePortlets = new HashSet<Portlet>(allPortlets.size());
+ for (Portlet portlet : allPortlets)
{
- Portlet portlet = (Portlet)iterator.next();
log.debug("Found portlet: " + portlet.getContext());
if (isRemotable(portlet))
{
@@ -501,12 +499,9 @@
{
return remotable.booleanValue();
}
- else
+ else if (isRemotableByDefault() != null)
{
- if (isRemotableByDefault() != null)
- {
- return isRemotableByDefault().booleanValue();
- }
+ return isRemotableByDefault().booleanValue();
}
return false;
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerConfigurationServiceImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerConfigurationServiceImpl.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerConfigurationServiceImpl.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -63,7 +63,6 @@
private String configLocation;
private ProducerConfiguration configuration;
- private File dataDir;
private File config;
private static DefaultSchemaResolver RESOLVER;
@@ -96,6 +95,7 @@
{
MBeanServer server = MBeanServerLocator.locateJBoss();
ObjectName oname = ObjectNameFactory.create("jboss.system:type=ServerConfig");
+ File dataDir;
try
{
dataDir = (File)server.getAttribute(oname, "ServerDataDir");
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -38,7 +38,7 @@
* @version $Revision:5865 $
* @since 2.6
*/
-public class RegistrationPropertyDescription implements Cloneable, PropertyDescription
+public class RegistrationPropertyDescription implements PropertyDescription
{
private Long key;
private QName name;
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -36,7 +36,6 @@
import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;
-import java.util.Iterator;
import java.util.Map;
/**
@@ -76,9 +75,9 @@
tmp.append("servletPath=").append(req.getServletPath()).append('\n');
//
- for (Iterator i = req.getParameterMap().entrySet().iterator(); i.hasNext();)
+ for (Object o : req.getParameterMap().entrySet())
{
- Map.Entry entry = (Map.Entry)i.next();
+ Map.Entry entry = (Map.Entry)o;
String name = (String)entry.getKey();
String[] values = (String[])entry.getValue();
tmp.append("param.").append(name).append('=');
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/servlet/UserAccess.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/servlet/UserAccess.java 2007-12-17 15:01:58 UTC (rev 9359)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/servlet/UserAccess.java 2007-12-18 01:32:23 UTC (rev 9360)
@@ -35,6 +35,10 @@
*/
public class UserAccess
{
+ private UserAccess()
+ {
+ }
+
public static String getUser()
{
HttpServletRequest req = ServletAccess.getRequest();
18 years, 4 months
JBoss Portal SVN: r9359 - demo/trunk/portlets/jbosswiki.
by portal-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2007-12-17 10:01:58 -0500 (Mon, 17 Dec 2007)
New Revision: 9359
Modified:
demo/trunk/portlets/jbosswiki/wiki-common.jar
Log:
oups
Modified: demo/trunk/portlets/jbosswiki/wiki-common.jar
===================================================================
(Binary files differ)
18 years, 4 months
JBoss Portal SVN: r9358 - modules/common/trunk/common.
by portal-commits@lists.jboss.org
Author: bdaw
Date: 2007-12-17 07:02:30 -0500 (Mon, 17 Dec 2007)
New Revision: 9358
Modified:
modules/common/trunk/common/pom.xml
Log:
use httpclient from other groupId
Modified: modules/common/trunk/common/pom.xml
===================================================================
--- modules/common/trunk/common/pom.xml 2007-12-17 08:35:10 UTC (rev 9357)
+++ modules/common/trunk/common/pom.xml 2007-12-17 12:02:30 UTC (rev 9358)
@@ -61,7 +61,7 @@
</dependency>
<dependency>
- <groupId>apache-httpclient</groupId>
+ <groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.0.1</version>
</dependency>
18 years, 4 months