Author: anuzzolese
Date: Wed Mar 28 14:28:55 2012
New Revision: 1306370

URL: http://svn.apache.org/viewvc?rev=1306370&view=rev
Log:
[STANBOL-560] Initial commit of the adapters' root.

Added:
    incubator/stanbol/trunk/rules/adapters/abstract/pom.xml
    incubator/stanbol/trunk/rules/adapters/abstract/src/
    incubator/stanbol/trunk/rules/adapters/abstract/src/license/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/license/THIRD-PARTY.properties
    incubator/stanbol/trunk/rules/adapters/abstract/src/main/
    incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/
    incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/
    incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AbstractAdaptableAtom.java
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AbstractRuleAdapter.java
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AdaptableAtom.java
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/RuleAdaptersFactoryImpl.java
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/RuleAdaptersManagerImpl.java
    incubator/stanbol/trunk/rules/adapters/abstract/src/main/resources/
    incubator/stanbol/trunk/rules/adapters/abstract/src/main/resources/META-INF/
    incubator/stanbol/trunk/rules/adapters/abstract/src/main/resources/OSGI-INF/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/resources/OSGI-INF/metatype/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/main/resources/OSGI-INF/metatype/metatype.properties
    incubator/stanbol/trunk/rules/adapters/abstract/src/test/
    incubator/stanbol/trunk/rules/adapters/abstract/src/test/java/
    incubator/stanbol/trunk/rules/adapters/abstract/src/test/java/org/
    incubator/stanbol/trunk/rules/adapters/abstract/src/test/java/org/apache/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/test/java/org/apache/stanbol/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/test/java/org/apache/stanbol/rules/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/test/java/org/apache/stanbol/rules/adapter/
    
incubator/stanbol/trunk/rules/adapters/abstract/src/test/java/org/apache/stanbol/rules/adapter/impl/
    incubator/stanbol/trunk/rules/adapters/abstract/src/test/resources/
Modified:
    incubator/stanbol/trunk/rules/adapters/abstract/   (props changed)

Propchange: incubator/stanbol/trunk/rules/adapters/abstract/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Mar 28 14:28:55 2012
@@ -0,0 +1,5 @@
+.classpath
+.project
+.settings
+.DS_Store
+target

Added: incubator/stanbol/trunk/rules/adapters/abstract/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/abstract/pom.xml?rev=1306370&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/abstract/pom.xml (added)
+++ incubator/stanbol/trunk/rules/adapters/abstract/pom.xml Wed Mar 28 14:28:55 
2012
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more 
contributor 
+       license agreements. See the NOTICE file distributed with this work for 
additional 
+       information regarding copyright ownership. The ASF licenses this file 
to 
+       You under the Apache License, Version 2.0 (the "License"); you may not 
use 
+       this file except in compliance with the License. You may obtain a copy 
of 
+       the License at http://www.apache.org/licenses/LICENSE-2.0 Unless 
required 
+       by applicable law or agreed to in writing, software distributed under 
the 
+       License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
CONDITIONS 
+       OF ANY KIND, either express or implied. See the License for the 
specific 
+       language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+       <modelVersion>4.0.0</modelVersion>
+
+       <parent>
+               <groupId>org.apache.stanbol</groupId>
+               <artifactId>stanbol-parent</artifactId>
+               <version>0.9.0-incubating-SNAPSHOT</version>
+               <relativePath>../../parent</relativePath>
+       </parent>
+
+       <groupId>org.apache.stanbol</groupId>
+       <artifactId>org.apache.stanbol.rules.adapters.abstract</artifactId>
+       <packaging>bundle</packaging>
+
+       <name>Apache Stanbol Rules - Adapters</name>
+       <description>
+    The set of functionalities for manipulating
+    inference rules, complete with built-in atoms.
+  </description>
+
+       <inceptionYear>2010</inceptionYear>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <extensions>true</extensions>
+                               <configuration>
+                                       <instructions>
+                                               <Bundle-ClassPath>
+                                                       .,
+                                                       META-INF
+                               </Bundle-ClassPath>
+                                               <Export-Package>
+                                                       
org.apache.stanbol.rules.adapters.*
+                               </Export-Package>
+                                               <Import-Package>
+                                                       org.slf4j.*,
+                                                       *
+                               </Import-Package>
+                                               <_nouses>true</_nouses>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-scr-plugin</artifactId>
+                       </plugin>
+               </plugins>
+       </build>
+
+       <dependencies>
+
+               <!-- OSGi deps -->
+               <dependency>
+                       <groupId>org.apache.felix</groupId>
+                       
<artifactId>org.apache.felix.scr.annotations</artifactId>
+               </dependency>
+
+               <!-- Stanbol deps -->
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       <artifactId>org.apache.stanbol.rules.base</artifactId>
+               </dependency>
+               
+               <!-- Testing deps -->
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+               </dependency>
+
+       </dependencies>
+
+</project>

Added: 
incubator/stanbol/trunk/rules/adapters/abstract/src/license/THIRD-PARTY.properties
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/abstract/src/license/THIRD-PARTY.properties?rev=1306370&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/rules/adapters/abstract/src/license/THIRD-PARTY.properties
 (added)
+++ 
incubator/stanbol/trunk/rules/adapters/abstract/src/license/THIRD-PARTY.properties
 Wed Mar 28 14:28:55 2012
@@ -0,0 +1,26 @@
+# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
+#-------------------------------------------------------------------------------
+# Already used licenses in project :
+# - Apache 2
+# - Apache License
+# - BSD
+# - BSD-style license
+# - CDDL 1.1
+# - Common Development and Distribution License (CDDL) v1.0
+# - Common Public License Version 1.0
+# - GPL2 w/ CPE
+# - ICU License
+# - MIT License
+# - The Apache Software License, Version 2.0
+#-------------------------------------------------------------------------------
+# Please fill the missing licenses for dependencies :
+#
+#
+#Wed Feb 15 19:05:24 CET 2012
+asm--asm--3.1=BSD License
+javax.servlet--servlet-api--2.4=Common Development And Distribution License 
(CDDL), Version 1.0
+org.codehaus.jettison--jettison--1.3=The Apache Software License, Version 2.0
+org.osgi--org.osgi.compendium--4.1.0=The Apache Software License, Version 2.0
+org.osgi--org.osgi.core--4.1.0=The Apache Software License, Version 2.0
+owlapi--owlapi--3.2.3=The Apache Software License, Version 2.0
+xerces--xercesImpl--2.7.1=The Apache Software License, Version 2.0

Added: 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AbstractAdaptableAtom.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AbstractAdaptableAtom.java?rev=1306370&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AbstractAdaptableAtom.java
 (added)
+++ 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AbstractAdaptableAtom.java
 Wed Mar 28 14:28:55 2012
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters;
+
+import org.apache.stanbol.rules.base.api.RuleAdapter;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+
+/**
+ * Abstract class for an {@link AdaptableAtom}.<br/>
+ * This class should be extended by any implementation o an {@link 
AdaptableAtom} as it override the
+ * <code>setRuleAdapter</code> method providing a general implementation.
+ * 
+ * @author anuzzolese
+ * 
+ */
+public abstract class AbstractAdaptableAtom implements AdaptableAtom {
+
+    protected RuleAdapter adapter;
+
+    @Override
+    public void setRuleAdapter(RuleAdapter adapter) {
+        this.adapter = adapter;
+    }
+
+    @Override
+    public abstract <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+                                                  
UnavailableRuleObjectException,
+                                                  
UnsupportedTypeForExportException;
+
+}

Added: 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AbstractRuleAdapter.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AbstractRuleAdapter.java?rev=1306370&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AbstractRuleAdapter.java
 (added)
+++ 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AbstractRuleAdapter.java
 Wed Mar 28 14:28:55 2012
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters;
+
+import org.apache.stanbol.rules.base.api.Adaptable;
+import org.apache.stanbol.rules.base.api.Recipe;
+import org.apache.stanbol.rules.base.api.Rule;
+import org.apache.stanbol.rules.base.api.RuleAdapter;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+
+/**
+ * Thi abstract class implements the method <code>adaptTo</code>
+ * 
+ * and introduced new methods that should be implemented by concrete adapters, 
i.e.,:
+ * <ul>
+ * <li><code>adaptRecipeTo</code></li>
+ * <li><code>adaptRuleTo</code></li>
+ * <li><code>adaptRuleAtomTo</code></li>
+ * </ul>
+ * 
+ * @author anuzzolese
+ * 
+ */
+public abstract class AbstractRuleAdapter implements RuleAdapter {
+
+    public <T> T adaptTo(Adaptable adaptable, Class<T> type) throws 
RuleAtomCallExeption,
+                                                            
UnavailableRuleObjectException,
+                                                            
UnsupportedTypeForExportException {
+        if (adaptable instanceof Recipe) {
+            return adaptRecipeTo((Recipe) adaptable, type);
+        } else if (adaptable instanceof Rule) {
+            return adaptRuleTo((Rule) adaptable, type);
+        } else if (adaptable instanceof RuleAtom) {
+            return adaptRuleAtomTo((RuleAtom) adaptable, type);
+        } else {
+            throw new UnavailableRuleObjectException("The adaptable class " + 
adaptable.getClass()
+                                                     + " is not supported by 
the adapter " + this.getClass());
+        }
+    }
+
+    /**
+     * It allows to adapt a {@link Recipe} object passed as first argument to 
an instance of the class passed
+     * as second argument.
+     * 
+     * @param <T>
+     * @param recipe
+     *            {@link Recipe}
+     * @param type
+     *            {@link Class}
+     * @return the <code>recipe</code> adapted to {@link Class} 
<code>type</code>
+     * @throws RuleAtomCallExeption
+     * @throws UnsupportedTypeForExportException
+     * @throws UnavailableRuleObjectException
+     */
+    protected abstract <T> T adaptRecipeTo(Recipe recipe, Class<T> type) 
throws RuleAtomCallExeption,
+                                                                        
UnsupportedTypeForExportException,
+                                                                        
UnavailableRuleObjectException;
+
+    /**
+     * 
+     * It allows to adapt a {@link Rule} object passed as first argument to an 
instance of the class passed as
+     * second argument.
+     * 
+     * @param <T>
+     * @param rule
+     *            {@link Rule}
+     * @param type
+     *            {@link Class}
+     * @return the <code>rule</code> adapted to the {@link Class} 
<code>type</code>
+     * @throws RuleAtomCallExeption
+     * @throws UnsupportedTypeForExportException
+     * @throws UnavailableRuleObjectException
+     */
+    protected abstract <T> T adaptRuleTo(Rule rule, Class<T> type) throws 
RuleAtomCallExeption,
+                                                                  
UnsupportedTypeForExportException,
+                                                                  
UnavailableRuleObjectException;
+
+    /**
+     * 
+     * It allows to adapt a {@link RuleAtom} object passed as first argument 
to an instance of the class
+     * passed as second argument.
+     * 
+     * @param <T>
+     * @param ruleAtom
+     *            {@link RuleAtom}
+     * @param type
+     *            {@link Class}
+     * @return the <code>ruleAtom</code> adapted to the {@link Class} 
<code>type</code>
+     * @throws RuleAtomCallExeption
+     * @throws UnsupportedTypeForExportException
+     * @throws UnavailableRuleObjectException
+     */
+    protected abstract <T> T adaptRuleAtomTo(RuleAtom ruleAtom, Class<T> type) 
throws RuleAtomCallExeption,
+                                                                              
UnsupportedTypeForExportException,
+                                                                              
UnavailableRuleObjectException;
+}

Added: 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AdaptableAtom.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AdaptableAtom.java?rev=1306370&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AdaptableAtom.java
 (added)
+++ 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/AdaptableAtom.java
 Wed Mar 28 14:28:55 2012
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters;
+
+import org.apache.stanbol.rules.base.api.RuleAdapter;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+
+/**
+ * 
+ * An adaptable atom is any rule atom that the adapters provide for converting 
Stanbol rules to the
+ * destination format.
+ * 
+ * @author anuzzolese
+ * 
+ */
+public interface AdaptableAtom {
+
+    /**
+     * It sets the rule adapter.
+     * 
+     * @param adapter
+     *            the {@link RuleAdapter}
+     */
+    public void setRuleAdapter(RuleAdapter adapter);
+
+    /**
+     * 
+     * @param <T>
+     * @param ruleAtom
+     *            a {@link RuleAtom}
+     * @return The <code>ruleAtom</code> converted to the class <T>
+     * @throws RuleAtomCallExeption
+     * @throws UnsupportedTypeForExportException
+     * @throws UnavailableRuleObjectException
+     */
+    public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+                                         UnsupportedTypeForExportException,
+                                         UnavailableRuleObjectException;
+}

Added: 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/RuleAdaptersFactoryImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/RuleAdaptersFactoryImpl.java?rev=1306370&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/RuleAdaptersFactoryImpl.java
 (added)
+++ 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/RuleAdaptersFactoryImpl.java
 Wed Mar 28 14:28:55 2012
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters.impl;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.rules.base.api.RuleAdapter;
+import org.apache.stanbol.rules.base.api.RuleAdaptersFactory;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A concrete implementation of a {@link RuleAdaptersFactory}.
+ * 
+ * @author anuzzolese
+ * 
+ */
+@Component(immediate = true, metatype = true)
+@Service(RuleAdaptersFactory.class)
+public class RuleAdaptersFactoryImpl implements RuleAdaptersFactory, 
ServiceListener {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private Map<Class<?>,RuleAdapter> ruleAdapters;
+
+    private ComponentContext componentContext;
+
+    public RuleAdaptersFactoryImpl() {
+        ruleAdapters = new HashMap<Class<?>,RuleAdapter>();
+    }
+
+    /**
+     * Used to configure an instance within an OSGi container.
+     * 
+     * @throws IOException
+     */
+    @SuppressWarnings({"unchecked", "unused"})
+    @Activate
+    protected void activate(ComponentContext context) throws IOException {
+
+        context.getBundleContext().addServiceListener(this);
+
+        this.componentContext = context;
+        log.info("in " + RuleAdaptersFactoryImpl.class + " activate with 
context " + context);
+        if (context == null) {
+            throw new IllegalStateException("No valid" + 
ComponentContext.class + " parsed in activate!");
+        }
+        activate((Dictionary<String,Object>) context.getProperties());
+    }
+
+    /**
+     * Should be called within both OSGi and non-OSGi environments.
+     * 
+     * @param configuration
+     * @throws IOException
+     */
+    protected void activate(Dictionary<String,Object> configuration) throws 
IOException {
+
+        log.info("RuleExportServiceManager is active", this);
+    }
+
+    @Deactivate
+    protected void deactivate(ComponentContext context) {
+        log.info("in " + RuleAdaptersFactoryImpl.class + " deactivate with 
context " + context);
+    }
+
+    @Override
+    public void serviceChanged(ServiceEvent event) {
+        ServiceReference serviceReference = event.getServiceReference();
+
+        Object service = 
componentContext.getBundleContext().getService(serviceReference);
+
+        if (service instanceof RuleAdapter) {
+            RuleAdapter RuleAdapter = (RuleAdapter) 
componentContext.getBundleContext().getService(
+                serviceReference);
+
+            switch (event.getType()) {
+                case ServiceEvent.MODIFIED:
+
+                    try {
+                        removeRuleAdapter(RuleAdapter);
+                        log.info("Removed Rule Adapter " + 
RuleAdapter.getClass().getCanonicalName());
+
+                        addRuleAdapter(RuleAdapter);
+                        log.info("Added Rule Adapter " + 
RuleAdapter.getClass().getCanonicalName());
+                    } catch (UnavailableRuleObjectException e) {
+                        log.error("Unavailable Rule Object " + e.getMessage());
+                    }
+                    break;
+                case ServiceEvent.REGISTERED:
+                    try {
+                        addRuleAdapter(RuleAdapter);
+                        log.info("Added Rule Adapter " + 
RuleAdapter.getClass().getCanonicalName());
+                    } catch (UnavailableRuleObjectException e) {
+                        log.error("Unavailable Rule Object " + e.getMessage());
+                    }
+
+                    break;
+                case ServiceEvent.UNREGISTERING:
+                    try {
+                        removeRuleAdapter(RuleAdapter);
+                        log.info("Removed Rule Adapter " + 
RuleAdapter.getClass().getCanonicalName());
+                    } catch (UnavailableRuleObjectException e) {
+                        log.error("Unavailable Rule Object " + e.getMessage());
+                    }
+                    break;
+
+                default:
+                    break;
+            }
+
+            log.info(ruleAdapters.entrySet().size() + " active rule adapters 
");
+        }
+    }
+
+    @Override
+    public List<RuleAdapter> listRuleAdapters() {
+
+        List<RuleAdapter> ruleAdapters = Collections.emptyList();
+        ruleAdapters.addAll(this.ruleAdapters.values());
+        return ruleAdapters;
+
+    }
+
+    @Override
+    public RuleAdapter getRuleAdapter(Class<?> type) throws 
UnavailableRuleObjectException {
+
+        return ruleAdapters.get(type);
+    }
+
+    @Override
+    public synchronized void addRuleAdapter(RuleAdapter ruleAdapter) throws 
UnavailableRuleObjectException {
+
+        ruleAdapters.put((Class<?>) ruleAdapter.getExportClass(), ruleAdapter);
+
+    }
+
+    @Override
+    public synchronized void removeRuleAdapter(RuleAdapter ruleAdapter) throws 
UnavailableRuleObjectException {
+        ruleAdapters.remove(ruleAdapter.getExportClass());
+
+    }
+
+}

Added: 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/RuleAdaptersManagerImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/RuleAdaptersManagerImpl.java?rev=1306370&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/RuleAdaptersManagerImpl.java
 (added)
+++ 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/java/org/apache/stanbol/rules/adapters/impl/RuleAdaptersManagerImpl.java
 Wed Mar 28 14:28:55 2012
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters.impl;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.List;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.rules.base.api.Adaptable;
+import org.apache.stanbol.rules.base.api.RuleAdapter;
+import org.apache.stanbol.rules.base.api.RuleAdapterManager;
+import org.apache.stanbol.rules.base.api.RuleAdaptersFactory;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A concrete implementation of a {@link RuleAdapterManager}.
+ * 
+ * @author anuzzolese
+ * 
+ */
+
+@Component(immediate = true, metatype = true)
+@Service(RuleAdapterManager.class)
+public class RuleAdaptersManagerImpl implements RuleAdapterManager {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference
+    RuleAdaptersFactory ruleAdaptersFactory;
+
+    public RuleAdaptersManagerImpl() {
+
+    }
+
+    /**
+     * Constructor for non-OSGi environments.
+     */
+    public RuleAdaptersManagerImpl(Dictionary<String,Object> configuration,
+                                   RuleAdaptersFactory ruleAdaptersFactory) {
+        this.ruleAdaptersFactory = ruleAdaptersFactory;
+
+        try {
+            activate(configuration);
+        } catch (IOException e) {
+            log.error("Unable to access the configuration.", e);
+        }
+    }
+
+    @Override
+    public <AdaptedTo> RuleAdapter getAdapter(Adaptable adaptable, 
Class<AdaptedTo> adaptedToType) throws UnavailableRuleObjectException {
+
+        return ruleAdaptersFactory.getRuleAdapter(adaptedToType);
+
+    }
+
+    /**
+     * Used to configure an instance within an OSGi container.
+     * 
+     * @throws IOException
+     */
+    @SuppressWarnings("unchecked")
+    @Activate
+    protected void activate(ComponentContext context) throws IOException {
+        log.info("in " + RuleAdaptersManagerImpl.class + " activate with 
context " + context);
+        if (context == null) {
+            throw new IllegalStateException("No valid" + 
ComponentContext.class + " parsed in activate!");
+        }
+        activate((Dictionary<String,Object>) context.getProperties());
+    }
+
+    /**
+     * Should be called within both OSGi and non-OSGi environments.
+     * 
+     * @param configuration
+     * @throws IOException
+     */
+    protected void activate(Dictionary<String,Object> configuration) throws 
IOException {
+
+        log.info("RuleAdapterManagerImpl is active", this);
+    }
+
+    @Deactivate
+    protected void deactivate(ComponentContext context) {
+        log.info("in " + RuleAdaptersManagerImpl.class + " deactivate with 
context " + context);
+    }
+
+    @Override
+    public List<RuleAdapter> listRuleAdapters() {
+
+        return ruleAdaptersFactory.listRuleAdapters();
+    }
+
+}

Added: 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/abstract/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1306370&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/resources/OSGI-INF/metatype/metatype.properties
 (added)
+++ 
incubator/stanbol/trunk/rules/adapters/abstract/src/main/resources/OSGI-INF/metatype/metatype.properties
 Wed Mar 28 14:28:55 2012
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#===============================================================================
+#Properties defined by the Rule Store
+#===============================================================================
+org.apache.stanbol.rules.manager.changes.RuleStoreImpl.name = Apache Stanbol 
Rule Store
+org.apache.stanbol.rules.manager.changes.RuleStoreImpl.description = A storage 
facility for Apache Stanbol rules and recipes.
+
+org.apache.stanbol.rules.base.rule_namespace.name = Rule namespace
+org.apache.stanbol.rules.base.rule_namespace.description = The default 
namespace of Stanbol rule instances in the rule ontology.
+
+org.apache.stanbol.rules.base.rule_ontology.name = Rule ontology location
+org.apache.stanbol.rules.base.rule_ontology.description = The URL of the 
ontology containing the default rule set. Can be overridden programmatically.
\ No newline at end of file


Reply via email to