Project

General

Profile

1
/**
2
 *  Name: SrbJavaGlue.java
3
 *  Institution: National Center for Ecological Analysis and Synthesis
4
 *  Copyright: 2000 The Regents of the University of California and
5
 *         National Center for Ecological Analysis and Synthesis,
6
 *         University of California, Santa Barbara 2000.
7
 *         All rights reserved.
8
 *
9
 *  Authors: Dan Higgins, John Moreland
10
 *
11
 *     Version: '$Id: SrbJavaGlue.java 299 2000-07-27 17:14:36Z higgins $'
12
 */
13

    
14
 /* Note: Based on Java code originally produced at SDSC
15
 * Copyright   1999   The Regents of the University of California
16
 * All Rights Reserved
17
 */
18

    
19
/**
20
 * SrbJavaGlue
21
 *
22
 * Implementation of RMI Interface
23
 *
24
 * @version 1.1 6/8/00
25
 * @author Dan Higgins - NCEAS
26
 */
27
 
28
 import java.rmi.*;
29
 import java.rmi.server.*;
30
 import java.io.*;   //DFH 6/8/00
31
 
32
 
33
public class SrbJavaGlue extends UnicastRemoteObject implements SrbJavaGlueInterface
34
{
35
 byte[] ByteData;
36
 String FileName;
37
 boolean previouslyConnected = false;
38
    
39
	// JNI (Java Native Interface) Glue Routines for the SRB client library.
40

    
41
public SrbJavaGlue() throws RemoteException {
42
                  super();
43
              }
44

    
45
	public synchronized native int clConnectJ( String host, String port, String auth );
46
	
47
	public synchronized int rmiConnectJ(String host, String port, String auth, String user ) {
48
	    if (previouslyConnected) {
49
	        return -1;
50
	    }
51
	    else {
52
	        writeMdasEnv(user);
53
	        int res = clConnectJ(host, port, auth );
54
	        if (res>0) {previouslyConnected = true;}
55
	        return res;
56
	        
57
	    }
58
	}
59

    
60
	public synchronized native int srbListCollectJ( int conn, int catType,
61
		String collectionName, String flag, int types[] );
62

    
63
	public synchronized native String getFileListItem( int index );
64

    
65
	public synchronized native int clFinishJ( int conn );
66
	
67
	public synchronized int rmiFinishJ(int conn) {
68
	    Reset();
69
	    return clFinishJ(conn);
70
	}
71

    
72
	public synchronized native int srbObjCopyNewJ( String srcDir, String srcFile,
73
		String dstDir, String dstFile, String dstRes );
74

    
75
	public synchronized native int srbListResourceJ( int bs );
76

    
77
	public synchronized native String getResListItem( int index );
78

    
79
	public synchronized native String getDefCollection();
80

    
81
	public synchronized native String getDefResource();
82

    
83
	public synchronized native String getUser();
84

    
85
	public synchronized native String getDomain();
86

    
87
	public synchronized native String getLocalCacheDir();
88

    
89
	public synchronized native int srbObjReplicateJ(int conn, int catType,
90
	  String objID, String replNum, String collection, String resource);
91

    
92
	public synchronized native int srbCollReplicateJ(int conn, int catType,
93
	  String collection, String resource);
94

    
95
	public synchronized native int queryDataInCollJ (int conn, int catType, 
96
	  String parColl);
97

    
98
	public synchronized native int queryDataJ (int conn, int catType, String objID,
99
	  String parColl);
100

    
101
	public synchronized native int querySubCollInCollJ (int conn, int catType, 
102
	  String parColl);
103

    
104
	public synchronized native String getDataResultJ( int metaIndex, int rowIndex );
105

    
106
	public synchronized native String getCollResultJ( int metaIndex, int rowIndex );
107

    
108
	public synchronized native String getGenQueResultJ( int metaIndex, int rowIndex );
109

    
110
	public synchronized native int getNCollAttriJ ();
111

    
112
	public synchronized native int getNDataAttriJ ();
113

    
114
	public synchronized native int srbObjUnlinkJ (int conn,  int catType, 
115
	  String objID, String replNum, String parColl);
116

    
117
	public synchronized native int srbCreateCollectJ (int conn,  int catType, 
118
	  String parColl, String newColl);
119

    
120
	public synchronized native int srbModifyDatasetMetaDJ (int conn,  int catType,
121
	  String objID, String collection, 
122
	   String newValue1, String newValue2, int retractionType);
123
	   
124
	public synchronized native int srbModifyCollectMetaDJ (int conn,  int catType,
125
	  String collection, String newValue1, String newValue2, 
126
	   String newValue3, int retractionType);
127
	   
128
	public synchronized native int importToOldObjJ (int conn,  int catType, 
129
	  String objID, String replNum, String parColl, String resource,
130
	   String localFile, String container);
131

    
132
	public synchronized native int importToNewObjJ (int conn,  int catType, 
133
	 String objID, String parColl, String resource, String localFile,
134
	  String container);
135

    
136
	public synchronized native int importDirJ (int conn,  int catType, 
137
	  String parColl, String resource, String localDir, String container);
138

    
139
	public synchronized native int srbRmCollJ (int conn, int catType, String parColl);
140

    
141
	public synchronized native int srbUnregCollJ (int conn, int catType, String parColl);
142

    
143
	public synchronized native int copyToOldObjJ (int conn,  int catType, 
144
	 String objID, String replNum, String srcColl, String targObj, 
145
	  String targReplNum, String targColl, String targResource, 
146
	   String container);
147

    
148
	public synchronized native int copyDataToCollJ (int conn,  int catType, 
149
	 String objID, String replNum, String srcColl,
150
	  String dataType, String size, String targColl, String targResource,
151
	   String container);
152

    
153
	public synchronized native int copyCollToCollJ (int conn, int catType, 
154
	 String srcColl, String targColl, String targResource, 
155
	  String container);
156

    
157
	public synchronized native int exportToFileJ(int conn, int catType,
158
	 String objID, String replNum, String srcColl,
159
	  String targFile, int forceFlag);
160

    
161
	public synchronized native int exportToDirJ(int conn, int catType,
162
	 String objID, String replNum, String srcColl,
163
	  String targDir);
164

    
165
	public synchronized native int exportCollToDirJ(int conn, int catType,
166
	 String srcColl, String targDir);
167

    
168
	public synchronized native int srbGenQuery (int conn, int catType,
169
	 String[] qval, int qvalInx[], int selVal[]);
170
	
171
        public synchronized native int srbRegisterDatasetJ(int conn, int catType,
172
         String objID, String dataType, String resource, String collection,
173
	  String pathName, int dataSize);
174

    
175
	public synchronized native int srbUnregisterDatasetJ (int conn, int catType,
176
	 String objID, String replNum, String collection);
177

    
178
        public synchronized native int srbRegisterDirJ (int conn, int catType,
179
	 String srcDirPath, String targColl, String resource);
180

    
181
        public synchronized native int getMoreDataRowsJ (int conn, int catType);
182

    
183
        public synchronized native int getMoreCollRowsJ (int conn, int catType);
184

    
185
        public synchronized native int getMoreGenQueRowsJ (int conn, int catType);
186
	
187
	public synchronized native int chmodInCollJ (int conn, int catType, 
188
	 String collection, String user, String domain, String mode);
189

    
190
	public synchronized native int ingestUserJ (int conn, int catType, 
191
	 String userName, String passwd, String domain, 
192
	  String userType, String userAddr, String userPhone, String userEmail,
193
	   String parentColl);
194

    
195
	public synchronized native int ingestGroupJ (int conn, int catType, 
196
	 String groupName, String passwd,
197
	  String groupAddr, String groupPhone, String groupEMail);
198

    
199
	public synchronized native int ingestLocJ (int conn, int catType, 
200
	 String locName, String fullAddr, String parentLoc); 
201

    
202
        public synchronized native int ingestResourceJ (int conn, int catType,
203
         String rescName, String rescType, String location, String phyPath);
204

    
205
        public synchronized native int ingestLogRescJ (int conn, int catType,
206
         String logRescName, String phyResc, String phyPath);
207

    
208
        public synchronized native int addLogRescJ (int conn, int catType,
209
         String logResc, String phyResc, String phyPath);
210

    
211
        public synchronized native int modifyUserJ (int conn, int catType,
212
         int modOpr, String userName, String domain, String modValue);
213

    
214
	public synchronized native int containerCreateJ (int conn, int catType,
215
	 String contName, String dataType, String logResc, int size);
216

    
217
	public synchronized native int containerDeleteJ (int conn, int catType,
218
	 String contName, int forceFlag);
219

    
220
        public native int containerSyncJ (int conn, int catType,
221
         String contName, int purgeFlag);
222
         
223
 //DFH 6/8/00
224
 public synchronized byte[] getByteData(String name) {
225
    File tmp = new File("./tmp/");
226
    if (!tmp.exists()) { tmp.mkdir();}
227
  
228
    File temp = new File("./tmp/"+name);    // looks for file in tmp dir under current directory
229
    if (temp.exists()) {
230
        ByteData = new byte[(int)temp.length()];
231
        try{
232
            FileInputStream fis = new FileInputStream(temp);
233
            fis.read(ByteData);
234
            fis.close();
235
        }
236
        catch (Exception e) {;}
237
        temp.delete();
238
    }
239
    else {
240
        ByteData = new byte[0];   
241
    }
242
    return ByteData;
243
 } 
244
 
245
 public synchronized void setByteData(String name, byte[] in) {
246
    ByteData = in;
247
    FileName = name;
248
    File tmp = new File("./tmp/");
249
    if (!tmp.exists()) { tmp.mkdir();}
250

    
251
    File temp = new File("./tmp/"+name);
252
        try{
253
            FileOutputStream fos = new FileOutputStream(temp);
254
            fos.write(ByteData);
255
            fos.close();
256
        }
257
        catch (Exception e) {;}
258
 }
259
 
260
 public synchronized void clearTmpFiles() {
261
    File temp = new File("./tmp/"+FileName);
262
    if (temp.exists()) { temp.delete(); }
263
 }
264
 
265
 public synchronized void Reset() {
266
      try{
267
        String[] cmdarray = {"java", "-Djava.security.policy=mypolicy", "SrbJavaGlue"};
268
	    Runtime.getRuntime().exec(cmdarray);
269
        Runtime.getRuntime().exit(0);
270
      }
271
      catch (Exception e) {System.out.println("Could not run exec and exit"); }
272
 }
273
 
274
 public synchronized void writeMdasEnv(String username) {
275
	   try{
276
	    String userhome = System.getProperty("user.home");
277
	    File file = new File(userhome+"/.srb/.MdasEnv");
278
		FileWriter fw = new FileWriter(file);
279
		StringBuffer env = new StringBuffer();
280
		env.append("mdasCollectionHome '/home/higgins.bioinfo'\n");
281
		env.append("mdasDomainHome 'bioinfo'\n");
282
		env.append("srbUser '"+username+"'\n");
283
		env.append("srbHost 'penelope.nceas.ucsb.edu'\n");
284
		env.append("defaultResource 'test-unix-nceas'\n");
285
		env.append("SEA_OPT '0'");
286
		StringReader sr = new StringReader(env.toString());
287
		int c;
288
		while ((c = sr.read()) != -1)
289
                 {    
290
                    fw.write(c);
291
                 }
292
		fw.close();
293
		sr.close();
294
	   }
295
	   catch (Exception e) {}  
296
 }
297
 
298
 // --
299

    
300
	static
301
	{
302
		System.loadLibrary( "SrbJavaGlue" );
303
	}
304
	
305
	    public static void main(String[] args) {
306
                  if (System.getSecurityManager() == null) {
307
                      System.setSecurityManager(new RMISecurityManager());
308
                  }
309
                  String name = "//localhost/SrbJavaGlue";
310
                  if (args.length==1) name = "//localhost" + ":"+args[0]+"/SrbJavaGlue";
311
                  try {
312
                      SrbJavaGlue engine = new SrbJavaGlue();
313
                      Naming.rebind(name, engine);
314
                      System.out.println("SrbJavaGlue bound");
315
                  } catch (Exception e) {
316
                      System.err.println("SrbJavaGlue exception: " + 
317
                                         e.getMessage());
318
                      e.printStackTrace();
319
                  }
320
              }
321
	
322
	
323
}
324

    
(6-6/11)