More code import from php
AttributeOrdering converted to java