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/04/18 18:57:24 UTC

svn commit: r1094648 [1/2] - in /incubator/stanbol/trunk/entityhub: generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/ generic/core/src/main/java/org/apache/stanbol/ent...

Author: rwesten
Date: Mon Apr 18 16:57:23 2011
New Revision: 1094648

URL: http://svn.apache.org/viewvc?rev=1094648&view=rev
Log:
resolves STANBOL-175: All methods of the Entityhub now correctly return null instead of an IllegalArgumentException when the creation of a Sign with the wrong type is requested for an parsed ID. This resolves STANBOL-175 because in case null is returned the RESTful service returns the expected NOT_FOUND code. 

Other changes:
 - The type of the Sign is now stored in the Representation. This allows the type checks needed to reslove STANBOL-175
 - All Constructors of the default implementations for Signs (Sign, EntityMapping and Symbol) are now protected. The new DefaultSignFactory needs now to be used to create instances. This change makes now sense because with the added sign type information the new factory allows an easy and consistent way to create Signs.
 - Corrected three occasions where ReferencedSite specific configuration had not overridden defaults of the Entityhub.
 - Some clarification in the JavaDoc of the Entityhub Interfaces (especially related to RuntimeExceptions)
 - All Enumerations for States and the new one for SignTypes do now include static methods to lookup the Enum instance for the URL

Changes in Entityhub Jerey

Added the Documentation for the RESTful API had some side effects. Especially a missing Accept header on a normal service call caused to HTML documentation to be returned.
Changed the Implementation to only return the Documentation if "text/html" is part of the Accept header AND if no further (form) parameters are parsed with the request.

Added:
    incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignFactory.java   (with props)
Modified:
    incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/EntityhubImpl.java
    incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ReferencedSiteImpl.java
    incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultEntityMappingImpl.java
    incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignImpl.java
    incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSymbolImpl.java
    incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/utils/ModelUtils.java
    incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/Entityhub.java
    incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/EntityMapping.java
    incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/Sign.java
    incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/Symbol.java
    incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityMappingResource.java
    incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java
    incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java
    incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java

Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/EntityhubImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/EntityhubImpl.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/EntityhubImpl.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/EntityhubImpl.java Mon Apr 18 16:57:23 2011
@@ -20,6 +20,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -32,8 +33,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.stanbol.entityhub.core.mapping.DefaultFieldMapperImpl;
 import org.apache.stanbol.entityhub.core.mapping.FieldMappingUtils;
 import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory;
-import org.apache.stanbol.entityhub.core.model.DefaultEntityMappingImpl;
-import org.apache.stanbol.entityhub.core.model.DefaultSymbolImpl;
+import org.apache.stanbol.entityhub.core.model.DefaultSignFactory;
 import org.apache.stanbol.entityhub.core.query.DefaultQueryFactory;
 import org.apache.stanbol.entityhub.core.query.QueryResultListImpl;
 import org.apache.stanbol.entityhub.core.utils.ModelUtils;
@@ -46,6 +46,8 @@ import org.apache.stanbol.entityhub.serv
 import org.apache.stanbol.entityhub.servicesapi.model.Representation;
 import org.apache.stanbol.entityhub.servicesapi.model.Sign;
 import org.apache.stanbol.entityhub.servicesapi.model.Symbol;
+import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
+import org.apache.stanbol.entityhub.servicesapi.model.Sign.SignTypeEnum;
 import org.apache.stanbol.entityhub.servicesapi.model.rdf.RdfResourceEnum;
 import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
 import org.apache.stanbol.entityhub.servicesapi.query.FieldQueryFactory;
@@ -88,6 +90,10 @@ public final class EntityhubImpl impleme
     private FieldMapper fieldMapper;
 
     /**
+     * Used to create Sign instances
+     */
+    private DefaultSignFactory signFactory = DefaultSignFactory.getInstance();
+    /**
      * Tracks the availability of the Yard used by the Entityhub.
      */
     private ServiceTracker entityhubYardTracker; //reference initialised in the activate method
@@ -300,22 +306,21 @@ public final class EntityhubImpl impleme
         if(symbolId == null || symbolId.isEmpty()){
             throw new IllegalArgumentException("The parsed symbolID MUST NOT be NULL nor empty!");
         }
-        Representation rep = lookupYard().getRepresentation(symbolId);
-        if(rep != null){
-            try {
-                return new DefaultSymbolImpl(config.getEntityhubPrefix(),rep);
-            } catch(IllegalArgumentException e){
-                String msg = "Unable to create Symbol based on the representation as stored in the Entityhub";
-                log.warn(msg);
-                if(log.isWarnEnabled()){
-                    log.warn(ModelUtils.getRepresentationInfo(rep));
-                }
-                throw new IllegalStateException(msg,e); //re-throw for now
-            }
+        Sign symbol = getSignFormYard(symbolId);
+        if(symbol == null || symbol instanceof Symbol){
+            return (Symbol)symbol;
         } else {
+            log.info("The parsed id does not represent a Symbol, but a {} (uri={})! -> return null",
+                symbol.getType(),symbol.getType().getUri());
             return null;
         }
     }
+    /**
+     * Creates a new Symbol (internal Entity) by importing the parsed sign
+     * @param sign the sign to import
+     * @return the imported and stored symbol. 
+     * @throws YardException
+     */
     protected Symbol createSymbol(Sign sign) throws YardException{
         if(sign == null){
             return null;
@@ -326,11 +331,46 @@ public final class EntityhubImpl impleme
             return null;
         }
         Yard entityhubYard = lookupYard();
+        ValueFactory valueFactory = entityhubYard.getValueFactory();
+        //Create the Symbol
         Representation symbolRep = entityhubYard.create(constructResourceId(DEFAULT_SYMBOL_PREFIX));
+        Symbol symbol = importSign(sign, signSite, symbolRep, valueFactory);
+
+        //Second create and init the Mapping
+        Representation entityMappingRepresentation = entityhubYard.create(
+            constructResourceId(DEFAULT_MAPPING_PREFIX));
+        EntityMapping entityMapping = establishMapping(symbol, sign, signSite, entityMappingRepresentation);
+        
+        //Store the symbol and the mappedEntity in the entityhubYard
+        entityhubYard.store(symbol.getRepresentation());
+        entityhubYard.store(entityMapping.getRepresentation());
+        return symbol;
+    }
+    /**
+     * Imports a {@link Sign} from a {@link ReferencedSite}. This Method imports
+     * the {@link Representation} by applying all configured mappings. It also
+     * sets the SymbolState to the configured default value by the referenced
+     * site of the Sign or the default for the Entityhub if the site does not
+     * define this configuration.<p>
+     * @param sign The sign (external entity) to import
+     * @param signSite the referenced site of the sign (external entity)
+     * @param symbolRep the Representation used to store the imported information
+     * @param valueFactory the valusFactory used to create instance while importing
+     * @return the symbol (internal Entity)
+     */
+    private Symbol importSign(Sign sign,
+                              ReferencedSite signSite,
+                              Representation symbolRep,
+                              ValueFactory valueFactory) {
+        Symbol symbol = signFactory.createSign(config.getID(),Symbol.class, symbolRep);
+        Symbol.SymbolState state = signSite.getConfiguration().getDefaultSymbolState();
+        if(state == null){
+            state =  config.getDefaultSymbolState();
+        }
+        symbol.setState(state);
         //and set the initial state
         symbolRep.addReference(Symbol.STATE, config.getDefaultSymbolState().getUri());
         //create a FieldMapper containing the Entityhub Mappings and the Site specific mappings
-        //TODO: one could cache such instances
         FieldMapper siteMapper = signSite.getFieldMapper();
         FieldMapper mapper = this.fieldMapper.clone();
         for(FieldMapping siteMapping : siteMapper.getMappings()){
@@ -339,37 +379,40 @@ public final class EntityhubImpl impleme
         Representation signRep = sign.getRepresentation();
         //TODO: As soon as MappingActivities are implemented we need to add such
         //      information to the EntityMapping instance!
-        mapper.applyMappings(signRep, symbolRep,entityhubYard.getValueFactory());
-        //Second create the symbol and init the data
-        Symbol symbol;
-        try {
-            symbol = new DefaultSymbolImpl(config.getEntityhubPrefix(),symbolRep);
-        } catch (IllegalArgumentException e){
-            //unable to create Symbol based on available Information
-            // -> clean up and return null;
-            log.warn("Unable to create Symbol for Representation "+symbolRep.getId()+
-                    ", because of missing required fields! -> return null (see more Infos after Stack Trace)",e);
-            if(log.isWarnEnabled()){
-                log.warn(ModelUtils.getRepresentationInfo(symbolRep));
-            }
-            try { //try to remove the created representation in the store
-                entityhubYard.remove(symbolRep.getId());
-            } catch (YardException e1) {
-                log.warn("Unable to remove Representation "+symbolRep.getId(),e1);
-            }
-            return null;
-        }
-        //Third create and init the mapped Entity
-        EntityMapping entityMapping = new DefaultEntityMappingImpl(
-                config.getEntityhubPrefix(), symbolRep.getId(), signRep.getId(),
-                config.getDefaultMappingState(),
-                entityhubYard.create(constructResourceId(DEFAULT_MAPPING_PREFIX)));
-        //Store the symbol and the mappedEntity in the entityhubYard
-        entityhubYard.store(symbol.getRepresentation());
-        entityhubYard.store(entityMapping.getRepresentation());
+        mapper.applyMappings(signRep, symbolRep,valueFactory);
         return symbol;
-
-        //we need to set the label and the description!
+    }
+    /**
+     * Creates a new {@link EntityMapping} for the parsed Sign and Symbol. This
+     * also sets the State and the expire date based on the configurations of the
+     * ReferencesSite of the Sign and the defaults of the Entityhub 
+     * @param symbol the Symbol (internal Entity) to link
+     * @param sign the Sign (external Entity)  to link
+     * @param signSite the referenced site of the Sign (external Entity)
+     * @param entityMappingRepresentation the Representation used to store the data
+     * @return the EntityMapping
+     */
+    private EntityMapping establishMapping(Symbol symbol,
+                                           Sign sign,
+                                           ReferencedSite signSite,
+                                           Representation entityMappingRepresentation) {
+        EntityMapping entityMapping = signFactory.createSign(config.getID(),
+            EntityMapping.class, entityMappingRepresentation);
+        //now init the mappingState and the expireDate based on the config of the
+        //ReferencedSite of the sign (considering also the defaults of the entityhub)
+        EntityMapping.MappingState mappingState = signSite.getConfiguration().getDefaultMappedEntityState();
+        if(mappingState == null){
+            mappingState = config.getDefaultMappingState();
+        }
+        entityMapping.setState(mappingState);
+        long expireDuration = signSite.getConfiguration().getDefaultExpireDuration();
+        if(expireDuration < 0){
+            Date expireDate = new Date(System.currentTimeMillis()+expireDuration);
+            entityMapping.setExpires(expireDate);
+        }
+        entityMapping.getRepresentation().setReference(EntityMapping.ENTITY_ID, sign.getId());
+        entityMapping.getRepresentation().setReference(EntityMapping.SYMBOL_ID, symbol.getId());
+        return entityMapping;
     }
     /**
      * Uses the Prefix as configured by the {@link #config} and the parsed
@@ -416,20 +459,31 @@ public final class EntityhubImpl impleme
         }
         FieldQuery fieldQuery = getQueryFavtory().createFieldQuery();
         fieldQuery.setConstraint(RdfResourceEnum.mappedEntity.getUri(), new ReferenceConstraint(reference));
-        QueryResultList<String> resultList = lookupYard().findReferences(fieldQuery);
+        QueryResultList<Representation> resultList = lookupYard().findRepresentation(fieldQuery);
         if(!resultList.isEmpty()){
-            Iterator<String> resultIterator = resultList.iterator();
-            EntityMapping entityMapping = getEntityMappingFromYard(resultIterator.next());
-            if(resultIterator.hasNext()){
-                log.warn("Multiple Mappings found for Entity "+reference+"!");
-                log.warn("  > "+entityMapping.getId()+" -> returned instance");
+            Iterator<Representation> resultIterator = resultList.iterator();
+            Sign mapping = signFactory.getSign(config.getID(), resultIterator.next());
+            if(!(mapping.getType() == SignTypeEnum.EntityMapping)){
+                // This query should only return EntityMappings 
+                //  ... something very bad happens :(
+                log.error("Unable to create EntityMapping {} for Entity {} because SignType != EntityMapping but {}!",
+                    new Object[]{
+                                 mapping.getId(),
+                                 reference,
+                                 mapping.getType()
+                    });
+            }
+          //print warnings in case of multiple mappings
+            if(resultIterator.hasNext()){ 
+                log.warn("Multiple Mappings found for Entity {}!",reference);
+                log.warn("  > {} -> returned instance",mapping.getId());
                 while(resultIterator.hasNext()){
-                    log.warn("  > "+resultIterator.next()+" -> ignored");
+                    log.warn("  > {} -> ignored",resultIterator.next());
                 }
             }
-            return entityMapping;
+            return (EntityMapping)mapping;
         } else {
-            log.debug("No Mapping found for Entity "+reference);
+            log.debug("No Mapping found for Entity {}",reference);
             return null;
         }
     }
@@ -441,38 +495,49 @@ public final class EntityhubImpl impleme
         }
         FieldQuery fieldQuery = getQueryFavtory().createFieldQuery();
         fieldQuery.setConstraint(RdfResourceEnum.mappedSymbol.getUri(), new ReferenceConstraint(symbol));
-        QueryResultList<String> resultList = lookupYard().findReferences(fieldQuery);
+        QueryResultList<Representation> resultList = lookupYard().findRepresentation(fieldQuery);
         Collection<EntityMapping> mappings = new HashSet<EntityMapping>();
-        for(String mappingId : resultList){
-            EntityMapping entityMapping = getEntityMappingFromYard(mappingId);
-            if(entityMapping != null){
-                mappings.add(entityMapping);
+        for(Representation rep : resultList){
+            Sign entityMapping = signFactory.getSign(config.getID(), rep);
+            if(entityMapping.getType() == SignTypeEnum.EntityMapping){
+                mappings.add((EntityMapping)entityMapping);
             } else {
-                log.info("Unable to getEntityMapping for "+mappingId+" (id was returned as result for a query for EntityMappings -> so that should only happen if the Mapping was deleted in the meantime)");
+                // This query should only return EntityMappings 
+                //  ... something very bad happens :(
+                log.error("Unable to create EntityMapping {} for Symbol {} because SignType != EntityMapping but {}!",
+                    new Object[]{
+                                 entityMapping.getId(),
+                                 symbol,
+                                 entityMapping.getType()
+                    });
             }
         }
         return mappings;
     }
-    /**
-     * Getter for the EntityMapping by ID
-     * @param id the ID
-     * @return the EntityMapping or <code>null</code> if no Sign is present 
-     * within the EntityhubYard for the parsed ID
-     * @throws IllegalArgumentException if the Sign referenced by the parsed ID 
-     * is not an valid {@link EntityMapping}.
-     */
-    protected EntityMapping getEntityMappingFromYard(String id) throws IllegalArgumentException,YardException {
-       Representation rep = lookupYard().getRepresentation(id);
+
+    protected Sign getSignFormYard(String id) throws YardException {
+        Representation rep = lookupYard().getRepresentation(id);
         if(rep != null){
-            return new DefaultEntityMappingImpl(config.getEntityhubPrefix(),rep);
+            return signFactory.getSign(config.getID(), rep);
         } else {
             return null;
         }
     }
+    
 
     @Override
-    public EntityMapping getMappingById(String id) throws EntityhubException{
-        return getEntityMappingFromYard(id);
+    public EntityMapping getMappingById(String id) throws IllegalArgumentException, EntityhubException{
+        if(id == null || id.isEmpty()){
+            throw new IllegalArgumentException("The parsed id MUST NOT be NULL nor empty");
+        }
+        Sign mapping = getSignFormYard(id);
+        if(mapping == null || mapping instanceof EntityMapping){
+            return (EntityMapping)mapping;
+        } else {
+            log.info("The parsed id does not represent an Mapping, but a {} (uri={}) -> return null!",
+                mapping.getType(),mapping.getType().getUri());
+            return null;
+        }
     }
     @Override
     public FieldQueryFactory getQueryFavtory() {

Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ReferencedSiteImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ReferencedSiteImpl.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ReferencedSiteImpl.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ReferencedSiteImpl.java Mon Apr 18 16:57:23 2011
@@ -41,9 +41,9 @@ import org.apache.stanbol.commons.stanbo
 import org.apache.stanbol.entityhub.core.mapping.DefaultFieldMapperImpl;
 import org.apache.stanbol.entityhub.core.mapping.FieldMappingUtils;
 import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory;
+import org.apache.stanbol.entityhub.core.model.DefaultSignFactory;
 import org.apache.stanbol.entityhub.core.query.DefaultQueryFactory;
 import org.apache.stanbol.entityhub.core.query.QueryResultListImpl;
-import org.apache.stanbol.entityhub.core.utils.ModelUtils;
 import org.apache.stanbol.entityhub.core.utils.OsgiUtils;
 import org.apache.stanbol.entityhub.servicesapi.mapping.FieldMapper;
 import org.apache.stanbol.entityhub.servicesapi.mapping.FieldMapping;
@@ -236,6 +236,10 @@ public class ReferencedSiteImpl implemen
     private final Logger log;
     private ComponentContext context;
     private FieldMapper fieldMappings;
+    /**
+     * Used to create Sign instances
+     */
+    private DefaultSignFactory signFactory = DefaultSignFactory.getInstance();
 
     private final Object searcherAndDereferencerLock = new Object();
     private Boolean dereferencerEqualsEntitySearcherComponent;
@@ -296,7 +300,7 @@ public class ReferencedSiteImpl implemen
                     QueryResultList<Representation> representations = cache.findRepresentation((query));
                     results = new ArrayList<Sign>(representations.size());
                     for(Representation result : representations){
-                        results.add(ModelUtils.createSign(result, getId()));
+                        results.add(signFactory.getSign(getId(),result));
                     }
                     return new QueryResultListImpl<Sign>(query, results, Sign.class);
                 } catch (YardException e) {
@@ -520,7 +524,7 @@ public class ReferencedSiteImpl implemen
             log.info(String.format("  - loaded Representation %s from Cache in %d ms",
                     id, (System.currentTimeMillis() - start)));
         }
-        return rep != null ? ModelUtils.createSign(rep, getId()) : null;
+        return rep != null ? signFactory.getSign(getId(),rep) : null;
     }
     @Override
     public SiteConfiguration getConfiguration() {

Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultEntityMappingImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultEntityMappingImpl.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultEntityMappingImpl.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultEntityMappingImpl.java Mon Apr 18 16:57:23 2011
@@ -16,10 +16,7 @@
  */
 package org.apache.stanbol.entityhub.core.model;
 
-import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.stanbol.entityhub.servicesapi.model.EntityMapping;
 import org.apache.stanbol.entityhub.servicesapi.model.Reference;
@@ -36,46 +33,37 @@ public class DefaultEntityMappingImpl ex
 
     private static final Logger log = LoggerFactory.getLogger(DefaultEntityMappingImpl.class);
 
-    public static final Map<String,MappingState> MAPPING_STATE_MAP;
-    static{
-        Map<String,MappingState> tmp = new HashMap<String, MappingState>();
-        for(MappingState state : MappingState.values()){
-            tmp.put(state.getUri(), state);
-        }
-        MAPPING_STATE_MAP = Collections.unmodifiableMap(tmp);
-    }
-    /**
-     * Creates a new EntityMapping between the parsed symbol and entity
-     * @param entityhubId The ID of the Entityhub that defines this mapping
-     * @param symbol the ID of the symbol
-     * @param entity the ID of the entity
-     * @param state the state or <code>null</code> to use the {@link EntityMapping#DEFAULT_MAPPING_STATE}
-     * @param representation The representation to store the information of this EntityMapping
-     * @throws IllegalArgumentException If the EntityMapping Instance can not be created based on the parsed parameter.
-     * This includes <ul>
-     * <li> the Entityhub ID is <code>null</code> or empty
-     * <li> the symbol ID is <code>null</code> or empty
-     * <li> the entity ID is <code>null</code> or empty
-     * <li> the representation is <code>null</code>
-     * </ul>
-     * TODO: Maybe also add an valid {@link MappingState} value for the {@link EntityMapping#STATE}
-     *       to the requirements
-     */
-    public DefaultEntityMappingImpl(String entityhubId, String symbol,String entity,MappingState state,Representation representation) throws IllegalArgumentException {
-        super(entityhubId,representation);
-        if(symbol == null || symbol.isEmpty()){
-            throw new IllegalArgumentException("Parsed symbol ID MUST NOT be NULL nor empty");
-        }
-        if(entity == null || entity.isEmpty()){
-            throw new IllegalArgumentException("Parsed entity ID MUST NOT be NULL nor empty");
-        }
-        representation.setReference(EntityMapping.SYMBOL_ID, symbol);
-        representation.setReference(EntityMapping.ENTITY_ID, entity);
-        if(state == null){
-            state = EntityMapping.DEFAULT_MAPPING_STATE;
-        }
-        representation.setReference(EntityMapping.STATE, state.getUri());
-    }
+// NOTE: No longer used after switching to the DefaultSignFactory 
+//    /**
+//     * Creates a new EntityMapping between the parsed symbol and entity
+//     * @param entityhubId The ID of the Entityhub that defines this mapping
+//     * @param symbol the ID of the symbol
+//     * @param entity the ID of the entity
+//     * @param state the state or <code>null</code> to use the {@link EntityMapping#DEFAULT_MAPPING_STATE}
+//     * @param representation The representation to store the information of this EntityMapping
+//     * @throws IllegalArgumentException If the EntityMapping Instance can not be created based on the parsed parameter.
+//     * This includes <ul>
+//     * <li> the Entityhub ID is <code>null</code> or empty
+//     * <li> the symbol ID is <code>null</code> or empty
+//     * <li> the entity ID is <code>null</code> or empty
+//     * <li> the representation is <code>null</code>
+//     * </ul>
+//     */
+//    protected DefaultEntityMappingImpl(String entityhubId, String symbol,String entity,MappingState state,Representation representation) throws IllegalArgumentException {
+//        super(entityhubId,representation);
+//        if(symbol == null || symbol.isEmpty()){
+//            throw new IllegalArgumentException("Parsed symbol ID MUST NOT be NULL nor empty");
+//        }
+//        if(entity == null || entity.isEmpty()){
+//            throw new IllegalArgumentException("Parsed entity ID MUST NOT be NULL nor empty");
+//        }
+//        representation.setReference(EntityMapping.SYMBOL_ID, symbol);
+//        representation.setReference(EntityMapping.ENTITY_ID, entity);
+//        if(state == null){
+//            state = EntityMapping.DEFAULT_MAPPING_STATE;
+//        }
+//        representation.setReference(EntityMapping.STATE, state.getUri());
+//    }
     /**
      *
      * @param siteId
@@ -90,15 +78,15 @@ public class DefaultEntityMappingImpl ex
      * <li> the representation is <code>null</code>
      * </ul>
      */
-    public DefaultEntityMappingImpl(String siteId, Representation representation) {
+    protected DefaultEntityMappingImpl(String siteId, Representation representation) {
         super(siteId,representation);
-        //check required fields
-        if(getEntityId() == null){
-            throw new IllegalArgumentException("Representation "+getId()+" does not define required field "+EntityMapping.ENTITY_ID);
-        }
-        if(getSymbolId() == null){
-            throw new IllegalArgumentException("Representation "+getId()+" does not define required field "+EntityMapping.SYMBOL_ID);
-        }
+        //check no longer required -> allows to set values after creation ...
+//        if(getEntityId() == null){
+//            throw new IllegalArgumentException("Representation "+getId()+" does not define required field "+EntityMapping.ENTITY_ID);
+//        }
+//        if(getSymbolId() == null){
+//            throw new IllegalArgumentException("Representation "+getId()+" does not define required field "+EntityMapping.SYMBOL_ID);
+//        }
     }
     @Override
     public final String getEntityId() {
@@ -114,17 +102,16 @@ public class DefaultEntityMappingImpl ex
     @Override
     public final MappingState getState() {
         Reference stateUri = representation.getFirstReference(EntityMapping.STATE);
-        MappingState state;
         if(stateUri != null){
-            state = MAPPING_STATE_MAP.get(stateUri.getReference());
+            if(MappingState.isState(stateUri.getReference())){
+                return MappingState.getState(stateUri.getReference());
+            } else {
+                log.warn("Value {} for field {} is not a valied MappingState! -> return null",
+                    stateUri,EntityMapping.STATE);
+                return null;
+            }
         } else {
-            state = null;
-        }
-        if(state == null){
-            log.warn("Value "+stateUri+" for field "+EntityMapping.STATE+" is not a valied MappingState! -> return null");
             return null;
-        } else {
-            return state;
         }
     }
 

Added: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignFactory.java?rev=1094648&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignFactory.java (added)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignFactory.java Mon Apr 18 16:57:23 2011
@@ -0,0 +1,133 @@
+package org.apache.stanbol.entityhub.core.model;
+
+import org.apache.stanbol.entityhub.servicesapi.model.EntityMapping;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.model.Sign;
+import org.apache.stanbol.entityhub.servicesapi.model.Sign.SignTypeEnum;
+import org.apache.stanbol.entityhub.servicesapi.model.Symbol;
+
+/**
+ * Factory for the default implementations of {@link Sign} and its subclasses
+ * {@link EntityMapping} and {@link Symbol}.
+ * @author Rupert Westenthaler
+ *
+ */
+public class DefaultSignFactory {
+
+    /**
+     * Singleton instance
+     */
+    private static DefaultSignFactory instance;
+
+    public static DefaultSignFactory getInstance(){
+        if(instance == null){
+            instance = new DefaultSignFactory();
+        }
+        return instance;
+    }
+    /**
+     * Reads the {@link Sign#SIGN_TYPE} value in the parsed 
+     * {@link Representation} and creates the Sign of the according type
+     * @param signSite the site for the sign (not stored in the Representation
+     * @param rep the representation of the sign
+     * @return the sign instance based on the data in the Representation
+     * @throws IllegalArgumentException if any of the parsed parameter is 
+     * <code>null</code>
+     */
+    public Sign getSign(String signSite,Representation rep) throws IllegalArgumentException {
+        if(signSite == null){
+            throw new IllegalArgumentException("The Site for the Sign MUST NOT be NULL");
+        }
+        if(rep == null){
+            throw new IllegalArgumentException("The Representation for the Sign MUST NOT be NULL");
+        }
+        SignTypeEnum signType = DefaultSignImpl.parseSignType(rep);
+        return createInstance(signSite, signType, rep);
+    }
+
+    /**
+     * Creates a Sign of the given type. The {@link Sign#SIGN_TYPE} is set to
+     * the parsed uri of the parsed {@link SignTypeEnum}.
+     * @param signSite the site of the sign
+     * @param signType the type of the sign
+     * @param rep the Representation for the sign
+     * @return the created sign instance ({@link Sign}, {@link EntityMapping} or
+     * {@link Symbol} depending on the parsed signType).
+     * @throws IllegalArgumentException If the parsed signSite or representation
+     * is <code>null</code>.
+     */
+    public Sign createSign(String signSite,Sign.SignTypeEnum signType,Representation rep) throws IllegalArgumentException{
+        if(signSite == null){
+            throw new IllegalArgumentException("The Site for the Sign MUST NOT be NULL");
+        }
+        if(rep == null){
+            throw new IllegalArgumentException("The Representation for the Sign MUST NOT be NULL");
+        }
+        if(signType == null){ //if null is parsed as type
+            signType = Sign.SignTypeEnum.Sign; //set to default
+        }
+        rep.setReference(Sign.SIGN_TYPE, signType.getUri());
+        return createInstance(signSite, signType, rep);
+    }
+    /**
+     * Internally used to create the sign instance.
+     * @param signSite the site for the sign
+     * @param signType the type for the sign. <code>null</code> defaults to Sign
+     * @param rep the Representation to use
+     * @return the {@link Symbol}, {@link EntityMapping} or {@link Sign} depending
+     * on the parsed signType
+     * @throws IllegalArgumentException if the parsed signType has an other value
+     * as {@link SignTypeEnum#Sign}, {@link SignTypeEnum#EntityMapping} or
+     * {@link SignTypeEnum#Symbol}. Meaning that an additional type was added to
+     * the enumeration without adapting this implementation!)
+     */
+    private Sign createInstance(String signSite,Sign.SignTypeEnum signType,Representation rep){
+        if(signType == null){
+            signType = Sign.SignTypeEnum.Sign;
+        }
+        switch (signType) {
+            case Sign:
+                return new DefaultSignImpl(signSite, rep);
+            case EntityMapping:
+                return new DefaultEntityMappingImpl(signSite, rep);
+            case Symbol:
+                return new DefaultSymbolImpl(signSite, rep);
+            default:
+                throw new IllegalStateException("Unknown SignType "+signType+". " +
+                        "This implementation is outdated and need to be adapted to the new Sign Type!");
+        }
+    }
+    /**
+     * Creates a sign by using the parsed type. The {@link Sign#SIGN_TYPE} according
+     * to the parsed signType is set to the parsed {@link Representation}.
+     * @param <T> the type of the sign.
+     * @param signSite the site for the sign
+     * @param signType one of {@link Sign}, {@link EntityMapping} or {@link Symbol}
+     * @param rep the representation of the sign
+     * @return The sign of the requested type
+     * @throws IllegalArgumentException if any of the parsed Parameter is 
+     * <code>null</code> or the signType is not one of {@link Sign}, 
+     * {@link EntityMapping} or {@link Symbol}
+     */
+    @SuppressWarnings("unchecked")
+    public <T extends Sign> T createSign(String signSite,Class<T> signType, Representation rep){
+        if(signSite == null){
+            throw new IllegalArgumentException("The Site for the sign MUST NOT be NULL");
+        }
+        if(rep == null){
+            throw new IllegalArgumentException("The Representation for the sign MUST NOT be NULL");
+        }
+        if(signType == null){
+            throw new IllegalArgumentException("The Class representing the type of the sign MUST NOT be NULL");
+        }
+        if(Symbol.class.getName().equals(signType.getName())){
+            return (T)createSign(signSite, Sign.SignTypeEnum.Symbol, rep);
+        } else if(EntityMapping.class.getName().equals(signType.getName())){
+            return (T)createSign(signSite, Sign.SignTypeEnum.EntityMapping, rep);
+        } else if(Sign.class.getName().equals(signType.getName())){
+            return (T)createSign(signSite, Sign.SignTypeEnum.Sign, rep);
+        } else {
+            throw new IllegalArgumentException("The parsed Class representing the sign type MUST BE one of Sign, EntityMapping or Symbol");
+        }
+    }
+}

Propchange: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignImpl.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignImpl.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSignImpl.java Mon Apr 18 16:57:23 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.stanbol.entityhub.core.model;
 
+import org.apache.stanbol.entityhub.servicesapi.model.Reference;
 import org.apache.stanbol.entityhub.servicesapi.model.Representation;
 import org.apache.stanbol.entityhub.servicesapi.model.Sign;
 import org.slf4j.Logger;
@@ -26,7 +27,6 @@ public class DefaultSignImpl implements 
     Logger log = LoggerFactory.getLogger(DefaultSignImpl.class);
     
     protected final Representation representation;
-//    private final String TYPE = RdfResourceEnum.signType.getUri();
     private final String signSite;
 
 //    public DefaultSignImpl(Representation representation) {
@@ -38,7 +38,8 @@ public class DefaultSignImpl implements 
 //        }
 //        this.representation = representation;
 //    }
-    public DefaultSignImpl(String siteId,Representation representation) {
+    protected DefaultSignImpl(String siteId,Representation representation) {
+        super();
         if(representation == null){
             throw new IllegalArgumentException("NULL value ist not allowed for the Representation");
         }
@@ -63,33 +64,41 @@ public class DefaultSignImpl implements 
     }
     
     @Override
-    public String getSignSite() {
+    public final String getSignSite() {
         return signSite;
     }
 
     @Override
-    public String getId() {
+    public final String getId() {
         return representation.getId();
     }
 
     @Override
-    public Representation getRepresentation() {
+    public final Representation getRepresentation() {
         return representation;
     }
-//    @Override
-//    public SignTypeEnum getType() {
-//        Reference ref = representation.getFirstReference(TYPE);
-//        if(ref == null){
-//            return DEFAULT_SIGN_TYPE;
-//        } else {
-//            SignTypeEnum type = ModelUtils.getSignType(ref.getReference());
-//            if(type == null){
-//                log.warn("Sign "+getId()+" is set to an unknown SignType "+ref.getReference()+"! -> return default type (value is not reseted)");
-//                return DEFAULT_SIGN_TYPE;
-//            } else {
-//                return type;
-//            }
-//        }
-//    }
-
+    @Override
+    public final SignTypeEnum getType() {
+        SignTypeEnum type = parseSignType(representation);
+        return type == null?SignTypeEnum.Sign:type;
+    }
+    /**
+     * Parses the SignType from the parsed Representation
+     * @param rep the representation
+     * @return the type of the sign or <code>null</code> if the representation
+     * does not contain the necessary information
+     * @throws IllegalArgumentException if the parsed Representation contains an
+     * {@link Sign#SIGN_TYPE} value that is not an valid URI for 
+     * {@link SignTypeEnum#getType(String)}.
+     */
+    public static SignTypeEnum parseSignType(Representation rep) throws IllegalArgumentException {
+        SignTypeEnum signType;
+        Reference typeRef = rep.getFirstReference(Sign.SIGN_TYPE);
+        if(typeRef != null){
+            signType = SignTypeEnum.getType(typeRef.getReference());
+        } else {
+            signType = null;
+        }
+        return signType;
+    }
 }

Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSymbolImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSymbolImpl.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSymbolImpl.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/model/DefaultSymbolImpl.java Mon Apr 18 16:57:23 2011
@@ -16,10 +16,7 @@
  */
 package org.apache.stanbol.entityhub.core.model;
 
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map;
 
 import org.apache.stanbol.entityhub.core.utils.ToStringIterator;
 import org.apache.stanbol.entityhub.servicesapi.model.Reference;
@@ -44,60 +41,26 @@ public class DefaultSymbolImpl extends D
 
     private static final Logger log = LoggerFactory.getLogger(DefaultSymbolImpl.class);
 
-    private String defaultLanguage;
+    private String defaultLanguage = null;
+
     private static final String[] ALT_LABEL_LANGUAGES = new String[]{null,"en"};
-    public static final Map<String,SymbolState> SYMBOL_STATE_MAP;
-    static{
-        Map<String,SymbolState> tmp = new HashMap<String, SymbolState>();
-        for(SymbolState state : SymbolState.values()){
-            tmp.put(state.getUri(), state);
-        }
-        SYMBOL_STATE_MAP = Collections.unmodifiableMap(tmp);
-    }
 
     /**
-     * Creates a Symbol Wrapper over the parsed representation with
-     * <code>null</code> as default language
-     * @param entityhubId the ID of the Entityhub that manages this Symbol
-     * @param representation the representation holding the state of the symbol
-     * @throws IllegalArgumentException If the Symbol instance can not be initialised based on the parsed parameter.
-     * This includes: <ul>
-     * <li> the Entityhub ID is <code>null</code> or empty
-     * <li> the parsed representation does not define a label
-     *      (provide a value for the {@link Symbol#LABEL} field)
-     * <li> the parsed representation does not define a valid symbol state
-     *      (provide a value of {@link SymbolState} for the {@link Symbol#STATE} field)
-     * <li> the representation is <code>null</code>
-     * </ul>
-     */
-    public DefaultSymbolImpl(String entityhubId,Representation representation){
-        this(entityhubId,representation,null);
-    }
-    /**
      * Creates a Symbol Wrapper over the parsed representation
      * @param entityhubId the ID of the Entityhub that manages this Symbol
      * @param representation the representation holding the state of the symbol
-     * @param defaultLanguage the language for requests without an language
-     * (e.g. methods like {@link #getLabel()})
-     * @throws IllegalArgumentException If the Symbol instance can not be initialised based on the parsed parameter.
-     * This includes: <ul>
-     * <li> the Entityhub ID is <code>null</code> or empty
-     * <li> the parsed representation does not define a label
-     *      (provide a value for the {@link Symbol#LABEL} field)
-     * <li> the parsed representation does not define a valid symbol state
-     *      (provide a value of {@link SymbolState} for the {@link Symbol#STATE} field)
-     * <li> the representation is <code>null</code>
-     * </ul>
+     * @throws IllegalArgumentException If the parsed ID is <code>null</code> or
+     * empty or the parsed Representation is <code>null</code>.
      */
-    public DefaultSymbolImpl(String entityhubId,Representation representation,String defaultLanguage) throws IllegalArgumentException {
+    protected DefaultSymbolImpl(String entityhubId,Representation representation) throws IllegalArgumentException {
         super(entityhubId,representation);
-        if(getLabel() == null){
-            throw new IllegalArgumentException("Representation "+getId()+" does not define required field "+Symbol.LABEL);
-        }
-        if(getState() == null){
-            throw new IllegalArgumentException("Representation "+getId()+" does not define required field "+Symbol.STATE);
-        }
-        this.defaultLanguage = defaultLanguage;
+        //checks no longer required,
+//        if(getLabel() == null){
+//            throw new IllegalArgumentException("Representation "+getId()+" does not define required field "+Symbol.LABEL);
+//        }
+//        if(getState() == null){
+//            throw new IllegalArgumentException("Representation "+getId()+" does not define required field "+Symbol.STATE);
+//        }
     }
     @Override
     public final void addDescription(String description) {
@@ -162,17 +125,16 @@ public class DefaultSymbolImpl extends D
     @Override
     public final SymbolState getState() {
         Reference stateUri = representation.getFirstReference(Symbol.STATE);
-        SymbolState state;
         if(stateUri != null){
-            state = SYMBOL_STATE_MAP.get(stateUri.getReference());
+            if(SymbolState.isState(stateUri.getReference())){
+                return SymbolState.getState(stateUri.getReference());
+            } else {
+                log.warn("Value {} for field {} is not a valied SymbolState! -> return null",
+                    stateUri,Symbol.STATE);
+                return null;
+            }
         } else {
-            state = null;
-        }
-        if(state == null){
-            log.warn("Value "+stateUri+" for field "+Symbol.STATE+" is not a valied SymbolState! -> return null");
             return null;
-        } else {
-            return state;
         }
     }
 
@@ -223,6 +185,26 @@ public class DefaultSymbolImpl extends D
 
     @Override
     public final void setState(SymbolState state) throws IllegalArgumentException {
-        representation.setReference(Symbol.STATE, state.getUri());
+        if(state != null){
+            representation.setReference(Symbol.STATE, state.getUri());
+        } else {
+            throw new IllegalArgumentException("SymbolState can not be set to NULL!");
+        }
+    }
+    /**
+     * Getter for the default language used for {@link #getLabel()}
+     * @return the preferred language used for {@link #getLabel()}
+     */
+    public final String getDefaultLanguage() {
+        return defaultLanguage;
+    }
+    /**
+     * Setter for the default language used for {@link #getLabel()} (
+     * <code>null</code> is supported)
+     * @param defaultLanguage the preferred language used for {@link #getLabel()} 
+     */
+    public final void setDefaultLanguage(String defaultLanguage) {
+        this.defaultLanguage = defaultLanguage;
     }
+
 }

Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/utils/ModelUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/utils/ModelUtils.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/utils/ModelUtils.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/utils/ModelUtils.java Mon Apr 18 16:57:23 2011
@@ -31,9 +31,6 @@ import java.util.UUID;
 
 import javax.xml.namespace.QName;
 
-import org.apache.stanbol.entityhub.core.model.DefaultEntityMappingImpl;
-import org.apache.stanbol.entityhub.core.model.DefaultSignImpl;
-import org.apache.stanbol.entityhub.core.model.DefaultSymbolImpl;
 import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
 import org.apache.stanbol.entityhub.servicesapi.model.Reference;
 import org.apache.stanbol.entityhub.servicesapi.model.Representation;
@@ -267,45 +264,46 @@ public final class ModelUtils {
             }
         }
     }
-    /**
-     * Creates a Sign for the parsed Representation and the signSite id
-     * @param rep the Represetnation
-     * @param signSite the id of the site for the sign
-     * @return the sign
-     * @throws IllegalArgumentException if any of the two parameter is <code>null</code>.
-     */
-    public static Sign createSign(Representation rep,String signSite) throws IllegalArgumentException {
-        if(rep == null){
-            throw new IllegalArgumentException("The parsed Representation MUST NOT be NULL!");
-        }
-        if(signSite == null){
-            throw new IllegalArgumentException("The parsed ID of the SignSite MUST NOT be NULL!");
-        }
-        rep.setReference(Sign.SIGN_SITE, signSite);
-        SignTypeEnum signType = ModelUtils.getSignType(rep);
-        //instantiate the correct Sign Implementation
-        Sign sign;
-        /*
-         * TODO: change this part to separate the implementation of the
-         * ReferencedSite with the instantiation of Sign Type Implementations
-         * Maybe introduce an SignFactory or add such Methods to the
-         * existing ValueFactory
-         */
-        switch (signType) {
-        case Symbol:
-            sign = new DefaultSymbolImpl(signSite,rep);
-            break;
-        case EntityMapping:
-            sign = new DefaultEntityMappingImpl(signSite,rep);
-            break;
-        case Sign:
-            sign = new DefaultSignImpl(signSite,rep);
-            break;
-        default:
-            log.warn("Unsupported SignType "+signType.getUri()+" (create Sign instance). Please adapt this implementation!");
-            sign = new DefaultSignImpl(signSite,rep);
-            break;
-        }
-        return sign;
-    }
+    //No longer needed after the introduction of the DefaultSignFactory!
+//    /**
+//     * Creates a Sign for the parsed Representation and the signSite id
+//     * @param rep the Represetnation
+//     * @param signSite the id of the site for the sign
+//     * @return the sign
+//     * @throws IllegalArgumentException if any of the two parameter is <code>null</code>.
+//     */
+//    public static Sign createSign(Representation rep,String signSite) throws IllegalArgumentException {
+//        if(rep == null){
+//            throw new IllegalArgumentException("The parsed Representation MUST NOT be NULL!");
+//        }
+//        if(signSite == null){
+//            throw new IllegalArgumentException("The parsed ID of the SignSite MUST NOT be NULL!");
+//        }
+//        rep.setReference(Sign.SIGN_SITE, signSite);
+//        SignTypeEnum signType = ModelUtils.getSignType(rep);
+//        //instantiate the correct Sign Implementation
+//        Sign sign;
+//        /*
+//         * TODO: change this part to separate the implementation of the
+//         * ReferencedSite with the instantiation of Sign Type Implementations
+//         * Maybe introduce an SignFactory or add such Methods to the
+//         * existing ValueFactory
+//         */
+//        switch (signType) {
+//        case Symbol:
+//            sign = new DefaultSymbolImpl(signSite,rep);
+//            break;
+//        case EntityMapping:
+//            sign = new DefaultEntityMappingImpl(signSite,rep);
+//            break;
+//        case Sign:
+//            sign = new DefaultSignImpl(signSite,rep);
+//            break;
+//        default:
+//            log.warn("Unsupported SignType "+signType.getUri()+" (create Sign instance). Please adapt this implementation!");
+//            sign = new DefaultSignImpl(signSite,rep);
+//            break;
+//        }
+//        return sign;
+//    }
 }

Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/Entityhub.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/Entityhub.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/Entityhub.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/Entityhub.java Mon Apr 18 16:57:23 2011
@@ -109,7 +109,8 @@ public interface Entityhub {
      * @return the Symbol or <code>null</code> if no {@link Symbol} with that
      * ID is managed by the Entityhub.
      * @throws IllegalArgumentException if <code>null</code> or an empty String
-     * is parsed as symbolId
+     * is parsed as symbolId or if the parsed ID does not represent a
+     * {@link Symbol}
      * @throws EntityhubException On any error while performing the operation
      */
     Symbol getSymbol(String symbolId) throws IllegalArgumentException, EntityhubException;
@@ -138,8 +139,11 @@ public interface Entityhub {
      * @param id the id of the mapped entity
      * @return the MappedEntity or <code>null</code> if none was found
      * @throws EntityhubException On any error while performing the operation
+     * @throws IllegalArgumentException If <code>null</code> or an empty string
+     * is parsed as ID or if the parsed ID does not represent an 
+     * {@link EntityMapping}
      */
-    EntityMapping getMappingById(String id) throws EntityhubException;
+    EntityMapping getMappingById(String id) throws EntityhubException, IllegalArgumentException;
     /**
      * Getter for all mappings for a entity
      * TODO: check if an Entity can be mapped to more than one Symbol

Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/EntityMapping.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/EntityMapping.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/EntityMapping.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/EntityMapping.java Mon Apr 18 16:57:23 2011
@@ -21,6 +21,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.stanbol.entityhub.servicesapi.model.Symbol.SymbolState;
 import org.apache.stanbol.entityhub.servicesapi.model.rdf.RdfResourceEnum;
 
 public interface EntityMapping extends Sign {
@@ -73,19 +74,32 @@ public interface EntityMapping extends S
             return uri;
         }
         // ---- reverse Mapping based on URI ----
-        private static Map<String,MappingState> uri2state;
+        private static Map<String,MappingState> URI_TO_STATE;
         static {
             Map<String, MappingState> mappings = new HashMap<String, MappingState>();
             for(MappingState state : MappingState.values()){
                 mappings.put(state.getUri(), state);
             }
-            uri2state = Collections.unmodifiableMap(mappings);
+            URI_TO_STATE = Collections.unmodifiableMap(mappings);
         }
-        public static MappingState getState(String uri){
-            return uri2state.get(uri);
+        /**
+         * Getter for the State based on the URI.
+         * @param uri the URI
+         * @return the State
+         * @throws IllegalArgumentException if the parsed URI does not represent
+         * a state
+         */
+        public static MappingState getState(String uri) throws IllegalArgumentException{
+            MappingState state = URI_TO_STATE.get(uri);
+            if(state == null){
+                throw new IllegalArgumentException(String.format(
+                    "Unknown MappingState URI %s (supported states URIs: %s)",
+                    uri,URI_TO_STATE.keySet()));
+            }
+            return state;
         }
         public static boolean isState(String uri){
-            return uri2state.containsKey(uri);
+            return URI_TO_STATE.containsKey(uri);
         }
     }
     //    /**

Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/Sign.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/Sign.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/Sign.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/Sign.java Mon Apr 18 16:57:23 2011
@@ -16,6 +16,11 @@
  */
 package org.apache.stanbol.entityhub.servicesapi.model;
 
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.stanbol.entityhub.servicesapi.model.EntityMapping.MappingState;
 import org.apache.stanbol.entityhub.servicesapi.model.rdf.RdfResourceEnum;
 /**
  * A Sign links three things together
@@ -51,7 +56,7 @@ public interface Sign {
         ;
         private String uri;
         SignTypeEnum(String uri){
-
+            this.uri = uri;
         }
         public String getUri(){
             return uri;
@@ -60,6 +65,34 @@ public interface Sign {
         public String toString() {
             return uri;
         }
+        // ---- reverse Mapping based on URI ----
+        private static Map<String,SignTypeEnum> URI_TO_STATE;
+        static {
+            Map<String, SignTypeEnum> mappings = new HashMap<String, SignTypeEnum>();
+            for(SignTypeEnum state : SignTypeEnum.values()){
+                mappings.put(state.getUri(), state);
+            }
+            URI_TO_STATE = Collections.unmodifiableMap(mappings);
+        }
+        /**
+         * Getter for the SignType based on the URI.
+         * @param uri the URI
+         * @return the State
+         * @throws IllegalArgumentException if the parsed URI does not represent
+         * a state
+         */
+        public static SignTypeEnum getType(String uri) throws IllegalArgumentException{
+            SignTypeEnum state = URI_TO_STATE.get(uri);
+            if(state == null){
+                throw new IllegalArgumentException(String.format(
+                    "Unknown SignType URI %s (supported states URIs: %s)",
+                    uri,URI_TO_STATE.keySet()));
+            }
+            return state;
+        }
+        public static boolean isState(String uri){
+            return URI_TO_STATE.containsKey(uri);
+        }
     }
     /**
      * The default type of a {@link Sign} (set to {@link SignTypeEnum#Sign})
@@ -87,13 +120,18 @@ public interface Sign {
      * @return the site of this Sign
      */
     String getSignSite();
-//    /**
-//     * Getter for the type of a sign. Subclasses may restrict values of this
-//     * property. (e.g. {@link #getType()} for {@link Symbol} always returns
-//     * {@link SignTypeEnum#Symbol})
-//     * @return the type
-//     */
-//    SignTypeEnum getType();
+    
+    /**
+     * The property used to store the type of the type
+     */
+    String SIGN_TYPE = RdfResourceEnum.signType.getUri();
+    /**
+     * Getter for the type of a sign. Subclasses may restrict values of this
+     * property. (e.g. {@link #getType()} for {@link Symbol} always returns
+     * {@link SignTypeEnum#Symbol})
+     * @return the type
+     */
+    SignTypeEnum getType();
 
     /**
      * Getter for the {@link Representation} of that sign as defined/managed by the site

Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/Symbol.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/Symbol.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/Symbol.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/Symbol.java Mon Apr 18 16:57:23 2011
@@ -16,8 +16,12 @@
  */
 package org.apache.stanbol.entityhub.servicesapi.model;
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 
+import org.apache.stanbol.entityhub.servicesapi.model.EntityMapping.MappingState;
 import org.apache.stanbol.entityhub.servicesapi.model.rdf.RdfResourceEnum;
 
 public interface Symbol extends Sign{
@@ -63,6 +67,34 @@ public interface Symbol extends Sign{
         public String toString() {
             return uri;
         }
+        private static Map<String,SymbolState> URI_TO_STATE;
+        static {
+            Map<String, SymbolState> mappings = new HashMap<String, SymbolState>();
+            for(SymbolState state : SymbolState.values()){
+                mappings.put(state.getUri(), state);
+            }
+            URI_TO_STATE = Collections.unmodifiableMap(mappings);
+        }
+        /**
+         * Getter for the State based on the URI.
+         * @param uri the URI
+         * @return the State
+         * @throws IllegalArgumentException if the parsed URI does not represent
+         * a state
+         */
+        public static SymbolState getState(String uri) throws IllegalArgumentException{
+            SymbolState state = URI_TO_STATE.get(uri);
+            if(state == null){
+                throw new IllegalArgumentException(String.format(
+                    "Unknown SymbolState URI %s (supported states URIs: %s)",
+                    uri,URI_TO_STATE.keySet()));
+            }
+            return state;
+        }
+        public static boolean isState(String uri){
+            return URI_TO_STATE.containsKey(uri);
+        }
+
     }
 
     /**

Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityMappingResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityMappingResource.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityMappingResource.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityMappingResource.java Mon Apr 18 16:57:23 2011
@@ -18,7 +18,7 @@ package org.apache.stanbol.entityhub.jer
 
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
-import static javax.ws.rs.core.MediaType.TEXT_HTML;
+import static javax.ws.rs.core.MediaType.*;
 import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
 import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.N3;
 import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.N_TRIPLE;
@@ -27,9 +27,13 @@ import static org.apache.clerezza.rdf.co
 import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.TURTLE;
 import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.X_TURTLE;
 
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
 
 import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
@@ -57,6 +61,13 @@ import com.sun.jersey.api.view.Viewable;
 /**
  * RESTful interface for the {@link EntityMapping}s defined by the {@link Entityhub}.
  * 
+ * NOTE to RESTful Service Documentation in the header:
+ *   Removed all Methods used to provide the RESTful Service documentation and
+ *   incorporated them to the methods using the same path but with the id
+ *   parameter. The reason for that was that the documentation methods where
+ *   called even if an id parameter was provided if the "Accept:" header was
+ *   not specified in requests.
+ * 
  * @author Rupert Westenthaler
  */
 @Path("/entityhub/mapping")
@@ -65,33 +76,41 @@ public class EntityMappingResource exten
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     private ServletContext context;
-
+    
     // bind the job manager by looking it up from the servlet request context
     public EntityMappingResource(@Context ServletContext context) {
         super();
         this.context = context;
     }
 
-    @GET
-    @Path("/")
-    @Produces(MediaType.TEXT_HTML)
-    public Response getMappingPage() {
-        return Response.ok(new Viewable("index", this), TEXT_HTML).build();
-    }
+// see NOTE to RESTful Service Documentation in the header
+//    @GET
+//    @Path("/")
+//    @Produces(MediaType.TEXT_HTML)
+//    public Response getMappingPage() {
+//        return Response.ok(new Viewable("index", this), TEXT_HTML).build();
+//    }
     
     @GET
     @Path("/")
-    @Produces( {APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE})
+    @Produces( {APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE,TEXT_HTML})
     public Response getMapping(@QueryParam("id") String reference, @Context HttpHeaders headers)
                                                                             throws WebApplicationException {
         log.debug("get mapping for request > id : {} > accept: {}",
             reference, headers.getAcceptableMediaTypes());
-
-        MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+        Set<String> supported = new HashSet<String>(JerseyUtils.REPRESENTATION_SUPPORTED_MEDIA_TYPES);
+        supported.add(TEXT_HTML);
+        MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(
+            headers,supported, APPLICATION_JSON_TYPE);
         
         if (reference == null || reference.isEmpty()) {
-            return Response.status(Status.BAD_REQUEST).entity("The mapping ID (URI) is missing.").header(
-                HttpHeaders.ACCEPT, acceptedMediaType).build();
+            //if HTML -> print the docu of the restfull service
+            if(TEXT_HTML_TYPE.isCompatible(acceptedMediaType)){
+              return Response.ok(new Viewable("index", this), TEXT_HTML).build();
+            } else {
+                return Response.status(Status.BAD_REQUEST).entity("The mapping id (URI) is missing.\n").header(
+                    HttpHeaders.ACCEPT, acceptedMediaType).build();
+            }
         }
         Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, context);
         EntityMapping mapping;
@@ -102,33 +121,41 @@ public class EntityMappingResource exten
             return Response.status(Status.INTERNAL_SERVER_ERROR).build();
         }
         if (mapping == null) {
-            return Response.status(Status.NOT_FOUND).entity("No mapping found for '" + reference + "'.")
+            return Response.status(Status.NOT_FOUND).entity("No mapping found for '" + reference + "'.\n")
                     .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
         } else {
             return Response.ok(mapping, acceptedMediaType).build();
         }
     }
-    
-    @GET
-    @Path("/entity")
-    @Produces(MediaType.TEXT_HTML)
-    public Response getEntityMappingPage() {
-        return Response.ok(new Viewable("entity", this), TEXT_HTML).build();
-    }
+// see NOTE to RESTful Service Documentation in the header
+//    @GET
+//    @Path("/entity")
+//    @Produces(MediaType.TEXT_HTML)
+//    public Response getEntityMappingPage() {
+//        return Response.ok(new Viewable("entity", this), TEXT_HTML).build();
+//    }
 
     @GET
     @Path("/entity")
-    @Produces( {APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE})
+    @Produces( {APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE,TEXT_HTML})
     public Response getEntityMapping(@QueryParam("id") String entity, @Context HttpHeaders headers)
                                                                             throws WebApplicationException {
         log.debug("getEntityMapping() POST Request > entity: {} > accept: {}",
             entity, headers.getAcceptableMediaTypes());
         
-        MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+        Set<String> supported = new HashSet<String>(JerseyUtils.REPRESENTATION_SUPPORTED_MEDIA_TYPES);
+        supported.add(TEXT_HTML);
+        MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(
+            headers,supported, APPLICATION_JSON_TYPE);
 
         if (entity == null || entity.isEmpty()) {
-            return Response.status(Status.BAD_REQUEST).entity("No entity given. Missing parameter ID.")
+            //if HTML -> print the docu of the restfull service
+            if(TEXT_HTML_TYPE.isCompatible(acceptedMediaType)){
+                return Response.ok(new Viewable("entity", this), TEXT_HTML).build();
+            } else {
+                return Response.status(Status.BAD_REQUEST).entity("No entity given. Missing parameter id.\n")
                     .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
+            }
         }
         
         Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, context);
@@ -139,33 +166,41 @@ public class EntityMappingResource exten
             throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
         }
         if (mapping == null) {
-            return Response.status(Status.NOT_FOUND).entity("No mapping found for entity '" + entity + "'.")
+            return Response.status(Status.NOT_FOUND).entity("No mapping found for entity '" + entity + "'.\n")
                     .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
         } else {
             return Response.ok(mapping, acceptedMediaType).build();
         }
     }
-
-    @GET
-    @Path("/symbol")
-    @Produces(MediaType.TEXT_HTML)
-    public Response getSymbolMappingPage() {
-        return Response.ok(new Viewable("symbol", this), TEXT_HTML).build();
-    }
+ // see NOTE to RESTful Service Documentation in the header
+//    @GET
+//    @Path("/symbol")
+//    @Produces(MediaType.TEXT_HTML)
+//    public Response getSymbolMappingPage() {
+//        return Response.ok(new Viewable("symbol", this), TEXT_HTML).build();
+//    }
     
     @GET
     @Path("/symbol")
-    @Produces( {APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE})
+    @Produces( {APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE,TEXT_HTML})
     public Response getSymbolMappings(@QueryParam("id") String symbol, @Context HttpHeaders headers)
                                                                             throws WebApplicationException {
         log.debug("getSymbolMappings() POST Request > symbol: {} > accept: {}",
             symbol, headers.getAcceptableMediaTypes());
         
-        MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+        Set<String> supported = new HashSet<String>(JerseyUtils.REPRESENTATION_SUPPORTED_MEDIA_TYPES);
+        supported.add(TEXT_HTML);
+        MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(
+            headers,supported, APPLICATION_JSON_TYPE);
 
         if (symbol == null || symbol.isEmpty()) {
-            return Response.status(Status.BAD_REQUEST).entity("No symbol given. Missing parameter ID.")
-            .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
+            //if HTML -> print the docu of the restfull service
+            if(TEXT_HTML_TYPE.isCompatible(acceptedMediaType)){
+                return Response.ok(new Viewable("symbol", this), TEXT_HTML).build();
+            } else {
+                return Response.status(Status.BAD_REQUEST).entity("No symbol given. Missing parameter id.\n")
+                    .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
+            }
         }
         Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, context);
         Collection<EntityMapping> mappings;
@@ -175,7 +210,7 @@ public class EntityMappingResource exten
             throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
         }
         if (mappings == null || mappings.isEmpty()) {
-            return Response.status(Status.NOT_FOUND).entity("No mapping found for symbol '" + symbol + "'.")
+            return Response.status(Status.NOT_FOUND).entity("No mapping found for symbol '" + symbol + "'.\n")
             .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
         } else {
             // TODO: Implement Support for list of Signs, Representations and Strings

Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java?rev=1094648&r1=1094647&r2=1094648&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java Mon Apr 18 16:57:23 2011
@@ -32,7 +32,6 @@ import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -40,9 +39,8 @@ import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
 
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
 import org.apache.clerezza.rdf.ontologies.RDFS;
 import org.apache.stanbol.commons.web.base.ContextHelper;
@@ -155,7 +153,6 @@ public class ReferencedSiteRootResource 
         if(name == null || name.isEmpty()){
             //return all
         } else if(name.startsWith(LICENSE_NAME)){
-            int number;
             try {
                 String numberString = name.substring(LICENSE_NAME.length());
                 if(numberString.isEmpty()){
@@ -173,8 +170,9 @@ public class ReferencedSiteRootResource 
                     }
                 }
             }catch (NumberFormatException e) {
-                //not a valid licenseName
-                throw new WebApplicationException(Response.Status.NOT_FOUND);
+                return Response.status(Status.NOT_FOUND).
+                entity("No License found.\n")
+                .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
             }
         }
         return Response.status(Response.Status.NOT_FOUND).build();
@@ -200,9 +198,13 @@ public class ReferencedSiteRootResource 
         log.info("  > id       : " + id);
         log.info("  > accept   : " + headers.getAcceptableMediaTypes());
         log.info("  > mediaType: " + headers.getMediaType());
+        final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,
+            JerseyUtils.SIGN_SUPPORTED_MEDIA_TYPES, MediaType.APPLICATION_JSON_TYPE);
         if (id == null || id.isEmpty()) {
             log.error("No or emptpy ID was parsd as query parameter (id={})", id);
-            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+            return Response.status(Status.BAD_REQUEST).
+            entity("No or empty Entity ID parsed. Missing parameter id={entityID}.\n")
+            .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
         }
         log.info("handle Request for Entity {} of Site {}", id, site.getId());
         Sign sign;
@@ -213,8 +215,6 @@ public class ReferencedSiteRootResource 
                 " (id=" + site.getId() + ")", e);
             throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
-        final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,
-            MediaType.APPLICATION_JSON_TYPE);
         if (sign != null) {
             return Response.ok(sign, acceptedMediaType).build();
         } else {
@@ -222,7 +222,9 @@ public class ReferencedSiteRootResource 
             // create an Response with the the Error?
             log.info(" ... Entity {} not found on referenced site {}", 
                 id, site.getId());
-            throw new WebApplicationException(Response.Status.NOT_FOUND);
+            return Response.status(Status.NOT_FOUND).
+            entity("Entity '"+id+"' not found on referenced site '"+site.getId()+"'\n")
+            .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
         }
     }