Author: sohil.shah(a)jboss.com
Date: 2008-01-03 11:49:45 -0500 (Thu, 03 Jan 2008)
New Revision: 9427
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
Log:
deleting AssociationContext from codebase
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2008-01-03
13:51:51 UTC (rev 9426)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AssociationContext.java 2008-01-03
16:49:45 UTC (rev 9427)
@@ -1,568 +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.impl.model.container.spi.UIContainerObject;
-import org.jboss.portal.presentation.model.state.structural.StructuralObject;
-import org.jboss.portal.presentation.model.state.StateException;
-import org.jboss.portal.presentation.model.UIObject;
-
-import java.util.Iterator;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Collection;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-final class AssociationContext
-{
-
- /** . */
- ObjectContext owner;
-
- /** . */
- final ManyToOne parent = new ManyToOne()
- {
- protected StructuralObject doLoad()
- {
- return
owner.container.structuralStateContext.loadParent(owner.structuralObject);
- }
- protected ObjectContext getOwner()
- {
- return owner;
- }
- protected OneToMany getOneToMany(UIContainerObject related)
- {
- return ((ObjectContext)related.getContext()).associationContext.children;
- }
- };
-
- /** . */
- final OneToMany children = new OneToMany()
- {
- protected Collection<StructuralObject> doLoad()
- {
- return
owner.container.structuralStateContext.loadChildren(owner.structuralObject);
- }
- protected ObjectContext getOwner()
- {
- return owner;
- }
- protected ManyToOne getManyToOne(UIContainerObject related)
- {
- return ((ObjectContext)related.getContext()).associationContext.parent;
- }
- };
-
- static abstract class ManyToOne
- {
-
- /** . */
- private boolean loaded;
-
- /** . */
- private UIContainerObject related;
-
- /** The context pointing at us via a OneToMany. */
- private Set<ObjectContext> refs;
-
- private ManyToOne()
- {
- this.loaded = false;
- this.related = null;
- this.refs = new HashSet<ObjectContext>();
- }
-
- Set<ObjectContext> getReferences()
- {
- return refs;
- }
-
- boolean isLoaded()
- {
- return loaded;
- }
-
- void setLoadedRelated(UIContainerObject newParent)
- {
- if (newParent == null)
- {
- throw new IllegalArgumentException();
- }
- if (!loaded)
- {
- throw new IllegalStateException("Cannot set parent of non loaded
association");
- }
-
- // Downgrade the related side
- if (related != null)
- {
- detach();
- }
-
- //
- if (newParent != null)
- {
- attach(newParent);
- }
- else
- {
- related = null;
- loaded = false;
- }
- }
-
- UIContainerObject getLoadedRelated()
- {
- if (!loaded)
- {
- throw new IllegalStateException("Cannot set parent of non loaded
association");
- }
- return related;
- }
-
- void clearLoadedRelated()
- {
- if (!loaded)
- {
- throw new IllegalStateException("Cannot clear parent of non loaded
association");
- }
-
- // Downgrade realted
- detach();
-
- //
- loaded = false;
- }
-
- UIContainerObject getRelated()
- {
- ObjectContext owner = getOwner();
-
- //
- owner.checkAccess();
-
- //
- if (!loaded)
- {
- load();
- }
-
- //
- owner.checkAccess();
-
- //
- return related;
- }
-
- /**
- * Loads the related side.
- *
- * @return the loaded structural object
- * @throws StateException if the load operation cannot be achieved
- */
- protected abstract StructuralObject doLoad() throws StateException;
-
- protected abstract ObjectContext getOwner();
-
- protected abstract OneToMany getOneToMany(UIContainerObject related);
-
- private void attach(UIContainerObject related)
- {
- if (this.related != null)
- {
- throw new AssertionError("BUG");
- }
-
- //
- OneToMany oneToMany = getOneToMany(related);
- ObjectContext owner = getOwner();
-
- //
- if (oneToMany.refs.contains(owner))
- {
- throw new AssertionError("BUG");
- }
-
- //
- oneToMany.refs.add(owner);
- this.related = related;
- }
-
- private void detach()
- {
- if (related == null)
- {
- throw new AssertionError("BUG");
- }
-
- //
- OneToMany oneToMany = getOneToMany(related);
- ObjectContext owner = getOwner();
-
- //
- if (!oneToMany.refs.contains(owner))
- {
- throw new AssertionError("BUG");
- }
-
- //
- oneToMany.refs.remove(owner);
- this.related = null;
- }
-
- /**
- * Attempt for loading the related side. If a failure occurs during while loading
the related side
- * the load operation is aborted and the status of the association owner is updated
accordingly. If the loading
- * of the related side is succesful the association is updated.
- */
- private void load()
- {
- ObjectContext owner = getOwner();
-
- //
- try
- {
- StructuralObject relatedSO = doLoad();
-
- // If null it is the root so nothing is done
- if (relatedSO != null)
- {
- UIContainerObject related = owner.container.get(relatedSO);
-
- //
- if (related != null)
- {
- attach(related);
-
- //
- ObjectContext parentContext = (ObjectContext)related.getContext();
-
- //
- if (!relatedSO.compareTo(parentContext.structuralObject))
- {
- parentContext.status = UIObject.Status.STALE;
- }
- }
- else
- {
- related = owner.container.create(relatedSO);
-
- //
- owner.container.attach(related);
-
- //
- attach(related);
- }
- }
-
- // Set as loaded
- this.loaded = true;
- }
- catch (StateException e)
- {
- owner.updateStatus(e);
- }
- }
- }
-
- static abstract class OneToMany
- {
-
- /** . */
- private final LazySet list;
-
- /** . */
- private boolean loaded;
-
- /** . */
- private Set<UIContainerObject> relateds;
-
- /** The contexts pointing at us via a ManyToOne. */
- private Set<ObjectContext> refs;
-
- private OneToMany()
- {
- this.list = new LazySet();
- this.loaded = false;
- this.relateds = new HashSet<UIContainerObject>();
- this.refs = new HashSet<ObjectContext>();
- }
-
- boolean isLoaded()
- {
- return loaded;
- }
-
- void addLoadedRelated(UIContainerObject related)
- {
- if (!isLoaded())
- {
- throw new IllegalStateException("Not loaded");
- }
- if (related == null)
- {
- throw new IllegalArgumentException("No null child accepted");
- }
-
- //
- for (UIContainerObject r : relateds)
- {
- if (related.getId().equals(r.getId()))
- {
- throw new IllegalStateException("Cannot add duplicate");
- }
- }
-
- //
- attach(related);
- }
-
- void setLoadedRelateds(Set<UIContainerObject> relateds)
- {
- if (!isLoaded())
- {
- throw new IllegalStateException("Not loaded");
- }
-
- //
- for (UIContainerObject related : new
ArrayList<UIContainerObject>(this.relateds))
- {
- detach(related);
- }
-
- //
- for (UIContainerObject related : relateds)
- {
- attach(related);
- }
- }
-
- UIContainerObject removeLoadedRelated(String relatedId)
- {
- if (!isLoaded())
- {
- throw new IllegalStateException("Not loaded");
- }
- if (relatedId == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- for (UIContainerObject related : relateds)
- {
- if (relatedId.equals(related.getId()))
- {
- detach(related);
- return related;
- }
- }
-
- //
- throw new AssertionError("BUG");
- }
-
- Collection<UIContainerObject> getRelateds()
- {
- return list;
- }
-
- Set<ObjectContext> getReferences()
- {
- return refs;
- }
-
- /**
- * Load the related side.
- *
- * @return the list of structural objects
- * @throws StateException if the load operation cannot be achieved
- */
- protected abstract Collection<StructuralObject> doLoad() throws
StateException;
-
- protected abstract ObjectContext getOwner();
-
- protected abstract ManyToOne getManyToOne(UIContainerObject related);
-
- private void detach(UIContainerObject related)
- {
- ManyToOne manyToOne = getManyToOne(related);
-
- //
- ObjectContext owner = getOwner();
-
- //
- if (!manyToOne.refs.contains(owner))
- {
- throw new AssertionError("BUG");
- }
-
- //
- manyToOne.refs.remove(owner);
- relateds.remove(related);
- }
-
- private void attach(UIContainerObject related)
- {
- ManyToOne manyToOne = getManyToOne(related);
-
- //
- ObjectContext owner = getOwner();
-
- //
- if (manyToOne.refs.contains(owner))
- {
- throw new AssertionError("Context already referenced by the provided
object");
- }
-
- //
- manyToOne.refs.add(owner);
- relateds.add(related);
- }
-
- private void load()
- {
- ObjectContext owner = getOwner();
-
- //
- try
- {
- for (StructuralObject relatedSO : doLoad())
- {
- UIContainerObject related = owner.container.get(relatedSO);
-
- //
- if (related != null)
- {
- ObjectContext relatedContext = (ObjectContext)related.getContext();
-
- //
- if (!relatedContext.structuralObject.compareTo(relatedSO))
- {
- relatedContext.status = UIObject.Status.STALE;
- }
- }
- else
- {
- related = owner.container.create(relatedSO);
-
- //
- owner.container.attach(related);
- }
-
- //
- attach(related);
- }
-
- //
- this.loaded = true;
- }
- catch (StateException e)
- {
- owner.updateStatus(e);
- }
- }
-
- private class LazySet extends AbstractSet<UIContainerObject>
- {
-
- public Iterator<UIContainerObject> iterator()
- {
- final ObjectContext owner = getOwner();
-
- //
- owner.checkAccess();
-
- // Load the entire relationship
- if (!isLoaded())
- {
- load();
- }
-
- //
- owner.checkAccess();
-
- //
- final Iterator<UIContainerObject> iterator = relateds.iterator();
-
- //
- return new Iterator<UIContainerObject>()
- {
- public boolean hasNext()
- {
- owner.checkAccess();
-
- //
- return iterator.hasNext();
- }
-
- public UIContainerObject next()
- {
- owner.checkAccess();
-
- //
- return iterator.next();
- }
-
- public void remove()
- {
- owner.checkAccess();
-
- //
- throw new UnsupportedOperationException();
- }
- };
- }
-
- public int size()
- {
- ObjectContext owner = getOwner();
-
- //
- owner.checkAccess();
-
- //
- if (!isLoaded())
- {
- load();
- }
-
- //
- owner.checkAccess();
-
- //
- return relateds.size();
- }
-
- public String toString()
- {
- return "ProxyList[" + getOwner() + "]";
- }
- }
- }
-}