Skip to content

Commit 4681964

Browse files
author
Kannan Goundan
committed
Put "Dbx" prefix on namespace classes (Files -> DbxFiles, Users -> DbxUsers)
Also be uniform about referring to classes via "namespace.class". Before, we were sometimes doing that and sometimes importing the class.
1 parent 562da33 commit 4681964

File tree

6 files changed

+53
-54
lines changed

6 files changed

+53
-54
lines changed

ChangeLog.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- Put "Dbx" prefix on namespace classes (Files -> DbxFiles, etc.)
2+
13
---------------------------------------------
24
2.0-beta-1 (2015-10-13)
35
- Add support for Dropbox API v2. Moved API v1-specific classes to

examples/account-info/src/com/dropbox/core/examples/account_info/Main.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.dropbox.core.examples.account_info;
22

3-
import com.dropbox.core.*;
3+
import com.dropbox.core.DbxAuthInfo;
4+
import com.dropbox.core.DbxException;
5+
import com.dropbox.core.DbxRequestConfig;
6+
import com.dropbox.core.DbxWebAuth;
47
import com.dropbox.core.json.JsonReader;
58
import com.dropbox.core.v2.DbxClientV2;
6-
import com.dropbox.core.v2.Users;
9+
import com.dropbox.core.v2.DbxUsers;
710

811
import java.io.IOException;
912
import java.util.Locale;
@@ -57,8 +60,8 @@ public static void main(String[] args)
5760
DbxClientV2 dbxClient = new DbxClientV2(requestConfig, authInfo.accessToken, authInfo.host);
5861

5962
// Make the /account/info API call.
60-
Users.FullAccount dbxAccountInfo;
61-
Users.SpaceUsage dbxSpaceUsage;
63+
DbxUsers.FullAccount dbxAccountInfo;
64+
DbxUsers.SpaceUsage dbxSpaceUsage;
6265
try {
6366
dbxAccountInfo = dbxClient.users.getCurrentAccount();
6467
}

examples/upload-file/src/com/dropbox/core/examples/upload_file/Main.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.dropbox.core.DbxWebAuth;
77
import com.dropbox.core.json.JsonReader;
88
import com.dropbox.core.v2.DbxClientV2;
9+
import com.dropbox.core.v2.DbxFiles;
910
import com.dropbox.core.v2.DbxPathV2;
10-
import com.dropbox.core.v2.Files;
1111

1212
import java.io.FileInputStream;
1313
import java.io.IOException;
@@ -82,7 +82,7 @@ private static int _main(String[] args)
8282
DbxClientV2 dbxClient = new DbxClientV2(requestConfig, authInfo.accessToken, authInfo.host);
8383

8484
// Make the API call to upload the file.
85-
Files.FileMetadata metadata;
85+
DbxFiles.FileMetadata metadata;
8686
try {
8787
InputStream in = new FileInputStream(localPath);
8888
try {
@@ -91,7 +91,7 @@ private static int _main(String[] args)
9191
in.close();
9292
}
9393
}
94-
catch (Files.UploadException ex) {
94+
catch (DbxFiles.UploadException ex) {
9595
System.out.println("Error uploading to Dropbox: " + ex.getMessage());
9696
return 1;
9797
}

examples/web-file-browser/src/com/dropbox/core/examples/web_file_browser/DropboxBrowse.java

+18-19
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import com.dropbox.core.util.IOUtil;
88
import com.dropbox.core.util.StringUtil;
99
import com.dropbox.core.v2.DbxClientV2;
10+
import com.dropbox.core.v2.DbxFiles;
1011
import com.dropbox.core.v2.DbxPathV2;
11-
import com.dropbox.core.v2.Files;
1212

1313
import javax.servlet.ServletException;
1414
import javax.servlet.http.HttpServletRequest;
@@ -47,7 +47,7 @@ private DbxClientV2 requireDbxClient(HttpServletRequest request, HttpServletResp
4747
common.dbxAppInfo.host);
4848
}
4949

50-
private boolean checkPathError(HttpServletResponse response, String path, Files.LookupError le)
50+
private boolean checkPathError(HttpServletResponse response, String path, DbxFiles.LookupError le)
5151
throws IOException
5252
{
5353
switch (le.tag) {
@@ -62,24 +62,23 @@ private void renderFolder(HttpServletResponse response, User user, DbxClientV2 d
6262
throws IOException
6363
{
6464
// Get the folder listing from Dropbox.
65-
TreeMap<String,Files.Metadata> children = new TreeMap<String,Files.Metadata>();
65+
TreeMap<String,DbxFiles.Metadata> children = new TreeMap<String,DbxFiles.Metadata>();
6666

67-
Files.ListFolderResult result;
68-
outer:
67+
DbxFiles.ListFolderResult result;
6968
try {
7069
try {
7170
result = dbxClient.files.listFolder(path);
7271
}
73-
catch (Files.ListFolderException ex) {
74-
if (ex.errorValue.tag == Files.ListFolderError.Tag.path) {
72+
catch (DbxFiles.ListFolderException ex) {
73+
if (ex.errorValue.tag == DbxFiles.ListFolderError.Tag.path) {
7574
if (checkPathError(response, path, ex.errorValue.getPath())) return;
7675
}
7776
throw ex;
7877
}
7978

8079
while (true) {
81-
for (Files.Metadata md : result.entries) {
82-
if (md instanceof Files.DeletedMetadata) {
80+
for (DbxFiles.Metadata md : result.entries) {
81+
if (md instanceof DbxFiles.DeletedMetadata) {
8382
children.remove(md.pathLower);
8483
} else {
8584
children.put(md.pathLower, md);
@@ -91,8 +90,8 @@ private void renderFolder(HttpServletResponse response, User user, DbxClientV2 d
9190
try {
9291
result = dbxClient.files.listFolderContinue(result.cursor);
9392
}
94-
catch (Files.ListFolderContinueException ex) {
95-
if (ex.errorValue.tag == Files.ListFolderContinueError.Tag.path) {
93+
catch (DbxFiles.ListFolderContinueException ex) {
94+
if (ex.errorValue.tag == DbxFiles.ListFolderContinueError.Tag.path) {
9695
if (checkPathError(response, path, ex.errorValue.getPath())) return;
9796
}
9897
throw ex;
@@ -126,7 +125,7 @@ private void renderFolder(HttpServletResponse response, User user, DbxClientV2 d
126125
out.println("</form>");
127126
// Listing of folder contents.
128127
out.println("<ul>");
129-
for (Files.Metadata child : children.values()) {
128+
for (DbxFiles.Metadata child : children.values()) {
130129
String href = "/browse?path=" + DbxRequestUtil.encodeUrlParam(child.pathLower);
131130
out.println(" <li><a href='" + escapeHtml4(href) + "'>" + escapeHtml4(child.name) + "</a></li>");
132131
}
@@ -138,7 +137,7 @@ private void renderFolder(HttpServletResponse response, User user, DbxClientV2 d
138137
out.flush();
139138
}
140139

141-
private void renderFile(HttpServletResponse response, String path, Files.FileMetadata f)
140+
private void renderFile(HttpServletResponse response, String path, DbxFiles.FileMetadata f)
142141
throws IOException
143142
{
144143
FormProtection fp = FormProtection.start(response);
@@ -192,14 +191,14 @@ public void doBrowse(HttpServletRequest request, HttpServletResponse response)
192191
response.sendError(400, "Invalid path: " + jq(path) + ": " + pathError);
193192
return;
194193
}
195-
Files.Metadata metadata;
194+
DbxFiles.Metadata metadata;
196195
try {
197196
metadata = dbxClient.files.getMetadata(path);
198197
}
199-
catch (Files.GetMetadataException ex) {
198+
catch (DbxFiles.GetMetadataException ex) {
200199
switch (ex.errorValue.tag) {
201200
case path:
202-
Files.LookupError le = ex.errorValue.getPath();
201+
DbxFiles.LookupError le = ex.errorValue.getPath();
203202
switch (le.tag) {
204203
case notFound:
205204
response.sendError(400, "Path doesn't exist on Dropbox: " + jq(path));
@@ -215,11 +214,11 @@ public void doBrowse(HttpServletRequest request, HttpServletResponse response)
215214
}
216215

217216
path = DbxPathV2.getParent(path) + "/" + metadata.name;
218-
if (metadata instanceof Files.FolderMetadata) {
217+
if (metadata instanceof DbxFiles.FolderMetadata) {
219218
renderFolder(response, user, dbxClient, path);
220219
}
221220
else {
222-
renderFile(response, path, (Files.FileMetadata) metadata);
221+
renderFile(response, path, (DbxFiles.FileMetadata) metadata);
223222
}
224223
}
225224
}
@@ -262,7 +261,7 @@ public void doUpload(HttpServletRequest request, HttpServletResponse response)
262261

263262
// Upload file to Dropbox
264263
String fullTargetPath = targetFolder + "/" + fileName;
265-
Files.FileMetadata metadata;
264+
DbxFiles.FileMetadata metadata;
266265
try {
267266
metadata = dbxClient.files.uploadBuilder(fullTargetPath).run(filePart.getInputStream());
268267
}

generator/java.babelg.py

+17-22
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,17 @@ def maptype(namespace, data_type, boxed=True):
136136
if data_type.name in type_map:
137137
return type_map[data_type.name]
138138
assert is_composite_type(data_type), data_type
139-
prefix = ""
140-
if data_type.namespace != namespace:
141-
prefix = classname(data_type.namespace.name) + '.'
142-
return prefix + classname(data_type.name)
139+
return type_ref(namespace, data_type)
140+
141+
142+
def type_ref(namespace, dt):
143+
ref = classname(dt.name)
144+
if dt.namespace != namespace:
145+
ref = namespace_ref(dt.namespace) + '.' + ref
146+
return ref
147+
148+
def namespace_ref(ns):
149+
return "Dbx" + classname(ns.name)
143150

144151

145152
def mapreader(namespace, data_type):
@@ -301,7 +308,7 @@ def generate(self, api):
301308

302309
def generate_namespace_wrapper(self, namespace, package_relpath, package_name):
303310
out = self.emit
304-
class_name = classname(namespace.name)
311+
class_name = namespace_ref(namespace)
305312
file_name = os.path.join(package_relpath, class_name + '.java')
306313
with self.output_to_relative_path(file_name):
307314
out('/* DO NOT EDIT */')
@@ -325,18 +332,6 @@ def generate_namespace_wrapper(self, namespace, package_relpath, package_name):
325332
out('import com.dropbox.core.json.JsonReadException;')
326333
out('import com.dropbox.core.json.JsonWriter;')
327334

328-
namespace_data_types = namespace.get_route_io_data_types()
329-
if namespace_data_types:
330-
to_import = []
331-
for data_type in namespace_data_types:
332-
if data_type.namespace != namespace:
333-
to_import.append((data_type.namespace.name, data_type.name))
334-
if to_import:
335-
out('')
336-
for ns_name, dt_name in to_import:
337-
out('import %s.%s.%s;' %
338-
(package_name, classname(ns_name), classname(dt_name)))
339-
340335
out('')
341336
self.generate_doc('Classes and routes in namespace "%s".' % namespace.name)
342337
with self.block('public final class %s' % class_name):
@@ -626,7 +621,7 @@ def generate_field_assignment(self, namespace, field):
626621
def generate_data_type_class(self, namespace, data_type):
627622
"""Generate a class definition for a datatype (a struct or a union)."""
628623
out = self.emit
629-
class_name = classname(data_type.name)
624+
class_name = type_ref(namespace, data_type)
630625
self.generate_doc(data_type.doc)
631626
if is_union_type(data_type):
632627
if has_value_fields(data_type):
@@ -638,7 +633,7 @@ def generate_data_type_class(self, namespace, data_type):
638633
assert is_struct_type(data_type)
639634
decl = 'public static class %s' % class_name
640635
if data_type.parent_type:
641-
decl += ' extends %s ' % classname(data_type.parent_type.name)
636+
decl += ' extends %s ' % type_ref(namespace, data_type.parent_type)
642637
with self.block(decl):
643638
out('// struct %s' % class_name)
644639
# Generate fields declarations.
@@ -863,7 +858,7 @@ def doit(dt):
863858
not dt.has_enumerated_subtypes()):
864859
# Collapse struct into union.
865860
out('%s._writer.writeFields(%s, g);' % (
866-
classname(dt.name), vn))
861+
type_ref(namespace, dt), vn))
867862
else:
868863
self.generate_write_field(namespace, field, vn)
869864

@@ -1022,7 +1017,7 @@ def generate_json_writer(self, namespace, class_name, data_type):
10221017
if tags:
10231018
out('g.writeStringField(".tag", "%s");' % '.'.join(tags))
10241019
for _, dt in ancestors:
1025-
out('%s._writer.writeFields(x, g);' % classname(dt.name))
1020+
out('%s._writer.writeFields(x, g);' % type_ref(namespace, dt))
10261021
out('g.writeEndObject();')
10271022

10281023
out('public final void writeFields(%s x, JsonGenerator g)' % class_name)
@@ -1120,7 +1115,7 @@ def generate_json_reader(self, namespace, class_name, data_type):
11201115
for field in data_type.get_enumerated_subtypes():
11211116
with self.block('if ("%s".equals(tags[%d]))' % (field.name, depth)):
11221117
out('return %s._reader.readFromTags(tags, parser);' %
1123-
classname(field.data_type.name))
1118+
type_ref(namespace, field.data_type))
11241119
out('// If no match, fall back to base class')
11251120
out('return readFields(parser);')
11261121

src/com/dropbox/core/v2/DbxClientV2.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222
public final class DbxClientV2 extends DbxRawClientV2 {
2323

24-
public final Files files;
25-
public final Users users;
26-
public final Sharing sharing;
24+
public final DbxFiles files;
25+
public final DbxUsers users;
26+
public final DbxSharing sharing;
2727

2828
/**
2929
* @param requestConfig
@@ -46,8 +46,8 @@ public DbxClientV2(DbxRequestConfig requestConfig, String accessToken) {
4646
*/
4747
public DbxClientV2(DbxRequestConfig requestConfig, String accessToken, DbxHost host) {
4848
super(requestConfig, accessToken, host);
49-
this.files = new Files(this);
50-
this.users = new Users(this);
51-
this.sharing = new Sharing(this);
49+
this.files = new DbxFiles(this);
50+
this.users = new DbxUsers(this);
51+
this.sharing = new DbxSharing(this);
5252
}
5353
}

0 commit comments

Comments
 (0)