Project

General

Profile

1 299 higgins
/**
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$'
12
 */
13 526 bojilova
/**************************************************************************
14
Copyright ^?? General Atomics, 1995-1999
15
All Rights Reserved
16
17
This file contains Original Code and/or Modifications of Original Code as
18
defined in and that are subject to the General Atomics Storage Resource
19
Broker Academic and Research Use  License (the 'License'). This license is
20
for academic and research use only. You may not use, copy, modify or
21
distribute SRB for commercial purposes, nor incorporate the SRB into
22
commercial products without the express written permission of General
23
Atomics nor may you distribute SRB to any third party.
24
25
You may not use this software except in compliance with the License. Please
26
obtain a copy of the License at http://www.npaci.edu/DICE/SRB/License and
27
read it before using this file.
28
29
The Original Code and all software distributed under the License are
30
distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
31
EXPRESS OR IMPLIED, AND GENERAL ATOMICS AND THE SAN DIEGO SUPERCOMPUTER
32
CENTER HEREBY DISCLAIM ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION,
33
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
34
NON-INFRINGEMENT OF ANY COPYRIGHT, PATENT , TRADEMARK OR OTHER RIGHTS.
35
GENERAL ATOMICS AND THE SAN DIEGO SUPERCOMPUTER CENTER FURTHER  HAVE NO
36
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCMENTS OR
37
MODIFICATIONS.. Please see the License for the specific language governing
38
rights and limitations under the License."
39
40
Please read the terms of this license carefully. By using the SRB software,
41
you are accepting and agreeing to the terms of this license with General
42
Atomics. If you are agreeing to this license on behalf of a company, or
43
other institution, you represent that you are authorized to bind the
44
company/institution to such a license. If you do not meet this criterion or
45
you do not agree to any of the terms of this license, you are not
46
authorized to use the software.
47
**************************************************************************/
48 299 higgins
49
 /* Note: Based on Java code originally produced at SDSC
50
 * Copyright   1999   The Regents of the University of California
51
 * All Rights Reserved
52
 */
53
54
/**
55
 * SrbJavaGlue
56
 *
57
 * Implementation of RMI Interface
58
 *
59
 * @version 1.1 6/8/00
60
 * @author Dan Higgins - NCEAS
61 526 bojilova
 * @version 1.0 10/23/97
62
 * @author John Moreland
63 299 higgins
 */
64
65
 import java.rmi.*;
66
 import java.rmi.server.*;
67
 import java.io.*;   //DFH 6/8/00
68
69
70
public class SrbJavaGlue extends UnicastRemoteObject implements SrbJavaGlueInterface
71 526 bojilova
72 299 higgins
{
73
 byte[] ByteData;
74
 String FileName;
75
76
	// JNI (Java Native Interface) Glue Routines for the SRB client library.
77
78
public SrbJavaGlue() throws RemoteException {
79
                  super();
80
              }
81
82 526 bojilova
	public native int clConnectJ( String host, String port, String auth,
83
	 String user, String domain );
84 299 higgins
85 526 bojilova
	public native int srbListCollectJ( int conn, int catType,
86 299 higgins
		String collectionName, String flag, int types[] );
87
88 526 bojilova
	public native String getFileListItem( int index );
89 299 higgins
90 526 bojilova
	public native int clFinishJ( int conn );
91 299 higgins
92 526 bojilova
	public native int srbObjCopyNewJ( String srcDir, String srcFile,
93 299 higgins
		String dstDir, String dstFile, String dstRes );
94
95 526 bojilova
	public native int srbListResourceJ( int bs );
96 299 higgins
97 526 bojilova
	public native String getResListItem( int index );
98 299 higgins
99 526 bojilova
	public native String getDefCollection();
100 299 higgins
101 526 bojilova
	public native String getDefResource();
102 299 higgins
103 526 bojilova
	public native String getUser();
104 299 higgins
105 526 bojilova
	public native String getDomain();
106 299 higgins
107 526 bojilova
	public native String getLocalCacheDir();
108 299 higgins
109 526 bojilova
	public native int srbObjReplicateJ(int conn, int catType,
110 299 higgins
	  String objID, String replNum, String collection, String resource);
111
112 526 bojilova
	public native int srbCollReplicateJ(int conn, int catType,
113 299 higgins
	  String collection, String resource);
114
115 526 bojilova
	public native int queryDataInCollJ (int conn, int catType,
116 299 higgins
	  String parColl);
117
118 526 bojilova
	public native int queryDataJ (int conn, int catType, String objID,
119 299 higgins
	  String parColl);
120
121 526 bojilova
	public native int querySubCollInCollJ (int conn, int catType,
122 299 higgins
	  String parColl);
123
124 526 bojilova
	public native String getDataResultJ( int metaIndex, int rowIndex );
125 299 higgins
126 526 bojilova
	public native String getCollResultJ( int metaIndex, int rowIndex );
127 299 higgins
128 526 bojilova
	public native String getGenQueResultJ( int metaIndex, int rowIndex );
129 299 higgins
130 526 bojilova
	public native int getNCollAttriJ ();
131 299 higgins
132 526 bojilova
	public native int getNDataAttriJ ();
133 299 higgins
134 526 bojilova
	public native int srbObjUnlinkJ (int conn,  int catType,
135 299 higgins
	  String objID, String replNum, String parColl);
136
137 526 bojilova
	public native int srbCreateCollectJ (int conn,  int catType,
138 299 higgins
	  String parColl, String newColl);
139
140 526 bojilova
	public native int srbModifyDatasetMetaDJ (int conn,  int catType,
141 299 higgins
	  String objID, String collection,
142
	   String newValue1, String newValue2, int retractionType);
143 526 bojilova
	public native int srbModifyCollectMetaDJ (int conn,  int catType,
144 299 higgins
	  String collection, String newValue1, String newValue2,
145
	   String newValue3, int retractionType);
146 526 bojilova
	public native int importToOldObjJ (int conn,  int catType,
147 299 higgins
	  String objID, String replNum, String parColl, String resource,
148
	   String localFile, String container);
149
150 526 bojilova
	public native int importToNewObjJ (int conn,  int catType,
151 299 higgins
	 String objID, String parColl, String resource, String localFile,
152
	  String container);
153
154 526 bojilova
	public native int importDirJ (int conn,  int catType,
155 299 higgins
	  String parColl, String resource, String localDir, String container);
156
157 526 bojilova
	public native int srbRmCollJ (int conn, int catType, String parColl);
158 299 higgins
159 526 bojilova
	public native int srbUnregCollJ (int conn, int catType, String parColl);
160 299 higgins
161 526 bojilova
	public native int copyToOldObjJ (int conn,  int catType,
162 299 higgins
	 String objID, String replNum, String srcColl, String targObj,
163
	  String targReplNum, String targColl, String targResource,
164
	   String container);
165
166 526 bojilova
	public native int copyDataToCollJ (int conn,  int catType,
167 299 higgins
	 String objID, String replNum, String srcColl,
168
	  String dataType, String size, String targColl, String targResource,
169
	   String container);
170
171 526 bojilova
	public native int copyCollToCollJ (int conn, int catType,
172 299 higgins
	 String srcColl, String targColl, String targResource,
173
	  String container);
174
175 526 bojilova
	public native int exportToFileJ(int conn, int catType,
176 299 higgins
	 String objID, String replNum, String srcColl,
177
	  String targFile, int forceFlag);
178
179 526 bojilova
	public native int exportToDirJ(int conn, int catType,
180 299 higgins
	 String objID, String replNum, String srcColl,
181
	  String targDir);
182
183 526 bojilova
	public native int exportCollToDirJ(int conn, int catType,
184 299 higgins
	 String srcColl, String targDir);
185
186 526 bojilova
	public native int srbGenQuery (int conn, int catType,
187 299 higgins
	 String[] qval, int qvalInx[], int selVal[]);
188
189 526 bojilova
        public native int srbRegisterDatasetJ(int conn, int catType,
190 299 higgins
         String objID, String dataType, String resource, String collection,
191
	  String pathName, int dataSize);
192
193 526 bojilova
	public native int srbUnregisterDatasetJ (int conn, int catType,
194 299 higgins
	 String objID, String replNum, String collection);
195
196 526 bojilova
        public native int srbRegisterDirJ (int conn, int catType,
197 299 higgins
	 String srcDirPath, String targColl, String resource);
198
199 526 bojilova
        public native int getMoreDataRowsJ (int conn, int catType);
200 299 higgins
201 526 bojilova
        public native int getMoreCollRowsJ (int conn, int catType);
202 299 higgins
203 526 bojilova
        public native int getMoreGenQueRowsJ (int conn, int catType);
204 299 higgins
205 526 bojilova
	public native int chmodInCollJ (int conn, int catType,
206 299 higgins
	 String collection, String user, String domain, String mode);
207
208 526 bojilova
	public native int ingestUserJ (int conn, int catType,
209 299 higgins
	 String userName, String passwd, String domain,
210
	  String userType, String userAddr, String userPhone, String userEmail,
211
	   String parentColl);
212
213 526 bojilova
	public native int ingestGroupJ (int conn, int catType,
214 299 higgins
	 String groupName, String passwd,
215
	  String groupAddr, String groupPhone, String groupEMail);
216
217 526 bojilova
	public native int ingestLocJ (int conn, int catType,
218
	 String locName, String fullAddr, String parentLoc,
219
	  String serverUser, String serverUserDomain);
220 299 higgins
221 526 bojilova
        public native int ingestResourceJ (int conn, int catType,
222
         String rescName, String rescType, String location, String phyPath,
223
	  String rscClass, int size);
224 299 higgins
225 526 bojilova
        public native int ingestLogRescJ (int conn, int catType,
226 299 higgins
         String logRescName, String phyResc, String phyPath);
227
228 526 bojilova
        public native int addLogRescJ (int conn, int catType,
229 299 higgins
         String logResc, String phyResc, String phyPath);
230
231 526 bojilova
        public native int modifyUserJ (int conn, int catType,
232 299 higgins
         int modOpr, String userName, String domain, String modValue);
233
234 526 bojilova
	public native int containerCreateJ (int conn, int catType,
235 299 higgins
	 String contName, String dataType, String logResc, int size);
236
237 526 bojilova
	public native int containerDeleteJ (int conn, int catType,
238 299 higgins
	 String contName, int forceFlag);
239
240
        public native int containerSyncJ (int conn, int catType,
241
         String contName, int purgeFlag);
242
243
 //DFH 6/8/00
244 526 bojilova
 public byte[] getByteData(String name) {
245 299 higgins
    File tmp = new File("./tmp/");
246
    if (!tmp.exists()) { tmp.mkdir();}
247
248
    File temp = new File("./tmp/"+name);    // looks for file in tmp dir under current directory
249
    if (temp.exists()) {
250
        ByteData = new byte[(int)temp.length()];
251
        try{
252
            FileInputStream fis = new FileInputStream(temp);
253
            fis.read(ByteData);
254
            fis.close();
255
        }
256
        catch (Exception e) {;}
257
        temp.delete();
258
    }
259
    else {
260
        ByteData = new byte[0];
261
    }
262
    return ByteData;
263
 }
264
265 526 bojilova
 public void setByteData(String name, byte[] in) {
266 299 higgins
    ByteData = in;
267
    FileName = name;
268
    File tmp = new File("./tmp/");
269
    if (!tmp.exists()) { tmp.mkdir();}
270
271
    File temp = new File("./tmp/"+name);
272
        try{
273
            FileOutputStream fos = new FileOutputStream(temp);
274
            fos.write(ByteData);
275
            fos.close();
276
        }
277
        catch (Exception e) {;}
278
 }
279
280 526 bojilova
 public void clearTmpFiles() {
281 299 higgins
    File temp = new File("./tmp/"+FileName);
282
    if (temp.exists()) { temp.delete(); }
283
 }
284
285
 // --
286
287
	static
288
	{
289
		System.loadLibrary( "SrbJavaGlue" );
290 526 bojilova
291 299 higgins
	}
292
293
	    public static void main(String[] args) {
294
                  if (System.getSecurityManager() == null) {
295
                      System.setSecurityManager(new RMISecurityManager());
296
                  }
297
                  String name = "//localhost/SrbJavaGlue";
298
                  if (args.length==1) name = "//localhost" + ":"+args[0]+"/SrbJavaGlue";
299
                  try {
300
                      SrbJavaGlue engine = new SrbJavaGlue();
301
                      Naming.rebind(name, engine);
302
                      System.out.println("SrbJavaGlue bound");
303
                  } catch (Exception e) {
304
                      System.err.println("SrbJavaGlue exception: " +
305
                                         e.getMessage());
306
                      e.printStackTrace();
307
                  }
308
              }
309
310
311
}