[WireHose-dev] WHRevision

Gary Teter bigdog at wirehose.com
Wed Jan 17 17:50:34 EST 2007


On Jan 17, 2007, at 2:40 PM, David Holt wrote:

> Can revisions be implemented with the existing tag classes? Or is  
> it just gone?

Here's the source to WHRevision.


// WHRevision.java
// Created on Mon Dec 23 10:17:18 US/Pacific 2002 by Apple EOModeler  
Version 5.2
// Copyright 2000-2006 Gary Teter. All rights reserved. WireHose is a  
trademark of Gary Teter.

package com.wirehose.base;

import com.webobjects.eoaccess.EOUtilities;
import com.webobjects.eocontrol.EOEditingContext;
import com.webobjects.eocontrol.EOEnterpriseObject;
import com.webobjects.foundation.*;
import java.util.Enumeration;

/**
     <p>Provides support for versioning WHTaggable objects. A  
WHRevision tag represents a particular resource, and can be assigned  
to another resource to indicate that a resource is a revision of  
another. Since  resources can have multiple tags, a given resource  
can be a revision of multiple other resources, and a given resource  
can have multiple revisions (and revisions of revisions, and so on).</p>

     <p>WHRevision provides three key methods for handling  
versioning: {@link #makeRevision(WHTaggable, WHTaggable, String)  
makeRevision} makes one resource a revision of another; {@link  
#revisionsForResource(EOEditingContext, WHTaggable)  
revisionsForResource} returns all revisions of a particular resource;  
and {@link #originalsForRevision(EOEditingContext, WHTaggable)  
originalsForRevision} returns the array of objects a particular  
revision is a revision of.</p>

     <p>Like WHTag, WHRevision uses affiliate-based entity  
inheritance, so you will generally be working with a subentity of  
WHRevision such as "SeattleRevision. See {@link WHEnterpriseObject}  
for details about WireHose entity inheritance.</p>

*/

public class WHRevision extends com.wirehose.base.WHTag {

     public WHRevision() {
         super();
     }


     /**
         Adds a revision tag for <code>original</code> to  
<code>revision</code>, indicating that <code>revision</code> is a  
revision of <code>original</code>. If <code>affiliateName</code> is  
null, the default affiliate is used.

         @return the tag which represents <code>original</code>
         @param original the resource which is being revised
         @param revision the resource which is a revision of  
<code>original</code>
         @param affiliateName determines the subentity of WHRevision  
the returned tag should be
         @see #revisionTagForResource(EOEditingContext, WHTaggable,  
String, boolean)
         @see WHTag#setDefaultAffiliate(String)
     */
     public static WHRevision makeRevision(WHTaggable original,  
WHTaggable revision, String affiliateName) {
         WHRevision revisionTag = revisionTagForResource 
(revision.editingContext(), original, affiliateName, true);
         WHTag.addTag(revision, revisionTag);
         return revisionTag;
     }

     /**
         Returns a tag which can be assigned to a resource to  
indicate that it is a revision of <code>original</code>. If  
<code>affiliateName</code> is null, the default affiliate will be used.

         @return a tag which represents <code>original</code>
         @param editingContext the editing context in which the tag  
should be registered
         @param original the resource to be represented by the  
returned tag
         @param affiliateName determines the subentity of WHRevision  
the returned tag should be
         @param shouldCreateIfMissing whether or not to force  
creation of the tag
         @see #originalForRevisionTag(EOEditingContext, WHRevision)
         @see #originalsForRevision(EOEditingContext, WHTaggable)
         @see #revisionsForResource(EOEditingContext, WHTaggable)
         @see WHTag#setDefaultAffiliate(String)
     */
     public static WHRevision revisionTagForResource(EOEditingContext  
editingContext, WHTaggable original, String affiliateName, boolean  
shouldCreateIfMissing) {
         String tagEntityName =  
WHEnterpriseObject.subEntityNameForAffiliate("WHRevision",  
affiliateName);
         if (affiliateName == null && _defaultAffiliate != null) {
             String subEntityName =  
WHEnterpriseObject.subEntityNameForAffiliate("WHRevision",  
_defaultAffiliate);
             if (EOUtilities.modelGroup(editingContext).entityNamed 
(subEntityName) != null) {
                 tagEntityName = subEntityName;
             }
         }
         return _revisionTagForResource(editingContext, original,  
tagEntityName, shouldCreateIfMissing);
     }

     static WHRevision _revisionTagForResource(EOEditingContext  
editingContext, WHTaggable original, String tagEntityName, boolean  
shouldCreateIfMissing) {
         return (WHRevision)WHTag.topTag(editingContext, new  
NSDictionary(new Object[]{WHEnterpriseObject.encodedGlobalIDForObject 
(original), tagEntityName}, new Object[]{"name", "entity"}),  
shouldCreateIfMissing, null);
     }

     /**
         Returns the resource identified by <code>revisionTag</code>.

         @return the original resource identified by  
<code>revisionTag</code>
         @param editingContext the editing context in which the  
resource should be registered
         @param revisionTag the tag representing the resource
         @see #revisionTagForResource(EOEditingContext, WHTaggable,  
String, boolean)
         @see #originalsForRevision(EOEditingContext, WHTaggable)
         @see #revisionsForResource(EOEditingContext, WHTaggable)
     */
     public static WHTaggable originalForRevisionTag(EOEditingContext  
editingContext, WHRevision revisionTag) {
         return (WHTaggable)WHEnterpriseObject.faultForEncodedGlobalID 
(editingContext, revisionTag.name());
     }

     /**
         Returns the resources that <code>revision</code> is an  
immediate revision of, or an empty array if <code>revision</code> is  
not a revision of any other resources.

         @return the resources that <code>revision</code> is an  
immediate revision of, or an empty array if <code>revision</code> is  
not a revision of any other resources
         @param editingContext the editing context in which the  
returned resources should be registered
         @param revision the resource which may be a revision
         @see #originalForRevisionTag(EOEditingContext, WHRevision)
         @see #revisionTagForResource(EOEditingContext, WHTaggable,  
String, boolean)
         @see #revisionsForResource(EOEditingContext, WHTaggable)
         @TypeInfo WHTaggable
     */
     public static NSArray originalsForRevision(EOEditingContext  
editingContext, WHTaggable revision) {
         NSMutableSet resources = new NSMutableSet();
         Enumeration enumerator = revision.tags().objectEnumerator();
         WHTag aTag;
         EOEnterpriseObject aResource;
         while (enumerator.hasMoreElements()) {
             aTag = (WHTag)enumerator.nextElement();
             if (aTag instanceof WHRevision) {
                 aResource =  
WHEnterpriseObject.faultForEncodedGlobalID(editingContext, aTag.name());
                 if (aResource != null) {
                     resources.addObject(aResource);
                 }
             }
         }
         return resources.allObjects();
     }


     /**
         Returns the resources which are immediate revisions of  
<code>original</code>, or an empty array if <code>original</code> has  
no revisions.

         @return the resources which are immediate revisions of  
<code>original</code>, or an empty array if <code>original</code> has  
no revisions
         @param editingContext the editing context in which the  
fetched resources should be registered
         @param original the resource which may have been revised
         @see #revisionTagForResource(EOEditingContext, WHTaggable,  
String, boolean)
         @see #originalForRevisionTag(EOEditingContext, WHRevision)
         @see #originalsForRevision(EOEditingContext, WHTaggable)
         @TypeInfo WHTaggable
     */
     public static NSArray revisionsForResource(EOEditingContext  
editingContext, WHTaggable original) {
         WHTag revisionTag = _revisionTagForResource(editingContext,  
original, "WHRevision", false);
         if (revisionTag != null) {
             WHTagDataSource ds = new WHTagDataSource(editingContext);
             ds.setFreshLimit(new Integer(WHFetcher.MatchAnyDate));
             ds.setFetchLimit(new Integer(WHFetcher.FetchAllObjects));
             ds.addToOptionalTags(revisionTag);
             NSArray resources = ds.resources("*");
             ds.dispose();
             return resources;
         } else {
             return NSArray.EmptyArray;
         }
     }


      /**
         Returns the resource identified by this tag.

         @return the resource identified by this tag
         @see #originalForRevisionTag(EOEditingContext, WHRevision)
         @see #revisionTagForResource(EOEditingContext, WHTaggable,  
String, boolean)
         @see #originalsForRevision(EOEditingContext, WHTaggable)
         @see #revisionsForResource(EOEditingContext, WHTaggable)
     */
     public WHTaggable resource() {
         return (WHTaggable)WHEnterpriseObject.faultForEncodedGlobalID 
(editingContext(), name());
     }


}

-- 
WireHose: Smart metadata and personalization for WebObjects.
http://wirehose.com/




More information about the WireHose-dev mailing list