Skip to content

Commit 3d6fc5d

Browse files
author
Steve Powell
committed
Make BasicProperties mutable again, with deprecated setters and boxed fields.
1 parent 79de5cf commit 3d6fc5d

File tree

3 files changed

+139
-93
lines changed

3 files changed

+139
-93
lines changed

codegen.py

Lines changed: 46 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,20 @@ def java_constant_name(c):
5151
'Date'
5252
])
5353

54-
# the scalar types in the range of javaTypeMap must be in java_scala_types
55-
java_scalar_types = set([
54+
# the scalar types in the range of javaTypeMap must be in javaScalarTypes
55+
javaScalarTypes = set([
5656
'int',
5757
'long',
5858
'boolean'
5959
])
60-
javaScalarDefaultMap = {
61-
'int': '0',
62-
'long': '0L',
63-
'boolean': 'false'
64-
}
65-
def java_scalar_default(jtype):
66-
if jtype in java_scalar_types:
67-
return javaScalarDefaultMap[jtype]
68-
else:
69-
return 'null'
70-
71-
# the java_scalar_types must be in the domain of javaBoxedTypeMap
60+
# the javaScalarTypes must be in the domain of javaBoxedTypeMap
7261
javaBoxedTypeMap = {
7362
'int': 'Integer',
7463
'long': 'Long',
7564
'boolean': 'Boolean'
7665
}
7766
def java_boxed_type(jtype):
78-
if jtype in java_scalar_types:
67+
if jtype in javaScalarTypes:
7968
return javaBoxedTypeMap[jtype]
8069
else:
8170
return jtype
@@ -248,56 +237,37 @@ def printClassInterfaces():
248237
def printReadProperties(c):
249238
if c.fields:
250239
for f in c.fields:
251-
(jfName, jfType) = (java_field_name(f.name), java_field_type(spec, f.domain))
252-
if jfType in java_scalar_types:
253-
print " this.%sIsSet = reader.readPresence();" % (jfName)
254-
else:
255-
print " boolean %s_present = reader.readPresence();" % (jfName)
240+
print " boolean %s_present = reader.readPresence();" % (java_field_name(f.name))
256241
print
257242

258243
print " reader.finishPresence();"
259244

260245
if c.fields:
261246
print
262247
for f in c.fields:
263-
(jfName, jfType, jfClass) = (java_field_name(f.name), java_field_type(spec, f.domain), java_class_name(f.domain))
264-
if jfType in java_scalar_types:
265-
print " if (this.%sIsSet) { this.%s = reader.read%s(); }" % (jfName, jfName, jfClass)
266-
print " else { this.%s = %s; }" % (jfName, java_scalar_default(jfType))
267-
else:
268-
print " this.%s = %s_present ? reader.read%s() : null;" % (jfName, jfName, jfClass)
248+
(jfName, jfClass) = (java_field_name(f.name), java_class_name(f.domain))
249+
print " this.%s = %s_present ? reader.read%s() : null;" % (jfName, jfName, jfClass)
269250

270251
def printWritePropertiesTo(c):
271252
print
272253
print " public void writePropertiesTo(ContentHeaderPropertyWriter writer)"
273254
print " throws IOException"
274255
print " {"
275-
for f in c.fields:
276-
(jfName, jfType) = (java_field_name(f.name), java_field_type(spec, f.domain))
277-
if jfType in java_scalar_types:
278-
print " writer.writePresence(this.%sIsSet);" % (jfName)
279-
else:
280-
print " writer.writePresence(this.%s != null);" % (jfName)
281-
256+
if c.fields:
257+
for f in c.fields:
258+
print " writer.writePresence(this.%s != null);" % (java_field_name(f.name))
259+
print
282260
print " writer.finishPresence();"
283-
284-
for f in c.fields:
285-
(jfName, jfType, jfClass) = (java_field_name(f.name), java_field_type(spec, f.domain), java_class_name(f.domain))
286-
if jfType in java_scalar_types:
287-
print " if (this.%sIsSet) writer.write%s(this.%s);" % (jfName, jfClass, jfName)
288-
else:
261+
if c.fields:
262+
print
263+
for f in c.fields:
264+
(jfName, jfClass) = (java_field_name(f.name), java_class_name(f.domain))
289265
print " if (this.%s != null) writer.write%s(this.%s);" % (jfName, jfClass, jfName)
290266
print " }"
291267

292268
def printAppendArgumentDebugStringTo(c):
293-
def optionalValueClause(jField, jType):
294-
if jType in java_scalar_types:
295-
return "this.%sIsSet ? String.valueOf(this.%s) : \"unset\"" % (jField, jField)
296-
else:
297-
return "this.%s" % (jField)
298-
299-
appendList = [ "%s=\")\n .append(%s)\n .append(\""
300-
% (f.name, optionalValueClause(java_field_name(f.name), java_field_type(spec, f.domain)))
269+
appendList = [ "%s=\")\n .append(this.%s)\n .append(\""
270+
% (f.name, java_field_name(f.name))
301271
for f in c.fields ]
302272
print
303273
print " public void appendArgumentDebugStringTo(StringBuffer acc) {"
@@ -306,35 +276,21 @@ def optionalValueClause(jField, jType):
306276

307277
def printPropertiesBuilderClass(c):
308278
def printBuilderSetter(fieldType, fieldName):
309-
if fieldType in java_scalar_types:
310-
print " public Builder %s(%s %s)" % (fieldName, fieldType, fieldName)
311-
print " { this.%s = %s; this.%sIsSet = true; return this; }" % (fieldName, fieldName, fieldName)
312-
print " public Builder %sUnSet() { this.%sIsSet = false; return this; }" % (fieldName, fieldName)
313-
if fieldType == "boolean":
314-
print " public Builder %s()" % (fieldName)
315-
print " { return this.%s(true); }" % (fieldName)
316-
else:
317-
print " public Builder %s(%s %s)" % (fieldName, fieldType, fieldName)
318-
print " { this.%s = %s; return this; }" % (fieldName, fieldName)
319-
if fieldType == "LongString":
320-
print " public Builder %s(String %s)" % (fieldName, fieldName)
321-
print " { return this.%s(LongStringHelper.asLongString(%s)); }" % (fieldName, fieldName)
322-
323-
def ctorParm(field):
324-
(fType, fName) = (java_field_type(spec, field.domain), java_field_name(field.name))
325-
if fType in java_scalar_types:
326-
return "%sIsSet ? %s : null" % (fName, fName)
327-
else:
328-
return fName
279+
print " public Builder %s(%s %s)" % (fieldName, java_boxed_type(fieldType), fieldName)
280+
print " { this.%s = %s; return this; }" % (fieldName, fieldName)
281+
if fieldType == "boolean":
282+
print " public Builder %s()" % (fieldName)
283+
print " { return this.%s(true); }" % (fieldName)
284+
elif fieldType == "LongString":
285+
print " public Builder %s(String %s)" % (fieldName, fieldName)
286+
print " { return this.%s(LongStringHelper.asLongString(%s)); }" % (fieldName, fieldName)
329287

330288
print
331289
print " public static final class Builder {"
332290
# fields
333291
for f in c.fields:
334292
(fType, fName) = (java_field_type(spec, f.domain), java_field_name(f.name))
335-
if fType in java_scalar_types:
336-
print " private boolean %sIsSet = false;" % (fName)
337-
print " private %s %s;" % (fType, fName)
293+
print " private %s %s;" % (java_boxed_type(fType), fName)
338294
# ctor
339295
print
340296
print " public Builder() {};"
@@ -346,7 +302,7 @@ def ctorParm(field):
346302
jClassName = java_class_name(c.name)
347303
# build()
348304
objName = "%sProperties" % (jClassName)
349-
ctor_parm_list = [ ctorParm(f) for f in c.fields ]
305+
ctor_parm_list = [ java_field_name(f.name) for f in c.fields ]
350306
print " public %s build() {" % (objName)
351307
print " return new %s" % (objName)
352308
print " ( %s" % ("\n , ".join(ctor_parm_list))
@@ -360,31 +316,33 @@ def printPropertiesBuilder(c):
360316
print " public Builder builder() {"
361317
print " Builder builder = new Builder();"
362318
setFieldList = [ "%s(%s)" % (fn, fn)
363-
for fn in [ java_field_name(f.name)
364-
for f in c.fields if java_field_type(spec, f.domain) not in java_scalar_types ] ]
319+
for fn in [ java_field_name(f.name) for f in c.fields ]
320+
]
365321
print " builder.%s;" % ("\n .".join(setFieldList))
366-
for f in c.fields:
367-
if java_field_type(spec, f.domain) in java_scalar_types:
368-
fn = java_field_name(f.name)
369-
print " if (%sIsSet) { builder.%s(%s); }" % (fn, fn, fn)
370322
print " return builder;"
371323
print " }"
372324

373325
def printPropertiesClass(c):
374326
def printGetter(fieldType, fieldName):
375327
capFieldName = fieldName[0].upper() + fieldName[1:]
376-
print " public %s get%s() { return this.%s; }" % (fieldType, capFieldName, fieldName)
328+
print " public %s get%s() { return this.%s; }" % (java_boxed_type(fieldType), capFieldName, fieldName)
329+
def printSetter(fieldType, fieldName):
330+
capFieldName = fieldName[0].upper() + fieldName[1:]
331+
print " @Deprecated"
332+
if fieldType == "Map<String,Object>":
333+
print " public void set%s(%s %s)" % (capFieldName, fieldType, fieldName)
334+
print " { this.%s = %s==null ? null : Collections.unmodifiableMap(new HashMap<String,Object>(%s)); }" % (fieldName, fieldName, fieldName)
335+
else:
336+
print " public void set%s(%s %s) { this.%s = %s; }" % (capFieldName, java_boxed_type(fieldType), fieldName, fieldName, fieldName)
377337

378338
jClassName = java_class_name(c.name)
379339

380340
print
381341
print " public static class %sProperties extends com.rabbitmq.client.impl.AMQ%sProperties {" % (jClassName, jClassName)
382342
#property fields
383343
for f in c.fields:
384-
(fType, fName) = (java_field_type(spec, f.domain), java_field_name(f.name))
385-
if fType in java_scalar_types:
386-
print " private final boolean %sIsSet;" % (fName)
387-
print " private final %s %s;" % (fType, fName)
344+
(fType, fName) = (java_boxed_type(java_field_type(spec, f.domain)), java_field_name(f.name))
345+
print " private %s %s;" % (fType, fName)
388346

389347
#explicit constructor
390348
if c.fields:
@@ -396,14 +354,10 @@ def printGetter(fieldType, fieldName):
396354
print " {"
397355
for f in c.fields:
398356
(fType, fName) = (java_field_type(spec, f.domain), java_field_name(f.name))
399-
if fType in java_scalar_types:
400-
print " if (%s == null) { this.%sIsSet = false; this.%s = %s; }" % (fName, fName, fName, java_scalar_default(fType))
401-
print " else { this.%sIsSet = true; this.%s = %s; }" % (fName, fName, fName)
357+
if fType == "Map<String,Object>":
358+
print " this.%s = %s==null ? null : Collections.unmodifiableMap(new HashMap<String,Object>(%s));" % (fName, fName, fName)
402359
else:
403-
if fType == "Map<String,Object>":
404-
print " this.%s = %s==null ? null : Collections.unmodifiableMap(new HashMap<String,Object>(%s));" % (fName, fName, fName)
405-
else:
406-
print " this.%s = %s;" % (fName, fName)
360+
print " this.%s = %s;" % (fName, fName)
407361
print " }"
408362

409363
#datainputstream constructor
@@ -425,7 +379,9 @@ def printGetter(fieldType, fieldName):
425379
#accessor methods
426380
print
427381
for f in c.fields:
428-
printGetter(java_field_type(spec, f.domain), java_field_name(f.name))
382+
(jType, jName) = (java_field_type(spec, f.domain), java_field_name(f.name))
383+
printGetter(jType, jName)
384+
printSetter(jType, jName)
429385

430386
printWritePropertiesTo(c)
431387
printAppendArgumentDebugStringTo(c)

src/com/rabbitmq/client/BasicProperties.java

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public interface BasicProperties {
4444
* Retrieve the value in the deliveryMode field.
4545
* @return deliveryMode field, or null if the field has not been set.
4646
*/
47-
public abstract int getDeliveryMode();
47+
public abstract Integer getDeliveryMode();
4848

4949
/**
5050
* Retrieve the value in the priority field.
5151
* @return priority field, or null if the field has not been set.
5252
*/
53-
public abstract int getPriority();
53+
public abstract Integer getPriority();
5454

5555
/**
5656
* Retrieve the value in the correlationId field.
@@ -100,5 +100,95 @@ public interface BasicProperties {
100100
*/
101101
public abstract String getAppId();
102102

103+
/**
104+
* Set the contentType field, or null indicating the field is not set
105+
* @param contentType the value to set the field to
106+
*/
107+
@Deprecated
108+
public abstract void setContentType(String contentType);
109+
110+
/**
111+
* Set the contentEncoding field, or null indicating the field is not set
112+
* @param contentEncoding - the value to set the field to
113+
*/
114+
@Deprecated
115+
public abstract void setContentEncoding(String contentEncoding);
116+
117+
/**
118+
* Set the headers table, or null indicating the field is not set
119+
* @param headers a map of table field names and values
120+
*/
121+
@Deprecated
122+
public abstract void setHeaders(Map<String, Object> headers);
123+
124+
/**
125+
* Set the deliveryMode field, or null indicating the field is not set
126+
* @param deliveryMode the value to set the field to
127+
*/
128+
@Deprecated
129+
public abstract void setDeliveryMode(Integer deliveryMode);
130+
131+
/**
132+
* Set the priority field, or null indicating the field is not set
133+
* @param priority the value to set the field to
134+
*/
135+
@Deprecated
136+
public abstract void setPriority(Integer priority);
137+
138+
/**
139+
* Set the correlationId field, or null indicating the field is not set
140+
* @param correlationId the value to set the field to
141+
*/
142+
@Deprecated
143+
public abstract void setCorrelationId(String correlationId);
144+
145+
/**
146+
* Set the replyTo field, or null indicating the field is not set
147+
* @param replyTo the value to set the field to
148+
*/
149+
@Deprecated
150+
public abstract void setReplyTo(String replyTo);
151+
152+
/**
153+
* Set the expiration field, or null indicating the field is not set
154+
* @param expiration the value to set the field to
155+
*/
156+
@Deprecated
157+
public abstract void setExpiration(String expiration);
158+
159+
/**
160+
* Set the messageId field, or null indicating the field is not set
161+
* @param messageId the value to set the field to
162+
*/
163+
@Deprecated
164+
public abstract void setMessageId(String messageId);
165+
166+
/**
167+
* Set the timestamp field, or null indicating the field is not set
168+
* @param timestamp the value to set the field to
169+
*/
170+
@Deprecated
171+
public abstract void setTimestamp(Date timestamp);
172+
173+
/**
174+
* Set the type field, or null indicating the field is not set
175+
* @param type the value to set the field to
176+
*/
177+
@Deprecated
178+
public abstract void setType(String type);
179+
180+
/**
181+
* Set the userId field, or null indicating the field is not set
182+
* @param userId the value to set the field to
183+
*/
184+
@Deprecated
185+
public abstract void setUserId(String userId);
186+
187+
/**
188+
* Set the appId field, or null indicating the field is not set
189+
* @param appId the value to set the field to
190+
*/
191+
@Deprecated
192+
public abstract void setAppId(String appId);
103193

104194
}

test/src/com/rabbitmq/client/test/ClonePropertiesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void testPropertyClonePreservesValues()
4444
assertEquals(MessageProperties.MINIMAL_PERSISTENT_BASIC.getDeliveryMode(),
4545
((BasicProperties) MessageProperties.MINIMAL_PERSISTENT_BASIC.clone())
4646
.getDeliveryMode());
47-
assertEquals(2,
47+
assertEquals(new Integer(2),
4848
((BasicProperties) MessageProperties.MINIMAL_PERSISTENT_BASIC.clone())
4949
.getDeliveryMode());
5050
}

0 commit comments

Comments
 (0)