Oracle JDeveloper 11gR2 Cookbook
上QQ阅读APP看书,第一时间看更新

Creating and applying property sets

In the Using a custom property to populate a sequence attribute and Overriding doDML() to populate an attribute with a gapless sequence recipes of this chapter, we introduced custom properties for generic ADF business component programming. In this recipe, we will present a technique to organize your custom properties in reusable property sets. By organizing application-wide properties in a property set and exporting them as part of an ADF Library JAR, you can then reference them from any other ADF-BC project. This in turn will allow you to centralize the custom properties used throughout your ADF application in a single property set.

getting ready

We will create a property set in the SharedComponets workspace. I suggest that you go over the Using a custom property to populate a sequence attribute and Overriding doDML() to populate an attribute with a gapless sequence recipes in this chapter before continuing with this recipe. To run the recipe's test cases, you will need access to the HR schema in the database.

How to do it...

  1. Start by opening the SharedComponets workspace. If needed, follow the steps in the referenced recipe to create it.
  2. Right-click on the SharedBC project and select New….
  3. On the New Gallery dialog select ADF Business Components under the Business Tier node and Property Set from the Items on the right.
  4. Click OK to proceed. This will open the Create Property Set dialog.
    How to do it...
  5. Enter the property set name and package in the appropriate fields. For this recipe, we will call it SharedProperties and use the com.packt.jdeveloper.cookbook.shared.bc.properties package. Click OK to continue.
  6. JDeveloper will create and open the SharedProperties property set.
  7. To add a custom property to the property set, click on the Add Custom Property button (the green plus sign icon).
  8. Go ahead and add two non-translatable properties called CommitSequenceDepartmentDepartmentId and CreateSequenceEmployeeEmployeeId. Set their values to DEPARTMENTS_SEQ and EMPLOYEES_SEQ respectively. Your property set should look similar to the following screenshot:
    How to do it...
  9. Next you need to change the create() method in the custom entity framework class so that the custom property is now similar to the following block of code:
    // construct the custom property name from the entity name and attribute
    String propertyName = CREATESEQ_PROPERTY + getEntityDef().getName() + atrbDef.getName();
    // check for a custom property called CREATESEQ_PROPERTY
    String sequenceName =(String)atrbDef.getProperty(propertyName);
  10. Similarly change the doDML() method in the custom entity framework class so that the custom property is also constructed, as shown in the following block of code:
    // construct the custom property name from the entity name and attribute
    String propertyName = COMMITSEQ_PROPERTY + getEntityDef().getName() + atrbDef.getName();
    // check for a custom property called COMMITSEQ_PROPERTY
    String sequenceName =(String)atrbDef.getProperty(propertyName);
  11. Redeploy the SharedComponets workspace into an ADF Library JAR.
  12. Open the HREmployees workspace and double-click on the HREmployeesBC business components project to bring up the Project Properties dialog.
  13. Select Imports under the ADF Business Components node and click on the Import… button on the right.
  14. On the Import Business Components XML File dialog browse for the shared components ADF Library JAR file in the ReUsableJARs directory. Select it and click Open.
  15. You should see the imported SharedBC project under the Imported Business Component Projects along with the imported packages and package contents. Click OK to continue with importing the business components.
    How to do it...
  16. Double-click on the Employee entity object and go to the Attributes tab.
  17. Click on the Details tab, and from the Property Set choice list select the imported property set.
  18. Repeat steps 12-17 for the HRDepartments workspace and apply the property set to the DepartmentId attribute of the Department entity object.

How it works...

Property sets are a way to gather all of your custom properties together into logical collections. Instead of applying each custom property separately to a business components object or to any of its attributes, custom properties defined in these collections can be applied at once on them. Property sets can be applied to entity objects and their attributes, view objects and their attributes, and application modules. You access custom properties programmatically as indicated earlier, by calling AttributeDef.getProperty() for properties applied to attributes, EntityDefImpl.getProperty() for properties applied to entity objects, ViewDefImpl.getProperty() for properties applied to view objects, and so on.

How you organize your custom properties into property sets is up to you. In this recipe, for example, we use a single property set called SharedProperties , which we define in the shared components ADF library. In this way, we kept all custom properties used by the application in a single container. For this to work, we had to devise a way to differentiate among them. The algorithm that we used was to combine the property name with the business components object name and the attribute name that the property applies to. So we have properties called CommitSequenceDepartmentDepartmentId and CreateSequenceEmployeeEmployeeId .

Finally, we import the property set from the SharedComponets workspace into the relevant business components projects using the Import Business Components facility of the business components Project Properties dialog.

There's more...

To test the recipe, you can run the EmployeeAppModule and DepartmentAppModule application modules in the HREmployees and HRDepartments workspaces respectively.

Note

Note that you can override any of the properties defined in a property set by explicitly adding the same property to the business component object or to any of its attributes.

Also note that property sets can be applied onto entity objects, view objects, and application modules by clicking on the Edit property set selection button (the pen icon) on the business component object definition General tab. On the same tab, you can add custom properties to the business component object by clicking on the Add Custom Property button (the green plus sign icon).

See also

  • Breaking up the application in multiple workspaces, Chapter 1, Pre-requisites to Success: ADF Project Setup and Foundations
  • Setting up BC base classes, Chapter 1, Pre-requisites to Success: ADF Project Setup and Foundations
  • Using a custom property to populate a sequence attribute, in this chapter
  • Overriding doDML() to populate an attribute with a gapless sequence, in this chapter