Author: julien(a)jboss.com
Date: 2007-12-26 08:37:47 -0500 (Wed, 26 Dec 2007)
New Revision: 9383
Removed:
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/UIObjectRelationship.java
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/UIObjectContext.java
Log:
- removed unused class
- move the relationship inner classes to the UIObjectContainer
Deleted:
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-21
22:17:58 UTC (rev 9382)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-26
13:37:47 UTC (rev 9383)
@@ -1,437 +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.container;
-
-import org.jboss.portal.presentation.model.StateType;
-import org.jboss.portal.presentation.model.UIObject;
-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;
-
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-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
-{
-
- /** . */
- private static final Map<String, String> EMPTY_STATE = Collections.emptyMap();
-
- /** The context. */
- protected final UIObjectContext context;
-
- /** . */
- final UIObjectOneToMany childrenRelationship;
-
- /** . */
- final UIObjectManyToOne parentRelationship;
-
- public AbstractUIObject(UIObjectContext context)
- {
- if (context == null)
- {
- throw new IllegalArgumentException("No null context accepted");
- }
-
- //
- this.context = context;
- this.childrenRelationship = new UIObjectOneToMany(context);
- this.parentRelationship = new UIObjectManyToOne(context);
- }
-
- // UIObject interface
implementation-----------------------------------------------------------------------------------------------------------------------------
-
- public final String getId()
- {
- return context.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 final Status getStatus()
- {
- return context.status;
- }
-
- protected final boolean isModifiable()
- {
- return true;
- }
-
- public void validate(Visitor scope)
- {
- context.container.validate(this, scope);
- }
-
- public final void validate()
- {
- refresh(SINGLE_NODE_VISITOR);
- }
-
- public void refresh(Visitor scope)
- {
- context.container.refresh(this, scope);
- }
-
- public final void refresh()
- {
- refresh(SINGLE_NODE_VISITOR);
- }
-
- public <T> T getProperty(StateType stateType, String propertyName,
Class<T> propertyType)
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (stateType == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyType == null)
- {
- throw new IllegalArgumentException();
- }
- Object value;
- switch (stateType)
- {
- case NAVIGATIONAL:
- value = context.container.navigationalStateContext.get(getId(),
propertyName);
- break;
- case STRUCTURAL:
- value =
context.structuralObject.getState().getProperties().get(propertyName);
- break;
- default:
- throw new AssertionError();
- }
- return safeCast(value, propertyType);
- }
-
- public final Object getProperty(StateType stateType, String propertyName)
- {
- return getProperty(stateType, propertyName, Object.class);
- }
-
- public final <T> void setProperty(StateType stateType, String propertyName, T
propertyValue) throws StateChangeVetoException
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (stateType == null)
- {
- throw new IllegalArgumentException();
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException();
- }
- if (!isModifiable())
- {
- throw new IllegalStateException("Cannot change state");
- }
-
- //
- String id = getId();
-
- //
- switch (stateType)
- {
- case NAVIGATIONAL:
- {
- // Have context process the change
- 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);
- context.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 =
context.container.structuralStateContext.update(context.structuralObject, changes);
- }
- catch (StateException e)
- {
- validate();
-
- //
- throw e;
- }
-
- //
- 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);
- context.container.fireEvent(event);
- }
- else
- {
- throw new StateChangeVetoException("Structural property value must be
string value");
- }
- break;
- }
- default:
- throw new AssertionError();
- }
- }
-
- public final 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))
- {
- return child;
- }
- }
-
- //
- return null;
- }
-
- public final String getName()
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
-
- //
- return context.structuralObject.getState().getName();
- }
-
- public final UIObject getParent()
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
-
- //
- return parentRelationship.get();
- }
-
- public final List<AbstractUIObject> getChildren()
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
-
- //
- return childrenRelationship.get();
- }
-
- public final <T extends UIObject> T createChild(String name, Class<T>
type) throws IllegalArgumentException
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (!isModifiable())
- {
- throw new IllegalStateException("Cannot change state");
- }
-
- //
- StructuralObject.Creation creation;
- try
- {
- creation =
context.container.structuralStateContext.create(context.structuralObject, type, name,
EMPTY_STATE);
- }
- catch (StateException e)
- {
- context.updateStatus(e);
-
- //
- throw e;
- }
-
- //
- context.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);
- context.container.fireEvent(event);
-
- //
- return type.cast(context.getObject(child.getId()));
- }
-
- public final void destroyChild(String name) throws IllegalArgumentException,
StateException
- {
- if (!context.isValid())
- {
- throw new IllegalStateException();
- }
- if (name == null)
- {
- throw new IllegalArgumentException();
- }
- if (!isModifiable())
- {
- throw new IllegalStateException("Cannot change state");
- }
-
- // 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 =
context.container.structuralStateContext.destroy(namedChild.context.structuralObject);
-
- //
- context.container.update(destruction);
- }
-
- public final void move(UIObject destination) throws IllegalArgumentException,
StateException
- {
- if (destination == null)
- {
- throw new IllegalArgumentException("No null object accepted");
- }
- if (!isModifiable())
- {
- throw new IllegalStateException("Cannot change state");
- }
-
- //
- 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);
-
- /**
- * Visitor that visits a single node only.
- */
- private static final Visitor SINGLE_NODE_VISITOR = new Visitor()
- {
- public boolean enterObject(UIObject object)
- {
- return true;
- }
-
- public void leaveObject(UIObject object)
- {
- }
-
- public boolean enterChildren(UIObject object)
- {
- return false;
- }
- };
-
-}
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-21
22:17:58 UTC (rev 9382)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-26
13:37:47 UTC (rev 9383)
@@ -36,6 +36,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.AbstractList;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -365,4 +366,114 @@
return containerObject;
}
+ public ManyToOne createManyToOne(UIObjectContext context)
+ {
+ return new ManyToOne(context);
+ }
+
+ class ManyToOne
+ {
+
+ /** . */
+ private final UIObjectContext owner;
+
+ /** . */
+ private boolean loaded;
+
+ /** . */
+ private UIContainerObject related;
+
+ private ManyToOne(UIObjectContext owner)
+ {
+ this.owner = owner;
+ }
+
+ UIContainerObject get()
+ {
+ if (!loaded)
+ {
+ related = getParent(owner.structuralObject);
+ }
+
+ // Try to resolve the relationship
+
+
+ //
+ return related;
+ }
+
+ void clear()
+ {
+ related = null;
+ loaded = false;
+ }
+ }
+
+ public OneToMany createOneToMany(UIObjectContext context)
+ {
+ return new OneToMany(context);
+ }
+
+ class OneToMany
+ {
+
+ /** . */
+ private final ProxyList list;
+
+ /** . */
+ private final UIObjectContext owner;
+
+ /** . */
+ private List<UIContainerObject> relateds;
+
+ private OneToMany(UIObjectContext object)
+ {
+ this.owner = object;
+ this.list = new ProxyList();
+ this.relateds = null;
+ }
+
+ List<UIContainerObject> get()
+ {
+ return list;
+ }
+
+ void clear()
+ {
+ relateds = null;
+ }
+
+ private class ProxyList extends AbstractList<UIContainerObject>
+ {
+ public UIContainerObject get(int i)
+ {
+ if (!owner.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
+
+ // Load the entire relationship
+ if (relateds == null)
+ {
+ relateds = getChildren(owner.structuralObject);
+ }
+
+ //
+ return relateds.get(i);
+ }
+
+ public int size()
+ {
+ if (!owner.isValid())
+ {
+ throw new IllegalStateException("Relationship not valid");
+ }
+ if (relateds == null)
+ {
+ relateds = getChildren(owner.structuralObject);
+ }
+ return relateds.size();
+ }
+ }
+ }
}
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-21
22:17:58 UTC (rev 9382)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContext.java 2007-12-26
13:37:47 UTC (rev 9383)
@@ -47,10 +47,10 @@
final UIManagedObject managedObject;
/** . */
- final UIObjectRelationship.OneToMany children;
+ final UIObjectContainer.OneToMany children;
/** . */
- final UIObjectRelationship.ManyToOne parent;
+ final UIObjectContainer.ManyToOne parent;
/** . */
StructuralObject structuralObject;
@@ -74,8 +74,8 @@
this.structuralObject = structuralObject;
this.status = UIObject.Status.VALID;
this.managedObject = new UIManagedObject(this);
- this.children = new UIObjectRelationship.OneToMany(this);
- this.parent = new UIObjectRelationship.ManyToOne(this);
+ this.children = container.createOneToMany(this);
+ this.parent = container.createManyToOne(this);
}
// Public
***********************************************************************************************************
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java 2007-12-21
22:17:58 UTC (rev 9382)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectRelationship.java 2007-12-26
13:37:47 UTC (rev 9383)
@@ -1,135 +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.container;
-
-import java.util.List;
-import java.util.AbstractList;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class UIObjectRelationship
-{
-
- final static class ManyToOne
- {
-
- /** . */
- private final UIObjectContext owner;
-
- /** . */
- private boolean loaded;
-
- /** . */
- private UIContainerObject related;
-
- ManyToOne(UIObjectContext owner)
- {
- this.owner = owner;
- }
-
- UIContainerObject get()
- {
- if (!loaded)
- {
- related = owner.container.getParent(owner.structuralObject);
- }
-
- // Try to resolve the relationship
-
-
- //
- return related;
- }
-
- void clear()
- {
- related = null;
- loaded = false;
- }
- }
-
- final static class OneToMany
- {
-
- /** . */
- private final ProxyList list;
-
- /** . */
- private final UIObjectContext owner;
-
- /** . */
- private List<UIContainerObject> relateds;
-
- OneToMany(UIObjectContext object)
- {
- this.owner = object;
- this.list = new ProxyList();
- this.relateds = null;
- }
-
- List<UIContainerObject> get()
- {
- return list;
- }
-
- void clear()
- {
- relateds = null;
- }
-
- private class ProxyList extends AbstractList<UIContainerObject>
- {
- public UIContainerObject get(int i)
- {
- if (!owner.isValid())
- {
- throw new IllegalStateException("Relationship not valid");
- }
-
- // Load the entire relationship
- if (relateds == null)
- {
- relateds = owner.container.getChildren(owner.structuralObject);
- }
-
- //
- return relateds.get(i);
- }
-
- public int size()
- {
- if (!owner.isValid())
- {
- throw new IllegalStateException("Relationship not valid");
- }
- if (relateds == null)
- {
- relateds = owner.container.getChildren(owner.structuralObject);
- }
- return relateds.size();
- }
- }
- }
-}