This information is for a release that is no longer supported by the Globus Toolkit. The currently supported versions of the Globus Toolkit are 4.2 (recommended) and 4.0.
GT 3.0: Java Coding Guidelines Core Framework
1. Base Coding Conventions:
Sun Coding Conventions for the Java Programming Language:
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
2. Additional Guidelines:
2.1 Imports
All imports must be single class and explicit. I.e. import <package>.* is not allowed.
2.2 Indentation
All indentation levels should be 4 spaces. No editor tabs are allowed unless they are converted to 4 spaces before saving the file.
2.3 Brackets
Two models are allowed (they must never be mixed within the same source file though, and should not be mixed within the same package):
1) Curly brackets ‘{}’are put on separate lines. E.g.
for (index = 0; index < length; index++)
{
<code>
}
2) As defined in the Java Coding guidelines. E.g.
for (index = 0; index < length; index++) {
<code>
}
2.4 Variables
No acronyms or abbreviations should be used. E.g. ‘a = b + mVarLen’ should be avoided and instead use: ‘totalLength = partLength + newLength’.
2.5 Instance Variables
Use ‘this.’ as prefix when referencing instance variables, e.g.:
public MyClass (ServicePropertiesInterface properties) {
this.properties = properties;
}
public int foo () {
int localInt = 3;
return this.instanceInt + localInt;
}
2.6 One-Liners
Even single line statements should be inside brackets. E.g.
if (isEmpty) {
return;
}
2.7 Logging
The Jakarta Commons API should be used exclusively. Log4j.properties should be used for configuring logs. System.out/err.println is not allowed.
2.8 Testing
Each component/class should have a JUnit test The tests should be put in test/ directory under each package directory.
2.9 Internationalization
2.9.1 What
- Rule of thumb: All messages exposed to clients should be translatable
- Errors: All error message strings exposed to clients should be translatable.
- Logging: All log messages with filter ERROR or WARNING should be translatable. All other log messages such as TRACE and DEBUG should not be translatable
- Samples/Tests: Messages in samples and tests should not be translatable.
- Experimental/Prototype code: nono
2.9.2. How
- Option 1:
- Provide a resource bundle class that contains your translated messages. See org.globus.ogsa.guide.impl.Resources.java
- Provide a mapping of a component name to the class name with the translated messages in a bundle.properties file.
- When getting a translated message use: org.globus.ogsa.utils.MessageUtils.getMessage(<component>, <message key>). See org.globus.ogsa.guide.impl.CounterClient.java
- Option 2:
- Use the I18n class from the Java CoG Kit.
2.10 Library Reuse
Treat all code as a library, and as a reusable component. Calls to System.exit() are disallowed (except the main method)
2.11 Exceptions
For local exceptions inherit from org.globus.ogsa.GridServiceException. If the exceptions should be exposed to remote clients define it in WSDL and extend the GridServiceFault defined in schema/core/faults/grid_service_fault.wsdl. Even though your wsdl operations don't throw any interface specific exception declare them to throw GridServiceFault.
