jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r385852 - in /incubator/jackrabbit/branches/1.0/jcr-server: server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/ webdav/src/java/org/apache/jackrabbit/webdav/version/report/
Date Tue, 14 Mar 2006 18:47:08 GMT
Author: jukka
Date: Tue Mar 14 10:47:08 2006
New Revision: 385852

URL: http://svn.apache.org/viewcvs?rev=385852&view=rev
Log:
1.0: Merged revisions 385458, 385459, and 385485: JCR-346, JCR-347, and JCR-341 as requested
by Angela.

Modified:
    incubator/jackrabbit/branches/1.0/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/ItemDefinitionImpl.java
    incubator/jackrabbit/branches/1.0/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/NodeTypeProperty.java
    incubator/jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java

Modified: incubator/jackrabbit/branches/1.0/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/ItemDefinitionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/branches/1.0/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/ItemDefinitionImpl.java?rev=385852&r1=385851&r2=385852&view=diff
==============================================================================
--- incubator/jackrabbit/branches/1.0/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/ItemDefinitionImpl.java
(original)
+++ incubator/jackrabbit/branches/1.0/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/ItemDefinitionImpl.java
Tue Mar 14 10:47:08 2006
@@ -101,8 +101,11 @@
      * @param document
      */
     public Element toXml(Document document) {
-	Element elem = document.createElement(getElementName());
-        elem.setAttribute(DECLARINGNODETYPE_ATTRIBUTE, getDeclaringNodeType().getName());
+        Element elem = document.createElement(getElementName());
+        NodeType dnt = getDeclaringNodeType();
+        if (dnt != null) {
+            elem.setAttribute(DECLARINGNODETYPE_ATTRIBUTE, dnt.getName());
+        }
         elem.setAttribute(NAME_ATTRIBUTE, getName());
         elem.setAttribute(AUTOCREATED_ATTRIBUTE, Boolean.toString(isAutoCreated()));
         elem.setAttribute(MANDATORY_ATTRIBUTE, Boolean.toString(isMandatory()));

Modified: incubator/jackrabbit/branches/1.0/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/NodeTypeProperty.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/branches/1.0/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/NodeTypeProperty.java?rev=385852&r1=385851&r2=385852&view=diff
==============================================================================
--- incubator/jackrabbit/branches/1.0/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/NodeTypeProperty.java
(original)
+++ incubator/jackrabbit/branches/1.0/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/NodeTypeProperty.java
Tue Mar 14 10:47:08 2006
@@ -15,8 +15,6 @@
  */
 package org.apache.jackrabbit.webdav.jcr.nodetype;
 
-import org.apache.jackrabbit.webdav.DavException;
-import org.apache.jackrabbit.webdav.DavServletResponse;
 import org.apache.jackrabbit.webdav.property.AbstractDavProperty;
 import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
@@ -42,7 +40,7 @@
     private final Set nodetypeNames = new HashSet();
 
     public NodeTypeProperty(DavPropertyName name, NodeType nodeType, boolean isProtected)
{
-        this(name, new NodeType[] {nodeType}, isProtected);
+        this(name, new NodeType[]{nodeType}, isProtected);
     }
 
     public NodeTypeProperty(DavPropertyName name, NodeType[] nodeTypes, boolean isProtected)
{
@@ -55,41 +53,54 @@
         }
     }
 
+    public NodeTypeProperty(DavPropertyName name, String[] nodeTypeNames, boolean isProtected)
{
+        super(name, isProtected);
+        for (int i = 0; i < nodeTypeNames.length; i++) {
+            if (nodeTypeNames[i] != null) {
+                nodetypeNames.add(nodeTypeNames[i]);
+            }
+        }
+    }
+
     /**
      * Create a new <code>NodeTypeProperty</code> from the specified general
      * DavProperty object.
      *
      * @param property
-     * @throws IllegalArgumentException if the content of the specified property
-     * contains elements other than {@link NodeTypeConstants#XML_NODETYPE}.
      */
-    public NodeTypeProperty(DavProperty property) throws DavException {
+    public NodeTypeProperty(DavProperty property) {
         super(property.getName(), property.isProtected());
-        Object propValue = property.getValue();
-        Iterator it;
-        if (propValue instanceof List) {
-            it = ((List)propValue).iterator();
-        } else if (propValue instanceof Element) {
-            List l = new ArrayList();
-            l.add(propValue);
-            it = l.iterator();
+        if (property instanceof NodeTypeProperty) {
+            nodetypeNames.addAll(((NodeTypeProperty)property).nodetypeNames);
         } else {
-            log.warn("Cannot build NodeTypeProperty from the given property.");
-            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Cannot build NodeTypeProperty
from the given property.");
+            // assume property has be built from xml
+            Object propValue = property.getValue();
+            if (propValue instanceof List) {
+                retrieveNodeTypeNames(((List)propValue));
+            } else if (propValue instanceof Element) {
+                List l = new ArrayList();
+                l.add(propValue);
+                retrieveNodeTypeNames(l);
+            } else {
+                log.debug("NodeTypeProperty '" + property.getName() + "' has no/unparsable
value.");
+            }
         }
+    }
 
-            while (it.hasNext()) {
-                Object content = it.next();
+    private void retrieveNodeTypeNames(List elementList) {
+        Iterator it = elementList.iterator();
+        while (it.hasNext()) {
+            Object content = it.next();
             if (!(content instanceof Element)) {
                 continue;
-                }
+            }
             Element el = (Element)content;
             if (XML_NODETYPE.equals(el.getLocalName()) && NodeTypeConstants.NAMESPACE.isSame(el.getNamespaceURI()))
{
-                String nodetypeName = DomUtil.getText(el);
+                String nodetypeName = DomUtil.getChildText(el, XML_NODETYPENAME, NodeTypeConstants.NAMESPACE);
                 if (nodetypeName != null && !"".equals(nodetypeName)) {
                     nodetypeNames.add(nodetypeName);
-            }
-	} else {
+                }
+            } else {
                 log.debug("'dcr:nodetype' element expected -> ignoring element '" + ((Element)content).getNodeName()
+ "'");
             }
         }

Modified: incubator/jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java?rev=385852&r1=385851&r2=385852&view=diff
==============================================================================
--- incubator/jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java
(original)
+++ incubator/jackrabbit/branches/1.0/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/version/report/ReportType.java
Tue Mar 14 10:47:08 2006
@@ -67,7 +67,7 @@
      */
     public Report createReport(DeltaVResource resource, ReportInfo info) throws DavException
{
         try {
-            Report report = (Report) reportClass.getConstructor(new Class[0]).newInstance(new
Object[0]);
+            Report report = (Report) reportClass.newInstance();
             report.init(resource, info);
             return report;
         } catch (Exception e) {
@@ -109,7 +109,7 @@
      */
     public String getReportName() {
         return key;
-            }
+    }
 
     /**
      *
@@ -117,7 +117,7 @@
      */
     public String getLocalName() {
         return localName;
-        }
+    }
 
     /**
      *
@@ -143,25 +143,19 @@
         if (localName == null || namespace == null || reportClass == null) {
             throw new IllegalArgumentException("A ReportType cannot be registered with a
null name, namespace or report class");
         }
-
         String key = DomUtil.getQualifiedName(localName, namespace);
         if (types.containsKey(key)) {
             return (ReportType) types.get(key);
         } else {
-            // test if this report class has an empty constructor and implements Report interface
-            boolean isValidClass = false;
-            Class[] interfaces = reportClass.getInterfaces();
-            for (int i = 0; i < interfaces.length && !isValidClass; i++) {
-                isValidClass = (interfaces[i] == Report.class);
-            }
-            if (!isValidClass) {
-                throw new IllegalArgumentException("The specified report class must implement
the Report interface.");
-            }
-
             try {
-                reportClass.getConstructor(new Class[0]);
-            } catch (NoSuchMethodException e) {
-                throw new IllegalArgumentException("The specified report class must provide
a default constructor.");
+                Object report =  reportClass.newInstance();
+                if (!(report instanceof Report)) {
+                    throw new IllegalArgumentException("Unable to register Report class:
" + reportClass + " does not implement the Report interface.");
+                }
+            } catch (IllegalAccessException e) {
+                throw new IllegalArgumentException("Error while validating Report class:
" + e.getMessage());
+            } catch (InstantiationException e) {
+                throw new IllegalArgumentException("Error while validating Report class.:
" + e.getMessage());
             }
 
             ReportType type = new ReportType(localName, namespace, key, reportClass);



Mime
View raw message