Author: chris.laprun(a)jboss.com
Date: 2011-07-17 12:33:30 -0400 (Sun, 17 Jul 2011)
New Revision: 6876
Added:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableResult.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterator.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/Adaptor.java
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PortalImpl.java
Log:
- Adapted to API changes.
- Added util package with AdaptedIterableResult, AdapterIterator and Adaptor classes meant
to convert between MOP and API data.
- Implemented NavigationImpl.getAll.
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-07-16
07:12:30 UTC (rev 6875)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-07-17
16:33:30 UTC (rev 6876)
@@ -36,8 +36,6 @@
import org.exoplatform.portal.pom.data.PortalData;
import org.exoplatform.portal.pom.data.PortalKey;
import org.gatein.api.GateIn;
-import org.gatein.api.IterableResult;
-import org.gatein.api.ParameterValidation;
import org.gatein.api.content.Application;
import org.gatein.api.content.Content;
import org.gatein.api.content.Gadget;
@@ -48,11 +46,13 @@
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Portal;
import org.gatein.api.portal.Site;
+import org.gatein.api.util.IterableResult;
+import org.gatein.api.util.ParameterValidation;
import org.gatein.portal.api.impl.portal.PortalImpl;
+import org.gatein.portal.api.impl.util.AdaptedIterableResult;
import org.picocontainer.Startable;
import java.net.URI;
-import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
@@ -82,7 +82,18 @@
begin();
final List<PortalData> portals = dataStorage.find(PORTALS).getAll();
- return new PortalIterableResult(portals);
+ return new AdaptedIterableResult<PortalData, Portal>(portals.size(),
portals.iterator())
+ {
+ public Portal adapt(PortalData old)
+ {
+ return new PortalImpl(old, GateInImpl.this);
+ }
+
+ public boolean contains(Id<Portal> id)
+ {
+ return getPortalDataFor(id) != null;
+ }
+ };
}
catch (Exception e)
{
@@ -249,60 +260,4 @@
{
RequestLifeCycle.begin(container);
}
-
- private static class PortalIterator implements Iterator<Portal>
- {
- private int current;
- private int size;
- private final List<PortalData> portals;
- private final GateInImpl gateIn;
-
- public PortalIterator(List<PortalData> portals, GateInImpl gateIn)
- {
- this.portals = portals;
- size = portals.size();
- this.gateIn = gateIn;
- }
-
-
- public boolean hasNext()
- {
- return current > size;
- }
-
- public Portal next()
- {
- return new PortalImpl(portals.get(current++), gateIn);
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- }
-
- private class PortalIterableResult implements IterableResult<Portal>
- {
- private final List<PortalData> portals;
-
- public PortalIterableResult(List<PortalData> portals)
- {
- this.portals = portals;
- }
-
- public int size()
- {
- return portals.size();
- }
-
- public boolean contains(Id<Portal> id)
- {
- return getPortalDataFor(id) != null;
- }
-
- public Iterator<Portal> iterator()
- {
- return new PortalIterator(portals, GateInImpl.this);
- }
- }
}
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-07-16
07:12:30 UTC (rev 6875)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-07-17
16:33:30 UTC (rev 6876)
@@ -25,17 +25,18 @@
import org.exoplatform.portal.mop.navigation.NodeContext;
import org.exoplatform.portal.mop.navigation.NodeModel;
import org.exoplatform.portal.mop.navigation.NodeState;
-import org.gatein.api.Filter;
import org.gatein.api.GateIn;
-import org.gatein.api.IterableResult;
-import org.gatein.api.Query;
import org.gatein.api.id.Context;
import org.gatein.api.id.Id;
import org.gatein.api.id.Identifiable;
import org.gatein.api.portal.Navigation;
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Site;
+import org.gatein.api.util.Filter;
+import org.gatein.api.util.IterableResult;
+import org.gatein.api.util.Query;
import org.gatein.portal.api.impl.GateInImpl;
+import org.gatein.portal.api.impl.util.AdaptedIterableResult;
import java.util.Iterator;
import java.util.regex.Pattern;
@@ -96,8 +97,18 @@
public IterableResult<Navigation> getAll()
{
-// context.getNodes()
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return new AdaptedIterableResult<NavigationImpl, Navigation>(size(),
context.iterator())
+ {
+ public Navigation adapt(NavigationImpl old)
+ {
+ return old;
+ }
+
+ public boolean contains(Id<Navigation> t)
+ {
+ return context.get(t.toString()) != null;
+ }
+ };
}
public int size()
@@ -110,16 +121,36 @@
return false; //To change body of implemented methods use File | Settings | File
Templates.
}
+ public boolean contains(Id<Navigation> navigationId)
+ {
+ return false; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public Navigation createAndAdd(String key)
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
+ public Navigation createAndAdd(Id<Navigation> navigationId)
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public Navigation get(String key)
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
+ public Navigation get(Id<Navigation> navigationId)
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public Id<Navigation> getIdForChild(String key)
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
public <U extends Navigation> IterableResult<U>
getAllWhere(Filter<U> filter)
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PortalImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PortalImpl.java 2011-07-16
07:12:30 UTC (rev 6875)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PortalImpl.java 2011-07-17
16:33:30 UTC (rev 6876)
@@ -29,12 +29,12 @@
import org.exoplatform.portal.mop.navigation.NodeModel;
import org.exoplatform.portal.mop.navigation.Scope;
import org.exoplatform.portal.pom.data.PortalData;
-import org.gatein.api.Container;
import org.gatein.api.content.ContentRegistry;
import org.gatein.api.portal.Navigation;
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Portal;
import org.gatein.api.portal.Site;
+import org.gatein.api.util.Container;
import org.gatein.portal.api.impl.GateInImpl;
import org.gatein.portal.api.impl.IdentifiableImpl;
Added:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableResult.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableResult.java
(rev 0)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterableResult.java 2011-07-17
16:33:30 UTC (rev 6876)
@@ -0,0 +1,57 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.gatein.portal.api.impl.util;
+
+import org.gatein.api.id.Identifiable;
+import org.gatein.api.util.IterableResult;
+
+import java.util.Iterator;
+
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public abstract class AdaptedIterableResult<O, N extends Identifiable> implements
IterableResult<N>, Adaptor<O, N>
+{
+ private final int size;
+ private final Iterator<O> adaptee;
+
+ public AdaptedIterableResult(int size, Iterator<O> adaptee)
+ {
+ this.size = size;
+ this.adaptee = adaptee;
+ }
+
+ public int size()
+ {
+ return size;
+ }
+
+ public Iterator<N> iterator()
+ {
+ return new AdaptedIterator<O, N>(adaptee)
+ {
+ public N adapt(O old)
+ {
+ return AdaptedIterableResult.this.adapt(old);
+ }
+ };
+ }
+}
Added:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterator.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterator.java
(rev 0)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/AdaptedIterator.java 2011-07-17
16:33:30 UTC (rev 6876)
@@ -0,0 +1,51 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.gatein.portal.api.impl.util;
+
+import java.util.Iterator;
+
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public abstract class AdaptedIterator<O, N> implements Iterator<N>,
Adaptor<O, N>
+{
+ private final Iterator<O> adaptee;
+
+ public AdaptedIterator(Iterator<O> adaptee)
+ {
+ this.adaptee = adaptee;
+ }
+
+ public boolean hasNext()
+ {
+ return adaptee.hasNext();
+ }
+
+ public N next()
+ {
+ return adapt(adaptee.next());
+ }
+
+ public void remove()
+ {
+ adaptee.remove();
+ }
+}
Added:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/Adaptor.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/Adaptor.java
(rev 0)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/util/Adaptor.java 2011-07-17
16:33:30 UTC (rev 6876)
@@ -0,0 +1,29 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.gatein.portal.api.impl.util;
+
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public interface Adaptor<O, N>
+{
+ N adapt(O old);
+}