[gatein-commits] gatein SVN: r2128 - in components/mop/trunk: core/src/main/java/org/gatein/mop/core/api/workspace and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Mar 10 16:12:30 EST 2010


Author: julien_viet
Date: 2010-03-10 16:12:29 -0500 (Wed, 10 Mar 2010)
New Revision: 2128

Added:
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/Attribute.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/AttributesImpl.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/BooleanAttribute.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/DateAttribute.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/IntegerAttribute.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/PathAttribute.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/StringAttribute.java
Modified:
   components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Page.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/PageImpl.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/TemplatizedImpl.java
   components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/WorkspaceObjectImpl.java
   components/mop/trunk/core/src/main/resources/conf/mop-nodetypes.xml
   components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/AttributesTestCase.java
   components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/POMTestCase.java
   components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/TestMOPService.java
Log:
actually improve how attribute must be defined and remove cascadoing of page attributes as anyway pages are not yet hierarchic in mop


Modified: components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Page.java
===================================================================
--- components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Page.java	2010-03-10 21:08:02 UTC (rev 2127)
+++ components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Page.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -50,13 +50,6 @@
    ObjectType<? extends Page> getObjectType();
 
    /**
-    * Returns the page attributes.
-    *
-    * @return the attributes
-    */
-   Attributes getCascadingAttributes();
-
-   /**
     * Returns the site that owns the page.
     *
     * @return the owner site
@@ -116,15 +109,6 @@
    void destroy();
 
    /**
-    * Returns the templatized objects for this page.
-    *
-    * @param type the type of templatized
-    * @param <T> the templatized workspace object type parameter
-    * @return the collection of templatized objects
-    */
-   <T extends WorkspaceObject> Collection<? extends T> getTemplatizedObjects(ObjectType<T> type);
-
-   /**
     * Templatize the provided object.
     *
     * @param object the object to templatize

Added: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/Attribute.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/Attribute.java	                        (rev 0)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/Attribute.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.mop.core.api.workspace;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.gatein.mop.api.Scope;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at PrimaryType(name = "mop:attribute")
+public abstract class Attribute<T>
+{
+
+   public abstract T getValue();
+
+   public abstract void setValue(T value);
+
+   @Property(name = "mop:scope")
+   public abstract Scope getScope();
+
+   public abstract void setScope(Scope scope);
+
+}

Added: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/AttributesImpl.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/AttributesImpl.java	                        (rev 0)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/AttributesImpl.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.mop.core.api.workspace;
+
+import org.chromattic.api.NameConflictResolution;
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.FormattedBy;
+import org.chromattic.api.annotations.NamingPolicy;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+import org.gatein.mop.core.api.MOPFormatter;
+import org.gatein.mop.core.util.AbstractAttributes;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at PrimaryType(name = "mop:attributes")
+ at FormattedBy(MOPFormatter.class)
+ at NamingPolicy(onDuplicate = NameConflictResolution.REPLACE)
+public abstract class AttributesImpl extends AbstractAttributes 
+{
+
+   @OneToMany
+   public abstract Map<String, Attribute> getChildren();
+
+   @Create
+   public abstract IntegerAttribute createInteger();
+
+   @Create
+   public abstract BooleanAttribute createBoolean();
+
+   @Create
+   public abstract DateAttribute createDate();
+
+   @Create
+   public abstract StringAttribute createString();
+
+   @Override
+   protected Object get(String name)
+   {
+      Map<String, Attribute> children = getChildren();
+      Attribute child = children.get(name);
+      return child != null ? child.getValue() : null;
+   }
+
+   @Override
+   protected void set(String name, Object o)
+   {
+      Map<String, Attribute> children = getChildren();
+      if (o != null)
+      {
+         if (o instanceof Integer)
+         {
+            IntegerAttribute i = createInteger();
+            children.put(name, i);
+            i.setValue((Integer)o);
+         }
+         else if (o instanceof Boolean)
+         {
+            BooleanAttribute b = createBoolean();
+            children.put(name, b);
+            b.setValue((Boolean)o);
+         }
+         else if (o instanceof Date)
+         {
+            DateAttribute d = createDate();
+            children.put(name, d);
+            d.setValue((Date)o);
+         }
+         else
+         {
+            StringAttribute s = createString();
+            children.put(name, s);
+            s.setValue((String)o);
+         }
+      }
+      else
+      {
+         children.remove(name);
+      }
+   }
+
+   public Set<String> getKeys()
+   {
+      Map<String, Attribute> children = getChildren();
+      return children.keySet();
+   }
+}

Added: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/BooleanAttribute.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/BooleanAttribute.java	                        (rev 0)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/BooleanAttribute.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.mop.core.api.workspace;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at PrimaryType(name = "mop:booleanattribute")
+public abstract class BooleanAttribute extends Attribute<Boolean>
+{
+
+   @Property(name = "mop:value")
+   public abstract Boolean getValue();
+
+   public abstract void setValue(Boolean value);
+}
\ No newline at end of file

Added: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/DateAttribute.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/DateAttribute.java	                        (rev 0)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/DateAttribute.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.mop.core.api.workspace;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+
+import java.util.Date;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at PrimaryType(name = "mop:dateattribute")
+public abstract class DateAttribute extends Attribute<Date>
+{
+
+   @Property(name = "mop:value")
+   public abstract Date getValue();
+
+   public abstract void setValue(Date value);
+}
\ No newline at end of file

Added: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/IntegerAttribute.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/IntegerAttribute.java	                        (rev 0)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/IntegerAttribute.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.mop.core.api.workspace;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at PrimaryType(name = "mop:integerattribute")
+public abstract class IntegerAttribute extends Attribute<Integer>
+{
+
+   @Property(name = "mop:value")
+   public abstract Integer getValue();
+
+   public abstract void setValue(Integer value);
+}
\ No newline at end of file

Modified: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/PageImpl.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/PageImpl.java	2010-03-10 21:08:02 UTC (rev 2127)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/PageImpl.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -28,16 +28,11 @@
 import org.chromattic.api.RelationshipType;
 import org.gatein.mop.api.workspace.Page;
 import org.gatein.mop.api.workspace.ObjectType;
-import org.gatein.mop.api.workspace.Navigation;
 import org.gatein.mop.api.workspace.Templatized;
 import org.gatein.mop.api.workspace.WorkspaceObject;
 import org.gatein.mop.api.workspace.link.PageLink;
-import org.gatein.mop.api.Attributes;
-import org.gatein.mop.core.util.AbstractAttributes;
 
 import java.util.Collection;
-import java.util.ArrayList;
-import java.util.Set;
 
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
@@ -47,25 +42,6 @@
 public abstract class PageImpl extends WorkspaceObjectImpl implements Page
 {
 
-   /** . */
-   private final Attributes cascadingAttributes = new AbstractAttributes()
-   {
-      public Set<String> getKeys()
-      {
-         throw new UnsupportedOperationException("todo ?");
-      }
-
-      protected Object get(String name)
-      {
-         return getCascadedPropertyValue(name);
-      }
-
-      protected void set(String name, Object o)
-      {
-         throw new UnsupportedOperationException("read only");
-      }
-   };
-
    @OneToMany(type = RelationshipType.PATH)
    @RelatedMappedBy("mop:template")
    public abstract Collection<NavigationImpl> getTemplatizedNavigations();
@@ -127,42 +103,11 @@
       return templatized;
    }
 
-   public <T extends WorkspaceObject> Collection<? extends T> getTemplatizedObjects(ObjectType<T> type)
-   {
-      if (Page.class.equals(type.getJavaType()))
-      {
-         ArrayList bilto = new ArrayList();
-         for (Page page : getTemplatizedPages())
-         {
-            bilto.add(page);
-         }
-         return bilto;
-      }
-      else if (Navigation.class.isAssignableFrom(type.getJavaType()))
-      {
-         ArrayList bilto = new ArrayList();
-         for (Navigation page : getTemplatizedNavigations())
-         {
-            bilto.add(page);
-         }
-         return bilto;
-      }
-      else
-      {
-         throw new IllegalArgumentException("Unaccepted templatized type");
-      }
-   }
-
    public ObjectType<? extends Page> getObjectType()
    {
       return ObjectType.PAGE;
    }
 
-   public Attributes getCascadingAttributes()
-   {
-      return cascadingAttributes;
-   }
-
    public SiteImpl getSite()
    {
       PageContainer parent = getParentContainer();
@@ -215,19 +160,4 @@
    {
       throw new UnsupportedOperationException();
    }
-
-   private Object getCascadedPropertyValue(String propertyName)
-   {
-      Attributes attributes = getAttributes();
-      Object value = attributes.getObject(propertyName);
-      if (value == null)
-      {
-         PageImpl parent = getParent();
-         if (parent != null)
-         {
-            value = parent.getCascadedPropertyValue(propertyName);
-         }
-      }
-      return value;
-   }
 }

Added: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/PathAttribute.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/PathAttribute.java	                        (rev 0)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/PathAttribute.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.mop.core.api.workspace;
+
+import org.chromattic.api.RelationshipType;
+import org.chromattic.api.annotations.ManyToOne;
+import org.chromattic.api.annotations.MappedBy;
+import org.chromattic.api.annotations.PrimaryType;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at PrimaryType(name = "mop:pathattribute")
+public abstract class PathAttribute extends Attribute<Object>
+{
+
+   @ManyToOne(type = RelationshipType.PATH)
+   @MappedBy("mop:value")
+   public abstract Object getValue();
+
+   public abstract void setValue(Object value);
+
+}

Added: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/StringAttribute.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/StringAttribute.java	                        (rev 0)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/StringAttribute.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.mop.core.api.workspace;
+
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at PrimaryType(name = "mop:stringattribute")
+public abstract class StringAttribute extends Attribute<String>
+{
+
+   @Property(name = "mop:value")
+   public abstract String getValue();
+
+   public abstract void setValue(String value);
+}

Modified: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/TemplatizedImpl.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/TemplatizedImpl.java	2010-03-10 21:08:02 UTC (rev 2127)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/TemplatizedImpl.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -19,11 +19,9 @@
 
 package org.gatein.mop.core.api.workspace;
 
-import org.chromattic.api.RelationshipType;
-import org.chromattic.api.annotations.ManyToOne;
 import org.chromattic.api.annotations.MappedBy;
 import org.chromattic.api.annotations.MixinType;
-import org.chromattic.api.annotations.Property;
+import org.chromattic.api.annotations.OneToOne;
 import org.gatein.mop.api.Scope;
 import org.gatein.mop.api.workspace.Page;
 import org.gatein.mop.api.workspace.Templatized;
@@ -36,24 +34,27 @@
 public abstract class TemplatizedImpl implements Templatized
 {
 
-   @ManyToOne(type = RelationshipType.PATH)
+   @OneToOne
    @MappedBy("mop:template")
-   public abstract PageImpl getPageTemplate();
+   public abstract PathAttribute getRelatedTemplate();
 
-   public abstract void setPageTemplate(PageImpl template);
-
    public void setTemplate(Page template)
    {
-      setPageTemplate((PageImpl)template);
+      getRelatedTemplate().setValue(template);
    }
 
    public Page getTemplate()
    {
-      return getPageTemplate();
+      return (Page)getRelatedTemplate().getValue();
    }
 
-   @Property(name = "mop:templatescope")
-   public abstract Scope getScope();
+   public Scope getScope()
+   {
+      return getRelatedTemplate().getScope();
+   }
 
-   public abstract void setScope(Scope scope);
+   public void setScope(Scope scope)
+   {
+      getRelatedTemplate().setScope(scope);
+   }
 }

Modified: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/WorkspaceObjectImpl.java
===================================================================
--- components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/WorkspaceObjectImpl.java	2010-03-10 21:08:02 UTC (rev 2127)
+++ components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/WorkspaceObjectImpl.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -19,20 +19,12 @@
 package org.gatein.mop.core.api.workspace;
 
 import org.chromattic.api.annotations.*;
-import org.chromattic.common.collection.AbstractFilterIterator;
 import org.gatein.mop.api.workspace.WorkspaceObject;
 import org.gatein.mop.api.workspace.ObjectType;
-import org.gatein.mop.api.Attributes;
 import org.gatein.mop.api.content.CustomizationContext;
 import org.gatein.mop.core.api.MOPFormatter;
 import org.gatein.mop.core.api.ModelImpl;
-import org.gatein.mop.core.util.AbstractAttributes;
 
-import java.util.Map;
-import java.util.Set;
-import java.util.AbstractSet;
-import java.util.Iterator;
-
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
@@ -45,72 +37,6 @@
    /** . */
    public ModelImpl model;
 
-   /** . */
-   private final Set<String> keys = new AbstractSet<String>()
-   {
-      @Override
-      public Iterator<String> iterator()
-      {
-         Map<String, Object> properties = getProperties();
-         return new AbstractFilterIterator<String, String>(properties.keySet().iterator())
-         {
-            protected String adapt(String internal)
-            {
-               if (internal.startsWith("mop:"))
-               {
-                  return internal.substring(4);
-               }
-               else
-               {
-                  return null;
-               }
-            }
-         };
-      }
-
-      public int size()
-      {
-         Map<String, Object> properties = getProperties();
-         int count = 0;
-         for (String key : properties.keySet())
-         {
-            if (key.startsWith("mop:"))
-            {
-               count++;
-            }
-         }
-         return count;
-      }
-   };
-
-   /** . */
-   private final AbstractAttributes attributes = new AbstractAttributes()
-   {
-      @Override
-      protected Object get(String name)
-      {
-         Map<String, Object> properties = getProperties();
-         return properties.get("mop:" + name);
-      }
-
-      @Override
-      protected void set(String name, Object o)
-      {
-         Map<String, Object> properties = getProperties();
-         properties.put("mop:" + name, o);
-      }
-
-      public Set<String> getKeys()
-      {
-         return keys;
-      }
-   };
-
-   public Attributes getAttributes()
-   {
-      return attributes;
-   }
-
    @Name
    public abstract String getName();
 
@@ -119,8 +45,9 @@
    @Id
    public abstract String getObjectId();
 
-   @Properties
-   public abstract Map<String, Object> getProperties();
+   @OneToOne
+   @MappedBy("mop:attributes")
+   public abstract AttributesImpl getAttributes();
 
    public <A> A adapt(Class<A> adaptedType)
    {

Modified: components/mop/trunk/core/src/main/resources/conf/mop-nodetypes.xml
===================================================================
--- components/mop/trunk/core/src/main/resources/conf/mop-nodetypes.xml	2010-03-10 21:08:02 UTC (rev 2127)
+++ components/mop/trunk/core/src/main/resources/conf/mop-nodetypes.xml	2010-03-10 21:12:29 UTC (rev 2128)
@@ -20,6 +20,90 @@
 -->
 <nodeTypes xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
 
+  <nodeType name="mop:attributes" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>nt:base</supertype>
+      <supertype>mix:referenceable</supertype>
+    </supertypes>
+    <childNodeDefinitions>
+      <childNodeDefinition name="*" defaultPrimaryType="mop:stringattribute" autoCreated="false" mandatory="false"
+        onParentVersion="COPY" protected="false" sameNameSiblings="false">
+        <requiredPrimaryTypes>
+          <requiredPrimaryType>mop:attribute</requiredPrimaryType>
+        </requiredPrimaryTypes>
+      </childNodeDefinition>
+    </childNodeDefinitions>
+  </nodeType>
+
+  <nodeType name="mop:attribute" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>nt:base</supertype>
+      <supertype>mix:referenceable</supertype>
+    </supertypes>
+    <propertyDefinitions>
+      <propertyDefinition name="mop:scope" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+        <valueConstraints/>
+      </propertyDefinition>
+    </propertyDefinitions>
+  </nodeType>
+
+  <nodeType name="mop:pathattribute" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>mop:attribute</supertype>
+    </supertypes>
+    <propertyDefinitions>
+      <propertyDefinition name="mop:value" requiredType="Path" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+        <valueConstraints/>
+      </propertyDefinition>
+    </propertyDefinitions>
+  </nodeType>
+
+  <nodeType name="mop:stringattribute" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>mop:attribute</supertype>
+    </supertypes>
+    <propertyDefinitions>
+      <propertyDefinition name="mop:value" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+        <valueConstraints/>
+      </propertyDefinition>
+    </propertyDefinitions>
+  </nodeType>
+
+  <nodeType name="mop:booleanattribute" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>mop:attribute</supertype>
+    </supertypes>
+    <propertyDefinitions>
+      <propertyDefinition name="mop:value" requiredType="Boolean" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+        <valueConstraints/>
+      </propertyDefinition>
+    </propertyDefinitions>
+  </nodeType>
+
+  <nodeType name="mop:integerattribute" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>mop:attribute</supertype>
+    </supertypes>
+    <propertyDefinitions>
+      <propertyDefinition name="mop:value" requiredType="Long" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+        <valueConstraints/>
+      </propertyDefinition>
+    </propertyDefinitions>
+  </nodeType>
+
+  <nodeType name="mop:dateattribute" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>mop:attribute</supertype>
+    </supertypes>
+    <propertyDefinitions>
+      <propertyDefinition name="mop:value" requiredType="Date" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+        <valueConstraints/>
+      </propertyDefinition>
+    </propertyDefinitions>
+  </nodeType>
+
+  <!-- -->
+
   <nodeType name="mop:customizationstate" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
     <supertypes>
       <supertype>nt:base</supertype>
@@ -154,12 +238,14 @@
       <supertype>nt:base</supertype>
       <supertype>mix:referenceable</supertype>
     </supertypes>
-    <propertyDefinitions>
-      <propertyDefinition name="*" requiredType="undefined" autoCreated="false" mandatory="false" onParentVersion="COPY"
-        protected="false" multiple="false">
-        <valueConstraints/>
-      </propertyDefinition>
-    </propertyDefinitions>
+    <childNodeDefinitions>
+      <childNodeDefinition name="mop:attributes" defaultPrimaryType="mop:attributes" autoCreated="true" mandatory="false"
+        onParentVersion="COPY" protected="false" sameNameSiblings="false">
+        <requiredPrimaryTypes>
+          <requiredPrimaryType>mop:attributes</requiredPrimaryType>
+        </requiredPrimaryTypes>
+      </childNodeDefinition>
+    </childNodeDefinitions>
   </nodeType>
 
   <nodeType name="mop:uicomponent" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
@@ -203,14 +289,14 @@
   </nodeType>
 
   <nodeType name="mop:templatized" isMixin="true" hasOrderableChildNodes="false" primaryItemName="">
-    <propertyDefinitions>
-      <propertyDefinition name="mop:template" requiredType="Path" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
-        <valueConstraints/>
-      </propertyDefinition>
-      <propertyDefinition name="mop:templatescope" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
-        <valueConstraints/>
-      </propertyDefinition>
-    </propertyDefinitions>
+    <childNodeDefinitions>
+      <childNodeDefinition name="mop:template" defaultPrimaryType="mop:pathattribute" autoCreated="true" mandatory="false"
+        onParentVersion="COPY" protected="false" sameNameSiblings="false">
+        <requiredPrimaryTypes>
+          <requiredPrimaryType>mop:pathattribute</requiredPrimaryType>
+        </requiredPrimaryTypes>
+      </childNodeDefinition>
+    </childNodeDefinitions>
   </nodeType>
 
   <nodeType name="mop:navigation" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">

Modified: components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/AttributesTestCase.java
===================================================================
--- components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/AttributesTestCase.java	2010-03-10 21:08:02 UTC (rev 2127)
+++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/AttributesTestCase.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -25,6 +25,8 @@
 import org.gatein.mop.api.workspace.Page;
 import org.gatein.mop.api.Attributes;
 
+import java.util.Date;
+
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
@@ -42,8 +44,26 @@
       Attributes pageAttributes = portal.getRootPage().getAttributes();
       pageAttributes.setString("foo", "bar");
       assertEquals("bar", pageAttributes.getString("foo"));
+
+      // Overwrite
+      pageAttributes.setString("foo", "bar2");
+      assertEquals("bar2", pageAttributes.getString("foo"));
    }
 
+   public void testTypes()
+   {
+      ModelImpl model = pomService.getModel();
+      Site portal = model.getWorkspace().addSite(ObjectType.PORTAL_SITE, "portal");
+      Attributes portalAttributes = portal.getAttributes();
+      portalAttributes.setInteger("integer", 4);
+      assertEquals(4, portalAttributes.getObject("integer"));
+      Date d = new Date();
+      portalAttributes.setDate("date", d);
+      assertEquals(d, portalAttributes.getObject("date"));
+      portalAttributes.setBoolean("boolean", true);
+      assertEquals(true, portalAttributes.getObject("boolean"));
+   }
+
    public void testCascadedAttributes()
    {
       ModelImpl model = pomService.getModel();
@@ -56,9 +76,5 @@
       aAttrs.setString("bar", "bar_a");
       rootAttrs.setString("juu", "juu_root");
       aAttrs.setString("juu", "juu_a");
-      Attributes combinedAttrs = a.getCascadingAttributes();
-      assertEquals("foo_root", combinedAttrs.getString("foo"));
-      assertEquals("bar_a", combinedAttrs.getString("bar"));
-      assertEquals("juu_a", combinedAttrs.getString("juu"));
    }
 }

Modified: components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/POMTestCase.java
===================================================================
--- components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/POMTestCase.java	2010-03-10 21:08:02 UTC (rev 2127)
+++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/POMTestCase.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -104,9 +104,11 @@
 
       // Try something with template relationships
 
+/*
       Collection<? extends Navigation> templatizedNavigations = template.getTemplatizedObjects(ObjectType.NAVIGATION);
       assertNotNull(templatizedNavigations);
       assertEquals(1, templatizedNavigations.size());
+*/
 
 /*
     Collection<Templatized> templatizedObjects = template.getTemplatizedObjects(Templatized.class);

Modified: components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/TestMOPService.java
===================================================================
--- components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/TestMOPService.java	2010-03-10 21:08:02 UTC (rev 2127)
+++ components/mop/trunk/core/src/test/java/org/gatein/mop/core/support/TestMOPService.java	2010-03-10 21:12:29 UTC (rev 2128)
@@ -22,16 +22,23 @@
 import org.chromattic.api.ChromatticBuilder;
 import org.gatein.mop.core.api.MOPService;
 import org.gatein.mop.core.api.content.ContentManagerRegistry;
+import org.gatein.mop.core.api.workspace.Attribute;
+import org.gatein.mop.core.api.workspace.AttributesImpl;
+import org.gatein.mop.core.api.workspace.BooleanAttribute;
+import org.gatein.mop.core.api.workspace.DateAttribute;
 import org.gatein.mop.core.api.workspace.GroupSite;
 import org.gatein.mop.core.api.workspace.GroupSiteContainer;
+import org.gatein.mop.core.api.workspace.IntegerAttribute;
 import org.gatein.mop.core.api.workspace.NavigationContainer;
 import org.gatein.mop.core.api.workspace.NavigationImpl;
 import org.gatein.mop.core.api.workspace.PageContainer;
 import org.gatein.mop.core.api.workspace.PageImpl;
 import org.gatein.mop.core.api.workspace.PageLinkImpl;
+import org.gatein.mop.core.api.workspace.PathAttribute;
 import org.gatein.mop.core.api.workspace.PortalSite;
 import org.gatein.mop.core.api.workspace.PortalSiteContainer;
 import org.gatein.mop.core.api.workspace.SecuredImpl;
+import org.gatein.mop.core.api.workspace.StringAttribute;
 import org.gatein.mop.core.api.workspace.TemplatizedImpl;
 import org.gatein.mop.core.api.workspace.UIBodyImpl;
 import org.gatein.mop.core.api.workspace.UIContainerImpl;
@@ -97,6 +104,15 @@
       builder.add(TemplatizedImpl.class);
 
       //
+      builder.add(AttributesImpl.class);
+      builder.add(Attribute.class);
+      builder.add(PathAttribute.class);
+      builder.add(StringAttribute.class);
+      builder.add(BooleanAttribute.class);
+      builder.add(IntegerAttribute.class);
+      builder.add(DateAttribute.class);
+
+      //
       builder.add(CustomizationContainer.class);
       builder.add(ContextTypeContainer.class);
       builder.add(ContextType.class);



More information about the gatein-commits mailing list