Hi,
I am currently writing some additions to say
<packageSubstitution packages="foo"
substituteWith="bar"
useAny="true"/>
Here, the first occurence of element foo in the path will
be replaced instead of the last (at least this is what turns
out). I.e. com.acme.foo.ejb.entity -> com.acme.bar.ejb.entity
I want this because I want to have all interfaces and VOs
each in their separate subtree no matter what package structure
they are in.
The attached patch works well for the creation of the package
statement within the generated files, but fails for the
path where the file is generated in.
In PackageTagssHandler I have packageNameAsPathFor(), but
this does not necessarily have knowledge about the current
subtask and its <packagesubsittution/> and its attributes ?
Thanks in advance
Heiko
--
Bancotec GmbH EMail: [EMAIL PROTECTED]
Calwer Str. 33 Telefon: +49 711 222 992 900
D-70173 Stuttgart Telefax: +49 711 222 992 999
Ein Unternehmen der Cellent AG http://www.cellent.de/
--- PackageTagsHandler.java,2 2003-03-18 17:39:14.000000000 +0100
+++ PackageTagsHandler.java 2003-03-20 17:52:01.000000000 +0100
@@ -60,16 +60,21 @@
PackageSubstitution ps = (PackageSubstitution)
packageSubstitutions.get(i);
StringTokenizer st = new StringTokenizer(ps.getPackages(), ",", false);
- while (st.hasMoreTokens()) {
- String packages = st.nextToken();
- String suffix = "." + packages;
+ if (ps.getUseAny() == false) {
+ while (st.hasMoreTokens()) {
+ String packages = st.nextToken();
+ String suffix = "." + packages;
- if (packageName.endsWith(suffix)) {
- packageName = packageName.substring(0, packageName.length() -
suffix.length()) + '.' + ps.getSubstituteWith();
- break;
+ if (packageName.endsWith(suffix)) {
+ packageName = packageName.substring(0, packageName.length() -
suffix.length()) + '.' + ps.getSubstituteWith();
+ break;
+ }
}
}
+ else {
+ packageName = replaceInline(packageName, ps.getPackages(),
ps.getSubstituteWith());
+ }
}
return packageName;
@@ -133,6 +138,22 @@
return qualifiedName.replace('.', '/');
}
+
+ /**
+ * Replace the first occourance of oldOne in original with newOne
+ *
+ * @param original String in which replacement should occour
+ * @param oldOne String to be replaced
+ * @param newOne String that replaces
+ * @return String original string with replacements
+ */
+ public static String replaceInline(String original, String oldOne, String newOne)
+ {
+ int index = original.indexOf(oldOne);
+
+ return original.substring(0, index) + newOne + original.substring(index +
oldOne.length());
+ }
+
/**
* Returns the current package name. If we're in the context of a package
iteration, this is the name of the current
* package. If we're in the context of a class iteration without a package
iteration, return the name of the current
@@ -243,6 +264,7 @@
return packageNameAsPathFor(packageName());
}
+
/**
* It's good practice to put interfaces (such as remote/local interfaces, data
objects and home interfaces) in a
* separate "interfaces" package rather than in the EJB bean implementation
package. Previous versions of XDoclet
@@ -263,6 +285,7 @@
{
private String packages = null;
private String substituteWith = null;
+ private boolean useAny = false;
/**
* Gets the Packages attribute of the PackageSubstitution object
@@ -285,6 +308,17 @@
}
/**
+ * return the useAny attribute. This attribute specifies if the substitution
can only appear at the end of a
+ * package (useAny=false) or also in the middle.
+ *
+ * @return boolean
+ */
+ public boolean getUseAny()
+ {
+ return this.useAny;
+ }
+
+ /**
* Sets the Packages attribute of the PackageSubstitution object
*
* @param packages The new Packages value
@@ -303,5 +337,17 @@
{
this.substituteWith = substituteWith;
}
+
+ /**
+ * Sets the useAny attribute
+ *
+ * @param any
+ */
+ public void setUseAny(boolean any)
+ {
+ this.useAny = any;
+
+ }
+
}
}