Sun Microsystems Logo
Products & Services
 
Support & Training
 
 

Previous Previous     Contents     Index     Next Next
Chapter 7

Creating JavaBeans Components Using the MOF Compiler

This chapter provides an overview of the Managed Object Format (MOF) compiler. This chapter also describes how to create JavaBeans™ components by using the -j option to the mofcomp command. This chapter covers the following topics.


Note - For more information on the MOF Compiler, see the mofcomp(1M) man page.


About the MOF Compiler

Managed Object Format (MOF) is a compiled language developed by the Distributed Management Task Force (DMTF). The MOF language defines static and dynamic classes and instances for CIM and WBEM. You can use the CIM and Solaris MOF files that are included with Solaris WBEM Services. You can also create your own MOF files. For more information on creating your own MOF files using the DMTF's MOF language, see the DMTF Web site at http://www.dmtf.org.

The MOF Compiler, mofcomp(1M) performs the following tasks:

  • Parses MOF files

  • Converts the classes and instances to Java programming language classes

  • Adds the classes to the CIM Object Manager Repository in the default (root\cimv2) or other specified namespace

You can easily convert MOF files to the Java programming language. As a result, applications based on Java technology can interpret and exchange data in MOF files on any machine that runs a Java Virtual Machine.

During a Solaris installation, the MOF compiler compiles the bundled MOF files that describe the CIM and Solaris Schema and adds those files to the CIM Object Manager Repository.

Generating JavaBeans Components Using mofcomp

In the context of WBEM, JavaBeans components, or beans, define methods for accessing and manipulating CIM classes and data. To simplify your development efforts, you can use the -j option to the mofcomp command to generate beans from the CIM classes in your MOF files. These automatically-generated beans define the interfaces. You must add the implementation code.


Note - To safeguard your program from changes that you make to the underlying JavaBeans implementation, use the interfaces rather than the original JavaBeans components.


When you specify the -j option with mofcomp, a Java interface, CIMBean.java, and a bean that implements that interface, CIMBeanImpl.java, are generated. CIMBeanImpl.javacontains all of the code that is common to the generated beans. All generated Java interfaces extend from CIMBean.java. All generated beans extend fromCIMBeanImpl.java, and inherit the base implementation.

For each CIM class that is defined in a MOF file, the MOF compiler JavaBeans generation feature generates a Java programming language interface that contains the following methods:

  • Accessor and mutator methods for the properties that are defined in the MOF file

  • Methods that are comparable to the invokeMethods that are defined in the MOF file

The Java interfaces are named CIMClassBean.java. Bean classes that implement those Java interfaces are named CIMClassBeanImpl.java. In addition, accessor methods for properties that contain the CIM DisplayName, Units, and Version qualifiers are generated.

For each invokeMethod that contains an OUT qualified parameter in a CIM class, a container interface that holds the output that the invoking of the method generates is generated. These interfaces are named CIMClass_MethodNameOutput.java. An instance of this CIMClass_MethodNameOutput.java container interface is required as the last parameter of the bean's method. This container interface is required because the object datatype or datatypes that the bean's method takes as parameters are not mutable. Therefore these data types cannot be used to hold both input and output data.

MOF File Elements

You must include the PACKAGE element in your MOF file to take advantage of the -j option. In addition, you can specify the IMPORTS and EXCEPTIONS elements in the following format:

PACKAGE=NameOfJavaPackage
IMPORTS=JavaClassName1:JavaClassName2:...
EXCEPTIONS=Exception1:Exception2:...

The following table describes these elements.

Table 7-1 MOF File Elements

Element

Description

PACKAGE

Required. Specifies the name of the Java package that contains the source files generated by the MOF compiler.

IMPORTS

Optional. Specifies the names of the Java classes to import into the generated source files. These classes are separated with a colon (:). You can specify as many Java classes as you want, on as many lines as you want.

EXCEPTIONS

Optional. Specifies the names of the Java exceptions that are included in the generated source files. These exceptions are separated with a colon (:). You can specify as many Java class exceptions as you want, on as many lines as you want.


Note - If you specify EXCEPTIONS, you must specify IMPORTS.


How CIM Maps to the Java Programming Language

The following table describes how CIM elements map to elements of the Java programming language.

Table 7-2 How CIM Elements Map to Java Elements

CIM Element

Java Element

Class

The CIM class name is used as the basis for the name of the generated Java source files. The generated Java classes follow the same inheritance as defined in the class-subclass relationships in the MOF.

Property

An accessor and a mutator method are created for each CIM property. The CIM property name is used as the basis for the associated accessor and mutator methods.

Method

For each CIM method, a comparable Java method is created. The method name is used as the basis for the related Java method name. The return value is the same, accounting for the Java data type mapping. Input and output parameters are used as arguments to the Java method. Output parameters are not directly included in the method signature. Instead, output parameters are encapsulated in an output container object that is included as a method parameter.

Qualifier

Qualifiers are described in Table 7-4 and Table 7-5.

Association

Nothing specific required.

Indication

Nothing specific required.

Reference

For each CIM reference, a reference to a generated Java interface is created.

Trigger

Nothing specific required.

Schema

Nothing specific required.

The following table describes how CIM data types map to Java data types.

Table 7-3 How CIM Data Types Map to Java Data Elements

CIM Data Type

Java Data Type

Accessor Method

Mutator Method

uint8 X

UnsignedInt8

UnsignedInt8 getX();

void setX(UnsignedInt8 x);

sint8 X

Byte

Byte getX();

void setX(Byte x);

uint16 X

UnsignedInt16

UnsignedInt16 getX();

void setX(UnsignedInt16 x);

sint16 X

Short

Short getX();

void setX(Short x);

uint32 X

UnsignedInt32

UnsignedInt32 getX();

void setX(UnsignedInt32 x);

sint32 X

Integer

Integer getX();

void setX(Integer x);

uint64 X

UnsignedInt64

UnsignedInt64 getX();

void setX(UnsignedInt64 x);

sint64 X

Long

Long getX();

void setX(Long x);

String X

String

String getX();

void setX(String x);

Boolean X

Boolean

Boolean isX();

void setX(Boolean x);

real32 X

Float

Float getX();

void setX(Float x);

real64 X

Double

Double getX();

void setX(Double x);

DateTime X

CIMDateTime

CIMDateTime getX();

void setX(CIMDateTime x);

Reference X

CIMObjectPath

CIMObjectPath getX();

void setX(CIMObjectPath x);

char16 X

Character

Character getX();

void setX(Character x);

The following table lists the meta qualifiers that refine the definition of the meta constructs in the model. These qualifiers are mutually exclusive and are used to refine the actual usage of an object class or property declaration within the MOF syntax.

Table 7-4 Meta Qualifiers

Qualifier

Scope

Type

Meaning

Association

class

Boolean

No affect on mapping

Indication

class

Boolean

Class is abstract

The following table lists the standard qualifiers and the effect that these qualifiers have on the mapping of a CIM object to a bean. There is no support for optional qualifiers. Javadoc API documentation is produced for each interface and class based on this mapping.

Table 7-5 Standard Qualifiers

Qualifier

Scope

Meaning

ABSTRACT

Class, Association, Indication

The class is abstract and has no effect on the Java programming language interfaces.

DESCRIPTION

Any

The information that is provided generates Javadoc comments in the source file.

DISPLAYNAME

Property

An accessor method for the display name is created:

public String displayNameForProperty();

IN

Parameter

Determines the method signature.

OUT

Parameter

Determines the method parameter signature and return values.

TERMINAL

Class

Class or interface is final.

UNITS

Property, Method, Parameter

Another accessor method is created:

public String getpropertyUnits();

VALUEMAP

Property, Method, Parameter

Beans contain generated constants for each property in a CIM class that has a CIM ValueMap or a Values qualifier. The way in which the constant name and constant value are obtained to generate these class variables depends on the data type of the property and the qualifiers that the property possesses.


Note - The ValueMap and Values qualifiers as defined in the CIM specification have meanings contrary to what the qualifier names might imply. ValueMap defines the legal set of values for a property. Values provides translation between an integer value and a string.


VALUES

Property, Method, Parameter

Beans contain generated constants for each property in a CIM class that has a CIM ValueMap or a Values qualifier. The way in which the constant name and constant value are obtained to generate these class variables depends on the data type of the property and qualifiers that the property possesses.


Note - The ValueMap and Values qualifiers as defined in the CIM specification have meanings contrary to what the qualifier names might imply. ValueMap defines the legal set of values for a property. Values provides translation between an integer value and a string.


VERSION

Class, Schema, Association, Indication

Class possesses a getClassVersion() method

The following table describes how MOF elements map to Java elements.

Table 7-6 How MOF Elements Map to Java Elements

MOF Element

Java Element

Description qualifier

Description of the class, property, or method

Complete MOF representation of the class

The Javadoc class description for both the Java interface and the implementation bean

Previous Previous     Contents     Index     Next Next
 

Updated: 2003-10-07, 17:09