The CentraSite meta model is the collection of object types (builtin and custom), and their attributes. As such, it is opposed to the CentraSite model, the collection of object type instances, which meet the specification given by the respective object types.
In theory, the registry can be much more fine grained than the meta model. In practice, that's rarely the case: The meta model is a full schema of the registries contents.
This implies, that you need the ability to read and manipulate the meta model: Whenever your model changes, the schema must be changed first.
Whenever you'd like to manipulate the meta model, you need a meta model accessor. The meta model accessor can be obtained like this:
ConnectionProvider connProvider = new DefaultConnectionProvider(url, userName, password, true); ModelDrivenRegistryFacade facade = new SimpleModelDrivenRegistryFacade(connProvider.getConnection()); ROMetaModelAccessor acc = facade.getMetaModelAccessor();
Note: We are using a special constructor of the DefaultConnectionProvider here. This is due to a problem in CentraSite, which requires special connection handling when manipulating the CentraSite meta model. Whether this problem still exists, as of this writing, is unknown. When in doubt, use the special constructor for manipulating the meta model. This special constructor is not required, if you only intend to read the meta model.
A meta model is an instance of ROMetaModel. There are multiple ways to obtain the meta model, including those:
acc.getMetaModel(); facade.getMetaModel(); facade.getModelAccessor().getMetaModel();
The former is recommended, if you are manipulating the meta model. In that case the meta model accessor is the anchor point of your work and nothing else is required. The latter variants are recommended for other work. You can omit using the meta model accessor.
The meta model provides several methods, which you might like to use: For example, you can ask for a particular type, or you may obtain the list of all object types:
ROType type = metaModel.getROType(QName.valueOf("{SomeNamespace}Organization")); if (type == null) { System.out.println("No such object type: {SomeNamespace}Organization"); } final Map<QName,ROType> allTypes = metaModel.getROTypes();
The recommended way to create a new object type is to read the type definition from an XML file. The XML file might look like this:
<?xml version="1.0" encoding="UTF-8"?> <roMetaModel xmlns="http://namespaces.csutils.sf.net/model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://namespaces.csutils.sf.net/model registryModel.xsd"> <roTypes> <roType qName="{SomeNamespace}Organization"> <attributes> <attribute maxOccurs="1" minOccurs="1" name="name" type="string"/> </attributes> </roType> <roType qName="{SomeNamespace}User"> <attributes> <attribute maxOccurs="1" minOccurs="1" name="name" type="string"/> <relation maxOccurs="1" minOccurs="1" name="employeeOf" type="relation" associationType="employeeOf"> <targetTypes> <targetType qName="{SomeNamespace}Organization"/> </targetTypes> </relation> </attributes> </roType> </roTypes> </roMetaModel>
This XML file might be used like this:
ROMetaModelReader reader = new ROMetaModelReader(); ROMetaModel importedMetaModel = reader.read(new File("myMetaModel.xml")); Map<QName,ROType> importedTypes = importedMetaModel.getROTypes(); for (ROType importedType : importedTypes) { ROType createdType = facade.getMetaModelAccessor().create(importedType); }