JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
Overview
Support
Development
Coding Standards

Here we provide an overview of the coding standards employed in JPOX. If you want to work on JPOX or contribute code to JPOX you are expected to use these coding standards. We know everyone has their own preference but these are ours so you follow them or any contributed code will not be directly included as is They may differ from SUNs coding conventions but then those are the conventions of some US company and that doesn't mean that they are necessarily "the best", "the official" or any such title. These are ours, so best get used to it ;-).

  • Indentation : 4 characters indent
  • Tabs : no tabs please!
  • Braces : insert a new line before opening brace and a new line before closing brace. Opening and closing braces should line up vertically.
  • Line Length : max line length 140
  • Imports : fully specify imports. Do NOT use * notation!
  • Java Language Level : write for JDK1.3+ wherever possible. Otherwise make sure that code is wrapped with "JavaUtils" restrictors.
  • Fields positioning : place fields at the top of a class
  • Logging : use org.jpox.util.JPOXLogger which wraps Log4j, JDK1.4 etc. Log as much info as is considered necessary at the appropriate level. See Logging Guide for details
  • Localisation : all output exception and log messages should be localised. Use org.jpox.util.Localiser. See Localisation Guide for details

If you are using Eclipse then we have an XML Configuration to specify in Eclipse.

Examples
/**
 * A sample source file for the code formatter preview
 */
package mypackage;

import java.util.LinkedList;

public class MyIntStack
{
    private final LinkedList fStack;

    public MyIntStack()
    {
        fStack = new LinkedList();
    }

    public int pop()
    {
        return ((Integer) fStack.removeFirst()).intValue();
    }

    public void push(int elem)
    {
        fStack.addFirst(new Integer(elem));
    }

    public boolean isEmpty()
    {
        return fStack.isEmpty();
    }
}
/**
 * Indentation
 */
class Example
{
    int[] myArray = {1, 2, 3, 4, 5, 6};
    int theInt = 1;
    String someString = "Hello";
    double aDouble = 3.0;

    void foo(int a, int b, int c, int d, int e, int f)
    {
        switch (a)
        {
            case 0 :
                Other.doFoo();
                break;
            default :
                Other.doBaz();
        }
    }

    void bar(List v)
    {
        for (int i = 0; i < 10; i++)
        {
            v.add(new Integer(i));
        }
    }
}
/**
 * If...else
 */
class Example
{
    void bar()
    {
        do
        {
        }
        while (true);
        try
        {
        }
        catch (Exception e)
        {
        }
    }

    void foo2()
    {
        if (true)
        {
            return;
        }
        if (true)
        {
            return;
        }
        else if (false)
        {
            return;
        }
        else
        {
            return;
        }
    }

    void foo(int state)
    {
        if (true)
        {
            return;
        }
        if (true)
        {
            return;
        }
        else if (false)
        {
            return;
        }
        else
        {
            return;
        }
    }
}                
                
References

In this document we describe just a small set of guidelines. Our references are really worth a read and must be followed during JPOX development.