001: /*
002: * Copyright 2004 Outerthought bvba and Schaubroeck nv
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.outerj.daisy.repository.commonimpl;
017:
018: import org.outerj.daisy.repository.ChangeType;
019: import org.outerj.daisy.repository.RepositoryException;
020: import org.outerj.daisy.repository.LockType;
021: import org.outerj.daisy.repository.VersionKey;
022: import org.outerj.daisy.repository.VersionState;
023: import org.outerj.daisy.repository.Document;
024:
025: import java.io.InputStream;
026:
027: /**
028: * Allows to customise some of the behaviour of the {@link CommonRepository}, and especially
029: * {@link DocumentImpl}.
030: *
031: * <p>The typical use of this is to provide two implementations of the repository API's:
032: * one for local (in-server) use, and one for remote (= client) use, by only having to
033: * implement twice those aspects which differ in each implementation.
034: *
035: * <p>The most important difference between the client and server API implementations
036: * will be how they load and store entities (such as Document objects): the client API
037: * implementation will do this by contacting the server, the server implementation will
038: * do this by using its persistence mechanisms (such as an RDBMS).
039: *
040: * <p>Note that this API is not really meant for public consumption, and the correct
041: * workings of its implementations (especially the server-side one) are crucial for
042: * the correct operation of the repository. It is important that the strategy implementation
043: * correctly initialiases, updates and interprets the internal state of the objects it handles.
044: *
045: * <p>Certain methonds, like {@link #load(DocId, long, long, AuthenticatedUser)}
046: * and {@link #store(org.outerj.daisy.repository.commonimpl.DocumentImpl)} need to check
047: * if the user has the rights to perform this operation. This is especially true for the serverside
048: * implementation, the client side implementation doesn't need to do this as it will contact the
049: * server which will automatically do this checks.
050: *
051: * <p>Certain methods, like {@link #store(org.outerj.daisy.repository.commonimpl.DocumentImpl)} might
052: * also need to send out events to eventlisteners.
053: */
054: public interface DocumentStrategy {
055: public Document load(DocId docId, long branchId, long languageId,
056: AuthenticatedUser user) throws RepositoryException;
057:
058: /**
059: * Stores a document. After successful storage, the document object status should be
060: * updates, i.e. the lastModified and lastModifier parts should be updated, and some
061: * dirty-indication flags should be reset.
062: */
063: public void store(DocumentImpl document) throws RepositoryException;
064:
065: /**
066: *
067: * @param startVersionId -1 for last version, -2 for live version
068: */
069: public Document createVariant(DocId docId, long startBranchId,
070: long startLanguageId, long startVersionId,
071: long newBranchId, long newLanguageId, AuthenticatedUser user)
072: throws RepositoryException;
073:
074: public AvailableVariantImpl[] getAvailableVariants(DocId docId,
075: AuthenticatedUser user) throws RepositoryException;
076:
077: public void deleteDocument(DocId docId, AuthenticatedUser user)
078: throws RepositoryException;
079:
080: public void deleteVariant(DocId docId, long branchId,
081: long languageId, AuthenticatedUser user)
082: throws RepositoryException;
083:
084: public VersionImpl loadVersion(DocumentVariantImpl documentVariant,
085: long versionId) throws RepositoryException;
086:
087: /**
088: * Loads the additional information skipped when the version was loaded via
089: * {@link #loadShallowVersions(org.outerj.daisy.repository.commonimpl.DocumentVariantImpl)}.
090: */
091: public void completeVersion(DocumentVariantImpl variant,
092: VersionImpl version) throws RepositoryException;
093:
094: /**
095: * Loads all Version objects for this document as shallow Version objects (i.e. without
096: * their full content, but only the data necessary to show a version overview table).
097: */
098: public VersionImpl[] loadShallowVersions(DocumentVariantImpl variant)
099: throws RepositoryException;
100:
101: public void storeVersion(DocumentImpl document,
102: VersionImpl version, VersionState versionState,
103: VersionKey syncedWith, ChangeType changeType,
104: String changeComment) throws RepositoryException;
105:
106: public InputStream getBlob(DocId docId, long branchId,
107: long languageId, long versionId, long partTypeId,
108: AuthenticatedUser user) throws RepositoryException;
109:
110: /**
111: * This method does not check access rights (unlike {@link #getBlob(DocId, long, long, long, long, AuthenticatedUser)},
112: * because this one is only intended for use by Part objects.
113: */
114: public InputStream getBlob(String blobKey)
115: throws RepositoryException;
116:
117: /**
118: * Tries to create a lock on the document. If there was alread a pessimitic lock on
119: * the document, this method will return a LockInfo object containing information about
120: * that lock, so it is important to check the info in the LockInfo object to know if
121: * the lock was successful.
122: */
123: public LockInfoImpl lock(DocumentVariantImpl documentVariant,
124: long duration, LockType lockType)
125: throws RepositoryException;
126:
127: public LockInfoImpl getLockInfo(DocumentVariantImpl documentVariant)
128: throws RepositoryException;
129:
130: public LockInfoImpl releaseLock(DocumentVariantImpl documentVariant)
131: throws RepositoryException;
132:
133: }
|