Esta página describe los estándares usados para el código de Apache Geronimo (java, xml, etc.). Código es leído por un humano con más frecuencia de lo que es escrito por un ser humano, haz el código placentero para ser leído.

Identación

Java

Sigamos las reglas estándar de código de Sun, las cuales son muy usuales en Java.

http://java.sun.com/docs/codeconv/

http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

Correct brace style:

public class Foo {
    public void foo(boolean a, int x, int y, int z) {
        do {
            try {
                if (x > 0) {
                    int someVariable = a ?  x : y;
                } else if (x < 0) {
                    int someVariable = (y + z);
                    someVariable = x = x + y;
                } else {
                    for (int i = 0; i < 5; i++) {
                        doSomething(i);
                    }
                }

                switch (a) {
                    case 0:
                        doCase0();
                        break;
                    default:
                        doDefault();
                }
            } catch (Exception e) {
                processException(e.getMessage(), x + y, z, a);
            } finally {
                processFinally();
            }
        } while (true);

        if (2 < 3) {
            return;
        }

        if (3 < 4) {
            return;
        }

        do {
            x++
        } while (x < 10000);

        while (x < 50000) {
            x++;
        }

        for (int i = 0; i < 5; i++) {
            System.out.println(i);
        }
    }

    private class InnerClass implements I1, I2 {
        public void bar() throws E1, E2 {
        }
    }
}

XML

Interfaces

Todo método de una interfaz es público abstracto (public abstract), por lo que no es necesario el especificar modificadores públicos abstractos (public abstract modifiers). De manera similar, todo campo es público estático final (public static final).

Sin embargo, el siguiente comportamiento funciona mejor con la mayoría de herramientas e IDEs y parece ser una práctica común, por lo que no observamos razón para negar dicha práctica, por ejemplo:

public interface MyInterface {
    public static final int MY_INTEGER = 0;

    public abstract void doSomething();
}

Lo anterior tiene la ventaja adicional de que la interfaz puede ser convertida en una clase abstracta (y copiar y pegar definiciones individuales) sin aplicar cambio alguno.

Preferentemente agrega public/static/final a constantes, y public/abstract a métodos, pero no es obligatorio. Sin embargo, si esta ahí, no lo quites.

------------------------> Falta traducción

Exceptions

Package Naming

For example, if the module name is common, then the base package name should be org.apache.geronimo.common.

Note: This is more of a guideline than a rule, as some modules simply can not follow this convention, but where applicable they should.

Imports

IDE Auto-Formatting

JavaDoc Tags

@version Should be: @version $Revision$ $Date$

@author Should not be used in source code at all.

Unit Test Cases

Logging

Levels

Example

private static final Log log = LogFactory.getLog(MyClass.class);

public void doSomeStuff(Stuff stuff) throws StuffException {
    boolean logTrace = log.isTraceEnabled();
    try {
        if (logTrace) {
            log.trace("About to do stuff " + stuff);
        }
        stuff.doSomething();
        if (logTrace) {
            log.trace("Did some stuff ");
        }
    } catch (BadException e) {
        // don't log - leave it to caller
        throw new StuffException("Something bad happened", e);
    } catch (IgnorableException e) {
        // didn't cache this as we don't expect to come here a lot
        if (log.isDebugEnabled()) {
            log.debug("Ignoring problem doing stuff "+stuff, e);
        }
    }
}

Abbreviations and Acronym in methods/classes/interfaces' names

Abbreviations are all written in capitals in methods/classes/interfaces' names.

public final class J2EELoader {

    public static EJBRef[] loadEJBRefs(Element parent) {
        //...
    }

}

GBean attribute and reference naming convention

The current convention is for attributes to follow Java variable naming conventions (i.e., lower case first character camel cased after) and for references to follow Java class naming conventions (i.e., capital first character camel cased after).
<------------------------ Falta traducción