jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1354509 - in /jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm: mapper/model/PropertyDefDescriptor.java nodemanagement/NodeTypeManager.java nodemanagement/impl/NodeTypeManagerImpl.java
Date Wed, 27 Jun 2012 13:59:59 GMT
Author: ard
Date: Wed Jun 27 13:59:57 2012
New Revision: 1354509

URL: http://svn.apache.org/viewvc?rev=1354509&view=rev
Log:
OCM-58 make OCM jackrabbit independent. Note that I did remove some methods from the NodeTypeManager
interface, but the NodeTypeManagerImpl didn't implement many of them any way. Jackrabbit dependency
is now only used as scope test

Added:
    jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/impl/NodeTypeManagerImpl.java
  (contents, props changed)
      - copied, changed from r1352024, jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/impl/jackrabbit/NodeTypeManagerImpl.java
Modified:
    jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/mapper/model/PropertyDefDescriptor.java
    jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/NodeTypeManager.java

Modified: jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/mapper/model/PropertyDefDescriptor.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/mapper/model/PropertyDefDescriptor.java?rev=1354509&r1=1354508&r2=1354509&view=diff
==============================================================================
--- jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/mapper/model/PropertyDefDescriptor.java
(original)
+++ jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/mapper/model/PropertyDefDescriptor.java
Wed Jun 27 13:59:57 2012
@@ -29,6 +29,8 @@ public interface PropertyDefDescriptor {
      */
     String getJcrName();
 
+    String getFieldName();
+
     /**
      * @return Returns the property type name.
      */

Modified: jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/NodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/NodeTypeManager.java?rev=1354509&r1=1354508&r2=1354509&view=diff
==============================================================================
--- jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/NodeTypeManager.java
(original)
+++ jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/NodeTypeManager.java
Wed Jun 27 13:59:57 2012
@@ -80,109 +80,15 @@ public interface NodeTypeManager {
     void createNodeTypes(Session session, ClassDescriptor[] classDescriptors)
     throws NodeTypeCreationException;
 
-    /** This method creates JCR node types based on jcr-mapping xml
-     * files.
-     *
-     * @param session Repository session
-     * @param mappingXmlFiles InputStreams to jcr-mapping xml files
-     * @throws NodeTypeCreationException NodeTypeCreationException
-     */
-    void createNodeTypesFromMappingFiles(Session session,
-            InputStream[] mappingXmlFiles)
-            throws NodeTypeCreationException;
-
     /** This method creates a single JCR node type identified by its ClassDescriptor
      * read from the jcr mapping file.
      *
      * @param session Repository session
      * @param classDescriptor ClassDescriptor object created by jcr-mapping
-     * @param jcrNodeType Name of the class that needs to be created identified
-     * by its jcrNodeType name
      * @throws NodeTypeCreationException NodeTypeCreationException
      */
     void createSingleNodeType(Session session, ClassDescriptor classDescriptor)
     throws NodeTypeCreationException;
 
-    /** This method creates a single JCR node type identified by its jcrNodeType
-     * name defined in a jcr-mapping xml file.
-     *
-     * @param session Repository session
-     * @param mappingXmlFile InputStream to a jcr-mapping xml file
-     * @param jcrNodeType Name of the class that needs to be created identified
-     * by its jcrNodeType name
-     * @throws NodeTypeCreationException NodeTypeCreationException
-     */
-    void createSingleNodeTypeFromMappingFile(Session session,
-            InputStream mappingXmlFile, String jcrNodeType)
-            throws NodeTypeCreationException;
-
-    /** This method creates a JCR node type from a given Java Bean class by using
-     * reflection. It creates required JCR property definitions from primitive
-     * Java class properties using the same property name. Non-primitive class
-     * properties are skipped.
-     *
-     * @param session Repository session
-     * @param clazz Java class
-     * @param jcrNodeType Name of JCR node type (including namespace)
-     * @param reflectSuperClasses If true, all base classes are also reflected
-     * @throws NodeTypeCreationException NodeTypeCreationException
-     */
-    void createNodeTypeFromClass(Session session, Class clazz,
-            String jcrNodeType, boolean reflectSuperClasses)
-            throws NodeTypeCreationException;
 
-    /** This method creates JCR node types from a JCR vendor specific
-     * configuration file.
-     *
-     * @param session Repository session
-     * @param jcrRepositoryXmlConfigurationFile InputStream to file
-     * @throws OperationNotSupportedException OperationNotSupportedException
-     * @throws NodeTypeCreationException NodeTypeCreationException
-     */
-    void createNodeTypesFromConfiguration(Session session,
-            InputStream jcrRepositoryConfigurationFile)
-            throws OperationNotSupportedException, NodeTypeCreationException;
-
-    /** This method removes all JCR node types that are defined in one to many
-     * jcr-mapping XML files.
-     *
-     * @param session Repository session
-     * @param mappingXmlFiles InputStreams to jcr-mapping xml file
-     * @throws NodeTypeRemovalException NodeTypeRemovalException
-     */
-    void removeNodeTypesFromMappingFile(Session session, InputStream[] mappingXmlFiles)
-    throws NodeTypeRemovalException;
-
-    /**
-     * This method removes JCR node types from a JCR vendor specific configuration file
-     * @param session Repository session
-     * @param jcrRepositoryConfigurationFile the file that contains the node type definition
-     * @throws NodeTypeRemovalException
-     */
-    void removeNodeTypesFromConfiguration(Session session, InputStream jcrRepositoryConfigurationFile)
-    throws NodeTypeRemovalException;
-
-    /** This method removes a single JCR node type identified by its jcrNodeType
-     * name.
-     *
-     * @param session Repository session
-     * @param jcrNodeType
-     * @throws NodeTypeRemovalException NodeTypeRemovalException
-     */
-    void removeSingleNodeType(Session session, String jcrNodeType)
-    throws NodeTypeRemovalException;
-
-    /** Returns the names of all node types in the repository identified by a
-     * given namespace.
-     *
-     * @param namespace Name of nodetypes to return
-     * @return list of matching JCR node types
-     */
-    List getPrimaryNodeTypeNames(Session session, String namespace);
-
-    /** Returns a list of all JCR node types.
-     *
-     * @return list of all JCR node types
-     */
-    List getAllPrimaryNodeTypeNames(Session session);
 }

Copied: jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/impl/NodeTypeManagerImpl.java
(from r1352024, jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/impl/jackrabbit/NodeTypeManagerImpl.java)
URL: http://svn.apache.org/viewvc/jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/impl/NodeTypeManagerImpl.java?p2=jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/impl/NodeTypeManagerImpl.java&p1=jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/impl/jackrabbit/NodeTypeManagerImpl.java&r1=1352024&r2=1354509&rev=1354509&view=diff
==============================================================================
--- jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/impl/jackrabbit/NodeTypeManagerImpl.java
(original)
+++ jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/impl/NodeTypeManagerImpl.java
Wed Jun 27 13:59:57 2012
@@ -1,38 +1,19 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.jackrabbit.ocm.nodemanagement.impl.jackrabbit;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
+package org.apache.jackrabbit.ocm.nodemanagement.impl;
+
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.Workspace;
-import javax.jcr.nodetype.NodeTypeDefinition;
-import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.nodetype.NodeDefinitionTemplate;
+import javax.jcr.nodetype.NodeTypeTemplate;
+import javax.jcr.nodetype.PropertyDefinitionTemplate;
 import javax.jcr.version.OnParentVersionAction;
 
-import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
-import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
-import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
 import org.apache.jackrabbit.ocm.mapper.model.BeanDescriptor;
 import org.apache.jackrabbit.ocm.mapper.model.ChildNodeDefDescriptor;
 import org.apache.jackrabbit.ocm.mapper.model.ClassDescriptor;
@@ -43,47 +24,14 @@ import org.apache.jackrabbit.ocm.mapper.
 import org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager;
 import org.apache.jackrabbit.ocm.nodemanagement.exception.NamespaceCreationException;
 import org.apache.jackrabbit.ocm.nodemanagement.exception.NodeTypeCreationException;
-import org.apache.jackrabbit.ocm.nodemanagement.exception.NodeTypeRemovalException;
-import org.apache.jackrabbit.ocm.nodemanagement.exception.OperationNotSupportedException;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.QNodeDefinition;
-import org.apache.jackrabbit.spi.QNodeTypeDefinition;
-import org.apache.jackrabbit.spi.QPropertyDefinition;
-import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.spi.QValueConstraint;
-import org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder;
-import org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder;
-import org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** This is the NodeTypeManager implementation for Apache Jackrabbit.
- *
- * @author <a href="mailto:okiessler@apache.org">Oliver Kiessler</a>
- */
-public class NodeTypeManagerImpl implements NodeTypeManager
-{
-    /**
-     * Logging.
-     */
-    private static Logger log = LoggerFactory.getLogger(NodeTypeManagerImpl.class);
-    private static final boolean debug = false;
-
-    /** Namespace helper class for Jackrabbit.
-     */
-    private NamespaceHelper namespaceHelper = new NamespaceHelper();
-
-    /** Creates a new instance of NodeTypeManagerImpl. */
-    public NodeTypeManagerImpl()
-    {
-    }
+public class NodeTypeManagerImpl implements NodeTypeManager {
 
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#createNamespace
-     */
-    public void createNamespace(Session session, String namespace, String namespaceUri)
-    throws NamespaceCreationException
-    {
+    private static Logger log = LoggerFactory.getLogger(NodeTypeManagerImpl.class);
+    @Override
+    public void createNamespace(final Session session, final String namespace, final String
namespaceUri) throws NamespaceCreationException {
         if (session != null)
         {
             try
@@ -99,15 +47,13 @@ public class NodeTypeManagerImpl impleme
         }
     }
 
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#createNodeTypes
-     */
-    public void createNodeTypes(Session session, MappingDescriptor mappingDescriptor)
-    throws NodeTypeCreationException
-    {
-    	if (mappingDescriptor != null && mappingDescriptor.getClassDescriptorsByClassName().size()
> 0)
-        {
-
+    @Override
+    public void createNodeTypes(final Session session, final MappingDescriptor mappingDescriptor)
throws NodeTypeCreationException {
+        if (mappingDescriptor != null && mappingDescriptor.getClassDescriptorsByClassName().size()
> 0)
+        {
+            final Collection classDescriptorObjects = mappingDescriptor.getClassDescriptorsByClassName().values();
+            final ClassDescriptor[] classDescriptors = (ClassDescriptor[])classDescriptorObjects.toArray(new
ClassDescriptor[classDescriptorObjects.size()]);
+            createNodeTypes(session, classDescriptors);
         }
         else
         {
@@ -115,12 +61,8 @@ public class NodeTypeManagerImpl impleme
         }
     }
 
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#createNodeTypes
-     */
-    public void createNodeTypes(Session session, ClassDescriptor[] classDescriptors)
-    throws NodeTypeCreationException
-    {
+    @Override
+    public void createNodeTypes(final Session session, final ClassDescriptor[] classDescriptors)
throws NodeTypeCreationException {
         if (classDescriptors != null && classDescriptors.length > 0)
         {
             log.info("Trying to create " + classDescriptors.length +
@@ -136,519 +78,235 @@ public class NodeTypeManagerImpl impleme
         }
     }
 
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#createNodeTypesFromMappingFiles
-     */
-    public void createNodeTypesFromMappingFiles(Session session,
-            InputStream[] mappingXmlFiles)
-            throws NodeTypeCreationException
-    {
-    }
-
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#createSingleNodeType
-     */
-    public void createSingleNodeType(Session session, ClassDescriptor classDescriptor)
-    throws NodeTypeCreationException
-    {
-        try
-        {
-            getNamespaceHelper().setRegistry(session.getWorkspace().getNamespaceRegistry());
-            ArrayList list = new ArrayList();
-
+    @Override
+    public void createSingleNodeType(final Session session, final ClassDescriptor classDescriptor)
throws NodeTypeCreationException {
+        try {
             if (classDescriptor.getJcrType() != null &&
                     (classDescriptor.getJcrType().startsWith("nt:")
-                    || classDescriptor.getJcrType().startsWith("mix:")))
-            {
+                            || classDescriptor.getJcrType().startsWith("mix:"))) {
                 throw new NodeTypeCreationException("Namespace nt and mix are reserved namespaces.
Please specify your own.");
             }
 
             if (checkSuperTypes(session.getWorkspace().getNodeTypeManager(),
-                    classDescriptor.getJcrSuperTypes()))
-            {
-                Name nodeTypeName = getNodeTypeName(classDescriptor.getJcrType(),
-			classDescriptor.getClassName());
+                    classDescriptor.getJcrSuperTypes())) {
 
-                List<QPropertyDefinition> propDefs = new ArrayList<QPropertyDefinition>();
-                List<QNodeDefinition> nodeDefs = new ArrayList<QNodeDefinition>();
-                if (classDescriptor.getFieldDescriptors() != null)
-                {
+                javax.jcr.nodetype.NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
+                final NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
+
+                if (classDescriptor.getJcrType() == null) {
+                    ntt.setName(classDescriptor.getClassName());
+                } else {
+                    ntt.setName(classDescriptor.getJcrType());
+                }
+                ntt.setAbstract(classDescriptor.isAbstract());
+                if (classDescriptor.getJcrSuperTypes() != null && classDescriptor.getJcrSuperTypes().length()
> 0) {
+                    String[] superTypesArray = classDescriptor.getJcrSuperTypes().split(",");
+                    //TODO  combine the mixins here as well as supertypes
+                    // Add classDescriptor.getJcrMixinTypes() to superTypesArray
+                    for (String s : classDescriptor.getJcrMixinTypes()) {
+                        System.out.println(s);
+                    }
+                    ntt.setDeclaredSuperTypeNames(superTypesArray);
+                }
+                // should we also support mixins to be created?
+                ntt.setMixin(false);
+                ntt.setQueryable(true);
+                ntt.setOrderableChildNodes(true);
+
+                final List nodeDefinitionTemplates = ntt.getNodeDefinitionTemplates();
+                final List propertyDefinitionTemplates = ntt.getPropertyDefinitionTemplates();
+
+                if (classDescriptor.getFieldDescriptors() != null) {
                     Iterator fieldIterator = classDescriptor.getFieldDescriptors().iterator();
-                    while (fieldIterator.hasNext())
-                    {
+                    while (fieldIterator.hasNext()) {
                         FieldDescriptor field = (FieldDescriptor) fieldIterator.next();
                         if (!field.isPath()) {
-                            propDefs.add(getPropertyDefinition(field.getFieldName(), field,
nodeTypeName));
+                            final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm,
session.getValueFactory(), field);
+                            // add the just created pdt to the nodetypetemplate
+                            propertyDefinitionTemplates.add(pdt);
                         }
                     }
-                }
 
-                if (classDescriptor.getBeanDescriptors() != null) {
-                    Iterator beanIterator = classDescriptor.getBeanDescriptors().iterator();
-                    while (beanIterator.hasNext()) {
-                        BeanDescriptor field = (BeanDescriptor) beanIterator.next();
-                        if (this.isPropertyType(field.getJcrType())) {
-                            propDefs.add(getPropertyDefinition(field.getFieldName(), field,
nodeTypeName));
-                        } else {
-                            nodeDefs.add(getNodeDefinition(field.getFieldName(), field, nodeTypeName));
+                    if (classDescriptor.getBeanDescriptors() != null) {
+                        Iterator beanIterator = classDescriptor.getBeanDescriptors().iterator();
+                        while (beanIterator.hasNext()) {
+                            BeanDescriptor field = (BeanDescriptor) beanIterator.next();
+                            if (this.isPropertyType(field.getJcrType())) {
+                                final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm,
session.getValueFactory(), field);
+                                // add the just created pdt to the nodetypetemplate
+                                propertyDefinitionTemplates.add(pdt);
+                            } else {
+                                final NodeDefinitionTemplate ndt = getNodeDefinition(ntm,
session.getValueFactory(), field);
+                                // add the just created pdt to the nodetypetemplate
+                                nodeDefinitionTemplates.add(ndt);
+                            }
                         }
                     }
-                }
 
-                if (classDescriptor.getCollectionDescriptors() != null) {
-                    Iterator collectionIterator = classDescriptor.getCollectionDescriptors().iterator();
-                    while (collectionIterator.hasNext()) {
-                        CollectionDescriptor field = (CollectionDescriptor) collectionIterator.next();
-                        if (this.isPropertyType(field.getJcrType())) {
-                            propDefs.add(getPropertyDefinition(field.getFieldName(), field,
nodeTypeName));
-                        } else {
-                            nodeDefs.add(getNodeDefinition(field.getFieldName(), field, nodeTypeName));
+                    if (classDescriptor.getCollectionDescriptors() != null) {
+                        Iterator collectionIterator = classDescriptor.getCollectionDescriptors().iterator();
+                        while (collectionIterator.hasNext()) {
+                            CollectionDescriptor field = (CollectionDescriptor) collectionIterator.next();
+                            if (this.isPropertyType(field.getJcrType())) {
+                                final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm,
session.getValueFactory(), field);
+                                // add the just created pdt to the nodetypetemplate
+                                propertyDefinitionTemplates.add(pdt);
+                            } else {
+                                final NodeDefinitionTemplate ndt = getNodeDefinition(ntm,
session.getValueFactory(), field);
+                                // add the just created pdt to the nodetypetemplate
+                                nodeDefinitionTemplates.add(ndt);
+                            }
                         }
                     }
+                    ntm.registerNodeType(ntt, false);
+                    log.info("Registered JCR node type '" + ntt.getName() +
+                            "' for class '" + classDescriptor.getClassName() + "'");
                 }
-
-                 QNodeTypeDefinition nodeTypeDef = getNodeTypeDef(
-                         classDescriptor.getJcrType(),
-                         classDescriptor.getJcrSuperTypes(),
-                         classDescriptor.getClassName(),
-                         nodeTypeName,
-                         propDefs,
-                         nodeDefs,
-                         classDescriptor.getJcrMixinTypes(),
-                         classDescriptor.isAbstract(),
-                         //TODO:is this correkt, how to decide whether mixin or not?
-                         classDescriptor.isInterface());
-
-                list.add(nodeTypeDef);
-                createNodeTypesFromList(session, list);
-                log.info("Registered JCR node type '" + nodeTypeDef.getName() +
-                        "' for class '" + classDescriptor.getClassName() + "'");
-            }
-            else
-            {
+            } else {
                 throw new NodeTypeCreationException("JCR supertypes could not be resolved.");
             }
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             log.error("Could not create node types from class descriptor.", e);
             throw new NodeTypeCreationException(e);
         }
     }
 
-    /** Checks if all JCR super types for a given node type exist.
-     *
-     * @param ntMgr NodeTypeManager
-     * @param superTypes Comma separated String with JCR node types
-     * @return true/false
-     */
-    private boolean checkSuperTypes(javax.jcr.nodetype.NodeTypeManager ntMgr,
-            String superTypes)
-    {
-        boolean exists = true;
-
-        if (superTypes != null && superTypes.length() > 0)
-        {
-            String[] superTypesArray = superTypes.split(",");
-            log.debug("JCR super types found: " + superTypesArray.length);
-            for (int i = 0; i < superTypesArray.length; i++)
-            {
-                try
-                {
-                    ntMgr.getNodeType(superTypesArray[i]);
-                }
-                catch (Exception e)
-                {
-                    log.error("JCR super type '" + superTypesArray[i] + "' does not exist!");
-                    exists = false;
-                    break;
-                }
-            }
-        }
-
-        return exists;
-    }
-
-        private Name getNodeTypeName(String jcrNodeType,String className) {
-                Name name = null;
-
-                if (jcrNodeType != null && (!jcrNodeType.equals(""))) {
-                        name = getNamespaceHelper().getName(jcrNodeType);
-
-                } else {
-                        name = getNamespaceHelper().getName(className);
-
-                }
-                return name;
-        }
-
-    /** Creates a NodeTypeDef object.
-     *
-     * @param jcrNodeType Name of JCR node type
-     * @param jcrSuperTypes JCR node super types
-     * @return type
-     */
-    public QNodeTypeDefinition getNodeTypeDef(String jcrNodeType, String jcrSuperTypes, String
className,
-            Name jcrNodeTypeName, List<QPropertyDefinition> propDefs, List<QNodeDefinition>
nodeDefs,
-            String[] jcrMixinTypes, boolean isAbstract, boolean isMixin)
-    {
-        QNodeTypeDefinitionBuilder ntdb = new QNodeTypeDefinitionBuilder();
-        ntdb.setAbstract(isAbstract);
-        ntdb.setChildNodeDefs(nodeDefs.toArray(QNodeDefinition.EMPTY_ARRAY));
-        //ntdb.setMixin(classDescriptor.isAbstract());
-        ntdb.setMixin(isMixin);
-        ntdb.setName(jcrNodeTypeName);
-        ntdb.setOrderableChildNodes(false);
-        //ntdb.setPrimaryItemName(primaryItemName);
-        ntdb.setPropertyDefs(propDefs.toArray(QPropertyDefinition.EMPTY_ARRAY));
-        ntdb.setQueryable(true);
-        ntdb.setSupertypes( getJcrSuperTypes(jcrSuperTypes) );
-        ntdb.setSupportedMixinTypes( getJcrMixinTypes(jcrMixinTypes) );
-
-        return ntdb.build();
-    }
-
-    /** Creates a PropDefImpl object.
-     *
-     * @param fieldName The name of the field
-     * @param field property definition descriptor
-     * @param declaringNodeType Node Type QName where the property belongs to
-     * @return property
-     */
-    public QPropertyDefinition getPropertyDefinition(String fieldName,
-            PropertyDefDescriptor field, Name declaringNodeType)
-    {
-            Name name = null;
-
-        if (field.getJcrName() != null)
-        {
-            name = getNamespaceHelper().getName(field.getJcrName());
-        }
-        else
-        {
-            name = getNamespaceHelper().getName(fieldName);
-        }
+    private NodeDefinitionTemplate getNodeDefinition(final javax.jcr.nodetype.NodeTypeManager
ntm,
+                                                     final ValueFactory valueFactory,
+                                                     final ChildNodeDefDescriptor field)
throws RepositoryException {
 
-        int requiredType = PropertyType.UNDEFINED;
 
-        if (field.getJcrType() != null)
-        {
-            requiredType = PropertyType.valueFromName(field.getJcrType());
-        }
-        else
-        {
-            log.info("No property type set for " + name.getLocalName() +
-                    ". Setting 'String' type.");
-            requiredType = PropertyType.STRING;
+        final NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
+        if (field.getJcrName() != null) {
+            ndt.setName(field.getJcrName());
+        } else {
+            ndt.setName("*");
         }
 
         int onParentVersion = OnParentVersionAction.IGNORE;
 
-        if (field.getJcrOnParentVersion() != null &&
-                field.getJcrOnParentVersion().length() > 0)
-        {
+        if (field.getJcrOnParentVersion() != null
+                && field.getJcrOnParentVersion().length() > 0) {
             onParentVersion = OnParentVersionAction.valueFromName(field.getJcrOnParentVersion());
         }
+        ndt.setOnParentVersion(onParentVersion);
+        ndt.setSameNameSiblings(field.isJcrSameNameSiblings());
 
-        QPropertyDefinitionBuilder pdb = new QPropertyDefinitionBuilder();
-        pdb.setAutoCreated(field.isJcrAutoCreated());
-        pdb.setAvailableQueryOperators(new String[0]);
-        pdb.setDeclaringNodeType(declaringNodeType);
-        pdb.setDefaultValues(QValue.EMPTY_ARRAY);
-        pdb.setFullTextSearchable(false);
-        pdb.setMandatory(field.isJcrMandatory());
-        pdb.setMultiple(field.isJcrMultiple());
-        pdb.setName(name);
-        pdb.setOnParentVersion(onParentVersion);
-        pdb.setProtected(field.isJcrProtected());
-        pdb.setQueryOrderable(false);
-        pdb.setRequiredType(requiredType);
-        pdb.setValueConstraints(QValueConstraint.EMPTY_ARRAY);
-
-        return pdb.build();
-    }
-
-    /** Creates a NodeDefImpl object.
-     *
-     * @param fieldName Name of the field
-     * @param field child node definition descriptor
-     * @param declaringNodeType Node Type QName where the chid node belongs to
-     * @return child node definition
-     */
-    private QNodeDefinition getNodeDefinition(String fieldName,
-        ChildNodeDefDescriptor field, Name declaringNodeType) {
-
-            Name name = null;
-
+        ndt.setAutoCreated(field.isJcrAutoCreated());
+        ndt.setDefaultPrimaryTypeName(field.getDefaultPrimaryType());
+        ndt.setMandatory(field.isJcrMandatory());
+        ndt.setProtected(field.isJcrProtected());
+        ndt.setRequiredPrimaryTypeNames(getJcrSuperTypes(field.getJcrType()));
+
+        return ndt;
+    }
+
+    private PropertyDefinitionTemplate getPropertyDefinition(final javax.jcr.nodetype.NodeTypeManager
ntm,
+                                                             final ValueFactory valueFactory,
+                                                             final PropertyDefDescriptor
field) throws RepositoryException {
+        final PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
         if (field.getJcrName() != null) {
-            name = getNamespaceHelper().getName(field.getJcrName());
+            pdt.setName(field.getJcrName());
         } else {
-            name = getNamespaceHelper().getName("*");
+            pdt.setName(field.getFieldName());
         }
 
-        int onParentVersion = OnParentVersionAction.IGNORE;
+        if (field.getJcrType() != null) {
+            try {
+                pdt.setRequiredType(PropertyType.valueFromName(field.getJcrType()));
+            } catch (IllegalArgumentException e) {
+                log.warn("Invalid property type '{}' for '{}'. Set default to String type",
field.getJcrType(), field.getJcrName());
+                pdt.setRequiredType(PropertyType.STRING);
+            }
+        } else {
+            log.info("No property type set for {}. Setting 'String' type.", field.getJcrName());
+            pdt.setRequiredType(PropertyType.STRING);
 
-        if (field.getJcrOnParentVersion() != null
-            && field.getJcrOnParentVersion().length() > 0) {
+        }
+        int onParentVersion = OnParentVersionAction.IGNORE;
+        if (field.getJcrOnParentVersion() != null &&
+                field.getJcrOnParentVersion().length() > 0) {
             onParentVersion = OnParentVersionAction.valueFromName(field.getJcrOnParentVersion());
         }
+        pdt.setOnParentVersion(onParentVersion);
 
-        QNodeDefinitionBuilder ndb = new QNodeDefinitionBuilder();
-        ndb.setAllowsSameNameSiblings(field.isJcrSameNameSiblings());
-        ndb.setAutoCreated(field.isJcrAutoCreated());
-        ndb.setDeclaringNodeType(declaringNodeType);
-        ndb.setDefaultPrimaryType(getNamespaceHelper().getName(field.getDefaultPrimaryType()));
-        ndb.setMandatory(field.isJcrMandatory());
-        ndb.setName(name);
-        ndb.setOnParentVersion(onParentVersion);
-        ndb.setProtected(field.isJcrProtected());
-        ndb.setRequiredPrimaryTypes(getJcrSuperTypes(field.getJcrType()));
-
-        return ndb.build();
-    }
-
-    /**
-     *
-     * @param propDef
-     * @return
-     */
-    protected String showPropertyDefinition(PropertyDefinition propDef)
-    {
-        StringBuffer sb = new StringBuffer();
-        sb.append("----");
-        sb.append("\nName: " + propDef.getName());
-        sb.append("\nAutocreated: " + propDef.isAutoCreated());
-        sb.append("\nMandatory: " + propDef.isMandatory());
-        sb.append("\n----");
-        return sb.toString();
-    }
-
-    /** Creates a QName array from a comma separated list of JCR super types in
-     * a given String.
-     *
-     * @param superTypes JCR super types
-     * @return qNameSuperTypes
-     */
-    public Name[] getJcrSuperTypes(String superTypes)
-    {
-        return getNames(superTypes.split(","), "super type");
-    }
-
+        pdt.setAutoCreated(field.isJcrAutoCreated());
+        pdt.setAvailableQueryOperators(new String[0]);
 
-    public Name[] getJcrMixinTypes(String[] jcrMixinTypes)
-    {
-    	return getNames(jcrMixinTypes, "mixin type");
-    }
-
-
-    private Name[] getNames(String[] jcrTypeNames, String logTypeKind)
-    {
-    	Name[] names = null;
-        if (jcrTypeNames != null && jcrTypeNames.length > 0)
-        {
-            log.debug("JCR " + logTypeKind + "'s types found: " + jcrTypeNames.length);
-            names = new Name[jcrTypeNames.length];
-            for (int i = 0; i < jcrTypeNames.length; i++)
-            {
-                String superTypeName = jcrTypeNames[i].trim();
-                names[i] = getNamespaceHelper().getName(superTypeName);
-                log.debug("Setting JCR " + logTypeKind +  ": " + superTypeName);
+        pdt.setFullTextSearchable(true);
+        pdt.setMandatory(field.isJcrMandatory());
+        pdt.setMultiple(field.isJcrMultiple());
+        pdt.setOnParentVersion(onParentVersion);
+        pdt.setProtected(field.isJcrProtected());
+        pdt.setQueryOrderable(true);
+
+        if (field instanceof  FieldDescriptor) {
+            FieldDescriptor f = (FieldDescriptor) field;
+            if (f.getJcrDefaultValue() != null) {
+                if (pdt.getRequiredType() == PropertyType.STRING) {
+                    Value[] vals = {valueFactory.createValue(f.getJcrDefaultValue())};
+                    pdt.setDefaultValues(vals);
+                } else {
+                    log.warn("Can only set default value for String properties. Skip for
field '{}'", field.getJcrName());
+                }
             }
+            pdt.setValueConstraints(f.getJcrValueConstraints());
         }
 
-        return names;
+        return pdt;
     }
 
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#createSingleNodeTypeFromMappingFile
-     */
-    public void createSingleNodeTypeFromMappingFile(Session session,
-            InputStream mappingXmlFile, String jcrNodeType)
-            throws NodeTypeCreationException
-    {
-    }
-
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#createNodeTypeFromClass
+    /** Checks if all JCR super types for a given node type exist.
+     *
+     * @param ntMgr NodeTypeManager
+     * @param superTypes Comma separated String with JCR node types
+     * @return returns <code>false</code> if one of the supertypes does not exist,
otherwise returns <code>true</code>
      */
-    public void createNodeTypeFromClass(Session session, Class clazz,
-            String jcrNodeType, boolean reflectSuperClasses)
-            throws NodeTypeCreationException
+    private boolean checkSuperTypes(javax.jcr.nodetype.NodeTypeManager ntMgr,
+                                    String superTypes)
     {
-    }
+        boolean exists = true;
 
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#createNodeTypesFromConfiguration
-     */
-    public void createNodeTypesFromConfiguration(Session session,
-            InputStream jcrRepositoryConfigurationFile)
-            throws OperationNotSupportedException, NodeTypeCreationException
-    {
-        try
+        if (superTypes != null && superTypes.length() > 0)
         {
-            QNodeTypeDefinition[] types = NodeTypeReader.read(jcrRepositoryConfigurationFile);
-
-            ArrayList list = new ArrayList();
-            for (int i = 0; i < types.length; i++)
+            String[] superTypesArray = superTypes.split(",");
+            log.debug("JCR super types found: " + superTypesArray.length);
+            for (int i = 0; i < superTypesArray.length; i++)
             {
-                list.add(types[i]);
+                try
+                {
+                    ntMgr.getNodeType(superTypesArray[i]);
+                }
+                catch (Exception e)
+                {
+                    log.error("JCR super type '" + superTypesArray[i] + "' does not exist!");
+                    exists = false;
+                    break;
+                }
             }
-
-            createNodeTypesFromList(session, list);
-            log.info("Registered " + list.size() + " nodetypes from xml configuration file.");
-        }
-        catch (Exception e)
-        {
-            log.error("Could not create node types from configuration file.", e);
-            throw new NodeTypeCreationException(e);
-        }
-    }
-
-    /**
-     *
-     * @param session
-     * @param nodeTypes
-     * @throws org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException
-     * @throws javax.jcr.RepositoryException
-     */
-    private void createNodeTypesFromList(Session session, List nodeTypes)
-    throws InvalidNodeTypeDefException, RepositoryException
-    {
-        getNodeTypeRegistry(session).registerNodeTypes(nodeTypes);
-    }
-
-    public void removeNodeTypesFromConfiguration(Session session, InputStream jcrRepositoryConfigurationFile)
-    throws NodeTypeRemovalException
-    {
-    	try
-        {
-            QNodeTypeDefinition[] types = NodeTypeReader.read(jcrRepositoryConfigurationFile);
-
-            ArrayList list = new ArrayList();
-            list.addAll(Arrays.asList(types));
-
-            removeNodeTypesFromList(session, list);
-            log.info("Registered " + list.size() + " nodetypes from xml configuration file.");
-        }
-        catch (Exception e)
-        {
-            log.error("Could not create node types from configuration file.", e);
-            throw new NodeTypeRemovalException(e);
-        }
-    }
-
-    private void removeNodeTypesFromList(Session session, List nodeTypes)
-    throws NodeTypeRemovalException
-    {
-        for (Iterator nodeTypeIterator = nodeTypes.iterator(); nodeTypeIterator.hasNext();)
-        {
-			NodeTypeDefinition nodeTypeDef = (NodeTypeDefinition) nodeTypeIterator.next();
-			this.removeSingleNodeType(session, nodeTypeDef.getName());
-
-		}
-
-    }
-
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#createSingleNodeTypeFromMappingFile
-     */
-    public void removeNodeTypesFromMappingFile(Session session, InputStream[] mappingXmlFile)
-            throws NodeTypeRemovalException
-    {
-    }
-
-    public void removeSingleNodeType(Session session, Name name)
-    throws NodeTypeRemovalException
-    {
-        try
-        {
-            getNodeTypeRegistry(session).unregisterNodeType(name);
-        }
-        catch (Exception e)
-        {
-            throw new NodeTypeRemovalException(e);
         }
-    }
 
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#removeSingleNodeType
-     */
-    public void removeSingleNodeType(Session session, String jcrNodeType)
-    throws NodeTypeRemovalException
-    {
-        try
-        {
-            getNodeTypeRegistry(session).unregisterNodeType(getNamespaceHelper().getName(jcrNodeType));
-        }
-        catch (Exception e)
-        {
-            throw new NodeTypeRemovalException(e);
-        }
-    }
-
-    /** Returns the jackrabbit NodeTypeRegistry from an open session.
-     *
-     * @param session Repository session
-     * @return nodeTypeRegistry
-     */
-    private NodeTypeRegistry getNodeTypeRegistry(Session session)
-    throws RepositoryException
-    {
-        Workspace wsp = session.getWorkspace();
-        javax.jcr.nodetype.NodeTypeManager ntMgr = wsp.getNodeTypeManager();
-        NodeTypeRegistry ntReg =
-                ((org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl) ntMgr).getNodeTypeRegistry();
-        return ntReg;
-    }
-
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#getPrimaryNodeTypeNames
-     */
-    public List getPrimaryNodeTypeNames(Session session, String namespace)
-    {
-        return null;
-    }
-
-    /**
-     * @see org.apache.jackrabbit.ocm.nodemanagement.NodeTypeManager#getAllPrimaryNodeTypeNames
-     */
-    public List getAllPrimaryNodeTypeNames(Session session)
-    {
-        return null;
-    }
-
-    /** Getter for property namespaceHelper.
-     *
-     * @return namespaceHelper
-     */
-    public NamespaceHelper getNamespaceHelper()
-    {
-        return namespaceHelper;
+        return exists;
     }
 
-    /** Setter for property namespaceHelper.
-     *
-     * @param object namespaceHelper
-     */
-    public void setNamespaceHelper(NamespaceHelper object)
+    public String[] getJcrSuperTypes(String superTypes)
     {
-        this.namespaceHelper = object;
+        return superTypes.split(",");
     }
 
-
     private boolean isPropertyType(String type)
     {
-    	return (type.equals(PropertyType.TYPENAME_BINARY) ||
-    	        type.equals(PropertyType.TYPENAME_BOOLEAN) ||
-    	        type.equals(PropertyType.TYPENAME_DATE) ||
-    	        type.equals(PropertyType.TYPENAME_DOUBLE) ||
-    	        type.equals(PropertyType.TYPENAME_LONG) ||
-    	        type.equals(PropertyType.TYPENAME_NAME) ||
-    	        type.equals(PropertyType.TYPENAME_PATH) ||
-    	        type.equals(PropertyType.TYPENAME_REFERENCE) ||
-    	        type.equals(PropertyType.TYPENAME_WEAKREFERENCE) ||
-    	        type.equals(PropertyType.TYPENAME_DECIMAL) ||
-    	        type.equals(PropertyType.TYPENAME_URI) ||
-    	        type.equals(PropertyType.TYPENAME_STRING));
+        return (type.equals(PropertyType.TYPENAME_BINARY) ||
+                type.equals(PropertyType.TYPENAME_BOOLEAN) ||
+                type.equals(PropertyType.TYPENAME_DATE) ||
+                type.equals(PropertyType.TYPENAME_DOUBLE) ||
+                type.equals(PropertyType.TYPENAME_LONG) ||
+                type.equals(PropertyType.TYPENAME_NAME) ||
+                type.equals(PropertyType.TYPENAME_PATH) ||
+                type.equals(PropertyType.TYPENAME_REFERENCE) ||
+                type.equals(PropertyType.TYPENAME_WEAKREFERENCE) ||
+                type.equals(PropertyType.TYPENAME_DECIMAL) ||
+                type.equals(PropertyType.TYPENAME_URI) ||
+                type.equals(PropertyType.TYPENAME_STRING));
     }
 }

Propchange: jackrabbit/commons/ocm/trunk/src/main/java/org/apache/jackrabbit/ocm/nodemanagement/impl/NodeTypeManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message