View Javadoc

1   package fr.in2p3.jsaga.impl.namespace;
2   
3   import fr.in2p3.jsaga.Base;
4   import fr.in2p3.jsaga.adaptor.data.DataAdaptor;
5   import fr.in2p3.jsaga.adaptor.data.read.FileReader;
6   import fr.in2p3.jsaga.adaptor.data.read.LogicalReader;
7   import fr.in2p3.jsaga.adaptor.data.write.FileWriter;
8   import fr.in2p3.jsaga.adaptor.data.write.LogicalWriter;
9   import fr.in2p3.jsaga.engine.factories.DataAdaptorFactory;
10  import fr.in2p3.jsaga.impl.file.DirectoryImpl;
11  import fr.in2p3.jsaga.impl.file.FileImpl;
12  import fr.in2p3.jsaga.impl.logicalfile.LogicalDirectoryImpl;
13  import fr.in2p3.jsaga.impl.logicalfile.LogicalFileImpl;
14  import fr.in2p3.jsaga.sync.namespace.SyncNSFactory;
15  import org.ogf.saga.error.*;
16  import org.ogf.saga.namespace.*;
17  import org.ogf.saga.session.Session;
18  import org.ogf.saga.url.URL;
19  
20  /* ***************************************************
21   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
22   * ***             http://cc.in2p3.fr/             ***
23   * ***************************************************
24   * File:   AbstractSyncNSFactoryImpl
25   * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
26   * Date:   29 mai 2009
27   * ***************************************************
28   * Description:                                      */
29  /**
30   *
31   */
32  public abstract class AbstractSyncNSFactoryImpl extends NSFactory implements SyncNSFactory {
33      protected static final String JSAGA_FACTORY = Base.getSagaFactory();
34  
35      private static final boolean PLUGIN_TYPE = DataAdaptorFactory.PHYSICAL;
36      private DataAdaptorFactory m_adaptorFactory;
37  
38      public AbstractSyncNSFactoryImpl(DataAdaptorFactory adaptorFactory) {
39          m_adaptorFactory = adaptorFactory;
40      }
41  
42      /**
43       * Notes:
44       * <br> - do not check existance of entry if flag <code>JSAGAFlags.BYPASSEXIST</code> is set.
45       * <br> - do not throw BadParameterException exception if entry is a directory, create a NSDirectory object instead.
46       */
47      public NSEntry doCreateNSEntrySync(Session session, URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
48          if (name.getPath().endsWith("/")) {
49              return this.doCreateNSDirectorySync(session, name, flags);
50          } else {
51              return this.doCreateNSFileSync(session, name, flags);
52          }
53      }
54  
55      /**
56       * Notes:
57       * <br> - do not check existance of entry if flag <code>JSAGAFlags.BYPASSEXIST</code> is set.
58       * <br> - support the CREATEPARENTS flag (from specification of method makeDir).
59       */
60      public NSDirectory doCreateNSDirectorySync(Session session, URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
61          DataAdaptor adaptor = m_adaptorFactory.getDataAdaptorAndConnect(name, session, PLUGIN_TYPE);
62          boolean isPhysical = adaptor instanceof FileReader || adaptor instanceof FileWriter;
63          boolean isLogical = adaptor instanceof LogicalReader || adaptor instanceof LogicalWriter;
64          if (isPhysical || !isLogical) {
65              return new DirectoryImpl(session, name, adaptor, flags);
66          } else {
67              return new LogicalDirectoryImpl(session, name, adaptor, flags);
68          }
69      }
70  
71      /**
72       * Notes:
73       * <br> - do not check existance of entry if flag <code>JSAGAFlags.BYPASSEXIST</code> is set.
74       * <br> - support the CREATEPARENTS flag (from specification of method makeDir).
75       */
76      private NSEntry doCreateNSFileSync(Session session, URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
77          DataAdaptor adaptor = m_adaptorFactory.getDataAdaptorAndConnect(name, session, PLUGIN_TYPE);
78          boolean isPhysical = adaptor instanceof FileReader || adaptor instanceof FileWriter;
79          boolean isLogical = adaptor instanceof LogicalReader || adaptor instanceof LogicalWriter;
80          if (isPhysical || !isLogical) {
81              return new FileImpl(session, name, adaptor, flags);
82          } else {
83              return new LogicalFileImpl(session, name, adaptor, flags);
84          }
85      }
86  }