Hi Alessandro, all In RICK (entity hub) the Yard (Storage) component is designed to run also without an OSGI environment. There I solved this issue by implementing a configuration class that simple wraps the key->value configuration used by OSGI. I also added a second constructor that uses an instance of this configuration class as parameter.
See [1] for the SolrYard implementation. Have a special look at the two constructors and the two activate methods (one for OSGI and the other for initialization outside of OSGI) [2] The configuration implementation provides also two constructors. The first with Dictionary<String, Object> as parameter that can be used to create an instance based on the configuration parsed by OSGI and the second with the minimal configuration needed to configure a SolrYard instance. I have decided to also use a Dictionary<String, Object> to store the actual configuration in [2]. This makes the implementation of the config class more complex, but has the advantage, that most of the validation of the configuration can be moved form the activate method of the component to the configuration class. This was also my first try to solve a problem like this. So any feedback is very welcome. best Rupert [1] http://svn.apache.org/repos/asf/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/impl/SolrYard.java [2] http://svn.apache.org/repos/asf/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/impl/SolrYardConfig.java] On Mon, Dec 20, 2010 at 8:25 PM, Alessandro Adamou (JIRA) <[email protected]> wrote: > > [ > https://issues.apache.org/jira/browse/STANBOL-10?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12973318#action_12973318 > ] > > Alessandro Adamou commented on STANBOL-10: > ------------------------------------------ > > I'd like to hint at a possible pattern we could adopt for taking advantage of > SCR without being a slave of it. All classes that implement > components/services could have the structure in the example below. > > Basically we provide a "manual" alternative for anything that would normally > be managed by SCR, yet the "manual methods" would only, indeed, be invoked > manually and ignored by SCR. Do you foresee any possible cons to the adoption > of such a strategy? > > ------------------------- > > @Component(immediate = true, metatype = true) > @Service(A.class) > public class AImpl implements A { > > private static String PROPERTY1_DEFAULT = "default_value"; > > �...@property(value = PROPERTY1_DEFAULT) > public static String PROPERTY_1 = "org.apache.stanbol.property1"; > > �...@reference > B var1; > > /** > * Called by SCR > */ > public AImpl() { > // ... > // constructor stuff > } > > /** > * Called by non-SCR environments (e.g. unit tests). > * > * This contructor requires as parameters the values > * that SCR would normally assign automatically. > */ > public AImpl(B var1, String pvalue) { > this(); > this.var1 = var1; > if (pvalue == null) > pvalue = PROPERTY1_DEFAULT; > initialize(pvalue); > } > > /** > * Here we perform what would normally be done by activate() > */ > private void initialize(String pvalue) { > // ... do something with pvalue > // ... other init code > } > > /* > * Here activate() simply passes values onto initialize() > */ > protected void activate(ComponentContext ce) { > // We can assume var1 to be assigned by SCR > // > // Get the vaue of the Felix property > String pvalue = (String) ce.getProperties().get(PROPERTY_1); > initialize(pvalue); > } > > protected void deactivate(ComponentContext ce) { > // ... > // Deactivation stuff > } > > } > >> KReS Rules Test Fails >> --------------------- >> >> Key: STANBOL-10 >> URL: https://issues.apache.org/jira/browse/STANBOL-10 >> Project: Stanbol >> Issue Type: Bug >> Components: KReS >> Environment: Ubuntu, JDK1.6, Maven 2.2.1 >> Reporter: Fabian Christ >> Attachments: >> eu.iksproject.kres.semion.reengineer.db.DBExtractorTest.txt, >> vcs-diff7641646626827419329.patch >> >> >> [INFO] >> ------------------------------------------------------------------------ >> [INFO] Building IKS KReS Rules >> [INFO] task-segment: [install] >> [INFO] >> ------------------------------------------------------------------------ >> ------------------------------------------------------- >> T E S T S >> ------------------------------------------------------- >> Running eu.iksproject.kres.rules.manager.KReSRemoveRecipeTest >> Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.772 sec >> Running eu.iksproject.kres.rules.manager.KReSRuleStoreTest >> ./src/main/resources/RuleOntology/TestKReSOntologyRules.owl >> ECCOMI >> /home/fchrist/Coding/Apache/Stanbol/src/kres/eu.iksproject.kres.rules/src/main/resources/RuleOntology/rmi_config.owl >> Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.132 sec >> Running eu.iksproject.kres.rules.manager.KReSGetRecipeTest >> Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.69 sec >> Running eu.iksproject.kres.rules.manager.KReSGetRuleTest >> Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.388 sec >> Running eu.iksproject.kres.rules.manager.KReSLoadRuleFileTest >> http://kres.iks-project.eu/ontology/meta/rmi.owl# >> 106 121 106 121 >> Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.349 sec >> Running eu.iksproject.kres.rules.manager.KReSAddRecipeTest >> Tests run: 5, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.711 sec >> <<< FAILURE! >> Running eu.iksproject.kres.rules.manager.KReSRemoveRuleTest >> Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.695 sec >> <<< FAILURE! >> Running eu.iksproject.kres.rules.manager.KReSAddRuleTest >> entriamo http://kres.iks-project.eu/ontology/meta/rmi.owl#MyRuleA >> Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.337 sec >> Running eu.iksproject.kres.rules.parser.KReSRuleParserTest >> RULE : RULE http://kres.iks-project.eu/ontology/meta/variables#rule1 ASSERTS >> THAT >> IF >> Individual http://kres.iks-project.eu/ontology/meta/variables#y has >> object property http://kres.iks-project.eu/ontology/meta/variables#y that >> refers to individual http://kres.iks-project.eu/ontology/meta/variables#z >> AND Individual http://kres.iks-project.eu/ontology/meta/variables#x >> has object property http://kres.iks-project.eu/ontology/meta/variables#x >> that refers to individual >> http://kres.iks-project.eu/ontology/meta/variables#y >> IMPLIES >> Individual http://kres.iks-project.eu/ontology/meta/variables#x has >> object property http://kres.iks-project.eu/ontology/meta/variables#x that >> refers to individual http://kres.iks-project.eu/ontology/meta/variables#z >> RULE LIST IS NULL >> Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.279 sec >> Results : >> Tests in error: >> testAddRecipe_3args_2(eu.iksproject.kres.rules.manager.KReSAddRecipeTest) >> testRemoveSingleRule(eu.iksproject.kres.rules.manager.KReSRemoveRuleTest) >> Tests run: 23, Failures: 0, Errors: 2, Skipped: 0 >> [INFO] >> ------------------------------------------------------------------------ >> [ERROR] BUILD FAILURE >> [INFO] >> ------------------------------------------------------------------------ >> [INFO] There are test failures. >> The same error also occurs in the old IKS Google SVN code base. > > -- > This message is automatically generated by JIRA. > - > You can reply to this email to add a comment to the issue online. > > -- | Rupert Westenthaler [email protected] | Bodenlehenstraße 11 ++43-699-11108907 | A-5500 Bischofshofen
