incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apope...@apache.org
Subject svn commit: r377514 - in /incubator/graffito/trunk/jcr/jcr-mapping/src: dtd/ java/org/apache/portals/graffito/jcr/mapper/impl/ java/org/apache/portals/graffito/jcr/mapper/model/
Date Mon, 13 Feb 2006 22:35:51 GMT
Author: apopescu
Date: Mon Feb 13 14:35:50 2006
New Revision: 377514

URL: http://svn.apache.org/viewcvs?rev=377514&view=rev
Log:
added basic support for inheritance

Modified:
    incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterDescriptorReader.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
    incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/MappingDescriptor.java

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd?rev=377514&r1=377513&r2=377514&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd (original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/dtd/graffito-jcr-mapping.dtd Mon Feb 13 14:35:50
2006
@@ -18,12 +18,20 @@
 -->
 
 <!ELEMENT graffito-jcr (class-descriptor*)>
+
+<!ATTLIST graffito-jcr package CDATA #IMPLIED>
+
 <!--
     Class descriptor - Each class descriptor describes the mapping strategy used for one
a java class
-    * className : the className
+    * className : the class name
     * jcrNodeType : the primary jcr node type, it can be nt:unstructured
     * jcrSuperTypes : the jcr super types, optional
     * jcrMixinTypes: the jcr mixin types (comma separated list) (optional)
+    * extends: name of super class (optional)
+    * extends-strategy:
+    * polymorphism: specify the behavior of this class in queries; default implicit
+    * abstract: true if this class is abstract and it is used in hierarchy mappings
+    * discriminator-value: use only when extends-strategy="concreteclass" and abstract="false"
 -->
 <!ELEMENT class-descriptor (field-descriptor*, bean-descriptor*, collection-descriptor*)>
 
@@ -31,7 +39,11 @@
 	className CDATA #REQUIRED
 	jcrNodeType CDATA #IMPLIED
     jcrSuperTypes CDATA #IMPLIED
-    jcrMixinTypes CDATA #IMPLIED>
+    jcrMixinTypes CDATA #IMPLIED
+    extends CDATA #IMPLIED
+	abstract (true|false) "false"
+	discriminatorValue CDATA #IMPLIED
+>
 
 <!--
     Field descriptor - A field descriptor maps one atomic object attribute (primitive types,
String, Long, ...)  into a JCR property
@@ -55,6 +67,7 @@
 	jcrName CDATA #IMPLIED 
 	id (true | false) "false"
 	path (true | false) "false"
+	descriminator (true | false) "false"
     jcrType (String | Date | Long | Double | Boolean | Binary) #IMPLIED
     jcrAutoCreated (true | false) "false"
     jcrMandatory (true | false) "false"

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterDescriptorReader.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterDescriptorReader.java?rev=377514&r1=377513&r2=377514&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterDescriptorReader.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterDescriptorReader.java
Mon Feb 13 14:35:50 2006
@@ -60,6 +60,7 @@
 			digester.setValidating(this.validating);
 
 			digester.addObjectCreate("graffito-jcr", MappingDescriptor.class);
+            digester.addSetProperties("graffito-jcr", "package", "package");
 
 			// --------------------------------------------------------------------------------
 			// Rules used for the class-descriptor element
@@ -70,6 +71,9 @@
 			digester.addSetProperties("graffito-jcr/class-descriptor", "jcrNodeType", "jcrNodeType");
             digester.addSetProperties("graffito-jcr/class-descriptor", "jcrSuperTypes", "jcrSuperTypes");
             digester.addSetProperties("graffito-jcr/class-descriptor", "jcrMixinTypes", "jcrMixinTypesList");
+            digester.addSetProperties("graffito-jcr/class-descriptor", "extends", "superClass");
+            digester.addSetProperties("graffito-jcr/class-descriptor", "abstract", "abstract");
+            digester.addSetProperties("graffito-jcr/class-descriptor", "discriminatorValue",
"discriminatorValue");
 
 			digester.addSetNext("graffito-jcr/class-descriptor", "addClassDescriptor");
 
@@ -83,6 +87,7 @@
 			digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrName",
"jcrName");
 			digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "id", "id");
 			digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "path", "path");
+            digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "descriminator",
"descriminator");
             digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrType",
"jcrType");
             digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrAutoCreated",
"jcrAutoCreated");
             digester.addSetProperties("graffito-jcr/class-descriptor/field-descriptor", "jcrMandatory",
"jcrMandatory");
@@ -130,7 +135,7 @@
             digester.addSetProperties("graffito-jcr/class-descriptor/collection-descriptor",
"jcrSameNameSiblings", "jcrSameNameSiblings");            
 			digester.addSetNext("graffito-jcr/class-descriptor/collection-descriptor", "addCollectionDescriptor");
 
-			return (MappingDescriptor) digester.parse(stream);
+            return (MappingDescriptor) digester.parse(stream);
 		}
 		catch (Exception e)
 		{

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java?rev=377514&r1=377513&r2=377514&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/impl/DigesterMapperImpl.java
Mon Feb 13 14:35:50 2006
@@ -18,10 +18,13 @@
 
 
 import java.io.InputStream;
+import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.portals.graffito.jcr.exception.InitMapperException;
+import org.apache.portals.graffito.jcr.exception.JcrMappingException;
 import org.apache.portals.graffito.jcr.mapper.Mapper;
 import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
 import org.apache.portals.graffito.jcr.mapper.model.MappingDescriptor;
@@ -142,6 +145,9 @@
                 this.mappingDescriptor.getClassDescriptors().putAll(anotherMappingDescriptor.getClassDescriptors());
             }
         }
+        if (null != this.mappingDescriptor) {
+            solveReferences();
+        }
         else {
             throw new InitMapperException("No mappings were provided");
         }
@@ -149,6 +155,26 @@
         return this;
     }
 
+    private void solveReferences() {
+        for(Iterator it = this.mappingDescriptor.getClassDescriptors().keySet().iterator();
it.hasNext(); ) {
+            Map.Entry entry = (Map.Entry) it.next();
+            ClassDescriptor cd = (ClassDescriptor) entry.getValue();
+            
+            if (null != cd.getSuperClass() && !"".equals(cd.getSuperClass())) {
+                ClassDescriptor superClassDescriptor = this.mappingDescriptor.getClassDescriptor(cd.getSuperClass());
+                
+                if (null == superClassDescriptor) {
+                    throw new JcrMappingException("Cannot find mapping for class "
+                            + cd.getSuperClass() + " references as extends from "
+                            + cd.getClassName());
+                }
+                else {
+                    cd.setSuperClassDescriptor(superClassDescriptor);
+                }
+            }
+        }
+    }
+    
     /**
      *
      * @see org.apache.portals.graffito.jcr.mapper.Mapper#getClassDescriptor(java.lang.Class)

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java?rev=377514&r1=377513&r2=377514&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/ClassDescriptor.java
Mon Feb 13 14:35:50 2006
@@ -18,6 +18,7 @@
 
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 /**
@@ -28,20 +29,76 @@
  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
  */
 public class ClassDescriptor {
+    public static final String NODETYPE_PER_HIERARCHY = "nodetypeperhierarchy";
+    public static final String NODETYPE_PER_CONCRETECLASS = "nodetypeperconcreteclass";
+
     private MappingDescriptor mappingDescriptor;
-    
+    private ClassDescriptor superClassDescriptor;
+
     private String className;
     private String jcrNodeType;
     private String jcrSuperTypes;
     private String[] jcrMixinTypes = new String[0];
     private FieldDescriptor idFieldDescriptor;
     private FieldDescriptor pathFieldDescriptor;
+    private FieldDescriptor discriminatorFieldDescriptor;
 
     private Map fieldDescriptors = new HashMap();
+    // collects all super field descriptors
+    private Map allFields = null;
     private Map beanDescriptors = new HashMap();
+    // collects all super bean descriptors
+    private Map allBeans = null;
     private Map collectionDescriptors = new HashMap();
+    // collects all super collection descriptors
+    private Map allCollections = null;
     private Map fieldNames = new HashMap();
 
+    private String superClassName;
+    private String extendsStrategy;
+    private boolean abstractClass = false;
+    private String descriminatorValue;
+
+
+    public void setAbstract(boolean flag) {
+        this.abstractClass = flag;
+    }
+
+    public boolean isAbstract() {
+        return this.abstractClass;
+    }
+
+    /**
+     * @return Returns the descriminatorValue.
+     */
+    public String getDescriminatorValue() {
+        return descriminatorValue;
+    }
+
+    /**
+     * In case this class is part of an hierarchy which is
+     * using <tt>NODETYPE_PER_HIERARCHY</tt> strategy the returned
+     * value represents the value of the <tt>discriminator</tt>
+     * property than identifies uniquely this type.
+     * 
+     * @param descriminatorValue The descriminatorValue to set.
+     */
+    public void setDescriminatorValue(String descriminatorValue) {
+        this.descriminatorValue= descriminatorValue;
+    }
+
+    /**
+     * Returns the inheritance strategy used by this descriptor. It can be either
+     * <tt>NODETYPE_PER_CONCRETECLASS</tt>, <tt>NODETYPE_PER_HIERARCHY</tt>
or
+     * <tt>null</tt> if no inheritance mechanism is used.
+     *
+     * @return Returns {@link #NODETYPE_PER_HIERARCHY} or {@link #NODETYPE_PER_CONCRETECLASS}
or
+     * <tt>null</tt>
+     */
+    public String getExtendsStrategy() {
+        return extendsStrategy;
+    }
+
     /**
      * @return Returns the className.
      */
@@ -79,10 +136,12 @@
         if (fieldDescriptor.isId()) {
             this.idFieldDescriptor = fieldDescriptor;
         }
-
         if (fieldDescriptor.isPath()) {
             this.pathFieldDescriptor = fieldDescriptor;
         }
+        if (fieldDescriptor.isDiscriminator()) {
+            this.discriminatorFieldDescriptor = fieldDescriptor;
+        }
 
         fieldDescriptors.put(fieldDescriptor.getFieldName(), fieldDescriptor);
         fieldNames.put(fieldDescriptor.getFieldName(), fieldDescriptor.getJcrName());
@@ -95,7 +154,7 @@
      * @return the {@link FieldDescriptor} found or null
      */
     public FieldDescriptor getFieldDescriptor(String fieldName) {
-        return (FieldDescriptor) fieldDescriptors.get(fieldName);
+        return (FieldDescriptor) this.allFields.get(fieldName);
     }
 
     /**
@@ -103,7 +162,7 @@
      * @return all {@link FieldDescriptor} defined in this ClassDescriptor
      */
     public Collection getFieldDescriptors() {
-        return fieldDescriptors.values();
+        return this.fieldDescriptors.values();
     }
 
     /**
@@ -124,14 +183,14 @@
      * @return the {@link BeanDescriptor} found or null
      */
     public BeanDescriptor getBeanDescriptor(String fieldName) {
-        return (BeanDescriptor) beanDescriptors.get(fieldName);
+        return (BeanDescriptor) this.allBeans.get(fieldName);
     }
 
     /**
      * @return all {@link BeanDescriptor} defined in this ClassDescriptor
      */
     public Collection getBeanDescriptors() {
-        return beanDescriptors.values();
+        return this.allBeans.values();
     }
 
     /**
@@ -152,14 +211,14 @@
      * @return the {@link CollectionDescriptor} found or null
      */
     public CollectionDescriptor getCollectionDescriptor(String fieldName) {
-        return (CollectionDescriptor) collectionDescriptors.get(fieldName);
+        return (CollectionDescriptor) this.allCollections.get(fieldName);
     }
 
     /**
      * @return all {@link BeanDescriptor} defined in this ClassDescriptor
      */
     public Collection getCollectionDescriptors() {
-        return collectionDescriptors.values();
+        return this.allCollections.values();
     }
 
     /**
@@ -176,6 +235,14 @@
         return pathFieldDescriptor;
     }
 
+    public FieldDescriptor getDiscriminatorFieldDescriptor() {
+        return this.discriminatorFieldDescriptor;
+    }
+
+    public boolean hasDiscriminatorField() {
+        return this.discriminatorFieldDescriptor != null;
+    }
+    
     /**
      * Check if this class has an ID
      * @return true if the class has an ID
@@ -211,7 +278,7 @@
 
     /**
      * Retrieve the mixin types.
-     * 
+     *
      * @return array of mixin types
      */
     public String[] getJcrMixinTypes() {
@@ -224,7 +291,7 @@
      * @param mixinTypes command separated list of mixins
      */
     public void setJcrMixinTypesList(String mixinTypes) {
-        if(null != mixinTypes) {
+        if (null != mixinTypes) {
             setJcrMixinTypes(mixinTypes.split(","));
         }
     }
@@ -246,4 +313,79 @@
     public void setMappingDescriptor(MappingDescriptor mappingDescriptor) {
         this.mappingDescriptor = mappingDescriptor;
     }
-}
+
+    /**
+     * @return <tt>true</tt> if the class descriptor is correct;
+     * <tt>false</tt> otherwise
+     */
+    public boolean validate() {
+        if (null == this.superClassDescriptor) {
+            this.allFields = this.fieldDescriptors;
+            this.allBeans = this.beanDescriptors;
+            this.allCollections = this.collectionDescriptors;
+        }
+        else {
+            this.allFields = merge(this.fieldDescriptors, this.superClassDescriptor.getFieldDescriptors());
+            this.allBeans = merge(this.beanDescriptors, this.superClassDescriptor.getBeanDescriptors());
+            this.allCollections = merge(this.collectionDescriptors, this.superClassDescriptor.getCollectionDescriptors());
+
+            if (null == this.discriminatorFieldDescriptor) {
+                this.discriminatorFieldDescriptor = this.superClassDescriptor.getDiscriminatorFieldDescriptor();
+            }
+
+            if (null == this.discriminatorFieldDescriptor) {
+                this.extendsStrategy = NODETYPE_PER_HIERARCHY;
+            }
+            else {
+                this.extendsStrategy = NODETYPE_PER_CONCRETECLASS;
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * @return return the super class name if defined in mapping, or
+     * <tt>null</tt> if not set
+     */
+    public String getSuperClass() {
+        return this.superClassName;
+    }
+
+    /**
+     * @param className
+     */
+    public void setSuperClass(String className) {
+        this.superClassName = className;
+    }
+
+    /**
+     * @return Returns the superClassDescriptor.
+     */
+    public ClassDescriptor getSuperClassDescriptor() {
+        return superClassDescriptor;
+    }
+
+    /**
+     * @param superClassDescriptor The superClassDescriptor to set.
+     */
+    public void setSuperClassDescriptor(ClassDescriptor superClassDescriptor) {
+        this.superClassDescriptor= superClassDescriptor;
+    }
+
+    private Map merge(Map existing, Collection superSource) {
+        if (null == superSource) {
+            return existing;
+        }
+
+        Map merged = new HashMap(existing);
+        for(Iterator it = superSource.iterator(); it.hasNext();) {
+            FieldDescriptor fd = (FieldDescriptor) it.next();
+            if (!merged.containsKey(fd.getFieldName())) {
+                merged.put(fd.getFieldName(), fd);
+            }
+        }
+
+        return merged;
+    }
+}
\ No newline at end of file

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java?rev=377514&r1=377513&r2=377514&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/FieldDescriptor.java
Mon Feb 13 14:35:50 2006
@@ -1,325 +1,298 @@
-/*
- * Copyright 2000-2005 The Apache Software Foundation.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.portals.graffito.jcr.mapper.model;
-
-/**
- * 
- *
- * FieldDescriptor is used by the mapper to read general information on a atomic field
- * 
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
- *
- */
-public class FieldDescriptor
-{
-     private String fieldName;
-     private String fieldType;
-     private Class fieldTypeClass;
-     private String jcrName;
-     private String jcrType;
-     private boolean jcrAutoCreated;
-     private boolean jcrMandatory;
-     private String jcrOnParentVersion;
-     private boolean jcrProtected;
-     private boolean jcrMultiple;
-     private ClassDescriptor classDescriptor;
-     private boolean id;
-     private boolean path;
-     
-    /**
-     * @return Returns the fieldName.
-     */
-    public String getFieldName()
-    {
-        return fieldName;
-    }
-
-    /**
-     * @param fieldName The fieldName to set.
-     */
-    public void setFieldName(String fieldName)
-    {
-        this.fieldName = fieldName;
-    }
-
-    /**
-     * @return the primitive or fully qualified class of the field
-     * or <tt>null</tt> if not specified in the mapping
-     */
-    public String getFieldType()
-    {
-        return this.fieldType;
-    }
-    
-    /**
-     * Sets the type of the field. It supports primitive types, specified as
-     * int, long, etc or fully qualified class names.
-     * 
-     * @param fieldType the type of the field
-     */
-    public void setFieldType(String fieldType)
-    {
-        this.fieldType = fieldType;
-    }
-    
-    /**
-     * @return the field class of the field
-     * or <tt>null</tt> if not specified in the mapping
-     * or if the class was not found
-     */
-    public Class getFieldTypeClass() 
-    {
-        if (this.fieldType == null) {
-            return null;
-        }
-        if (this.fieldTypeClass == null) {
-            this.fieldTypeClass = loadFieldTypeClass();
-        }
-        
-        return this.fieldTypeClass;
-    }
-    
-    /**
-     * @return Returns the jcrName.
-     */
-    public String getJcrName()
-    {
-        return jcrName;
-    }
-
-    /**
-     * @param jcrName The jcrName to set.
-     */
-    public void setJcrName(String jcrName)
-    {
-        this.jcrName = jcrName;
-    }
-    
-    /**
-     * 
-     * @return the associated class descriptor
-     */
-    public ClassDescriptor getClassDescriptor()
-    {
-        return classDescriptor;
-    }
-    
-    /**
-     * Set the associated class descriptor 
-     * @param classDescriptor  the class descriptor to set
-     */
-    public void setClassDescriptor(ClassDescriptor classDescriptor)
-    {
-        this.classDescriptor = classDescriptor;
-    }
-    
-    /**    
-     * @return true if the field is the class ID 
-     */
-    public boolean isId()
-    {
-        return id;
-    }
-    
-    /**
-     * 
-     * @param id
-     */
-    public void setId(boolean id)
-    {
-        this.id = id;
-    }
-
-	/**
-	 * @return Returns true if the field is the object JCR path.
-	 */
-	public boolean isPath()
-	{
-		return path;
-	}
-
-	/**
-	 * @param path The path to set.
-	 */
-	public void setPath(boolean path)
-	{
-		this.path = path;
-	}
-
-    /** Getter for property jcrType.
-     * 
-     * @return jcrType
-     */
-    public String getJcrType()
-    {
-        return jcrType;
-    }
-
-    /** Setter for property jcrType.
-     * 
-     * @param value jcrType
-     */
-    public void setJcrType(String value)
-    {
-        this.jcrType = value;
-    }
-
-    /** Getter for propery jcrAutoCreated.
-     * 
-     * @return jcrAutoCreated
-     */
-    public boolean isJcrAutoCreated()
-    {
-        return jcrAutoCreated;
-    }
-
-    /** Setter for property jcrAutoCreated.
-     * 
-     * @param value jcrAutoCreated
-     */
-    public void setJcrAutoCreated(boolean value)
-    {
-        this.jcrAutoCreated = value;
-    }
-
-    /** Getter for property jcrMandatory.
-     * 
-     * @return jcrMandatory
-     */
-    public boolean isJcrMandatory()
-    {
-        return jcrMandatory;
-    }
-
-    /** Setter for property jcrMandatory.
-     * 
-     * @param value jcrMandatory
-     */
-    public void setJcrMandatory(boolean value)
-    {
-        this.jcrMandatory = value;
-    }
-
-    /** Getter for property jcrOnParentVersion.
-     * 
-     * @return jcrOnParentVersion
-     */
-    public String getJcrOnParentVersion()
-    {
-        return jcrOnParentVersion;
-    }
-
-    /** Setter for property jcrOnParentVersion.
-     * 
-     * @param value jcrOnParentVersion
-     */
-    public void setJcrOnParentVersion(String value)
-    {
-        this.jcrOnParentVersion = value;
-    }
-
-    /** Getter for property jcrProtected.
-     * 
-     * @return jcrProtected
-     */
-    public boolean isJcrProtected()
-    {
-        return jcrProtected;
-    }
-
-    /** Setter for property jcrProtected.
-     * 
-     * @param value jcrProtected
-     */
-    public void setJcrProtected(boolean value)
-    {
-        this.jcrProtected = value;
-    }
-
-    /** Getter for property jcrMultiple.
-     * 
-     * @return jcrMultiple
-     */
-    public boolean isJcrMultiple()
-    {
-        return jcrMultiple;
-    }
-
-    /** Setter for property jcrMultiple.
-     * 
-     * @param value jcrMultiple
-     */
-    public void setJcrMultiple(boolean value)
-    {
-        this.jcrMultiple = value;
-    }
-    
-    /**
-     * Initialize the fieldTypeClass.
-     * 
-     * @return the primitive class or the class accordign to fieldType
-     */
-    private Class loadFieldTypeClass() {
-        if (this.fieldType == null) 
-        {
-            return null;
-        }
-        if ("byte".equals(this.fieldType)) 
-        {
-            return byte.class;
-        }
-        else if ("short".equals(this.fieldType)) 
-        {
-            return short.class;
-        }
-        else if ("int".equals(this.fieldType)) 
-        {
-            return int.class;
-        }
-        else if ("long".equals(this.fieldType)) 
-        {
-            return long.class;
-        }
-        else if ("float".equals(this.fieldType)) 
-        {
-            return float.class;
-        }
-        else if ("double".equals(this.fieldType)) 
-        {
-            return double.class;
-        }
-        else if ("char".equals(this.fieldType)) 
-        {
-            return char.class;
-        }
-        else if ("boolean".equals(this.fieldType))
-        {
-            return boolean.class;
-        }
-        else 
-        {
-            try {
-                return Class.forName(this.fieldType);
-            }
-            catch (ClassNotFoundException cnfe) 
-            {
-                ; // nothing to do; it will be dynamically determined
-            }
-        }
-        
-        return null;
-    }
-}
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.jcr.mapper.model;
+
+
+/**
+ *
+ *
+ * FieldDescriptor is used by the mapper to read general information on a atomic field
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe
</a>
+ *
+ */
+public class FieldDescriptor {
+    private String fieldName;
+    private String fieldType;
+    private Class fieldTypeClass;
+    private String jcrName;
+    private String jcrType;
+    private boolean jcrAutoCreated;
+    private boolean jcrMandatory;
+    private String jcrOnParentVersion;
+    private boolean jcrProtected;
+    private boolean jcrMultiple;
+    private ClassDescriptor classDescriptor;
+    private boolean id;
+    private boolean path;
+    private boolean discriminator;
+
+    /**
+     * @return Returns the fieldName.
+     */
+    public String getFieldName() {
+        return fieldName;
+    }
+
+    /**
+     * @param fieldName The fieldName to set.
+     */
+    public void setFieldName(String fieldName) {
+        this.fieldName = fieldName;
+    }
+
+    /**
+     * @return the primitive or fully qualified class of the field
+     * or <tt>null</tt> if not specified in the mapping
+     */
+    public String getFieldType() {
+        return this.fieldType;
+    }
+
+    /**
+     * Sets the type of the field. It supports primitive types, specified as
+     * int, long, etc or fully qualified class names.
+     *
+     * @param fieldType the type of the field
+     */
+    public void setFieldType(String fieldType) {
+        this.fieldType = fieldType;
+    }
+
+    /**
+     * @return the field class of the field
+     * or <tt>null</tt> if not specified in the mapping
+     * or if the class was not found
+     */
+    public Class getFieldTypeClass() {
+        if (this.fieldType == null) {
+            return null;
+        }
+        if (this.fieldTypeClass == null) {
+            this.fieldTypeClass = loadFieldTypeClass();
+        }
+
+        return this.fieldTypeClass;
+    }
+
+    /**
+     * @return Returns the jcrName.
+     */
+    public String getJcrName() {
+        return jcrName;
+    }
+
+    /**
+     * @param jcrName The jcrName to set.
+     */
+    public void setJcrName(String jcrName) {
+        this.jcrName = jcrName;
+    }
+
+    /**
+     *
+     * @return the associated class descriptor
+     */
+    public ClassDescriptor getClassDescriptor() {
+        return classDescriptor;
+    }
+
+    /**
+     * Set the associated class descriptor
+     * @param classDescriptor  the class descriptor to set
+     */
+    public void setClassDescriptor(ClassDescriptor classDescriptor) {
+        this.classDescriptor = classDescriptor;
+    }
+
+    /**
+     * @return true if the field is the class ID
+     */
+    public boolean isId() {
+        return id;
+    }
+
+    /**
+     *
+     * @param id
+     */
+    public void setId(boolean id) {
+        this.id = id;
+    }
+
+    /**
+     * @return Returns true if the field is the object JCR path.
+     */
+    public boolean isPath() {
+        return path;
+    }
+
+    /**
+     * @param path The path to set.
+     */
+    public void setPath(boolean path) {
+        this.path = path;
+    }
+
+    /** Getter for property jcrType.
+     *
+     * @return jcrType
+     */
+    public String getJcrType() {
+        return jcrType;
+    }
+
+    /** Setter for property jcrType.
+     *
+     * @param value jcrType
+     */
+    public void setJcrType(String value) {
+        this.jcrType = value;
+    }
+
+    /** Getter for propery jcrAutoCreated.
+     *
+     * @return jcrAutoCreated
+     */
+    public boolean isJcrAutoCreated() {
+        return jcrAutoCreated;
+    }
+
+    /** Setter for property jcrAutoCreated.
+     *
+     * @param value jcrAutoCreated
+     */
+    public void setJcrAutoCreated(boolean value) {
+        this.jcrAutoCreated = value;
+    }
+
+    /** Getter for property jcrMandatory.
+     *
+     * @return jcrMandatory
+     */
+    public boolean isJcrMandatory() {
+        return jcrMandatory;
+    }
+
+    /** Setter for property jcrMandatory.
+     *
+     * @param value jcrMandatory
+     */
+    public void setJcrMandatory(boolean value) {
+        this.jcrMandatory = value;
+    }
+
+    /** Getter for property jcrOnParentVersion.
+     *
+     * @return jcrOnParentVersion
+     */
+    public String getJcrOnParentVersion() {
+        return jcrOnParentVersion;
+    }
+
+    /** Setter for property jcrOnParentVersion.
+     *
+     * @param value jcrOnParentVersion
+     */
+    public void setJcrOnParentVersion(String value) {
+        this.jcrOnParentVersion = value;
+    }
+
+    /** Getter for property jcrProtected.
+     *
+     * @return jcrProtected
+     */
+    public boolean isJcrProtected() {
+        return jcrProtected;
+    }
+
+    /** Setter for property jcrProtected.
+     *
+     * @param value jcrProtected
+     */
+    public void setJcrProtected(boolean value) {
+        this.jcrProtected = value;
+    }
+
+    /** Getter for property jcrMultiple.
+     *
+     * @return jcrMultiple
+     */
+    public boolean isJcrMultiple() {
+        return jcrMultiple;
+    }
+
+    /** Setter for property jcrMultiple.
+     *
+     * @param value jcrMultiple
+     */
+    public void setJcrMultiple(boolean value) {
+        this.jcrMultiple = value;
+    }
+
+    public void setDiscriminator(boolean value) {
+        this.discriminator = value;
+    }
+
+    public boolean isDiscriminator() {
+        return this.discriminator;
+    }
+
+    /**
+     * Initialize the fieldTypeClass.
+     *
+     * @return the primitive class or the class accordign to fieldType
+     */
+    private Class loadFieldTypeClass() {
+        if (this.fieldType == null) {
+            return null;
+        }
+        if ("byte".equals(this.fieldType)) {
+            return byte.class;
+        }
+        else if ("short".equals(this.fieldType)) {
+            return short.class;
+        }
+        else if ("int".equals(this.fieldType)) {
+            return int.class;
+        }
+        else if ("long".equals(this.fieldType)) {
+            return long.class;
+        }
+        else if ("float".equals(this.fieldType)) {
+            return float.class;
+        }
+        else if ("double".equals(this.fieldType)) {
+            return double.class;
+        }
+        else if ("char".equals(this.fieldType)) {
+            return char.class;
+        }
+        else if ("boolean".equals(this.fieldType)) {
+            return boolean.class;
+        }
+        else {
+            try {
+                return Class.forName(this.fieldType);
+            }
+            catch (ClassNotFoundException cnfe) {
+                ; // nothing to do; it will be dynamically determined
+            }
+        }
+
+        return null;
+    }
+}

Modified: incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/MappingDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/MappingDescriptor.java?rev=377514&r1=377513&r2=377514&view=diff
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/MappingDescriptor.java
(original)
+++ incubator/graffito/trunk/jcr/jcr-mapping/src/java/org/apache/portals/graffito/jcr/mapper/model/MappingDescriptor.java
Mon Feb 13 14:35:50 2006
@@ -33,12 +33,30 @@
 
     private Mapper mapper;
 
+    private String packageName;
+    
+    public void setPackage(String pckgName) {
+        this.packageName = pckgName;
+    }
+    
     /**
      * Add a new ClassDescriptor
      *
      * @param classDescriptor The class descriptor to add
      */
     public void addClassDescriptor(ClassDescriptor classDescriptor) {
+        if (null != this.packageName && !"".equals(this.packageName)) {
+            classDescriptor.setClassName(this.packageName + "." + classDescriptor.getClassName());
+
+            if (null != classDescriptor.getSuperClass() && !"".equals(classDescriptor.getSuperClass()))
{
+                classDescriptor.setSuperClass(this.packageName + "." + classDescriptor.getSuperClass());
+            }
+        }
+
+        if (!classDescriptor.validate()) {
+            return;
+        }
+
         classDescriptors.put(classDescriptor.getClassName(), classDescriptor);
         classDescriptor.setMappingDescriptor(this);
     }



Mime
View raw message