Mechanism for linear and nonlinear optical effects in beta-BaB2O4 crystals