hivemind-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fernando Enrique Ocampo Calero <fdoca...@gmail.com>
Subject Re: properties file
Date Wed, 21 Sep 2005 15:03:12 GMT
Thanks a lot, it is a good solution. If I can improve your example (as you
say: "I bet that there is probably a simpler solution" ) I do not doubt in
putting here :^)=.

Regards,

Fernando

On 9/21/05, Liebig, Stefan <Stefan.Liebig@compeople.de> wrote:
>
>  I bet that there is probably a simpler solution, but how about writing
> you own ObjectPrivider? It is really not that much code.
>  The ObjectProvider:
>  public class ConfigObjectProvider implements ObjectProvider {
>  /**
> */
> public ConfigObjectProvider() {
> super();
> }
>  /**
> * @see org.apache.hivemind.service.ObjectProvider#
> * provideObject(org.apache.hivemind.internal.Module, java.lang.Class,
> java.lang.String, org.apache.hivemind.Location)
> */
> public Object provideObject( Module contributingModule, Class
> propertyType, String locator, Location location ) {
>  File configFile = new File( locator );
> Properties properties = new Properties();
> try {
> properties.load( new FileInputStream( configFile ) );
> return properties;
> } catch ( FileNotFoundException fnfe ) {
> throw new ApplicationRuntimeException( "Could not locate file: " +
> locator, fnfe );
> } catch ( IOException ioe ) {
> throw new ApplicationRuntimeException( "Could not load config file: " +
> locator, ioe );
> }
> }
> }
>  The hivemind fragment to define it:
>   <contribution configuration-id="hivemind.ObjectProviders">
> <provider prefix="config" service-id="ConfigObjectProvider"/>
> </contribution>
>  <service-point id="ConfigObjectProvider" interface="
> org.apache.hivemind.service.ObjectProvider">
> <create-instance class="yourpackage.objectprovider.ConfigObjectProvider"/>
> </service-point>
>
> Usage example:
>   <service-point id="ConfigObjectProviderTest" interface="java.util.Map">
> This "service" now contains the config properties from
> c:\temp\test.properties!
>
> <invoke-factory>
> <construct class="java.util.HashMap">
> <object>config:c:\temp\test.properties</object>
> </construct>
> </invoke-factory>
> </service-point>
>  With the ObjectProvider you can inject the properties everywhere where
> you need a
> config file as a map.
>
> Hope that helps a little bit.
>  Stefan
>
> ------------------------------
> *Von:* Fernando Enrique Ocampo Calero [mailto:fdocampo@gmail.com]
> *Gesendet:* Mo 19.09.2005 16:44
> *An:* hivemind-user@jakarta.apache.org
> *Betreff:* properties file
>
> Hi,
>
> I am looking hivemind a few days ago (I think my project solution so far)
> and in a little example I tried to load in a Map some "key/values" based in
> the example of your hivemind documentation (successful test)... here the
> example:
>
> <configuration-point id="Simple">
> <schema>
> <element name="test" key-attribute="key">
> <attribute name="key"/>
> <attribute name="value" required="true"/>
> <rules>
> <push-attribute attribute="value"/>
> <invoke-parent method="addElement"/>
> </rules>
> </element>
> </schema>
> </configuration-point>
>
> <contribution configuration-id="Simple">
> <test key="Message" value="com.digicomm.messages.Message"/>
> <test key="BytesMessage" value="com.digicomm.messages.BytesMessage"/>
> <test key="ObjectMessage" value="com.digicomm.messages.ObjectMessage"/>
> <test key="StreamMessage" value="com.digicomm.messages.StreamMessage"/>
> <test key="TextMessage" value="com.digicomm.messages.TextMessage"/>
> <test key="MapMessage" value="com.digicomm.messages.MapMessage"/>
> <test key="xstreamalias.properties" value="nono"/>
> </contribution>
>
> As I say It is OK, but my question is what is the way (in hivemind) to
> avoid write the data (the key/values) in the .xml file? can does HiveMind
> read a properties file and convert it in a properties object? what is the
> way to do that?.
>
> If you don't understand my question, please let me know.
>
>
> Regards,
>
> Fernando
>

Mime
View raw message