You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2011/01/14 12:39:27 UTC

svn commit: r1058959 [1/4] - in /incubator/stanbol/trunk/rick: ./ generic/core/ generic/core/src/main/java/eu/iksproject/rick/core/model/ generic/core/src/main/java/eu/iksproject/rick/core/site/ generic/core/src/main/java/eu/iksproject/rick/core/utils/...

Author: rwesten
Date: Fri Jan 14 11:39:26 2011
New Revision: 1058959

URL: http://svn.apache.org/viewvc?rev=1058959&view=rev
Log:
Short Summary:
 - Added Unit Tests for RICK Model implementations
 - Applied this tests to the two current implementations
 - Resolved several Bugs, improved code and documentation
 - Some added functionalities for indexing utilities
 
Detailed Changes
 
Services API
 - corrected xml,xmi and xsd namespace within the NamespaceEnum (used '/' instead of '#')
 - Improved Java Doc especially regarding what Exception MUST BE thrown in specific cases (e.g. when NULL is parsed for an parameter)
 - added missing RuntimeExceptions to the throws declaration of methods
 - generally NullPointerExceptions are now thrown instead of IllegalArgumentExeptions if null is parsed as a parameter that does not support it. IllegalArgumentExceptions are now only used if the parsed parameter is not valid.
 - UnsupportedTypeException now extends IllegalArgumentException


Test Framework (eu.iksproject.rick.test)
This component is intended to define Unit Tests that can be used (and extended) by implementations of the Interfaces defined in the Services API.
 - added Unit Tests for Representation, ValueFactory, Text and Reference

Core (eu.iksproject.rick.core)
 - added Unit Tests for Representation, ValueFactory, Text and Reference
 - adapted Exception handling to confirm with the changes described for the Services API
 - Changed all the different Iterator implementations within the utils package to use the generic AdaptingInterator implementation.
 - Introduced a FilteringIterator that can be used in case one needs only to filter values of an Iteration but does not need to adapt/convert values
 - Fixed a Bug with the remove() method of all the previous Iterator implementations.
 - Corrected several Bugs discovered by the added Unit Tests
 - Removed the unused EnumIterator
 - remove the createComponentInstance from OsgiUtils because it was no longer used

Clerezza based Model Implementation (eu.iksproject.rick.model.clerezza)
 - added Unit Tests for Representation, ValueFactory, Text and Reference
 - added additional tests for specific types supported by this implementation
 - remove specific Iterator implementations and replaced them by Adapters and Filters using the AdaptingIterator and FilteringIterator provided by the Core bundle.
 - adapted Exception handling to confirm with the changes described for the Services API
 - Corrected several bugs related to handling natural language texts.
 - Corrected several bugs related to adding/removing Clerezza model instances.
 - Corrected bug that prevented removing multiple values with RdfRepresentation.remove(Stirng,Object) method.
 - Corrected several other bugs discovered while adding the unit tests

SolrYard
 - Corrected a bug where the SolrYard tried to modify the Collection returned by FieldQuery.getSelectedFields() in oder to add the Lucene Score.

indexing/genericRdf
Started to add support for an API based configuration for the RdfIndexer. This should make it more easy to used this Utiliy.
 - renamed a Constant to make its meaning more clear
 - removed unused Clerezza dependencies (this indexer directly uses Jena and Jena TDB)

indexing/dbPedia
 - An adaption needed to reflect the changes of the RdfIndexer

Added:
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/FilteringIterator.java   (with props)
    incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/
    incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/
    incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/
    incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/
    incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/
    incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryRepresentationTest.java   (with props)
    incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryValueFactoryTest.java   (with props)
    incubator/stanbol/trunk/rick/generic/test/src/main/java/eu/iksproject/rick/test/model/RepresentationTest.java   (with props)
    incubator/stanbol/trunk/rick/generic/test/src/main/java/eu/iksproject/rick/test/model/ValueFactoryTest.java   (with props)
    incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexerConfig.java   (with props)
    incubator/stanbol/trunk/rick/lifting/
    incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalTextFilter.java   (with props)
    incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/UriRef2ReferenceAdapter.java   (with props)
    incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/
    incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/
    incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/
    incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/
    incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/
    incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfRepresentationTest.java   (with props)
    incubator/stanbol/trunk/rick/model/clerezza/src/test/java/eu/iksproject/rick/model/clerezza/RdfValueFactoryTest.java   (with props)
Removed:
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/EnumIterator.java
    incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/NaturalLanguageLiteralIterator.java
    incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/ReferenceIterator.java
Modified:
    incubator/stanbol/trunk/rick/   (props changed)
    incubator/stanbol/trunk/rick/generic/core/pom.xml
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/model/InMemoryRepresentation.java
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/model/InMemoryValueFactory.java
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/site/CacheImpl.java
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/AdaptingIterator.java
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/ModelUtils.java
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/OsgiUtils.java
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/TextIterator.java
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/ToStringIterator.java
    incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/TypeSaveIterator.java
    incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/defaults/DataTypeEnum.java
    incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/defaults/NamespaceEnum.java
    incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Reference.java
    incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Representation.java
    incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Text.java
    incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/UnsupportedTypeException.java
    incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/ValueFactory.java
    incubator/stanbol/trunk/rick/generic/test/pom.xml
    incubator/stanbol/trunk/rick/indexing/dbPedia/   (props changed)
    incubator/stanbol/trunk/rick/indexing/dbPedia/src/main/java/eu/iksproject/rick/indexing/dbPedia/cli/CommandLineRunner.java
    incubator/stanbol/trunk/rick/indexing/genericRdf/pom.xml
    incubator/stanbol/trunk/rick/indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/RdfIndexer.java
    incubator/stanbol/trunk/rick/model/clerezza/pom.xml
    incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfReference.java
    incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfRepresentation.java
    incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfText.java
    incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/RdfValueFactory.java
    incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/Literal2TextAdapter.java
    incubator/stanbol/trunk/rick/model/clerezza/src/main/java/eu/iksproject/rick/model/clerezza/impl/LiteralAdapter.java
    incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/impl/SolrYard.java

Propchange: incubator/stanbol/trunk/rick/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jan 14 11:39:26 2011
@@ -0,0 +1,3 @@
+.project
+
+.classpath

Modified: incubator/stanbol/trunk/rick/generic/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/pom.xml?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/pom.xml (original)
+++ incubator/stanbol/trunk/rick/generic/core/pom.xml Fri Jan 14 11:39:26 2011
@@ -135,6 +135,12 @@
     </dependency>
     <!-- for tests -->
     <dependency>
+      <groupId>eu.iksproject</groupId>
+      <artifactId>eu.iksproject.rick.test</artifactId>
+      <version>0.1-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.7</version>

Modified: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/model/InMemoryRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/model/InMemoryRepresentation.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/model/InMemoryRepresentation.java (original)
+++ incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/model/InMemoryRepresentation.java Fri Jan 14 11:39:26 2011
@@ -30,14 +30,25 @@ public class InMemoryRepresentation impl
     protected final Map<String,Object> representation;
     protected final Map<String,Object> unmodRepresentation;
     private final String id;
-
-    public InMemoryRepresentation(String id){
+    /**
+     * creates a new InMemoryRepresentation for the parsed ID
+     * @param id the id of the representation
+     */
+    protected InMemoryRepresentation(String id){
         this(id,null);
     }
     /**
-     * Initialise a new InMemoryRepresenation that contains already some data.
-     * @param id
-     * @param representation
+     * Initialise a new InMemoryRepresenation with the parsed map. Note that the
+     * parsed map is directly used to store the data. That means that callers
+     * MUST keep in minds that changes to that map will influence the internal
+     * state of this instance.<br>
+     * The intension of this constructor is to allow also to define the actual
+     * map implementation used to store the data.
+     * If one also wants to directly parse data already contained within an
+     * other representation one MUST first create deep copy of the according
+     * map!
+     * @param id the id for the Representation
+     * @param representation the map used by this representation to store it's data
      */
     protected InMemoryRepresentation(String id, Map<String,Object> representation){
         if(id == null){
@@ -54,11 +65,14 @@ public class InMemoryRepresentation impl
     @SuppressWarnings("unchecked")
     @Override
     public void add(String field, Object parsedValue) {
-        //TODO:add processing of values
-        // URI, URL -> Reference
-        // String[] -> Text
-        // check Collections!
-        // The rest should be added as Objects
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
+        if(parsedValue == null){
+            throw new IllegalArgumentException("NULL values are not supported by Representations");
+        }
         Collection<Object> newValues = new ArrayList<Object>();
         ModelUtils.checkValues(valueFactory, parsedValue, newValues);
         Object values = representation.get(field);
@@ -81,12 +95,12 @@ public class InMemoryRepresentation impl
             representation.put(field, newValues.size() == 1?newValues.iterator().next():newValues);
         }
     }
-    protected void addValues(String field,Collection<Object> values){
-
-    }
 
     @Override
     public void addNaturalText(String field, String text, String... languages) {
+        if(text == null){
+            throw new IllegalArgumentException("NULL was parsed for the text! NULL values are not supported by Representations");
+        }
         if(languages == null || languages.length<1){ //if no language is parse add the default lanugage!
             add(field,valueFactory.createText(text, null));
         } else {
@@ -98,6 +112,9 @@ public class InMemoryRepresentation impl
 
     @Override
     public void addReference(String field, String reference) {
+        if(reference == null){
+            throw new IllegalArgumentException("NULL values are not supported by Representations");
+        }
         add(field, valueFactory.createReference(reference));
     }
     /**
@@ -108,6 +125,11 @@ public class InMemoryRepresentation impl
      */
     @SuppressWarnings("unchecked")
     private Collection<Object> getValuesAsCollection(String field){
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         Object value = representation.get(field);
         if(value == null){
             return Collections.emptySet();
@@ -125,6 +147,11 @@ public class InMemoryRepresentation impl
 
     @Override
     public Iterator<Object> get(String field) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         return getValuesAsCollection(field).iterator();
     }
     @Override
@@ -169,29 +196,53 @@ public class InMemoryRepresentation impl
 
     @SuppressWarnings("unchecked")
     @Override
-    public void remove(String field, Object value) {
+    public void remove(String field, Object parsedValue) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
+        Collection<Object> removeValues = new ArrayList<Object>();
+        ModelUtils.checkValues(valueFactory, parsedValue, removeValues);
         Object values = representation.get(field);
-        if(values == null) return;
-        if(value.equals(value)){
+        if(values == null) {
+            return;
+        } else if(removeValues.contains(values)){
+            //in case this field has a single value and this values is part of
+            //the values to remove -> remove the whole field
             representation.remove(field);
         } else if(values instanceof Collection<?>){
-            if(((Collection<Object>)values).remove(value) && //remove the Element
+            if(((Collection<Object>)values).removeAll(removeValues) && //remove all Elements
                     ((Collection<Object>)values).size()<2){ //if removed check for size
-                //it only one element remaining -> replace the collection with a Object
-                representation.put(field, ((Collection<Object>)values).iterator().next());
+                if(((Collection<Object>)values).size()==1){
+                    //only one element remaining -> replace the collection with a Object
+                    representation.put(field, ((Collection<Object>)values).iterator().next());
+                } else {
+                    //if no element remains, remove the field
+                    representation.remove(field);
+                }
             }
-
-        } //else ignore
+        } //else ignore (single value for field && value not to be removed)
     }
 
     @Override
     public void removeAll(String field) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         representation.remove(field);
     }
 
     @SuppressWarnings("unchecked")
     @Override
     public void removeAllNaturalText(String field, String... languages) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         Object values = representation.get(field);
         if(values == null) return;
         if(values instanceof Collection<?>){
@@ -220,6 +271,11 @@ public class InMemoryRepresentation impl
     @SuppressWarnings("unchecked")
     @Override
     public void removeNaturalText(String field, String text, String... languages) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         Object values = representation.get(field);
         if(values == null) return;
         if(values instanceof Collection<?>){
@@ -259,8 +315,15 @@ public class InMemoryRepresentation impl
 
     @Override
     public void set(String field, Object value) {
+        if(field == null){
+            throw new NullPointerException("The parsed field MUST NOT be NULL");
+        } else if(field.isEmpty()){
+            throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
+        }
         representation.remove(field);
-        add(field,value);
+        if(value != null){
+            add(field,value);
+        }
 
     }
 
@@ -307,7 +370,7 @@ public class InMemoryRepresentation impl
         Collection<Object> values = getValuesAsCollection(field);
         return new TypeSaveIterator<Reference>(values.iterator(), Reference.class);
     }
-    private static String getNaturalLanguageValue(Object check,Set<String> langSet,boolean isNullLanguage){
+    protected static String getNaturalLanguageValue(Object check,Set<String> langSet,boolean isNullLanguage){
         if(check instanceof Text){
             Text text = (Text)check;
             if(langSet == null || langSet.contains(text.getLanguage())){
@@ -318,7 +381,7 @@ public class InMemoryRepresentation impl
         } //type does not fit -> ignore
         return null; //no label found
     }
-    public static String getNaturalLanguageValue(Object check,String...languages){
+    protected static String getNaturalLanguageValue(Object check,String...languages){
         Set<String> langSet;
         boolean isNullLanguage;
         if(languages != null && languages.length>1){
@@ -335,7 +398,7 @@ public class InMemoryRepresentation impl
      * @param languages
      * @return
      */
-    public static boolean isNaturalLanguageValue(Object check,String...languages){
+    protected static boolean isNaturalLanguageValue(Object check,String...languages){
         return getNaturalLanguageValue(check,languages) != null;
     }
     @Override

Modified: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/model/InMemoryValueFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/model/InMemoryValueFactory.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/model/InMemoryValueFactory.java (original)
+++ incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/model/InMemoryValueFactory.java Fri Jan 14 11:39:26 2011
@@ -24,7 +24,7 @@ public class InMemoryValueFactory implem
     @Override
     public Reference createReference(Object value) {
         if(value == null){
-            throw new IllegalArgumentException("The parsed value MUST NOT be NULL");
+            throw new NullPointerException("The parsed value MUST NOT be NULL");
         }
         return new ReferenceImpl(value.toString());
     }
@@ -32,7 +32,7 @@ public class InMemoryValueFactory implem
     @Override
     public Text createText(Object value) {
         if(value == null){
-            throw new IllegalArgumentException("The parsed value MUST NOT be NULL");
+            throw new NullPointerException("The parsed value MUST NOT be NULL");
         }
         return createText(value.toString(),null);
     }
@@ -91,13 +91,13 @@ public class InMemoryValueFactory implem
 
         private final String value;
         private final String language;
-        protected TextImpl(String value) {
+        protected TextImpl(String value) throws NullPointerException {
             this(value,null);
         }
-        protected TextImpl(String value, String language) {
+        protected TextImpl(String value, String language) throws NullPointerException {
             super();
             if(value == null){
-                throw new IllegalArgumentException("The value of the Text MUST NOT be NULL!");
+                throw new NullPointerException("The value of the Text MUST NOT be NULL!");
             }
             this.value = value;
             this.language = language;
@@ -135,10 +135,12 @@ public class InMemoryValueFactory implem
     }
     @Override
     public Representation createRepresentation(String id) {
-        if(id != null){
-            return new InMemoryRepresentation(id);
-        } else {
-            throw new IllegalArgumentException("The parsed id MUST NOT be NULL");
+        if (id == null){
+            throw new NullPointerException("The parsed id MUST NOT be NULL!");
+         } else if(id.isEmpty()){
+             throw new IllegalArgumentException("The parsed id MUST NOT be empty!");
+         } else {
+             return new InMemoryRepresentation(id);
         }
     }
 //    @Override

Modified: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/site/CacheImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/site/CacheImpl.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/site/CacheImpl.java (original)
+++ incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/site/CacheImpl.java Fri Jan 14 11:39:26 2011
@@ -8,14 +8,11 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

Modified: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/AdaptingIterator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/AdaptingIterator.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/AdaptingIterator.java (original)
+++ incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/AdaptingIterator.java Fri Jan 14 11:39:26 2011
@@ -1,10 +1,26 @@
 package eu.iksproject.rick.core.utils;
 
 import java.util.Iterator;
+import java.util.NoSuchElementException;
+
 /**
  * Uses the parsed Adapter to convert values of type T to values of type
  * A. If an instance of T can not be converted to A, than such values are
- * filtered in the Iteration.
+ * filtered. This means that this implementation can be used for both filtering
+ * and converting of values of the base iterator. In fact the 
+ * FilteringIterator is implemented based on this class.<p>
+ * Note that {@link Iterator#remove()} only works as long as 
+ * {@link Iterator#hasNext()} was not called to determine if there are
+ * further elements. The reason for that is, that in order to filter elements
+ * of the parent iterator {@link Iterator#next()} has to be called to check
+ * weather any further element is valid against the used Filter.
+ * This call to {@link Iterator#next()} causes the parent Iterator to switch
+ * to the next element, meaning that after that the <code>remove()</code>
+ * method would delete a different element. To avoid that this Iterator
+ * throws an {@link IllegalStateException} in such cases. If the parent
+ * Iterator does not support <code>remove()</code> at all an
+ * {@link UnsupportedOperationException} is thrown. <p>
+ * 
  * @author Rupert Westenthaler
  *
  * @param <T> The type of the incoming elements
@@ -13,8 +29,10 @@ import java.util.Iterator;
 public class AdaptingIterator<T,A> implements Iterator<A> {
 
     /**
-     * Adapts values of type T to values of type A.
-     * @author westei
+     * Adapts values of type T to values of type A. <code>null</code> indicated
+     * that the adaption is not possible for the current value of T
+     * 
+     * @author Rupert Westenthaler
      *
      * @param <T>
      * @param <A>
@@ -30,10 +48,12 @@ public class AdaptingIterator<T,A> imple
          */
         A adapt(T value, Class<A> type);
     }
+    
     protected final Adapter<T, A> adapter;
     protected final Iterator<T> it;
     protected final Class<A> type;
     private A next;
+    private Boolean hasNext;
     /**
      * Constructs an instance based on an iterator of type T, an adapter and the
      * target type
@@ -54,23 +74,56 @@ public class AdaptingIterator<T,A> imple
         this.it = it;
         this.adapter = adapter;
         this.type = type;
-        //init next
-        next = prepareNext();
     }
     @Override
     public final boolean hasNext() {
-        return next != null;
+        if(hasNext == null){ // only once even with multiple calls
+            next = prepareNext();
+            hasNext = next != null;
+        }
+        return hasNext;
     }
 
     @Override
     public final A next() {
-        A current = next;
-        next = prepareNext();
-        return current;
+        hasNext(); //call hasNext (to init next Element if not already done)
+        if(!hasNext){
+            throw new NoSuchElementException();
+        } else {
+            A current = next;
+            next = null;
+            hasNext = null;
+            return current;
+        }
     }
-
+    /**
+     * This implementation of remove does have an additional restriction. It
+     * is only able to remove the current element of the parent Iterator (parsed
+     * in the constructor) if {@link #hasNext()} was not yet called. This is
+     * because {@link #hasNext()} needs to call {@link Iterator#next()} on the
+     * parent iterator to check if there are further elements that can be
+     * adapted successfully. This causes that the current element of this
+     * Iterator (stored in an local variable) is no longer the current element
+     * of the parent iterator and therefore calls to {@link #remove()} would
+     * delete an other object within the collection holding the elements used
+     * for this iteration. To prevent this this method throws an
+     * {@link IllegalStateException} ins such cases. Users of this method need
+     * therefore to ensure, that there are no calls to remove between a call
+     * to {@link #hasNext()} and {@link #next()} (what is not the case in
+     * typical use cases).
+     * @see Iterator#remove()
+     */
     @Override
     public final void remove() {
+        /*
+         * TODO: See java doc for a detailed description! 
+         * If someone has a better Idea how to solve this please let me know!
+         * all the best 
+         * Rupert Westenthaler
+         */
+        if(hasNext!= null){
+            throw new IllegalStateException("Remove can not be called after calling hasNext()! See java doc for more information.");
+        }
         it.remove();
     }
     protected A prepareNext(){

Added: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/FilteringIterator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/FilteringIterator.java?rev=1058959&view=auto
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/FilteringIterator.java (added)
+++ incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/FilteringIterator.java Fri Jan 14 11:39:26 2011
@@ -0,0 +1,64 @@
+package eu.iksproject.rick.core.utils;
+
+import java.util.Iterator;
+
+/**
+ * Implementation of an Iterator that iterates over a filtered set of elements
+ * of its parent Iterator.<p>
+ * Note that {@link Iterator#remove()} only works as long as 
+ * {@link Iterator#hasNext()} was not called to determine if there are
+ * further elements. The reason for that is, that in order to filter elements
+ * of the parent iterator {@link Iterator#next()} has to be called to check
+ * weather any further element is valid against the used {@link Filter}.
+ * This call to {@link Iterator#next()} causes the parent Iterator to switch
+ * to the next element, meaning that after that the <code>remove()</code>
+ * method would delete a different element. To avoid that this Iterator
+ * throws an {@link IllegalStateException} in such cases. If the parent
+ * Iterator does not support <code>remove()</code> at all an
+ * {@link UnsupportedOperationException} is thrown. <p>
+ * This implementation is based on the {@link AdaptingIterator} to avoid
+ * duplication of the filtering functionality also needed if an adapter can not
+ * convert a specific value of one type to an other. 
+ * 
+ * @author Rupert Westenthaler
+ *
+ * @param <T> the type of the elements
+ */
+public class FilteringIterator<T> extends AdaptingIterator<T,T>{
+    /**
+     * Interface used by the {@link FilteringIterator} to check if an element
+     * of the parent Iterator should be filtered or not. If {@link #isValid(Object)}
+     * returns true the element of the parent iterator is also returned by this
+     * Iterator. Otherwise the element is filtered.<p>
+
+     * @author Rupert Westenthaler
+     *
+     * @param <T>
+     */
+    public static interface Filter<T> {
+        boolean isValid(T value);
+    }
+    public FilteringIterator(Iterator<T> iterator,Filter<T> filter,Class<T> type) {
+        super(iterator,new FilterAdapter<T>(filter),type);
+    }
+    
+    private static class FilterAdapter<A> implements Adapter<A,A> {
+
+        private Filter<A> filter;
+        public FilterAdapter(Filter<A> filter) {
+            if(filter == null){
+                throw new NullPointerException("The parsed Filter MUST NOT be NULL!");
+            }
+            this.filter = filter;
+        }
+        @Override
+        public A adapt(A value, Class<A> type) {
+            if(filter.isValid(value)){
+                return value;
+            } else {
+                return null;
+            }
+        }
+        
+    }
+}

Propchange: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/FilteringIterator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/ModelUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/ModelUtils.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/ModelUtils.java (original)
+++ incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/ModelUtils.java Fri Jan 14 11:39:26 2011
@@ -3,6 +3,7 @@ package eu.iksproject.rick.core.utils;
 import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -95,6 +96,7 @@ public final class ModelUtils {
      * Processes a value parsed as object to the representation.
      * This processing includes:
      * <ul>
+     * <li> Removal of <code>null</code> values
      * <li> Converting URIs and URLs to {@link Reference}
      * <li> Converting String[] with at least a single entry where the first
      * entry is not null to {@link Text} (the second entry is used as language.
@@ -103,11 +105,16 @@ public final class ModelUtils {
      *      {@link Collection}), {@link Iterator} or {@link Enumeration} is parsed.
      * <li> All other Objects are added to the result list
      * </ul>
+     * TODO: Maybe we need to enable an option to throw {@link IllegalArgumentException}
+     * in case any of the parsed values is invalid. Currently invalid values are
+     * just ignored.
      * @param value the value to parse
      * @param results the collections the results of the parsing are added to.
      */
     public static void checkValues(ValueFactory valueFactory, Object value,Collection<Object> results){
-        if(value instanceof Iterable<?>){
+        if(value == null){
+            return;
+        } else if(value instanceof Iterable<?>){
             for(Object current : (Iterable<?>)value){
                 checkValues(valueFactory,current,results);
             }
@@ -126,7 +133,7 @@ public final class ModelUtils {
                 results.add(valueFactory.createText(((String[])value)[0],
                         ((String[])value).length>1?((String[])value)[1]:null));
             } else {
-                log.warn("String[] "+value+" is not a valied natural language array! -> ignore value");
+                log.warn("String[] "+Arrays.toString((String[])value)+" is not a valied natural language array! -> ignore value");
             }
         } else {
             results.add(value);

Modified: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/OsgiUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/OsgiUtils.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/OsgiUtils.java (original)
+++ incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/OsgiUtils.java Fri Jan 14 11:39:26 2011
@@ -9,18 +9,7 @@ import java.util.Enumeration;
 import java.util.Hashtable;
 
 import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.component.ComponentContext;
-import org.osgi.service.component.ComponentFactory;
-import org.osgi.service.component.ComponentInstance;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import eu.iksproject.rick.servicesapi.site.ConfiguredSite;
-import eu.iksproject.rick.servicesapi.site.EntityDereferencer;
-import eu.iksproject.rick.servicesapi.site.ReferencedSite;
 
 /**
  * This class contains some utilities for osgi
@@ -30,7 +19,7 @@ import eu.iksproject.rick.servicesapi.si
  */
 public final class OsgiUtils {
 
-    private static final Logger log = LoggerFactory.getLogger(OsgiUtils.class);
+    //private static final Logger log = LoggerFactory.getLogger(OsgiUtils.class);
 
     private OsgiUtils() {/* do not create instances of utility classes*/}
 
@@ -113,67 +102,67 @@ public final class OsgiUtils {
             throw new ConfigurationException(propertyName,String.format("Property value %s is not a member of Enumeration %s!",value,enumeration.getName()), e);
         }
     }
-    /**
-     * search for a {@link ComponentFactory} that has the component.name property
-     * as configured by {@link ConfiguredSite#DEREFERENCER_TYPE}. Than creates
-     * an new instance of an {@link EntityDereferencer} and configures it with
-     * all the properties present for this instance of {@link ReferencedSite} (
-     * only component.* and service.* properties are ignored).<br>
-     * The {@link ComponentInstance} and the {@link EntityDereferencer} are
-     * stored in the according memeber variables.
-     * @return the ComponentInstance of <code>null</code> if no ComponentFactory
-     *    was found for the parsed componentService
-     * @throws ConfigurationException if the {@link ConfiguredSite#DEREFERENCER_TYPE}
-     * is not present or it's value does not allow to create a {@link EntityDereferencer}
-     * instance.
-     */
-    public static ComponentInstance createComonentInstance(ComponentContext context, String property,Object componentName,Class<?> componentService) throws ConfigurationException {
-        //Object value = checkProperty(DEREFERENCER_TYPE);
-        final ServiceReference[] refs;
-        try {
-            refs = context.getBundleContext().getServiceReferences(
-                    ComponentFactory.class.getName(),
-                    "(component.name="+componentName+")");
-
-        } catch (InvalidSyntaxException e) {
-            throw new ConfigurationException(property, "Unable to get ComponentFactory for parsed value "+componentName.toString(),e);
-        }
-        if(refs != null && refs.length>0){
-            if(refs.length>1){ //log some warning if more than one Service Reference was found by the query!
-                log.warn("Multiple ComponentFactories found for the property "+property+"="+componentName+"! -> First one was used to instantiate the "+componentService+" Service");
-            }
-            Object dereferencerFactorySerivceObject = context.getBundleContext().getService(refs[0]);
-            if(dereferencerFactorySerivceObject != null){
-                try {
-                    // I trust the OSGI framework, that the returned service implements the requested Interface
-                    ComponentFactory dereferencerFactory = (ComponentFactory)dereferencerFactorySerivceObject;
-                    //log.debug("build configuration for "+EntityDereferencer.class.getSimpleName()+" "+componentName.toString());
-                    Dictionary<String, Object> config = copyConfig(context.getProperties());
-                    ComponentInstance dereferencerComponentInstance = dereferencerFactory.newInstance(config);
-                    dereferencerFactory = null;
-                    //now
-                    if(dereferencerComponentInstance == null){
-                        throw new IllegalStateException("Unable to create ComponentInstance for Property value "+componentName+"!");
-                    }
-                    if(componentService.isAssignableFrom(dereferencerComponentInstance.getInstance().getClass())){
-                        return dereferencerComponentInstance;
-                    } else {
-                        dereferencerComponentInstance.dispose(); //we can not use it -> so dispose it!
-                        dereferencerComponentInstance = null;
-                        throw new IllegalStateException("ComponentInstance created for Property value "+componentName+" does not provide the "+componentService+" Service!");
-                    }
-                } finally {
-                    //we need to unget the ComponentFactory!
-                    context.getBundleContext().ungetService(refs[0]);
-                    dereferencerFactorySerivceObject=null;
-                }
-            } else {
-                return null;
-            }
-        } else {
-            return null;
-        }
-    }
+//    /**
+//     * search for a {@link ComponentFactory} that has the component.name property
+//     * as configured by {@link ConfiguredSite#DEREFERENCER_TYPE}. Than creates
+//     * an new instance of an {@link EntityDereferencer} and configures it with
+//     * all the properties present for this instance of {@link ReferencedSite} (
+//     * only component.* and service.* properties are ignored).<br>
+//     * The {@link ComponentInstance} and the {@link EntityDereferencer} are
+//     * stored in the according memeber variables.
+//     * @return the ComponentInstance of <code>null</code> if no ComponentFactory
+//     *    was found for the parsed componentService
+//     * @throws ConfigurationException if the {@link ConfiguredSite#DEREFERENCER_TYPE}
+//     * is not present or it's value does not allow to create a {@link EntityDereferencer}
+//     * instance.
+//     */
+//    public static ComponentInstance createComonentInstance(ComponentContext context, String property,Object componentName,Class<?> componentService) throws ConfigurationException {
+//        //Object value = checkProperty(DEREFERENCER_TYPE);
+//        final ServiceReference[] refs;
+//        try {
+//            refs = context.getBundleContext().getServiceReferences(
+//                    ComponentFactory.class.getName(),
+//                    "(component.name="+componentName+")");
+//
+//        } catch (InvalidSyntaxException e) {
+//            throw new ConfigurationException(property, "Unable to get ComponentFactory for parsed value "+componentName.toString(),e);
+//        }
+//        if(refs != null && refs.length>0){
+//            if(refs.length>1){ //log some warning if more than one Service Reference was found by the query!
+//                log.warn("Multiple ComponentFactories found for the property "+property+"="+componentName+"! -> First one was used to instantiate the "+componentService+" Service");
+//            }
+//            Object dereferencerFactorySerivceObject = context.getBundleContext().getService(refs[0]);
+//            if(dereferencerFactorySerivceObject != null){
+//                try {
+//                    // I trust the OSGI framework, that the returned service implements the requested Interface
+//                    ComponentFactory dereferencerFactory = (ComponentFactory)dereferencerFactorySerivceObject;
+//                    //log.debug("build configuration for "+EntityDereferencer.class.getSimpleName()+" "+componentName.toString());
+//                    Dictionary<String, Object> config = copyConfig(context.getProperties());
+//                    ComponentInstance dereferencerComponentInstance = dereferencerFactory.newInstance(config);
+//                    dereferencerFactory = null;
+//                    //now
+//                    if(dereferencerComponentInstance == null){
+//                        throw new IllegalStateException("Unable to create ComponentInstance for Property value "+componentName+"!");
+//                    }
+//                    if(componentService.isAssignableFrom(dereferencerComponentInstance.getInstance().getClass())){
+//                        return dereferencerComponentInstance;
+//                    } else {
+//                        dereferencerComponentInstance.dispose(); //we can not use it -> so dispose it!
+//                        dereferencerComponentInstance = null;
+//                        throw new IllegalStateException("ComponentInstance created for Property value "+componentName+" does not provide the "+componentService+" Service!");
+//                    }
+//                } finally {
+//                    //we need to unget the ComponentFactory!
+//                    context.getBundleContext().ungetService(refs[0]);
+//                    dereferencerFactorySerivceObject=null;
+//                }
+//            } else {
+//                return null;
+//            }
+//        } else {
+//            return null;
+//        }
+//    }
 
     /**
      * Copy all properties excluding "{@value Constants#OBJECTCLASS}",

Modified: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/TextIterator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/TextIterator.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/TextIterator.java (original)
+++ incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/TextIterator.java Fri Jan 14 11:39:26 2011
@@ -9,12 +9,13 @@ import java.util.Set;
 import eu.iksproject.rick.servicesapi.model.Text;
 import eu.iksproject.rick.servicesapi.model.ValueFactory;
 
-public class TextIterator implements Iterator<Text> {
-    protected final Iterator<?> it;
-    private Text next;
-    protected final Set<String> languages;
-    private final boolean isNullLanguage;
-    protected final ValueFactory valueFactory;
+public class TextIterator extends AdaptingIterator<Object,Text> implements Iterator<Text> {
+//    protected final Iterator<?> it;
+//    private Text next;
+//    private Boolean hasNext;
+//    protected final Set<String> languages;
+//    private final boolean isNullLanguage;
+//    protected final ValueFactory valueFactory;
     /**
      * Creates an instance that iterates over values and returns {@link Text}
      * instances that confirm to the active languages. If no languages are parsed
@@ -25,55 +26,123 @@ public class TextIterator implements Ite
      * @param languages The active languages or no values to accept all languages
      */
     public TextIterator(ValueFactory valueFactory,Iterator<Object> it,String...languages){
-        if(it == null){
-            throw new IllegalArgumentException("Parsed iterator MUST NOT be NULL!");
-        }
-        if(valueFactory == null){
-            throw new IllegalArgumentException("Parsed ValueFactory MUST NOT be NULL!");
-        }
-        this.it = it;
-        this.valueFactory = valueFactory;
-        if(languages != null && languages.length>0){
-            this.languages = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(languages)));
-            isNullLanguage = this.languages.contains(null);
-        } else {
-            this.languages = null;
-            isNullLanguage = true;
-        }
-        //init next ...
-        next = prepareNext();
-    }
-    @Override
-    public final void remove() {
-        it.remove();
-
-    }
-
-    @Override
-    public final Text next() {
-        Text current = next;
-        next = prepareNext();
-        return current;
+        super(it,new TextAdapter(valueFactory, languages),Text.class);
+//        if(it == null){
+//            throw new IllegalArgumentException("Parsed iterator MUST NOT be NULL!");
+//        }
+//        this.it = it;
+//        if(valueFactory == null){
+//            throw new IllegalArgumentException("Parsed ValueFactory MUST NOT be NULL!");
+//        }
+//        this.valueFactory = valueFactory;
+//        if(languages != null && languages.length>0){
+//            this.languages = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(languages)));
+//            isNullLanguage = this.languages.contains(null);
+//        } else {
+//            this.languages = null;
+//            isNullLanguage = true;
+//        }
     }
+    private static class TextAdapter implements Adapter<Object,Text>{
+        protected final Set<String> languages;
+        private final boolean isNullLanguage;
+        protected final ValueFactory valueFactory;
+        
+        public TextAdapter(ValueFactory valueFactory,String...languages) {
+            if(valueFactory == null){
+                throw new IllegalArgumentException("Parsed ValueFactory MUST NOT be NULL!");
+            }
+            this.valueFactory = valueFactory;
+            if(languages != null && languages.length>0){
+                this.languages = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(languages)));
+                isNullLanguage = this.languages.contains(null);
+            } else {
+                this.languages = null;
+                isNullLanguage = true;
+            }
+            
+        }
 
-    @Override
-    public final boolean hasNext() {
-        return next != null;
-    }
-    protected Text prepareNext(){
-        Object check;
-        while(it.hasNext()){
-            check = it.next();
-            if(check instanceof Text){
-                Text text = (Text)check;
+        @Override
+        public Text adapt(Object value, Class<Text> type) {
+            if(value instanceof Text){
+                Text text = (Text)value;
                 if(languages == null || languages.contains(text.getLanguage())){
                     return text;
+                } else { //language does not fit -> filter
+                    return null;
                 }
-            } else if(isNullLanguage && check instanceof String){
-                return valueFactory.createText((String)check);
-            } //type does not fit -> ignore
+            } else if(isNullLanguage && value instanceof String){
+                return valueFactory.createText((String)value);
+            }  else {//type does not fit -> filter
+                return null;
+            }
         }
-        //no more element and still nothing found ... return end of iteration
-        return null;
+        
     }
+//    @Override
+//    public final void remove() {
+//        /*
+//         * TODO: Any Iterator that filters elements of the underlying Iterator
+//         * needs to call Iterator#next() in the underlying Iterator to get the
+//         * next element that confirms with the filter.
+//         * However the Iterator#remove() is defined as removing the last element
+//         * to be returned by Iterator#next(). Therefore calling hasNext would
+//         * change the element to be removed by this method.
+//         * Currently I do not know a way around that but I would also like to
+//         * keep the remove functionality for Iterator that filter elements of an
+//         * underlying Iterator. To prevent unpredictable behaviour in such cases 
+//         * I throw an IllegalStateException in such cases.
+//         * This decision assumes, that in most usage scenarios hasNext will not
+//         * likely be called before calling remove and even in such cases
+//         * it will be most likely be possible to refactor the code to confirm
+//         * with this restriction.
+//         * I hope this will help developers that encounter this exception to
+//         * modify there code!
+//         * If someone has a better Idea how to solve this please let me know!
+//         * best 
+//         * Rupert Westenthaler
+//         */
+//        if(hasNext!= null){
+//            throw new IllegalStateException("Remove can not be called after calling hasNext() because this Method needs to call next() on the underlying Interator and therefore would change the element to be removed :(");
+//        }
+//        it.remove();
+//    }
+//
+//    @Override
+//    public final Text next() {
+//        hasNext(); //call hasNext (to init next Element if not already done)
+//        if(!hasNext){
+//            throw new NoSuchElementException();
+//        } else {
+//            Text current = next;
+//            hasNext = null;
+//            return current;
+//        }
+//    }
+//
+//    @Override
+//    public final boolean hasNext() {
+//        if(hasNext == null){ // only once even with multiple calls
+//            next = prepareNext();
+//            hasNext = next != null;
+//        }
+//        return hasNext;
+//    }
+//    protected Text prepareNext(){
+//        Object check;
+//        while(it.hasNext()){
+//            check = it.next();
+//            if(check instanceof Text){
+//                Text text = (Text)check;
+//                if(languages == null || languages.contains(text.getLanguage())){
+//                    return text;
+//                }
+//            } else if(isNullLanguage && check instanceof String){
+//                return valueFactory.createText((String)check);
+//            } //type does not fit -> ignore
+//        }
+//        //no more element and still nothing found ... return end of iteration
+//        return null;
+//    }
 }

Modified: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/ToStringIterator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/ToStringIterator.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/ToStringIterator.java (original)
+++ incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/ToStringIterator.java Fri Jan 14 11:39:26 2011
@@ -2,12 +2,29 @@ package eu.iksproject.rick.core.utils;
 
 import java.util.Iterator;
 
+/**
+ * Implementation of an Iterator over {@link String} values, that uses the 
+ * {@link Object#toString()} on elements of the parent Iterator for the 
+ * conversion.<p>
+ * This Implementation does not use {@link AdaptingIterator}s implementation, 
+ * because the {@link Object#toString()} method can be used to create a string
+ * representation for every object and therefore there is no need for the
+ * filtering functionality provided by the {@link AdaptingIterator}.
+ * 
+ * @author Rupert Westenthaler
+ */
 public class ToStringIterator implements Iterator<String> {
 
     protected final Iterator<?> it;
-    public ToStringIterator(Iterator<?> it){
+    /**
+     * Creates an string iterator over parsed parent
+     * @param it the parent iterator
+     * @throws NullPointerException if <code>null</code> is parsed as parent
+     * iterator
+     */
+    public ToStringIterator(Iterator<?> it) throws NullPointerException{
         if(it == null){
-            throw new IllegalArgumentException("Parsed iterator MUST NOT be NULL!");
+            throw new NullPointerException("Parsed iterator MUST NOT be NULL!");
         }
         this.it = it;
     }

Modified: incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/TypeSaveIterator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/TypeSaveIterator.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/TypeSaveIterator.java (original)
+++ incubator/stanbol/trunk/rick/generic/core/src/main/java/eu/iksproject/rick/core/utils/TypeSaveIterator.java Fri Jan 14 11:39:26 2011
@@ -8,55 +8,107 @@ import java.util.Iterator;
  *
  * @param <T> the type of elements returned by this iterator
  */
-public class TypeSaveIterator<T> implements Iterator<T> {
+public class TypeSaveIterator<T> extends AdaptingIterator<Object,T> implements Iterator<T> {
 
-    protected final Iterator<?> it;
-    protected final Class<T> type;
-    private T next;
+//    protected final Iterator<?> it;
+//    protected final Class<T> type;
+//    private T next;
+//    private Boolean hasNext;
     /**
      * Constructs an iterator that selects only elements of the parsed iterator
      * that are assignable to the parse type
      * @param it the base iterator
      * @param type the type all elements of this Iterator need to be assignable to.
      */
+    @SuppressWarnings("unchecked")
     public TypeSaveIterator(Iterator<?> it,Class<T> type){
-        if(it == null){
-            throw new IllegalArgumentException("Parsed iterator MUST NOT be NULL!");
-        }
-        if(type == null){
-            throw new IllegalArgumentException("Parsed type MUST NOT be NULL!");
-        }
-        this.it = it;
-        this.type = type;
-        //init next ...
-        next = prepareNext();
-    }
-    @Override
-    public final void remove() {
-        it.remove();
-
-    }
-
-    @Override
-    public final T next() {
-        T current = next;
-        next = prepareNext();
-        return current;
+        super((Iterator<Object>)it,new AssignableFormAdapter<T>(),type);
+//        if(it == null){
+//            throw new IllegalArgumentException("Parsed iterator MUST NOT be NULL!");
+//        }
+//        if(type == null){
+//            throw new IllegalArgumentException("Parsed type MUST NOT be NULL!");
+//        }
+//        this.it = it;
+//        this.type = type;
     }
+//    @Override
+//    public final void remove() {
+//        /*
+//         * TODO: Any Iterator that filters elements of the underlying Iterator
+//         * needs to call Iterator#next() in the underlying Iterator to get the
+//         * next element that confirms with the filter.
+//         * However the Iterator#remove() is defined as removing the last element
+//         * to be returned by Iterator#next(). Therefore calling hasNext would
+//         * change the element to be removed by this method.
+//         * Currently I do not know a way around that but I would also like to
+//         * keep the remove functionality for Iterator that filter elements of an
+//         * underlying Iterator. To prevent unpredictable behaviour in such cases 
+//         * I throw an IllegalStateException in such cases.
+//         * This decision assumes, that in most usage scenarios hasNext will not
+//         * likely be called before calling remove and even in such cases
+//         * it will be most likely be possible to refactor the code to confirm
+//         * with this restriction.
+//         * I hope this will help developers that encounter this exception to
+//         * modify there code!
+//         * If someone has a better Idea how to solve this please let me know!
+//         * best 
+//         * Rupert Westenthaler
+//         */
+//        if(hasNext!= null){
+//            throw new IllegalStateException("Remove can not be called after calling hasNext() because this Method needs to call next() on the underlying Interator and therefore would change the element to be removed :(");
+//        }
+//        it.remove();
+//    }
+//
+//    @Override
+//    public final T next() {
+//        hasNext(); //call hasNext (to init next Element if not already done)
+//        if(!hasNext){
+//            throw new NoSuchElementException();
+//        } else {
+//            T current = next;
+//            next = null;
+//            hasNext = null;
+//            return current;
+//        }
+//    }
+//
+//    @Override
+//    public final boolean hasNext() {
+//        if(hasNext == null){ // only once even with multiple calls
+//            next = prepareNext();
+//            hasNext = next != null;
+//        }
+//        return hasNext;
+//    }
+//    @SuppressWarnings("unchecked")
+//    protected T prepareNext(){
+//        Object check;
+//        while(it.hasNext()){
+//            check = it.next();
+//            if(type.isAssignableFrom(check.getClass())){
+//                return (T)check;
+//            }
+//        }
+//        return null;
+//    }
+    /**
+     * Adapter implementation that uses {@link Class#isAssignableFrom(Class)}
+     * to check whether a value can be casted to the requested type
+     */
+    private static class AssignableFormAdapter<T> implements Adapter<Object,T> {
 
-    @Override
-    public final boolean hasNext() {
-        return next != null;
-    }
-    @SuppressWarnings("unchecked")
-    protected T prepareNext(){
-        Object check;
-        while(it.hasNext()){
-            check = it.next();
-            if(type.isAssignableFrom(check.getClass())){
-                return (T)check;
+        @SuppressWarnings("unchecked")
+        @Override
+        public T adapt(Object value, Class<T> type) {
+            if(type.isAssignableFrom(value.getClass())){
+              return (T)value;
+            } else {
+                return null;
             }
         }
-        return null;
+        
     }
 }
+

Added: incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryRepresentationTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryRepresentationTest.java?rev=1058959&view=auto
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryRepresentationTest.java (added)
+++ incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryRepresentationTest.java Fri Jan 14 11:39:26 2011
@@ -0,0 +1,27 @@
+package eu.iksproject.rick.core.model;
+
+import org.junit.Before;
+
+import eu.iksproject.rick.servicesapi.model.ValueFactory;
+import eu.iksproject.rick.test.model.RepresentationTest;
+
+public class InMemoryRepresentationTest extends RepresentationTest {
+    
+    private ValueFactory valueFactory;
+    
+    @Before
+    public void init(){
+     valueFactory = InMemoryValueFactory.getInstance();   
+    }
+    
+    @Override
+    protected ValueFactory getValueFactory() {
+        return valueFactory;
+    }
+
+    @Override
+    protected Object getUnsupportedValueInstance() {
+        return null; //indicates that all kinds of Objects are supported!
+    }
+ 
+}

Propchange: incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryRepresentationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryValueFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryValueFactoryTest.java?rev=1058959&view=auto
==============================================================================
--- incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryValueFactoryTest.java (added)
+++ incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryValueFactoryTest.java Fri Jan 14 11:39:26 2011
@@ -0,0 +1,31 @@
+package eu.iksproject.rick.core.model;
+
+import org.junit.Before;
+
+import eu.iksproject.rick.servicesapi.model.ValueFactory;
+import eu.iksproject.rick.test.model.ValueFactoryTest;
+
+public class InMemoryValueFactoryTest extends ValueFactoryTest {
+    
+    private ValueFactory valueFactory;
+    
+    @Before
+    public void init(){
+     valueFactory = InMemoryValueFactory.getInstance();   
+    }
+    @Override
+    protected Object getUnsupportedReferenceType() {
+        return null; //indicates that all types are supported
+    }
+    
+    @Override
+    protected Object getUnsupportedTextType() {
+        return null; //indicates that all types are supported
+    }
+    
+    @Override
+    protected ValueFactory getValueFactory() {
+        return valueFactory;
+    }
+    
+}

Propchange: incubator/stanbol/trunk/rick/generic/core/src/test/java/eu/iksproject/rick/core/model/InMemoryValueFactoryTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/defaults/DataTypeEnum.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/defaults/DataTypeEnum.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/defaults/DataTypeEnum.java (original)
+++ incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/defaults/DataTypeEnum.java Fri Jan 14 11:39:26 2011
@@ -20,22 +20,39 @@ import javax.xml.namespace.QName;
 import eu.iksproject.rick.servicesapi.model.Reference;
 import eu.iksproject.rick.servicesapi.model.Text;
 /**
- * Holds data types used by Rick. Uses the xsd data types where possible.
- *
+ * Defines the data types that need to be supported by the model 
+ * implementation.<p>
+ * Each data type defines:<ul>
+ * <li><b>short name:</b> An short and human readable ID that is unique within 
+ * the list of data types. Currently <code>prefix:localName</code> is used as 
+ * short name and prefixes are used as defined by the {@link NamespaceEnum}.
+ * <li><b>uri:</b> Ths is the global unique UD of the namespace. If possible the
+ * URI defined by XSD is used (e.g. http://www.w3.org/2001/XMLSchema#string for
+ * strings). 
+ * <li><b>java class:</b> Each data type is mapped to exactly one preferred 
+ * and 0..n optional java representations. Note that
+ * different data types may use the same preferred as well as optional java class 
+ * meaning. This means that the java class can not be used to uniquely identify 
+ * a data type.
+ * </ul>
+ * The {@link #name()} is not used, but typically the local name with an capital
+ * first letter is used. The URI of the data type is used by the implementation
+ * of {@link #toString()}.<p>
+ * In addition the the definition of all the data types this class also provides
+ * several utilities for getting the data type by short name, URI as well as
+ * preferred or all defined java class mappings.
+ * 
  * @author Rupert Westenthaler
  *
  */
 public enum DataTypeEnum {
     //Rick specific
-    //Reference
     Reference(NamespaceEnum.rickModel,"ref",Reference.class),
-    //Natural language Text
     Text(NamespaceEnum.rickModel,"text",Text.class),
     //xsd types
     /**
      * currently URIs are preferable mapped to {@link Reference}, because there
-     * may be RDF URIs that are not valid {@link URI}s nor {@link URL}s. However
-     * existing URI and URL instances are also accepted.
+     * may be RDF URIs that are not valid {@link URI}s nor {@link URL}s.
      */
     AnyUri("anyURI",Reference.class,URI.class,URL.class),
     Boolean("boolean",Boolean.class),
@@ -58,10 +75,10 @@ public enum DataTypeEnum {
     final String shortName;
     final String uri;
     final Set<Class<?>> additional;
-    DataTypeEnum(Class<?> javaType,Class<?>...additional){
+    private DataTypeEnum(Class<?> javaType,Class<?>...additional){
         this(null,null,javaType,additional);
     }
-    DataTypeEnum(String localName,Class<?> javaType,Class<?>...additional){
+    private DataTypeEnum(String localName,Class<?> javaType,Class<?>...additional){
         this(null,localName,javaType,additional);
     }
     private DataTypeEnum(NamespaceEnum namespace,Class<?> javaType,Class<?>...additional) {

Modified: incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/defaults/NamespaceEnum.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/defaults/NamespaceEnum.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/defaults/NamespaceEnum.java (original)
+++ incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/defaults/NamespaceEnum.java Fri Jan 14 11:39:26 2011
@@ -3,7 +3,12 @@ package eu.iksproject.rick.servicesapi.d
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
-
+/**
+ * Defines commonly used name spaces to prevent multiple definitions in several
+ * classes
+ * @author Rupert Westenthaler
+ *
+ */
 public enum NamespaceEnum {
     //Namespaces defined by RICK
     rickModel("rick","http://www.iks-project.eu/ontology/rick/model/"),
@@ -11,9 +16,9 @@ public enum NamespaceEnum {
 
 
     //First the XML Namespaces
-    xsd("http://www.w3.org/2001/XMLSchema/"),
-    xsi("http://www.w3.org/2001/XMLSchema-instance/"),
-    xml("http://www.w3.org/XML/1998/namespace/"),
+    xsd("http://www.w3.org/2001/XMLSchema#"),
+    xsi("http://www.w3.org/2001/XMLSchema-instance#"),
+    xml("http://www.w3.org/XML/1998/namespace#"),
     //Start with the semantic Web Namespaces
     rdf("http://www.w3.org/1999/02/22-rdf-syntax-ns#"),
     rdfs("http://www.w3.org/2000/01/rdf-schema#"),

Modified: incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Reference.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Reference.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Reference.java (original)
+++ incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Reference.java Fri Jan 14 11:39:26 2011
@@ -1,7 +1,8 @@
 package eu.iksproject.rick.servicesapi.model;
 
 /**
- * Defines a reference to an other entity
+ * Defines a reference to an other entity <p>
+ * Implementations of that interface MUST BE immutable
  * @author Rupert Westenthaler
  *
  */

Modified: incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Representation.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Representation.java?rev=1058959&r1=1058958&r2=1058959&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Representation.java (original)
+++ incubator/stanbol/trunk/rick/generic/servicesapi/src/main/java/eu/iksproject/rick/servicesapi/model/Representation.java Fri Jan 14 11:39:26 2011
@@ -1,5 +1,8 @@
 package eu.iksproject.rick.servicesapi.model;
 
+import java.util.Collection;
+import java.util.Date;
+import java.util.Enumeration;
 import java.util.Iterator;
 
 import eu.iksproject.rick.servicesapi.yard.Yard;
@@ -14,8 +17,6 @@ import eu.iksproject.rick.servicesapi.ya
  *       "normal" values feels to complex! Need to reevaluate if this differentiation
  *       is needed or can be done in a more easy way!
  * TODO: add an API that allows to attach Content!
- * TODO: Review this interface during the definition of a Query Language for the
- * Rick (or IKS in general)
  * TODO: Do we need subNodes or are "references" enough.
  *
  * TODO: Check to use also Wrappers for fields and values (in analogy to
@@ -37,8 +38,10 @@ public interface Representation {
      * @param type the type of the values
      * @return the (first) value of that field
      * @throws IllegalArgumentException if the type is not supported
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    <T> T getFirst(String field,Class<T> type) throws UnsupportedTypeException;
+    <T> T getFirst(String field,Class<T> type) throws UnsupportedTypeException, NullPointerException, IllegalArgumentException;
 
     /**
      * Getter for all values of a field
@@ -47,20 +50,26 @@ public interface Representation {
      * @param type the type
      * @return the values of the field
      * @throws UnsupportedTypeException if the parsed type is not supported
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    <T> Iterator<T> get(String field,Class<T> type) throws UnsupportedTypeException;
+    <T> Iterator<T> get(String field,Class<T> type) throws UnsupportedTypeException, NullPointerException, IllegalArgumentException;
     /**
      * Getter for the (first) value for a field
      * @param field the field
      * @return the first value of a field
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    Object getFirst(String field);
+    Object getFirst(String field) throws NullPointerException, IllegalArgumentException;
     /**
      * Getter for the first reference value for a field
      * @param field the field
      * @return the reference or null of the field has no reference as value
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    Reference getFirstReference(String field);
+    Reference getFirstReference(String field) throws NullPointerException, IllegalArgumentException;
     /**
      * Getter for the first natural language text value of a specific language
      * @param field the field
@@ -68,20 +77,26 @@ public interface Representation {
      *             (If <code>null</code> is parsed as language, than also labels
      *             without language tag are included in the Result)
      * @return the first natural language text found for the parsed field
-     */
-    Text getFirst(String field, String...language);
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
+    */
+    Text getFirst(String field, String...language) throws NullPointerException, IllegalArgumentException;
     /**
      * Getter for all values for the requested field
      * @param field the field
      * @return the values of the field
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    Iterator<Object> get(String field);
+    Iterator<Object> get(String field) throws NullPointerException, IllegalArgumentException;
     /**
      * Getter for all natural language text values of a field
      * @param field the field
      * @return the natural text values
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    Iterator<Text> getText(String field);
+    Iterator<Text> getText(String field) throws NullPointerException, IllegalArgumentException;
     /**
      * Getter for all natural language text values of a field
      * @param field the field
@@ -90,14 +105,18 @@ public interface Representation {
      *             without language tag are included in the Result)
      * @return iterator over all natural language text values in the requested
      *             language.
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    Iterator<Text> get(String field,String...language);
+    Iterator<Text> get(String field,String...language) throws NullPointerException, IllegalArgumentException;
     /**
      * Getter for all reference values of a field
      * @param field the field
      * @return Iterator over all reference values of a field
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    Iterator<Reference> getReferences(String field);
+    Iterator<Reference> getReferences(String field) throws NullPointerException, IllegalArgumentException;
     /**
      * Adds the object as value to the field.
      * <p>The type of the value is inferred based on the type of the Object.<br>
@@ -106,16 +125,23 @@ public interface Representation {
      * <li>{@link Reference}
      * <li>URL, URI: {@link Reference} instances are created for such values</li>
      * <li>Boolean, Integer, Long, Double and Float as primitive data types</li>
+     * <li>{@link Date} 
      * <li>{@link Text}
      * <li>String[]{text,language}: text and language (further entries are ignored)</li>
      * <li>String: mapped to {@link Text} with the <code>language=null</code></li>
-     * <li>Collection are used for adding multiple values
-     * <li>For other types the toString() method is used</li>
-     * </ul>
+     * <li>{@link Collection}s, {@link Enumeration}s and {@link Iterator}s are 
+     *     can be used to parse multiple values
+     * <li>For unsupported types it MUSST be assured the the toString() value
+     *     of the stored Object is equals to the toString() value of the parsed
+     *     object.</li>
+     * </ul> 
      * @param field the field
      * @param value the value to add
+     * @throws NullPointerException if <code>null</code> is parsed as field or
+     * value
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    void add(String field, Object value);
+    void add(String field, Object value) throws NullPointerException, IllegalArgumentException;
     /**
      * Adds an reference to the field.
      * @param field the field
@@ -123,8 +149,12 @@ public interface Representation {
      * the value will be interpreted as a "reference" so there might apply
      * some rules about the format of the string. Regardless of the implementation
      * any valid URI and URL need to be accepted as a valid reference value
+     * @throws NullPointerException if <code>null</code> is parsed as field or
+     * reference
+     * @throws IllegalArgumentException if an empty string is parsed as field
+     * or reference and/or <code>null</code> is parsed as value.
      */
-    void addReference(String field, String reference);
+    void addReference(String field, String reference) throws NullPointerException,IllegalArgumentException;
     /**
      * Adds a natural language text as value for one or more languages
      * @param field the field to add the text as value
@@ -132,28 +162,25 @@ public interface Representation {
      * @param language the text is set for all the parsed languages. Parse
      *             <code>null</code> to set the text also without any language
      *             information.
+     * @throws NullPointerException if <code>null</code> is parsed as field.
+     * @throws IllegalArgumentException if an empty string is parsed as field
+     * and/or <code>null</code> is parsed as text. NOTE that <code>null</code> 
+     * is supported for languages.
      */
-    void addNaturalText(String field,String text, String...languages);
+    void addNaturalText(String field,String text, String...languages) throws NullPointerException,IllegalArgumentException;
     /**
      * Sets the value of the field to the parsed object. If the parsed value
      * is <code>null</code> than this method removes all values for the given
-     * field
-     * <p>The type of the value is inferred based on the type of the Object.<br>
-     * Supported Types are:</p>
-     * <ul>
-     * <li>{@link Reference}
-     * <li>URL, URI: {@link Reference} instances are created for such values</li>
-     * <li>Boolean, Integer, Long, Double and Float as primitive data types</li>
-     * <li>{@link Text}
-     * <li>String[]{text,language}: text and language (further entries are ignored)</li>
-     * <li>String: mapped to {@link Text} with the <code>language=null</code></li>
-     * <li>Collection are used for adding multiple values
-     * <li>For other types the toString() method is used</li>
-     * </ul>
+     * field<br>
+     * This Method supports collections as well as value conversions for some
+     * types. Please see the documentation of {@link #add(String, Object)} for
+     * details.
      * @param field the field
      * @param value the new value for the field
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    void set(String field, Object value);
+    void set(String field, Object value) throws NullPointerException, IllegalArgumentException;
     /**
      * Setter for the reference of a field. If the parsed value
      * is <code>null</code> than this method removes all values for the given
@@ -163,8 +190,10 @@ public interface Representation {
      * the value will be interpreted as a "reference" so there might apply
      * some rules about the format of the string. Regardless of the implementation
      * any valid URI and URL need to be accepted as a valid reference value
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    void setReference(String field, String reference);
+    void setReference(String field, String reference) throws NullPointerException, IllegalArgumentException;
     /**
      * Setter for the natural language text value of a field in the given
      * languages. If <code>null</code> is parsed as text, all present values
@@ -175,23 +204,35 @@ public interface Representation {
      * @param language the languages of the parsed text. Parse
      *             <code>null</code> to set the text also without any language
      *             information.
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    void setNaturalText(String field,String text, String...language);
+    void setNaturalText(String field,String text, String...language) throws NullPointerException, IllegalArgumentException;
     /**
-     * Removes the parsed value form the field
+     * Removes the parsed value form the field. If <code>null</code> is parsed
+     * as value than the call is ignored.<p>
+     * This methods follows the same conventions as {@link #add(String, Object)}
+     * (e.g. parsing a {@link Collection} will cause all values within this
+     * collection to be removed). See the documentation of {@link #add(String, Object)}
+     * for details.
      * @param field the field
      * @param value the value to remove
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    void remove(String field, Object value);
+    void remove(String field, Object value) throws NullPointerException, IllegalArgumentException; 
     /**
-     * Removes to parsed reference as value for the given field.
+     * Removes to parsed reference as value for the given field. If <code>null</code>
+     * is parsed as reference, that the call is ignored.
      * @param field the field
      * @param reference the string representation of the reference. Note that
      * the value will be interpreted as a "reference" so there might apply
      * some rules about the format of the string. Regardless of the implementation
      * any valid URI and URL need to be accepted as a valid reference value
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    void removeReference(String field,String reference);
+    void removeReference(String field,String reference) throws NullPointerException, IllegalArgumentException;
     /**
      * Removes a natural language text in given languages form a field
      * @param field the field
@@ -199,21 +240,32 @@ public interface Representation {
      * @param language the language(s) of the natural language text
      *             (If <code>null</code> is parsed as language, than also labels
      *             without language tag might be removed)
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    void removeNaturalText(String field,String text,String...languages);
+    void removeNaturalText(String field,String text,String...languages) throws NullPointerException, IllegalArgumentException;
     /**
      * Removes all values of the field
      * @param field the field
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    void removeAll(String field);
+    void removeAll(String field) throws NullPointerException, IllegalArgumentException;
     /**
-     * Removes all natural language texts for the given languages
-     * @param field the field
-     * @param language the language(s) of the natural language text
-     *             (If <code>null</code> is parsed as language, than also all labels
-     *             without language tag are removed)
+     * Removes all natural language texts for the given languages or all natural
+     * language labels of no language or an empty array is parsed as language.
+     * To remove values with no language, parse <code>null</code> as entry of the
+     * languages array.
+     * @param field the field.
+     * @param languages the language(s) of the natural language text. If
+     *             <code>null</code> or an empty array is parsed, than all
+     *             natural language label are removed. To remove only labels with
+     *             no language, <code>null</code> needs to be parsed as entry of
+     *             this array. 
+     * @throws NullPointerException if <code>null</code> is parsed as field
+     * @throws IllegalArgumentException if an empty string is parsed as field
      */
-    void removeAllNaturalText(String field,String...languages);
+    void removeAllNaturalText(String field,String...languages) throws NullPointerException, IllegalArgumentException;
     /**
      * Getter for all the present fields
      * @return the fields