Java Reference
In-Depth Information
out.println("\t\tAD=" + ads[j].getName() + " - " +
ads[j].getDescription());
}
}
}
private MetaTypeService getMetaTypeService() {...}
}
The command is simple: you ask the MetaTypeService if a specified bundle has Meta-
TypeInformation objects associated with it. The type command accepts a bundle
identifier as an argument. You get the MetaTypeService and retrieve the Bundle
object associated with the specified bundle identifier. You invoke the getMetaType-
Information() method to retrieve the associated metatype information. If there is
metatype information, you get the PID s; and for each PID , you get the object class def-
inition. Likewise, for each object class definition, you get the AttributeDefinition s
and print their names and descriptions. You can now use this command to get a list of
all known PID s and their respective properties for any given bundle identifier.
To run this example, go back into the chapter09/combined-example/ directory of
the companion code. If you haven't already done so, type ant to build the example
and java -jar launcher.jar bundles to execute it. To interact with the shell, use
telnet localhost 7070 . This example uses the Apache Felix Metatype implementa-
tion ( http://felix.apache.org/site/apache-felix-metatype-service.html ) . Here's a ses-
sion using the type command:
-> bundles
...
[ 2] [ ACTIVE] managed.service
Location: file:bundles/managed.service-2.0.jar
Symbolic Name: org.foo.managed.service
...
-> type 2
org.foo.managed.service
OCD=EchoServer
AD=port - The port the Echo Server listens on
->
All you need to do is execute the type command with the bundle identifier of a bun-
dle providing metadata, and you get a description of what kind of properties any
associated PID s can understand. This makes it a little easier to properly configure arbi-
trary services.
Where are we now? You've learned how to configure bundles and provide meta-
type information about configuration properties. This combination allows you to cre-
ate externally and generically configurable applications. What more do you need? Not
all configuration information is intended to be externally managed; for example,
most preference settings in an application fall in this category. Where should a bundle
store such configuration information? The OSG i Preferences Service can help you
here; let's look at how it works next.
 
Search WWH ::




Custom Search