FODBSync4JSource.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  * 
00024  */
00025 package org.openmobileis.synchro.sync4j.server;
00026 
00027 import java.security.Principal;
00028 import java.sql.Timestamp;
00029 import java.util.ArrayList;
00030 
00031 import org.openmobileis.common.util.log.LogManager;
00032 
00033 import sync4j.framework.engine.SyncItem;
00034 import sync4j.framework.engine.SyncItemKey;
00035 import sync4j.framework.engine.SyncItemState;
00036 import sync4j.framework.engine.source.AbstractSyncSource;
00037 import sync4j.framework.engine.source.SyncSource;
00038 import sync4j.framework.engine.source.SyncSourceException;
00039 
00046 public abstract class  FODBSync4JSource extends AbstractSyncSource implements SyncSource {
00047   protected static final String MIMETYPE    = "text/plain";
00048 
00052   public FODBSync4JSource() {
00053     super();
00054     setType(MIMETYPE);
00055   }
00056 
00062   public FODBSync4JSource(String arg0, String arg1, String arg2) {
00063     super(arg0, arg1, arg2);
00064     setType(MIMETYPE);
00065   }
00066 
00070   public FODBSync4JSource(String arg0) {
00071     super(arg0);
00072     setType(MIMETYPE);
00073   }
00074 
00075   /* (non-Javadoc)
00076    * @see sync4j.framework.engine.source.SyncSource#getAllSyncItems(java.security.Principal)
00077    */
00078   public SyncItem[] getAllSyncItems(Principal principal) throws SyncSourceException {
00079     LogManager.traceDebug(0, "Calling getAllSyncItems [" + sourceURI + "]");
00080     return getSyncItems(principal, null, null);
00081   }
00082 
00083   /* (non-Javadoc)
00084    * @see sync4j.framework.engine.source.SyncSource#getDeletedSyncItemKeys(java.security.Principal, java.sql.Timestamp)
00085    */
00086   public SyncItemKey[] getDeletedSyncItemKeys(Principal arg0, Timestamp arg1) throws SyncSourceException {
00087    LogManager.traceDebug(0, "Calling getDeletedSyncItemKeys [" + sourceURI + "]");
00088    return new SyncItemKey[0];
00089   }
00090 
00091   /* (non-Javadoc)
00092    * @see sync4j.framework.engine.source.SyncSource#getDeletedSyncItems(java.security.Principal, java.sql.Timestamp)
00093    */
00094   public SyncItem[] getDeletedSyncItems(Principal principal, Timestamp since) throws SyncSourceException {
00095     LogManager.traceDebug(0, "Calling getDeletedSyncItems [" + sourceURI + "]");
00096 
00097     return getSyncItems(principal, String.valueOf(SyncItemState.DELETED), since);
00098   }
00099 
00100   /* (non-Javadoc)
00101    * @see sync4j.framework.engine.source.SyncSource#getNewSyncItemKeys(java.security.Principal, java.sql.Timestamp)
00102    */
00103   public SyncItemKey[] getNewSyncItemKeys(Principal arg0, Timestamp arg1) throws SyncSourceException {
00104     LogManager.traceDebug(0, "Calling getNewSyncItemKeys [" + sourceURI + "]");
00105     return new SyncItemKey[0];
00106   }
00107 
00108   /* (non-Javadoc)
00109    * @see sync4j.framework.engine.source.SyncSource#getNewSyncItems(java.security.Principal, java.sql.Timestamp)
00110    */
00111   public SyncItem[] getNewSyncItems(Principal principal, Timestamp since) throws SyncSourceException {
00112     LogManager.traceDebug(0, "Calling getNewSyncItemKeys [" + sourceURI + "]");
00113     return getSyncItems(principal, String.valueOf(SyncItemState.NEW), since);
00114   }
00115 
00116   /* (non-Javadoc)
00117    * @see sync4j.framework.engine.source.SyncSource#getSyncItemFromId(java.security.Principal, sync4j.framework.engine.SyncItemKey)
00118    */
00119   public SyncItem getSyncItemFromId(Principal principal, SyncItemKey syncItemKey) throws SyncSourceException {
00120     LogManager.traceDebug(0, "Calling getSyncItemFromId [" + sourceURI + "]");
00121     return getSyncItem(principal, syncItemKey.getKeyAsString());
00122   }
00123 
00124   /* (non-Javadoc)
00125    * @see sync4j.framework.engine.source.SyncSource#getSyncItemsFromIds(java.security.Principal, sync4j.framework.engine.SyncItemKey[])
00126    */
00127   public SyncItem[] getSyncItemsFromIds(Principal principal, SyncItemKey[] syncItemsKeys) throws SyncSourceException {
00128     LogManager.traceDebug(0, "Calling getSyncItemsFromIds [" + sourceURI + "]");
00129     ArrayList listItem = new ArrayList();
00130 
00131     int num = syncItemsKeys.length;
00132     for (int i = 0; i < num; i++) {
00133         listItem.add(getSyncItemFromId(principal, syncItemsKeys[i]));
00134     }
00135 
00136     SyncItem[] toReturn = (SyncItem[]) (listItem.toArray(new SyncItem[
00137         0]));
00138 
00139     return toReturn;
00140   }
00141 
00142   /* (non-Javadoc)
00143    * @see sync4j.framework.engine.source.SyncSource#getUpdatedSyncItems(java.security.Principal, java.sql.Timestamp)
00144    */
00145   public SyncItem[] getUpdatedSyncItems(Principal principal, Timestamp since) throws SyncSourceException {
00146     LogManager.traceDebug(0, "Calling getUpdatedSyncItems [" + sourceURI + "]");
00147     return getSyncItems(principal, String.valueOf(SyncItemState.UPDATED), since);
00148   }
00149 
00150   /* (non-Javadoc)
00151    * @see sync4j.framework.engine.source.SyncSource#removeSyncItem(java.security.Principal, sync4j.framework.engine.SyncItem)
00152    */
00153   public void removeSyncItem(Principal arg0, SyncItem arg1) throws SyncSourceException {
00154     LogManager.traceDebug(0, "Calling removeSyncItem [" + sourceURI + "]");
00155   }
00156 
00157   /* (non-Javadoc)
00158    * @see sync4j.framework.engine.source.SyncSource#removeSyncItems(java.security.Principal, sync4j.framework.engine.SyncItem[])
00159    */
00160   public void removeSyncItems(Principal principal, SyncItem[] syncItems) throws SyncSourceException {
00161     LogManager.traceDebug(0, "Calling removeSyncItem [" + sourceURI + "]");
00162     for (int i = 0; (syncItems != null) && (i < syncItems.length); i++) {
00163       removeSyncItem(principal, syncItems[i]);
00164     }
00165   }
00166 
00167   /* (non-Javadoc)
00168    * @see sync4j.framework.engine.source.SyncSource#setSyncItem(java.security.Principal, sync4j.framework.engine.SyncItem)
00169    */
00170   public SyncItem setSyncItem(Principal arg0, SyncItem arg1) throws SyncSourceException {
00171     LogManager.traceDebug(0, "Calling setSyncItem [" + sourceURI + "]");
00172     return null;
00173   }
00174 
00175   /* (non-Javadoc)
00176    * @see sync4j.framework.engine.source.SyncSource#setSyncItems(java.security.Principal, sync4j.framework.engine.SyncItem[])
00177    */
00178   public SyncItem[] setSyncItems(Principal principal, SyncItem[] syncItems) throws SyncSourceException {
00179     LogManager.traceDebug(0, "Calling setSyncItems [" + sourceURI + "]");
00180     for (int i = 0; (syncItems != null) && (i < syncItems.length); i++) {
00181       setSyncItem(principal, syncItems[i]);
00182   }
00183 
00184   return syncItems;
00185   }
00186 
00187   /* (non-Javadoc)
00188    * @see sync4j.framework.engine.source.SyncSource#getSyncItemFromTwin(java.security.Principal, sync4j.framework.engine.SyncItem)
00189    */
00190   public SyncItem getSyncItemFromTwin(Principal arg0, SyncItem arg1) throws SyncSourceException {
00191     LogManager.traceDebug(0, "Calling getSyncItemFromTwin [" + sourceURI + "]");
00192     return null;
00193   }
00194 
00195   /* (non-Javadoc)
00196    * @see sync4j.framework.engine.source.SyncSource#getSyncItemsFromTwins(java.security.Principal, sync4j.framework.engine.SyncItem[])
00197    */
00198   public SyncItem[] getSyncItemsFromTwins(Principal arg0, SyncItem[] arg1) throws SyncSourceException {
00199     LogManager.traceDebug(0, "Calling getSyncItemsFromTwins [" + sourceURI + "]");
00200     return new SyncItem[0];
00201   }
00202 
00203   /* (non-Javadoc)
00204    * @see sync4j.framework.engine.source.SyncSource#getUpdatedSyncItemKeys(java.security.Principal, java.sql.Timestamp)
00205    */
00206   public SyncItemKey[] getUpdatedSyncItemKeys(Principal arg0, Timestamp arg1) throws SyncSourceException {
00207     LogManager.traceDebug(0, "Calling getUpdatedSyncItemKeys [" + sourceURI + "]");
00208     return new SyncItemKey[0];
00209   }
00210   
00219   protected abstract SyncItem[] getSyncItems(Principal principal,
00220                                           String type,
00221                                           Timestamp since) throws SyncSourceException;
00222 
00230   protected abstract SyncItem getSyncItem(Principal principal, String itemId)
00231           throws SyncSourceException;
00232 
00233 }

Generated on Mon Dec 4 11:03:27 2006 for OpenMobileIS by  doxygen 1.5.1-p1