Manually Refactoring BC4J Components in JDev 9.0.3 and Before

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 9:24:48 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Manually Refactoring BC4J Components in JDev 9.0.3 and Before

In 9.0.4 there is a "Move package..." context menu on a BC4J component to move it to a new package (renamed for clarity in 9.0.5 to "Move to different package..."). However before 9.0.4 you need to manually rename the components to a new package.

I built an unsupported BC4JRenamePackage utility that myself and some customers have used to assist in manually renaming a package of BC4J components.

To use this utility, unzip the BC4JRenamePackage.jar file from within the zip, and then do:

$ java -jar BC4JRenamePackage.jar

to get a simple usage message.

This only handles modifying the XML metadata. You still have to move the *.java files and search/replace the old package name with the new package name in the following kinds of files (NOTE: might be an incomplete list for your project!):

*.java
*.xml
*.jpr
*.jpx
*.jsp
*.deploy
*.bcdeploy
*.properties

I found the Apache ANT build tool useful to further automate this string replace in various files. While building the BC4J Toy Store Demo, I used the following template refactor.xml ANT build script to assist in searching and replacing old package names with new package names in a whole tree of files.

<!--
 |
 | refactor.xml
 | ~~~~~~~~~~~~
 | Example ANT build script that does a search/replace of
 | various old-string to new-strings in a number of different
 | file types (by directory extension) in all subdirectories
 | of the current directory where it is run. In this example,
 | I was adding in an extra package level named "model"
 | into my package hierarchy where it did not exist before.
 |
 | Run (after backing up your files first!) by doing:
 |
 | $ ant -buildfile refactor.xml
 |
 +-->
<?xml version="1.0"?>
<project name="refactor" default="refactor" basedir=".">
    <target name="refactor">
      <replace dir=".">
        <include name="**/*.java"/>
        <include name="**/*.xml"/>
        <include name="**/*.jpr"/>
        <include name="**/*.jpx"/>
        <include name="**/*.jsp"/>
        <include name="**/*.deploy"/>
        <include name="**/*.bcdeploy"/>
        <include name="**/*.properties"/>
        <exclude name="refactor.xml"/>
        <!--
         | Sometimes packages are with dotted names
         +-->
        <replacefilter token="pet.businessobjects" value="pet.model.businessobjects"/>
        <replacefilter token="pet.dataaccess" value="pet.model.dataaccess"/>
        <replacefilter token="pet.datatypes" value="pet.model.datatypes"/>
        <replacefilter token="pet.services" value="pet.model.services"/>
        <!--
         | Sometimes packages are referred by indirectly as directory names
         +-->
        <replacefilter token="pet/businessobjects" value="pet/model/businessobjects"/>
        <replacefilter token="pet/dataaccess" value="pet/model/dataaccess"/>
        <replacefilter token="pet/datatypes" value="pet/model/datatypes"/>
        <replacefilter token="pet/services" value="pet/model/services"/>
      </replace>
   </target>
</project>

As mentioned above, in JDev 9.0.4 and beyond, this process becomes more automated.



© Copyright 2008 Steve Muench. Click here to send an email to the editor of this weblog.
Last update: 2/3/2008; 9:24:48 PM.