How can I have proprietary data ("custom config") for my component?
Q: My component needs some configuration. Instead of using environment variables, or config files on disk, I want to put the information into the CDB. The CDB is certainly the natural place to put proprietary information for components. You need to do the following steps. 1. Add a schema to the CDBCreate a schema like the following underĀ <?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="urn:schemas-cosylab-com:MYCOMP_CONFIG:1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-cosylab-com:MYCOMP_CONFIG:1.0" xmlns:cdb="urn:schemas-cosylab-com:CDB:1.0"> <xs:import namespace="urn:schemas-cosylab-com:CDB:1.0" schemaLocation="CDB.xsd"/> <xs:complexType name="MYCOMP_CONFIG"> <xs:attribute name="fileDir" type="xs:string" use="required" /> <xs:attribute name="nLogs" type="xs:integer" use="optional" default="20" /> </xs:complexType> <xs:element name="MYCOMP_CONFIG" type="MYCOMP_CONFIG"/> </xs:schema> 2. Add your config to the CDBCreate a file like the following underĀ <?xml version="1.0" encoding="UTF-8"?> <MYCOMP_CONFIG xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:schemas-cosylab-com:MYCOMP_CONFIG:1.0" fileDir="/mnt/var" nLogs="200" /> 3. Sample code (in Java) to read the custom config:Use code like this in your component: String mycomp = "MYCOMP"; // or use: String mycomp = containerservices.getName(); DAL dal = containerservices.getCDB(); DAO dao = dal.get_DAO_Servant("alma/" + myname + "_CONFIG"); String fileDir = dao.get_string("fileDir"); short nLogs = (short) dao.get_long("nLogs"); |
Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.
|