remm        01/07/05 22:13:13

  Modified:    src/share/org/apache/slide/common XMLUnmarshaller.java
  Log:
  - Remove old dead code.
  - The structure specified in Domain.xml will be recreated on each startup of
    Slide. That should make the namespace much more robust.
  - The revision element can be used to set properties. The behavior is that
    if the property is already present in the object's latest revision, it won't do 
anything.
    If the property doesn't exist the property will be set in the latest revision of 
the
    object, with the property value specified. If the property is already present, its
    value won't be replaced.
  - Note : I didn't fully test this, but I don't expect it to break things.
  
  Revision  Changes    Path
  1.15      +92 -120   
jakarta-slide/src/share/org/apache/slide/common/XMLUnmarshaller.java
  
  Index: XMLUnmarshaller.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/common/XMLUnmarshaller.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- XMLUnmarshaller.java      2001/06/22 04:23:58     1.14
  +++ XMLUnmarshaller.java      2001/07/06 05:13:10     1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/common/XMLUnmarshaller.java,v 1.14 
2001/06/22 04:23:58 msmith Exp $
  - * $Revision: 1.14 $
  - * $Date: 2001/06/22 04:23:58 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/common/XMLUnmarshaller.java,v 1.15 
2001/07/06 05:13:10 remm Exp $
  + * $Revision: 1.15 $
  + * $Date: 2001/07/06 05:13:10 $
    *
    * ====================================================================
    *
  @@ -82,7 +82,7 @@
    * XMLUnmarshaller class.
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  - * @version $Revision: 1.14 $
  + * @version $Revision: 1.15 $
    */
   public final class XMLUnmarshaller {
       
  @@ -165,16 +165,22 @@
                   // FIXME
               } else {
                   
  -                if (object instanceof LinkNode) {
  -                    String linkedUri = 
  -                        objectDefinition.getAttribute("linkedUri");
  -                    accessToken.getStructureHelper().createLink
  -                        (token, (LinkNode) object, uri, 
  -                         new SubjectNode(linkedUri));
  -                } else {
  -                    accessToken.getStructureHelper().create
  -                        (token, object, uri);
  +                try {
  +                    if (object instanceof LinkNode) {
  +                        String linkedUri = 
  +                            objectDefinition.getAttribute("linkedUri");
  +                        accessToken.getStructureHelper().createLink
  +                            (token, (LinkNode) object, uri, 
  +                             new SubjectNode(linkedUri));
  +                    } else {
  +                        accessToken.getStructureHelper().create
  +                            (token, object, uri);
  +                    }
  +                } catch (ObjectAlreadyExistsException e) {
  +                    // Ignore, log and continue
  +                    Domain.info("Object already exists at " + uri);
                   }
  +                
               }
               
               // Retrieving the list of permissions on the object
  @@ -239,10 +245,6 @@
                   
               }
               
  -        } catch (ObjectAlreadyExistsException e) {
  -            // Object creation failed.
  -            // The object probably does already exist in the data source.
  -            Domain.info("Object already exists at " + uri);
           } catch (ObjectNotFoundException e) {
               // Should NEVER happen
               e.printStackTrace();
  @@ -286,23 +288,33 @@
           // Retrieving the list of properties
           Enumeration propertyDefinitions =
               revisionDefinition.getConfigurations("property");
  -        // Retrieving the content element if it exists
  -        Configuration contentDefinition = null;
  -        try {
  -            contentDefinition = revisionDefinition.getConfiguration("content");
  -        } catch (ConfigurationException e) {
  -            // Silent catch, since the parameter is optional
  -        }
  +
           // Retrieving the revision number, if any
           NodeRevisionNumber revisionNumber = null;
           
  -        // TODO : Copy the contents at the specified URL to a temp file.
  -        // Then, get the content length ...
  -        long contentLength = 0;
  -        
           // Now creating the new revision descriptor object
  -        NodeRevisionDescriptor revisionDescriptor = 
  -            new NodeRevisionDescriptor(contentLength);
  +        NodeRevisionDescriptor revisionDescriptor = null;
  +
  +        NodeRevisionDescriptors revisionDescriptors = null;
  +        try {
  +            accessToken.getContentHelper().retrieve(token, uri);
  +        } catch (ObjectLockedException e) {
  +            // Ignore
  +        }
  +        if ((revisionDescriptors != null) 
  +            && (revisionDescriptors.hasRevisions())) {
  +            try {
  +                revisionDescriptor = accessToken.getContentHelper().retrieve
  +                    (token, revisionDescriptors);
  +            } catch (RevisionDescriptorNotFoundException e) {
  +                // Ignore
  +            } catch (ObjectLockedException e) {
  +                // Ignore
  +            }
  +        }
  +        if (revisionDescriptor == null) {
  +            revisionDescriptor = new NodeRevisionDescriptor(0);
  +        }
           
           while (propertyDefinitions.hasMoreElements()) {
               Configuration propertyDefinition = 
  @@ -311,103 +323,63 @@
               String propertyValue = propertyDefinition.getValue();
               String propertyNamespace = propertyDefinition.getAttribute
                   ("namespace", NodeProperty.DEFAULT_NAMESPACE);
  -            revisionDescriptor.setProperty(propertyName, propertyNamespace,
  -                propertyValue);
  +            NodeProperty property = revisionDescriptor.getProperty
  +                (propertyName, propertyNamespace);
  +            if (property == null)
  +                revisionDescriptor.setProperty(propertyName, propertyNamespace,
  +                                               propertyValue);
           }
           
           NodeRevisionContent revisionContent = null;
  -        
  -        if (contentDefinition != null) {
  -            // Get an InputStream on the temporary file
  -        }
           
  -        // TODO : Parse predecessor list, and make the appropriate method call
  -        
  -        try {
  -            accessToken.getContentHelper().create(token, uri, 
  -                                                  revisionDescriptor,
  -                                                  revisionContent);
  -        } catch(ObjectLockedException e) {
  -            // Should not happen
  -            e.printStackTrace();
  -            Domain.warn(e.getMessage());
  -        } catch(RevisionAlreadyExistException e) {
  -            // Should not happen
  -            e.printStackTrace();
  -            Domain.warn(e.getMessage());
  +        if ((revisionDescriptors != null) 
  +            && (revisionDescriptors.hasRevisions())) {
  +
  +            try {
  +                revisionContent = accessToken.getContentHelper()
  +                    .retrieve(token, uri, revisionDescriptor);
  +            } catch (RevisionContentNotFoundException e) {
  +                // Ignore
  +            } catch (ObjectLockedException e) {
  +                // Ignore
  +            } catch (RevisionNotFoundException e) {
  +                // Should not happen
  +                e.printStackTrace();
  +                Domain.warn(e.getMessage());
  +            }
  +            try {
  +                accessToken.getContentHelper().store
  +                    (token, uri, revisionDescriptor, revisionContent);
  +            }  catch (RevisionDescriptorNotFoundException e) {
  +                // Should not happen
  +                e.printStackTrace();
  +                Domain.warn(e.getMessage());
  +            } catch (RevisionNotFoundException e) {
  +                // Should not happen
  +                e.printStackTrace();
  +                Domain.warn(e.getMessage());
  +            } catch (ObjectLockedException e) {
  +                // Ignore
  +            }
  +
  +        } else {
  +
  +            try {
  +                accessToken.getContentHelper().create
  +                    (token, uri, revisionDescriptor, revisionContent);
  +            } catch(ObjectLockedException e) {
  +                // Should not happen
  +                e.printStackTrace();
  +                Domain.warn(e.getMessage());
  +            } catch(RevisionAlreadyExistException e) {
  +                // Should not happen
  +                e.printStackTrace();
  +                Domain.warn(e.getMessage());
  +            }
  +
           }
           
       }
       
  -    
  -    /**
  -     * Create the SlideProperties object associated with a ObjectNode.
  -     * 
  -     * @param slideObject ObjectNode
  -     * @param propertiesDef Castor object describing the properties associated 
  -     * with the ObjectNode
  -     * @exception SlideException A data access error occured
  -     */
  -    private static void loadProperties(NamespaceAccessToken accessToken, 
  -                                       SlideToken token, 
  -                                       ObjectNode slideObject)
  -        throws ServiceAccessException {
  -        
  -        // FIXME !
  -        /*
  -        // We first create a blank SlideProperties object.
  -        SlideProperties properties = new SlideProperties();
  -        
  -        // Set its basic fields.
  -        properties.setName(propertiesDef.getName());
  -        properties.setContentLanguage(propertiesDef.getContentlanguage());
  -        properties.setContentType(propertiesDef.getContenttype());
  -        
  -        try {
  -            // Try to create the SlideProperties object within the Store.
  -            namespaceInterface.getDataHelper()
  -            .create(token, properties, slideObject.getUri());
  -            
  -            // Retrive from the Castor object a list containing 
  -            // the definition of all the 
  -            // SlideRevision objects associated with the SlideProperties object.
  -            Enumeration revisionsDef = propertiesDef.enumerateRevision();
  -            while (revisionsDef.hasMoreElements()) {
  -                // Retrieve the definition of the revision
  -                org.apache.slide.common.xml.Revision revisionDef =
  -                    (org.apache.slide.common.xml.Revision) 
revisionsDef.nextElement();
  -                // Create a new associated Revision Slide object
  -                SlideRevision revision = new SlideRevision();
  -                // Set its fields
  -                revision.setAuthor(revisionDef.getAuthor());
  -                // The revision content should be a pointer to some binary content 
somewhere.
  -                //revision.setContent(revisionDef.getContent());
  -                revision.setCreationDate(new Date((new 
Long(revisionDef.getCreationdate())).longValue()));
  -                revision.setId(new SlideRevisionId(revisionDef.getId()));
  -                revision.setName(revisionDef.getName());
  -                
  -                // Create the new revision
  -                namespaceInterface.getVersionHelper().create(token, properties, 
revision);
  -            }
  -            
  -            // Version.create(properties, revision) both modifies the creationDate 
and the LatestRevision marker
  -            // of the properties object. We must reinitialize it, and store it 
again in the repository.
  -            properties.setLatestRevisionId(new 
SlideRevisionId(propertiesDef.getLatestrevisionid()));
  -            properties.setCreationDate(new Date(new 
Long(propertiesDef.getCreationdate()).longValue()));
  -            namespaceInterface.getDataHelper().store(token, properties);
  -            
  -        } catch (VersionException e) {
  -            // We stop at the first error, which would probably indicate that
  -            // the stuff we try to create already exists.
  -     } catch (DataException e) {
  -            // We stop at the first error, which would probably indicate that
  -            // the stuff we try to create already exists.
  -     } catch (AccessDeniedException e) {
  -            // Idem
  -        } catch (ObjectLockedException e) {
  -            // Idem
  -        }
  -        */
  -    }
       
   }
  
  
  

Reply via email to