Breaking up the application in multiple workspaces
When dealing with large enterprise scale applications, the organization and structure of the overall application in terms of JDeveloper workspaces, projects, and libraries is essential. Organizing and packaging ADF application artifacts, such as business components, task flows, templates, Java code, and so on, into libraries will promote and ensure modularity, and the reuse of these artifacts throughout the application. In this recipe, we will create an application that comprises reusable components. We will construct reusable libraries for shared components, business domain specific components, and a main application for consuming these components.
How to do it…
1. To create the
SharedComponents
library, start by selecting New Application… in the Application Navigator. This will start the application creation wizard.2. In the New Gallery dialog, click on the Applications node (under the General category) and select Fusion Web Application (ADF) from the list of Items.
3. In the Name your application page, enter the Application Name, Directory and the Application Package Prefix.
4. In the Name your project page, enter the business component's Project Name and Directory. For this recipe, we have called it
SharedBC
.5. In the Configure Java settings page for the business components project, accept the defaults for Default Package, Java Source Path, and Output Directory.
6. Similarly, in the Name your project page for the ViewController project, enter the Project Name and Directory. For this recipe, we have called the project
SharedViewController
. Ensuring that you enter a unique package structure for both projects is the best guarantee for avoiding naming conflicts when these projects are deployed as ADF Library JARs.7. Accept the defaults in the Configure Java settings and click Finish to proceed with the creation of the workspace.
8. Now, in the Application Navigator, you should see the two projects comprising the
SharedComponents
workspace, one for the business components and another for the ViewController.9. You will be using this workspace to add reusable business and ViewController components. For now, we will package the workspace into an ADF library JAR, without any components in it yet. In order to do this, you will need to first setup the project dependencies. Double-click on the
SharedViewController
project to bring up the Project Properties dialog and select Dependencies.10. Click on Edit Dependencies (the small pen icon) to bring up the Edit Dependencies dialog and then click on the Build Output checkbox under the business components project.
11. Click OK to close the dialog and return to the Project Properties dialog.
12. The next step is to set up the deployment profile. While at the ViewController Project Properties dialog, click on the Deployment node.
13. Since we will not be deploying this application as a WAR, select the default WAR deployment profile generated automatically by JDeveloper and delete it.
14. Then, click New… to create a new deployment profile.
15. On the Create Deployment Profile dialog, select ADF Library JAR File for the Profile Type and enter the name of the deployment profile. For this recipe, we have called the deployment profile
SharedComponents
. Click OK to proceed with its creation.16. In the Edit ADF Library JAR Deployment Profile Properties dialog that is opened, select JAR Options and specify a location where you will be placing all the reusable JAR libraries. For this recipe, we will place all reusable libraries in a directory called
ReUsableJARs
.17. When done, completely exit from the Project Properties dialog, saving your changes by clicking OK.
18. The last step involves the creation of the ADF Library JAR. You do this by right-clicking on the
ViewController
project in the Application Navigator selecting Deploy and then the name of the deployment profile name (SharedComponents in this case).19. Select Deploy to ADF Library JAR file in the Deployment Action page and click Finish to initiate the deployment process. The deployment progress will begin. Its status is shown in the Deployment tab of the Log window.
20. To create the
HRDepartments
components library, similarly create a new Fusion web application for theHRDepartment
components. Follow the previous steps to setup the project dependencies. No database connection to theHR
schema is needed at this stage.21. Create the deployment profile and deploy the ADF Library JAR. We will not be placing any components yet in this library.
22. To create the
HREmployees
components library, repeat the previous steps once more in order to create another ADF Library JAR for theHR Employee
related reusable components.23. Now create another Fusion web application, which will be used as the main application. This application will consume any of the components that reside in the ADF Library JARs created in the previous steps.
24. This can easily be done via the Resource Palette by creating a file system connection to the directory where we saved the reusable ADF Library JARs, that is, the directory called
ReUsableJARs
. If the Resource Palette is not visible, select View | Resource Palette to show it. In the Resource Palette, click on the New icon and select New Connection | File System….25. In the Create File System Connection dialog that is displayed, enter the name of the connection and the directory where you have deployed the reusable components in the previous steps.
26. Click OK to continue. You should be able to see the new File System Connection in the Resource Palette.
27. To consume reusable components, first select the appropriate project on the Application Navigator, then right-click on the ADF Library JAR on the Resource Palette and select Add to Project….
28. On the Confirm Add ADF Library dialog, click on the Add Library button to proceed.
29. Alternatively, expand the ADF Library JAR and drag-and-drop the reusable component onto its appropriate place in the workspace.
How it works…
When you deploy a project as an ADF Library JAR, all ADF reusable components and code are packaged in it and they become available to other consuming applications and libraries. Reusable components include business components, database connections, data controls, task flows, task flow templates, page templates, declarative components, and of course Java code. By setting up the dependencies among the business components and ViewController projects in the way that we have—that is, including the build output of the business components project during the deployment of the ViewController project—you will be producing a single ADF Library JAR file with all the components from all the projects in the workspace. When you add an ADF Library JAR to your project, the library is added to the project's class path. The consuming project can then use any of the components in library. The same happens when you drag-and-drop a reusable component into your project.
There's more…
For this recipe, we packaged both of the business components and ViewController projects in the same ADF Library JAR. If this strategy is not working for you, you have other options, such as adjusting the dependencies among the two and packaging each project in a separate ADF Library JAR. In this case, you will need an additional deployment profile and a separate deployment for the business components project.
Adding the ADF Library JAR manually
You can add an ADF Library JAR into your project manually using the Project Properties dialog. Select the Libraries and Classpath node and click on the Add Library… button. This will display the Add Library dialog. On it, click the New… button to display the Create Library dialog. Enter a name for the library, select Project for the library location, and click on the Deployed by Default check button. Finally, click on the Add Entry… button to locate the ADF Library JAR. The Deployed by Default checkbox when checked indicates that the library will be copied to the application's destination archive during deployment of the consuming application. If you leave it unchecked, then the library will not be copied and it must be located in some other way (for example, deployed separately as a shared library on the application server).
Defining the application module granularity
One related topic that also needs to be addressed in the early architectural stages of the ADF project is the granularity for the application modules, that is, how the data model will be divided into application modules. As a general rule of thumb, each application module should satisfy a particular use case. Related use cases and, therefore, application modules can then be packaged into the same reusable ADF Library JAR. In general, avoid creating monolithic application modules that satisfy multiple use cases each.
Entity objects, list of values (LOVs), validation queries
Entity objects, list of values (LOVs) and validation queries should be defined only once for each business components project. To avoid duplication of entity objects, LOVs and validation queries among multiple business components projects, consider defining them only once in a separate business components project.
Note
Structuring of the overall ADF application in reusable components should be well thought and incorporated in the early design and architectural phases of the project.
As your application grows, it is important to watch out for and eliminate circular dependencies among the reusable components that you develop. When they occur, this could indicate a flaw in your design. Use available dependency analyzer tools, such as Dependency Finder (available from http://depfind.sourceforge.net) during the development process, to detect and eliminate any circular dependencies that may occur.