- private String generateParentPath(String path, String pkg) {
- List<String> dirs = new ArrayList<String>();
- String pkgPath = "";
- if (pkg != null) {
- if (pkg.length() > 0) {
- if (pkg.contains(".")) {
- String[] split = pkg.split("\\.");
- for (String dir : split) {
- dirs.add(dir);
- }
- } else {
- dirs.add(pkg);
- }
- for (int i = 0; i < dirs.size(); i++) {
- if (i == 0) {
- pkgPath += dirs.get(i);
- } else {
- pkgPath += File.separator + dirs.get(i);
- }
- }
- }
+ private File generateTypeToJavaFile(final File parentDir, final Type type, final CodeGenerator generator, String fileNameSuffix)
+ throws IOException {
+ if (parentDir == null) {
+ log.warn("Parent Directory not specified, files will be generated "
+ + "accordingly to generated Type package path.");
+ }
+ if (type == null) {
+ log.error("Cannot generate Type into Java File because " + "Generated Type is NULL!");
+ throw new IllegalArgumentException("Generated Type Cannot be NULL!");
+ }
+ if (generator == null) {
+ log.error("Cannot generate Type into Java File because " + "Code Generator instance is NULL!");
+ throw new IllegalArgumentException("Code Generator Cannot be NULL!");
+ }
+ final File packageDir = packageToDirectory(parentDir, type.getPackageName());
+
+ if (!packageDir.exists()) {
+ packageDir.mkdirs();