MetaBoss
User Guides
Synopsis
Beginner's Guide
Configuration Guide
Design Studio Guide
Programming Model Guide
Testing Framework Guide
'How To ...' Guides
References
Synopsis
Design Model Reference
Design Model UML Profile
Test Schema Reference
MetaBoss design library
Run-time libraries API
Dev-time libraries API
HatMaker Example
Synopsis
Enterprise Model Description
Enterprise Model Reference
SystemTest Example
WebServices Example
Miscellaneous
About MetaBoss
Quality Assurance
Compatibility Notes
Acknowledgments
Glossary
Change Log
Version 1.4.0001
Built on 15 Dec 2005 22:31:47

Accessing Metamodel from Java program

In Brief

  • From your own java code access Model repository as follows:
    This example shows how obtain an instance of the MetaBoss model repository
    
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import com.metaboss.sdlctools.models.ModelRepository;
    
    // Obtain instance of the model repository via JNDI
    // The Metamodel of the MetaBoss Enterprise Model is already preloaded with
    // name "MetaBossMetaModel"
    Context lContext = new javax.naming.InitialContext();
    ModelRepository lModelRepository = (ModelRepository)lContext.lookup(ModelRepository.COMPONENT_URL);
    
    // Now we can use the repository object to
    // open, create, explore and update the models
    
    
  • To open existing enterprise model:
    This example shows how to open existing enterprise model
    
    import java.io.File;
    import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
    import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
    
    // Open the model stored in file and load id in
    // the repository under the name "SampleEnterpriseModel"
    File lModelFile = new File("c:/SampleModel/Model.xml"); 
    lModelRepository.openModel("SampleEnterpriseModel",lModelFile,"MetaBossMetaModel", null);
    
    // Obtain the singleton representing outermost model package
    MetaBossModelPackage lModelPackage = (MetaBossModelPackage)lModelRepository.getModelExtent("SampleEnterpriseModel");
    
    // Load the enteprise object the root of the enterorise model
    Enterprise lEnterprise = (Enterprise)lMetaBossModelPackage.getModelElement().getByRef("Enterprise");
    
    // Having the model package and enterprise is enough to discover the rest of the model
    
    
    
  • Include following jars into the classpath of the running application:

    ${metaboss_home}/lib/MetaBossCore.jarMetaBoss core utilities library
    ${metaboss_home}/lib/MetaBossComponentNamingProvider.jarMetaBoss component naming engine library
    ${metaboss_home}/lib/MetaBossEnterprise.jarMetaBoss enterprise components frameworkk library
    ${metaboss_home}/lib/MetaBossModel.jarMetaBoss design model access library
    ${metaboss_home}/thirdpartylib/commons-logging-1.0.3.jarApache Commons Logging abstraction library
    ${metaboss_home}/thirdpartylib/log4j-1.2.8.jarApache Log4j library
    ${metaboss_home}/thirdpartylib/netbeansmdr-20040212/jmi.jarPart of NetBeans MDR framework
    ${metaboss_home}/thirdpartylib/netbeansmdr-20040212/jmiutils.jarPart of NetBeans MDR framework
    ${metaboss_home}/thirdpartylib/netbeansmdr-20040212/mdrapi.jarPart of NetBeans MDR framework
    ${metaboss_home}/thirdpartylib/netbeansmdr-20040212/mof.jarPart of NetBeans MDR framework
    ${metaboss_home}/thirdpartylib/netbeansmdr-20040212/nbmdr.jarPart of NetBeans MDR framework
    ${metaboss_home}/thirdpartylib/netbeansmdr-20040212/openide-util.jarPart of NetBeans MDR framework

  • Set the MetaBoss.Home Java system property to point to the top level installation directory of MetaBoss. (eg. use -D command line VM argument)
  • You may want to use log4j.properties file similar to the one below if you want to see debug information coming out of the MetaBoss libraries:
    # This example shows the log4j configuration enabling debug output
    # from all the packages
    
    # Set root logger level to DEBUG and its only appender to A1.
    log4j.rootLogger=DEBUG, A1
    
    # A1 is set to be a ConsoleAppender.
    log4j.appender.A1=org.apache.log4j.ConsoleAppender
    
    # A1 uses PatternLayout.
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
    
    

Additional Notes

The MetaBoss metamodel repository is a storage mechanism for enterprise metadata. It is being edited with use of MetaBoss Design Studio and it is being read by practically every generator in MetaBoss suite.

The MetaBoss metamodel repository is based on MDR (stands for Metadata Repository) library, which is a subproject of the NetBeans project. The MDR is really a reference implementation of the JMI (stands for Java Metadata Interchange) standard, which in turn is based on MOF (stands for Meta Object Facility) standard published by OMG.

MetaBoss repository has a few important features not present so far in MDR framework:

  • Ability to define directory tree structure for the models and save and retrieve files in accordance with this definition. MDR has theoretical ability to save and read multiple XMI files, but MetaBoss repository is more sutable for practitioners. For example it only saves files, which have been changed.
  • Ability to attach file to any element of the model. This feature somehow is not part of current JMI/MOF standards, but again it is very useful for practitioners.
It is, of course our intention to retire MetaBoss's extra features as soon as MDR/JMI/MOF will provide something similar.

Typically application, which wants to use metamodel will lookup com.metaboss.sdlctools.models.ModelRepository component via JNDI, open or create model storage and navigate around model elements to complete its job. The repository can hold any number of instances of the model. It can also hold instances of the different models. At run time such application needs to include some java libraries and set some system propertries, so MetaBoss metamodel access library can have everything it needs to find and use the model files.

References

To find out more about MDR, JMI and MOF use following links: