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/12 19:09:31 UTC
svn commit: r1091500 [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/site/
generic/servicesapi/src/main/java/org/apache/stanb...
Author: rwesten
Date: Tue Apr 12 17:09:31 2011
New Revision: 1091500
URL: http://svn.apache.org/viewvc?rev=1091500&view=rev
Log:
To prepare work on STANBOL-161:
The ReferencedSite interface is no longer a subclass of ConfiguredSite. ConfiguredSite was renamed to SiteConfiguration. Therefore the configuration and metadata of ReferencedSites are no longer a direct part of the API, but accessible via the new "SiteConfiguration getConfiguration()" method.
Extended the SiteConfiguration with methods related to License and Attribution.
Also changed some loggings to use {} instead of "+var+"
Added:
incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/DefaultSiteConfiguration.java (with props)
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/site/SiteConfiguration.java (contents, props changed)
- copied, changed from r1089869, incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/site/ConfiguredSite.java
Removed:
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/site/ConfiguredSite.java
Modified:
incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ReferenceManagerImpl.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/site/AbstractEntityDereferencer.java
incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/site/AbstractEntitySearcher.java
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/mapping/FieldMapperConfig.java
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/site/EntityDereferencer.java
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/site/EntitySearcher.java
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/site/ReferencedSite.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java
Added: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/DefaultSiteConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/DefaultSiteConfiguration.java?rev=1091500&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/DefaultSiteConfiguration.java (added)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/DefaultSiteConfiguration.java Tue Apr 12 17:09:31 2011
@@ -0,0 +1,592 @@
+package org.apache.stanbol.entityhub.core.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+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.Symbol.SymbolState;
+import org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration;
+import org.apache.stanbol.entityhub.servicesapi.site.ReferencedSite;
+import org.apache.stanbol.entityhub.servicesapi.yard.CacheStrategy;
+import org.osgi.service.cm.ConfigurationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default implementation of the {@link SiteConfiguration} interface with
+ * getter and setters.<p>
+ * Site configurations are read only and usually set during the activation and
+ * through accessible via the {@link ReferencedSite} interface they MUST NOT
+ * be changed by other components. Because of this there is the possibility to
+ * create readonly instances of this class. In this case all setter methods will
+ * throw {@link UnsupportedOperationException}s.
+ *
+ * @author Rupert Westenthaler
+ *
+ */
+public class DefaultSiteConfiguration implements SiteConfiguration {
+ /**
+ * The logger
+ */
+ private final static Logger log = LoggerFactory.getLogger(DefaultSiteConfiguration.class);
+
+ /**
+ * Internally used to store the configuration.
+ */
+ private Map<String,Object> config;
+ /**
+ * The readonly switch (only set by the constructor
+ */
+ private final boolean readonly;
+
+ private DefaultSiteConfiguration(boolean readonly){
+ this.readonly = readonly;
+ this.config = new HashMap<String,Object>();
+ }
+ /**
+ * Creates a configuration based on the parsed parameter. The parsed
+ * configuration is validated.<p>
+ * Changes to the parsed configuration do have no affect on the state of
+ * the created instance.
+ * @param readonly if <code>true</code> the configuration can not be
+ * be modified after creation. Calling any setter method will result in
+ * {@link UnsupportedOperationException}s to be thrown
+ * @param parsed the configuration used for the initialisation.
+ * @throws ConfigurationException if the parsed properties are not valid
+ */
+ public DefaultSiteConfiguration(boolean readonly,Map<String,Object> parsed) throws ConfigurationException {
+ this(readonly);
+ //now add the parsed configuration
+ if(parsed != null){
+ //use local variable because the field might be a read only wrapper!
+ config.putAll(parsed);
+ }
+ //validate the configuration and transform values to the preferred
+ //type (e.g. strings to enums)
+ validateConfiguration();
+ //if readonly replace with an unmodifiable map
+ if(readonly){
+ this.config = Collections.unmodifiableMap(config);
+ }
+ }
+ /**
+ * Constructs an empty read/write configuration
+ */
+ public DefaultSiteConfiguration(){
+ this(false);
+ }
+ /**
+ * Constructs an readonly instance based on the parsed configuration. The parsed
+ * configuration is validated.<p>
+ * Changes to the parsed configuration do have no affect on the state of
+ * the created instance.
+ * @param config the configuration to use
+ * @throws ConfigurationException if the parsed properties are not valid
+ */
+ public DefaultSiteConfiguration(Map<String,Object> config) throws ConfigurationException {
+ this(true,config);
+ }
+ /**
+ * Validates if the current configuration is valid and also perform type
+ * transformations on values (e.g. converting string values to the enumerated
+ * types).<p>
+ * This Method requires write access to the configuration and will therefore
+ * fail in case this instance is readonly. Constructors that do have an
+ * config as parameter call this method to validate the configuration.
+ * @throws ConfigurationException if the validation of an property fails
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ */
+ public void validateConfiguration() throws ConfigurationException, UnsupportedOperationException {
+ if(getId() == null || getId().isEmpty()){
+ throw new ConfigurationException(ID, "The id of a ReferencedSite configuration MUST NOT be NULL nor empty!");
+ }
+ //check if all the Enumerated values are valid strings and convert them
+ //to enumeration instances
+ try {
+ setDefaultMappedEntityState(getDefaultMappedEntityState());
+ } catch (IllegalArgumentException e) {
+ throw new ConfigurationException(DEFAULT_MAPPING_STATE,
+ String.format("Unknown default MappingState (%s=%s) for Site %s! Valid values are %s ",
+ DEFAULT_MAPPING_STATE,config.get(DEFAULT_MAPPING_STATE),getId(),
+ Arrays.toString(MappingState.values())),e);
+ }
+ try {
+ setDefaultSymbolState(getDefaultSymbolState());
+ } catch (IllegalArgumentException e) {
+ throw new ConfigurationException(DEFAULT_SYMBOL_STATE,
+ String.format("Unknown default SymbolState (%s=%s) for Site %s! Valid values are %s ",
+ DEFAULT_SYMBOL_STATE,config.get(DEFAULT_SYMBOL_STATE),getId(),
+ Arrays.toString(SymbolState.values()),e));
+ }
+ try {
+ setCacheStrategy(getCacheStrategy());
+ } catch (IllegalArgumentException e) {
+ throw new ConfigurationException(CACHE_STRATEGY,
+ String.format("Unknown CachStrategy (%s=%s) for Site %s! Valid values are %s ",
+ CACHE_STRATEGY,config.get(CACHE_STRATEGY),getId(),
+ Arrays.toString(CacheStrategy.values()),e));
+ }
+ //check if the default expire duration is a number
+ try {
+ setDefaultExpireDuration(getDefaultExpireDuration());
+ } catch (NumberFormatException e) {
+ throw new ConfigurationException(DEFAULT_EXPIRE_DURATION,
+ String.format("Unable to parse Number for %s=%s. Will return -1 (no expire duration)",
+ DEFAULT_EXPIRE_DURATION,config.get(DEFAULT_EXPIRE_DURATION)),e);
+ }
+ //check if the prefixes can be converted to an String[]
+ try {
+ setEntityPrefixes(getEntityPrefixes());
+ } catch (IllegalArgumentException e) {
+ throw new ConfigurationException(ENTITY_PREFIX, e.getMessage(),e);
+ }
+ //check if the fieldMappings can be converted to an String[]
+ try {
+ setFieldMappings(getFieldMappings());
+ } catch (IllegalArgumentException e) {
+ throw new ConfigurationException(SITE_FIELD_MAPPINGS, e.getMessage(),e);
+ }
+ //check that a cacheId is set if the CacheStrategy != none
+ if(CacheStrategy.none != getCacheStrategy() && getCacheId() == null){
+ throw new ConfigurationException(CACHE_ID,
+ String.format("The CacheID (%s) MUST NOT be NULL nor empty if the the CacheStrategy != %s",
+ CACHE_ID,CacheStrategy.none));
+ }
+ //check that a accessUri and an entity dereferencer is set if the
+ //cacheStrategy != CacheStrategy.all
+ if(CacheStrategy.all != getCacheStrategy()){
+ if(getAccessUri() == null){
+ throw new ConfigurationException(ACCESS_URI,
+ String.format("An AccessUri (%s) MUST be configured if the CacheStrategy != %s",
+ ACCESS_URI,CacheStrategy.all));
+ }
+ if(getEntityDereferencerType() == null){
+ throw new ConfigurationException(ENTITY_DEREFERENCER_TYPE,
+ String.format("An EntityDereferencer (%s) MUST be configured if the CacheStrategy != %s",
+ ENTITY_DEREFERENCER_TYPE,CacheStrategy.all));
+ }
+ }
+ }
+ /**
+ * Getter for the readonly state.
+ * @return if <code>true</code> this configuration is readonly and all
+ * setter methods will throw {@link UnsupportedOperationException}s.
+ */
+ public final boolean isReadonly() {
+ return readonly;
+ }
+
+ @Override
+ public final String getAccessUri() {
+ Object accessUri = config.get(ACCESS_URI);
+ return accessUri == null?null:accessUri.toString();
+ }
+ /**
+ *
+ * @param uri
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getAccessUri()
+ */
+ public final void setAccessUri(String uri) throws UnsupportedOperationException{
+ if(uri == null){
+ config.remove(ACCESS_URI);
+ } else {
+ config.put(ACCESS_URI, uri);
+ }
+ }
+
+ @Override
+ public final String getAttribution() {
+ Object attribution = config.get(SITE_ATTRIBUTION);
+ return attribution == null || attribution.toString().isEmpty() ?
+ null : attribution.toString();
+ }
+ /**
+ *
+ * @param attribution
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getAttribution()
+ */
+ public final void setAttribution(String attribution) throws UnsupportedOperationException {
+ if(attribution == null){
+ config.remove(SITE_ATTRIBUTION);
+ } else {
+ config.put(SITE_ATTRIBUTION, attribution);
+ }
+ }
+
+ @Override
+ public final String getCacheId() {
+ Object id = config.get(CACHE_ID);
+ return id == null || id.toString().isEmpty() ?
+ null : id.toString();
+ }
+ /**
+ *
+ * @param id
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getCacheId()
+ */
+ public final void setCacheId(String id) throws UnsupportedOperationException {
+ if(id == null || id.isEmpty()){
+ config.remove(CACHE_ID);
+ } else {
+ config.put(CACHE_ID, id);
+ }
+ }
+
+ @Override
+ public final CacheStrategy getCacheStrategy() {
+ Object cacheStrategy = config.get(CACHE_STRATEGY);
+ if(cacheStrategy == null){
+ return null;
+ } else if(cacheStrategy instanceof CacheStrategy){
+ return (CacheStrategy)cacheStrategy;
+ } else {
+ return CacheStrategy.valueOf(cacheStrategy.toString());
+ }
+ }
+ /**
+ *
+ * @param strategy
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getCacheStrategy()
+ */
+ public final void setCacheStrategy(CacheStrategy strategy) throws UnsupportedOperationException {
+ if(strategy == null){
+ config.remove(CACHE_STRATEGY);
+ } else {
+ config.put(CACHE_STRATEGY, strategy);
+ }
+ }
+
+ @Override
+ public final long getDefaultExpireDuration() {
+ Object duration = config.get(DEFAULT_EXPIRE_DURATION);
+ if(duration == null){
+ return 0;
+ } else if(duration instanceof Long){
+ return (Long) duration;
+ } else {
+ return Long.valueOf(duration.toString());
+ }
+ }
+ /**
+ *
+ * @param duration
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getDefaultExpireDuration()
+ */
+ public final void setDefaultExpireDuration(long duration) throws UnsupportedOperationException {
+ if(duration <= 0){
+ config.remove(DEFAULT_EXPIRE_DURATION);
+ } else {
+ config.put(DEFAULT_EXPIRE_DURATION, duration);
+ }
+ }
+
+ @Override
+ public final MappingState getDefaultMappedEntityState() {
+ Object defaultMappingState = config.get(DEFAULT_MAPPING_STATE);
+ if(defaultMappingState == null){
+ return null;
+ } else if(defaultMappingState instanceof MappingState){
+ return (MappingState)defaultMappingState;
+ } else {
+ return MappingState.valueOf(defaultMappingState.toString());
+ }
+ }
+ /**
+ *
+ * @param state
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getDefaultMappedEntityState()
+ */
+ public final void setDefaultMappedEntityState(MappingState state) throws UnsupportedOperationException {
+ if(state == null){
+ config.remove(DEFAULT_MAPPING_STATE);
+ } else {
+ config.put(DEFAULT_MAPPING_STATE, state);
+ }
+ }
+
+ @Override
+ public final SymbolState getDefaultSymbolState() {
+ Object defaultSymbolState = config.get(DEFAULT_SYMBOL_STATE);
+ if(defaultSymbolState == null){
+ return null;
+ } else if(defaultSymbolState instanceof SymbolState){
+ return (SymbolState)defaultSymbolState;
+ } else {
+ return SymbolState.valueOf(defaultSymbolState.toString());
+ }
+ }
+ /**
+ *
+ * @param state
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getDefaultSymbolState()
+ */
+ public final void setDefaultSymbolState(SymbolState state) throws UnsupportedOperationException {
+ if(state == null){
+ config.remove(DEFAULT_SYMBOL_STATE);
+ } else {
+ config.put(DEFAULT_SYMBOL_STATE, state);
+ }
+ }
+ @Override
+ public final String getEntityDereferencerType() {
+ Object dereferencer = config.get(ENTITY_DEREFERENCER_TYPE);
+ return dereferencer == null ||dereferencer.toString().isEmpty() ?
+ null : dereferencer.toString();
+ }
+ /**
+ *
+ * @param entityDereferencerType
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getEntityDereferencerType()
+ */
+ public final void setEntityDereferencerType(String entityDereferencerType) throws UnsupportedOperationException {
+ if(entityDereferencerType == null){
+ config.remove(entityDereferencerType);
+ } else {
+ config.put(ENTITY_DEREFERENCER_TYPE, entityDereferencerType);
+ }
+ }
+
+ @Override
+ public final String getDescription() {
+ Object description = config.get(DESCRIPTION);
+ return description == null || description.toString().isEmpty() ?
+ null : description.toString();
+ }
+ /**
+ *
+ * @param description
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getDescription()
+ */
+ public final void setDescription(String description) throws UnsupportedOperationException {
+ if(description == null){
+ config.remove(DESCRIPTION);
+ } else {
+ config.put(DESCRIPTION, description);
+ }
+ }
+ @Override
+ public String[] getFieldMappings() {
+ Object fieldMappings = config.get(SITE_FIELD_MAPPINGS);
+ if(fieldMappings == null){
+ return null;
+ } else if (fieldMappings instanceof String[]){
+ return (String[]) fieldMappings;
+ } else if (fieldMappings instanceof Iterable<?>){
+ Collection<String> prefixes = new ArrayList<String>();
+ for(Object value : (Iterable<?>)fieldMappings){
+ if(value != null && value.toString().isEmpty()){
+ prefixes.add(value.toString());
+ }
+ }
+ return prefixes.toArray(new String[prefixes.size()]);
+ } else if(fieldMappings instanceof String) {
+ return new String[]{fieldMappings.toString()};
+ } else {
+ throw new IllegalArgumentException(
+ String.format("Unable to parse FieldMappings form class %s (supported are String, String[] and Iterables)",
+ fieldMappings.getClass()));
+ }
+ }
+ public final void setFieldMappings(String[] mappings) throws UnsupportedOperationException {
+ if(mappings == null){
+ config.remove(SITE_FIELD_MAPPINGS);
+ } else {
+ config.put(SITE_FIELD_MAPPINGS, mappings);
+ }
+ }
+
+ @Override
+ public final String[] getEntityPrefixes() {
+ Object entityPrefixes = config.get(ENTITY_PREFIX);
+ if(entityPrefixes == null){
+ return null;
+ } else if (entityPrefixes instanceof String[]){
+ return (String[]) entityPrefixes;
+ } else if (entityPrefixes instanceof Iterable<?>){
+ Collection<String> prefixes = new ArrayList<String>();
+ for(Object value : (Iterable<?>)entityPrefixes){
+ if(value != null){
+ prefixes.add(value.toString());
+ }
+ }
+ return prefixes.toArray(new String[prefixes.size()]);
+ } else if(entityPrefixes instanceof String) {
+ return new String[]{entityPrefixes.toString()};
+ } else {
+ throw new IllegalArgumentException(
+ String.format("Unable to parse EnityPrefixes form class %s (supported are String String[] and Iterables)",
+ entityPrefixes.getClass()));
+ }
+ }
+ /**
+ *
+ * @param prefixes
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getEntityPrefixes()
+ */
+ public final void setEntityPrefixes(String[] prefixes) throws UnsupportedOperationException {
+ if(prefixes == null){
+ config.remove(ENTITY_PREFIX);
+ } else {
+ config.put(ENTITY_PREFIX, prefixes);
+ }
+ }
+
+ @Override
+ public final String getId() {
+ Object id = config.get(ID);
+ return id == null ? null : id.toString();
+ }
+ /**
+ *
+ * @param id
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @throws IllegalArgumentException in case the parsed ID is NULL or an empty String
+ * @see #getId()
+ */
+ public final void setId(String id) throws UnsupportedOperationException, IllegalArgumentException {
+ if(id == null){
+ throw new IllegalArgumentException("The ID of the Site MUST NOT be set to NULL!");
+ } else if (id.isEmpty()){
+ throw new IllegalArgumentException("The ID of the Site MIST NOT be set to an empty String!");
+ } else {
+ config.put(ID, id);
+ }
+ }
+
+ @Override
+ public final String getLicenseName() {
+ Object name = config.get(SITE_LICENCE_NAME);
+ return name == null || name.toString().isEmpty() ? null : name.toString();
+ }
+ /**
+ *
+ * @param name
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getLicenseName()
+ */
+ public final void setLicenseName(String name) throws UnsupportedOperationException {
+ if(name == null){
+ config.remove(SITE_LICENCE_NAME);
+ } else {
+ config.put(SITE_LICENCE_NAME, name);
+ }
+ }
+
+ @Override
+ public String getLicenseText() {
+ Object text = config.get(SITE_LICENCE_TEXT);
+ return text == null || text.toString().isEmpty() ? null : text.toString();
+ }
+ /**
+ *
+ * @param licenseText
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getLicenseText()
+ */
+ public void setLicenseText(String licenseText) throws UnsupportedOperationException {
+ if(licenseText == null){
+ config.remove(SITE_LICENCE_TEXT);
+ } else {
+ config.put(SITE_LICENCE_TEXT, licenseText);
+ }
+ }
+
+ @Override
+ public String getLicenseUrl() {
+ Object url = config.get(SITE_LICENCE_URL);
+ return url == null || url.toString().isEmpty() ? null : url.toString();
+ }
+ /**
+ *
+ * @param licenseUrl
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getLicenseUrl()
+ */
+ public final void setLicenseUrl(String licenseUrl) throws UnsupportedOperationException {
+ if(licenseUrl == null){
+ config.remove(SITE_LICENCE_URL);
+ } else {
+ config.put(SITE_LICENCE_URL, licenseUrl);
+ }
+ }
+
+ @Override
+ public String getName() {
+ Object name = config.get(NAME);
+ //use ID as fallback!
+ return name == null || name.toString().isEmpty() ? getId() : name.toString();
+ }
+ /**
+ *
+ * @param name
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getName()
+ */
+ public final void setName(String name) throws UnsupportedOperationException {
+ if(name == null){
+ config.remove(NAME);
+ } else {
+ config.put(NAME, name);
+ }
+ }
+
+ @Override
+ public String getEntitySearcherType() {
+ Object type = config.get(ENTITY_SEARCHER_TYPE);
+ return type == null || type.toString().isEmpty() ? null : type.toString();
+ }
+ /**
+ *
+ * @param entitySearcherType
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getEntitySearcherType()
+ */
+ public final void setEntitySearcherType(String entitySearcherType) throws UnsupportedOperationException {
+ if(entitySearcherType == null){
+ config.remove(ENTITY_SEARCHER_TYPE);
+ } else {
+ config.put(ENTITY_SEARCHER_TYPE, entitySearcherType);
+ }
+ }
+ @Override
+ public String getQueryUri() {
+ Object uri = config.get(QUERY_URI);
+ return uri == null || uri.toString().isEmpty() ? null : uri.toString();
+ }
+ /**
+ *
+ * @param queryUri
+ * @throws UnsupportedOperationException in case this configuration is {@link #readonly}
+ * @see #getQueryUri()
+ */
+ public final void setQueryUri(String queryUri) throws UnsupportedOperationException {
+ if(queryUri == null){
+ config.remove(QUERY_URI);
+ } else {
+ config.put(QUERY_URI, queryUri);
+ }
+ }
+ /**
+ * Provides direct access to the internal configuration
+ * @return the configuration wrapped by this class
+ */
+ protected final Map<String,Object> getConfiguration(){
+ return config;
+ }
+
+}
Propchange: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/DefaultSiteConfiguration.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ReferenceManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ReferenceManagerImpl.java?rev=1091500&r1=1091499&r2=1091500&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ReferenceManagerImpl.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ReferenceManagerImpl.java Tue Apr 12 17:09:31 2011
@@ -98,13 +98,11 @@ public class ReferenceManagerImpl implem
@Activate
protected void activate(ComponentContext context) {
-// this.context = context;
- log.info("Activate ReferenceManager with context" + context);
+ log.debug("Activate ReferenceManager");
}
@Deactivate
protected void deactivate(ComponentContext context) {
- log.info("Deactivate ReferenceManager with context" + context);
-// this.context = null;
+ log.debug("Deactivate ReferenceManager");
synchronized (prefixMap) {
this.prefixList.clear();
this.prefixMap.clear();
@@ -119,13 +117,13 @@ public class ReferenceManagerImpl implem
}
protected void bindReferencedSites(ReferencedSite referencedSite){
- log.info(" ... binding ReferencedSite "+referencedSite.getId());
+ log.debug(" ... binding ReferencedSite {}",referencedSite.getId());
referencedSites.add(referencedSite);
idMap.put(referencedSite.getId(), referencedSite);
addEntityPrefixes(referencedSite);
}
protected void unbindReferencedSites(ReferencedSite referencedSite){
- log.info(" ... unbinding ReferencedSite "+referencedSite.getId());
+ log.debug(" ... unbinding ReferencedSite {}",referencedSite.getId());
referencedSites.remove(referencedSite);
idMap.remove(referencedSite.getId());
removeEntityPrefixes(referencedSite);
@@ -135,7 +133,7 @@ public class ReferenceManagerImpl implem
* @param referencedSite
*/
private void addEntityPrefixes(ReferencedSite referencedSite) {
- for(String prefix : referencedSite.getEntityPrefixes()){
+ for(String prefix : referencedSite.getConfiguration().getEntityPrefixes()){
synchronized (prefixMap) {
Collection<ReferencedSite> sites = prefixMap.get(prefix);
if(sites == null){
@@ -158,7 +156,7 @@ public class ReferenceManagerImpl implem
* @param referencedSite
*/
private void removeEntityPrefixes(ReferencedSite referencedSite) {
- for(String prefix : referencedSite.getEntityPrefixes()){
+ for(String prefix : referencedSite.getConfiguration().getEntityPrefixes()){
synchronized (prefixMap) {
Collection<ReferencedSite> sites = prefixMap.get(prefix);
if(sites != null){
@@ -218,13 +216,13 @@ public class ReferenceManagerImpl implem
} else {
String prefix = prefixList.get(prefixPos);
if(entityUri.startsWith(prefix)){
- log.debug("Found prefix "+prefix+" for Entity "+entityUri);
+ log.debug("Found prefix {} for Entity {}",prefix,entityUri);
return prefixMap.get(prefix);
} //else the parsed entityPrefix does not start with the found prefix
// this may only happen, when the prefixPos == prefixList.size()
}
}
- log.info("No registered prefix for entity "+entityUri);
+ log.info("No registered prefix for entity {}",entityUri);
return Collections.emptySet();
}
@Override
@@ -237,7 +235,8 @@ public class ReferenceManagerImpl implem
entityIds.add(entityId);
}
} catch (ReferencedSiteException e) {
- log.warn("Unable to access Site "+site.getName()+" (url = "+site.getAccessUri()+")",e);
+ log.warn("Unable to access Site "+site.getConfiguration().getName()+
+ " (id = "+site.getId()+")",e);
}
}
return new QueryResultListImpl<String>(query, entityIds.iterator(),String.class);
@@ -251,11 +250,14 @@ public class ReferenceManagerImpl implem
if(!representations.contains(rep)){ //do not override
representations.add(rep);
} else {
- log.info("Entity "+rep.getId()+" found on more than one Referenced Site -> Representation of Site "+site.getName()+" is ignored");
+ log.info("Entity {} found on more than one Referenced Site" +
+ " -> Representation of Site {} is ignored",
+ rep.getId(),site.getConfiguration().getName());
}
}
} catch (ReferencedSiteException e) {
- log.warn("Unable to access Site "+site.getName()+" (url = "+site.getAccessUri()+")",e);
+ log.warn("Unable to access Site "+site.getConfiguration().getName()+
+ " (id = "+site.getId()+")",e);
}
}
return new QueryResultListImpl<Representation>(query, representations,Representation.class);
@@ -269,11 +271,14 @@ public class ReferenceManagerImpl implem
if(!entities.contains(rep)){ //do not override
entities.add(rep);
} else {
- log.info("Entity "+rep.getId()+" found on more than one Referenced Site -> Representation of Site "+site.getName()+" is ignored");
+ log.info("Entity {} found on more than one Referenced Site" +
+ " -> Representation of Site {} is ignored",
+ rep.getId(),site.getConfiguration().getName());
}
}
} catch (ReferencedSiteException e) {
- log.warn("Unable to access Site "+site.getName()+" (url = "+site.getAccessUri()+")",e);
+ log.warn("Unable to access Site "+site.getConfiguration().getName()+
+ " (id = "+site.getId()+")",e);
}
}
return new QueryResultListImpl<Sign>(query, entities,Sign.class);
@@ -282,8 +287,8 @@ public class ReferenceManagerImpl implem
public InputStream getContent(String entityId, String contentType) {
Collection<ReferencedSite> sites = getReferencedSitesByEntityPrefix(entityId);
if(sites.isEmpty()){
- log.info("No Referenced Site registered for Entity "+entityId+"");
- log.debug("Registered Prefixes "+prefixList);
+ log.info("No Referenced Site registered for Entity {}",entityId);
+ log.debug("Registered Prefixes {}",prefixList);
return null;
}
for(ReferencedSite site : sites){
@@ -291,23 +296,25 @@ public class ReferenceManagerImpl implem
try {
content = site.getContent(entityId, contentType);
if(content != null){
- log.debug("Return Content of type "+contentType+" for Entity "+entityId+" from referenced site "+site.getName());
+ log.debug("Return Content of type {} for Entity {} from referenced site {}",
+ new Object[]{contentType,entityId,site.getConfiguration().getName()});
return content;
}
} catch (ReferencedSiteException e) {
- log.warn("Unable to access Site "+site.getName()+" (url = "+site.getAccessUri()+")",e);
+ log.warn("Unable to access Site "+site.getConfiguration().getName()+
+ " (id = "+site.getId()+")",e);
}
}
- log.debug("Entity "+entityId+" not found on any of the following Sites "+sites);
+ log.debug("Entity {} not found on any of the following Sites {}",entityId,sites);
return null;
}
@Override
public Sign getSign(String entityId) {
Collection<ReferencedSite> sites = getReferencedSitesByEntityPrefix(entityId);
if(sites.isEmpty()){
- log.info("No Referenced Site registered for Entity "+entityId+"");
- log.debug("Registered Prefixes "+prefixList);
+ log.info("No Referenced Site registered for Entity {}",entityId);
+ log.debug("Registered Prefixes {}",prefixList);
return null;
}
for(ReferencedSite site : sites){
@@ -315,15 +322,17 @@ public class ReferenceManagerImpl implem
try {
entity = site.getSign(entityId);
if(entity != null){
- log.debug("Return Representation of Site "+site.getName()+" for Entity "+entityId);
+ log.debug("Return Representation of Site {} for Entity {}",
+ site.getConfiguration().getName(),entityId);
return entity;
}
} catch (ReferencedSiteException e) {
- log.warn("Unable to access Site "+site.getName()+" (url = "+site.getAccessUri()+")",e);
+ log.warn("Unable to access Site "+site.getConfiguration().getName()+
+ " (id = "+site.getId()+")",e);
}
}
- log.debug("Entity "+entityId+" not found on any of the following Sites "+sites);
+ log.debug("Entity {} not found on any of the following Sites {}",entityId,sites);
return null;
}
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=1091500&r1=1091499&r2=1091500&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 Tue Apr 12 17:09:31 2011
@@ -19,9 +19,11 @@ package org.apache.stanbol.entityhub.cor
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -41,24 +43,21 @@ import org.apache.stanbol.entityhub.core
import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory;
import org.apache.stanbol.entityhub.core.query.DefaultQueryFactory;
import org.apache.stanbol.entityhub.core.query.QueryResultListImpl;
-import org.apache.stanbol.entityhub.core.site.AbstractEntityDereferencer;
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;
-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.Symbol;
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;
import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
-import org.apache.stanbol.entityhub.servicesapi.site.ConfiguredSite;
import org.apache.stanbol.entityhub.servicesapi.site.EntityDereferencer;
import org.apache.stanbol.entityhub.servicesapi.site.EntitySearcher;
import org.apache.stanbol.entityhub.servicesapi.site.ReferencedSite;
import org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteException;
+import org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration;
import org.apache.stanbol.entityhub.servicesapi.yard.Cache;
import org.apache.stanbol.entityhub.servicesapi.yard.CacheStrategy;
import org.apache.stanbol.entityhub.servicesapi.yard.Yard;
@@ -92,27 +91,27 @@ import org.slf4j.LoggerFactory;
* specific to the used protocol/technology of the referenced site.
* Because of that calls to methods defined in this interface are forwarded
* to an site specific instance of the {@link EntityDereferencer} interface
- * as configured by the {@link ConfiguredSite#DEREFERENCER_TYPE} property.<br>
+ * as configured by the {@link SiteConfiguration#ENTITY_DEREFERENCER_TYPE} property.<br>
* During activation the the {@link BundleContext} is used to
* search for {@link ComponentFactory} with the configuration <code>
* "component.name= {@link ComponentContext#getProperties()}.get(
- * {@link ConfiguredSite#DEREFERENCER_TYPE})</code>. This factory is used
+ * {@link SiteConfiguration#ENTITY_DEREFERENCER_TYPE})</code>. This factory is used
* to create an instance of {@link EntityDereferencer}. <br>
* Note also, that the configuration of this instance that is covered
- * by the {@link ConfiguredSite} interface are parsed to the
+ * by the {@link SiteConfiguration} interface are parsed to the
* {@link EntityDereferencer} instance.
* <li> <b> {@link EntitySearcher}:</b> Implementations of this interface are
* also specific to the used protocol/technology of the referenced site.
* Because of that calls to methods defined in this interface are forwarded
* to an site specific instance of the {@link EntitySearcher} interface
- * as configured by the {@link ConfiguredSite#SEARCHER_TYPE} property.<br>
+ * as configured by the {@link SiteConfiguration#ENTITY_SEARCHER_TYPE} property.<br>
* The initialisation of this instance works similar as described for the
- * {@link EntityDereferencer}. However if the value of the {@link ConfiguredSite#SEARCHER_TYPE}
- * is equals to {@link ConfiguredSite#DEREFERENCER_TYPE} or the
- * {@link ConfiguredSite#SEARCHER_TYPE} is not defined at all, than the
+ * {@link EntityDereferencer}. However if the value of the {@link SiteConfiguration#ENTITY_SEARCHER_TYPE}
+ * is equals to {@link SiteConfiguration#ENTITY_DEREFERENCER_TYPE} or the
+ * {@link SiteConfiguration#ENTITY_SEARCHER_TYPE} is not defined at all, than the
* Dereferencer Instance is also used as {@link EntitySearcher}. If the
* according cast does not succeed, an {@link ConfigurationException} for the
- * {@link ConfiguredSite#SEARCHER_TYPE} property is thrown.
+ * {@link SiteConfiguration#ENTITY_SEARCHER_TYPE} property is thrown.
* <li> <b>{@link Cache}: </b> An instance of a {@link Cache} is used to
* cache {@link Representation}s loaded form the Site. A cache is a wrapper
* over a {@link Yard} instance that allows to configure what data are
@@ -135,94 +134,94 @@ import org.slf4j.LoggerFactory;
)
@Service(value=ReferencedSite.class)
@Properties(value={
- @Property(name=ConfiguredSite.ID,value="dbpedia"),
- @Property(name=ConfiguredSite.NAME,value="DB Pedia"),
- @Property(name=ConfiguredSite.DESCRIPTION, value="The OLD Endpoint for Wikipedia"),
+ @Property(name=SiteConfiguration.ID,value="dbpedia"),
+ @Property(name=SiteConfiguration.NAME,value="DB Pedia"),
+ @Property(name=SiteConfiguration.DESCRIPTION, value="The OLD Endpoint for Wikipedia"),
/*
* TODO: can't use Integer.MAX_VALUE here, because I get a NumberFormatException
* in den maven scr plugin. For now use a big number instead
*/
- @Property(name=ConfiguredSite.ENTITY_PREFIX, cardinality=10000, value={
+ @Property(name=SiteConfiguration.ENTITY_PREFIX, cardinality=10000, value={
"http://dbpedia.org/resource/","http://dbpedia.org/ontology/"
}),
- @Property(name=ConfiguredSite.ACCESS_URI, value="http://dbpedia.org/sparql/"),
- @Property(name=ConfiguredSite.DEREFERENCER_TYPE,
+ @Property(name=SiteConfiguration.ACCESS_URI, value="http://dbpedia.org/sparql/"),
+ @Property(name=SiteConfiguration.ENTITY_DEREFERENCER_TYPE,
options={
@PropertyOption(
- value='%'+ConfiguredSite.DEREFERENCER_TYPE+".option.none",
+ value='%'+SiteConfiguration.ENTITY_DEREFERENCER_TYPE+".option.none",
name=""),
@PropertyOption(
- value='%'+ConfiguredSite.DEREFERENCER_TYPE+".option.sparql",
+ value='%'+SiteConfiguration.ENTITY_DEREFERENCER_TYPE+".option.sparql",
name="org.apache.stanbol.entityhub.dereferencer.SparqlDereferencer"),
@PropertyOption(
- value='%'+ConfiguredSite.DEREFERENCER_TYPE+".option.coolUri",
+ value='%'+SiteConfiguration.ENTITY_DEREFERENCER_TYPE+".option.coolUri",
name="org.apache.stanbol.entityhub.dereferencer.CoolUriDereferencer")
},value="org.apache.stanbol.entityhub.dereferencer.SparqlDereferencer"),
- @Property(name=ConfiguredSite.QUERY_URI, value="http://dbpedia.org/sparql"), //the deri server has better performance
- @Property(name=ConfiguredSite.SEARCHER_TYPE,
+ @Property(name=SiteConfiguration.QUERY_URI, value="http://dbpedia.org/sparql"), //the deri server has better performance
+ @Property(name=SiteConfiguration.ENTITY_SEARCHER_TYPE,
options={
@PropertyOption(
- value='%'+ConfiguredSite.SEARCHER_TYPE+".option.none",
+ value='%'+SiteConfiguration.ENTITY_SEARCHER_TYPE+".option.none",
name=""),
@PropertyOption(
- value='%'+ConfiguredSite.SEARCHER_TYPE+".option.sparql",
+ value='%'+SiteConfiguration.ENTITY_SEARCHER_TYPE+".option.sparql",
name="org.apache.stanbol.entityhub.searcher.SparqlSearcher"),
@PropertyOption(
- value='%'+ConfiguredSite.SEARCHER_TYPE+".option.sparql-virtuoso",
+ value='%'+SiteConfiguration.ENTITY_SEARCHER_TYPE+".option.sparql-virtuoso",
name="org.apache.stanbol.entityhub.searcher.VirtuosoSearcher"),
@PropertyOption(
- value='%'+ConfiguredSite.SEARCHER_TYPE+".option.sparql-larq",
+ value='%'+SiteConfiguration.ENTITY_SEARCHER_TYPE+".option.sparql-larq",
name="org.apache.stanbol.entityhub.searcher.LarqSearcher")
},value="org.apache.stanbol.entityhub.searcher.VirtuosoSearcher"),
- @Property(name=ConfiguredSite.DEFAULT_SYMBOL_STATE,
+ @Property(name=SiteConfiguration.DEFAULT_SYMBOL_STATE,
options={
@PropertyOption( //seems, that name and value are exchanged ...
- value='%'+ConfiguredSite.DEFAULT_SYMBOL_STATE+".option.proposed",
+ value='%'+SiteConfiguration.DEFAULT_SYMBOL_STATE+".option.proposed",
name="proposed"),
@PropertyOption(
- value='%'+ConfiguredSite.DEFAULT_SYMBOL_STATE+".option.active",
+ value='%'+SiteConfiguration.DEFAULT_SYMBOL_STATE+".option.active",
name="active")
//the other states make no sense for new symbols
}, value="proposed"),
- @Property(name=ConfiguredSite.DEFAULT_MAPPING_STATE,
+ @Property(name=SiteConfiguration.DEFAULT_MAPPING_STATE,
options={
@PropertyOption(
- value='%'+ConfiguredSite.DEFAULT_MAPPING_STATE+".option.proposed",
+ value='%'+SiteConfiguration.DEFAULT_MAPPING_STATE+".option.proposed",
name="proposed"),
@PropertyOption(
- value='%'+ConfiguredSite.DEFAULT_MAPPING_STATE+".option.confirmed",
+ value='%'+SiteConfiguration.DEFAULT_MAPPING_STATE+".option.confirmed",
name="confirmed")
//the other states make no sense for new symbols
}, value="proposed"),
- @Property(name=ConfiguredSite.DEFAULT_EXPIRE_DURATION,
+ @Property(name=SiteConfiguration.DEFAULT_EXPIRE_DURATION,
options={
@PropertyOption(
- value='%'+ConfiguredSite.DEFAULT_EXPIRE_DURATION+".option.oneMonth",
+ value='%'+SiteConfiguration.DEFAULT_EXPIRE_DURATION+".option.oneMonth",
name=""+(1000L*60*60*24*30)),
@PropertyOption(
- value='%'+ConfiguredSite.DEFAULT_EXPIRE_DURATION+".option.halfYear",
+ value='%'+SiteConfiguration.DEFAULT_EXPIRE_DURATION+".option.halfYear",
name=""+(1000L*60*60*24*183)),
@PropertyOption(
- value='%'+ConfiguredSite.DEFAULT_EXPIRE_DURATION+".option.oneYear",
+ value='%'+SiteConfiguration.DEFAULT_EXPIRE_DURATION+".option.oneYear",
name=""+(1000L*60*60*24*365)),
@PropertyOption(
- value='%'+ConfiguredSite.DEFAULT_EXPIRE_DURATION+".option.none",
+ value='%'+SiteConfiguration.DEFAULT_EXPIRE_DURATION+".option.none",
name="0")
}, value="0"),
- @Property(name=ConfiguredSite.CACHE_STRATEGY,
+ @Property(name=SiteConfiguration.CACHE_STRATEGY,
options={
@PropertyOption(
- value='%'+ConfiguredSite.CACHE_STRATEGY+".option.none",
+ value='%'+SiteConfiguration.CACHE_STRATEGY+".option.none",
name="none"),
@PropertyOption(
- value='%'+ConfiguredSite.CACHE_STRATEGY+".option.used",
+ value='%'+SiteConfiguration.CACHE_STRATEGY+".option.used",
name="used"),
@PropertyOption(
- value='%'+ConfiguredSite.CACHE_STRATEGY+".option.all",
+ value='%'+SiteConfiguration.CACHE_STRATEGY+".option.all",
name="all")
}, value="none"),
- @Property(name=ConfiguredSite.CACHE_ID),
- @Property(name=ConfiguredSite.SITE_FIELD_MAPPINGS,cardinality=1000, //positive number to use an Array
+ @Property(name=SiteConfiguration.CACHE_ID),
+ @Property(name=SiteConfiguration.SITE_FIELD_MAPPINGS,cardinality=1000, //positive number to use an Array
value={
"dbp-ont:*",
"dbp-ont:thumbnail | d=xsd:anyURI > foaf:depiction",
@@ -236,7 +235,6 @@ public class ReferencedSiteImpl implemen
static final int maxInt = Integer.MAX_VALUE;
private final Logger log;
private ComponentContext context;
- private Dictionary<String,?> properties;
private FieldMapper fieldMappings;
private final Object searcherAndDereferencerLock = new Object();
@@ -244,20 +242,18 @@ public class ReferencedSiteImpl implemen
private ComponentFactoryListener dereferencerComponentFactoryListener;
private ComponentFactoryListener searcherComponentFactoryListener;
- private String dereferencerComponentName;
+// private String dereferencerComponentName;
private ComponentInstance dereferencerComponentInstance;
private EntityDereferencer dereferencer;
- private String entitySearcherComponentName;
+// private String entitySearcherComponentName;
private EntitySearcher entitySearcher;
private ComponentInstance entitySearcherComponentInstace;
- private String accessUri;
- private String queryUri;
- private CacheStrategy cacheStrategy;
- private String cacheId;
private ServiceTracker cacheTracker;
+ private SiteConfiguration siteConfiguration;
+
/**
* The {@link OfflineMode} is used by Stanbol to indicate that no external
* service should be referenced. For the ReferencedSiteImpl this means that
@@ -285,118 +281,13 @@ public class ReferencedSiteImpl implemen
this.log = log;
log.info("create instance of "+this.getClass().getName());
}
-
-
-
- @Override
- public final String getAccessUri() {
- return accessUri;
- }
-
- @Override
- public final CacheStrategy getCacheStrategy() {
- return cacheStrategy;
- }
-
- /**
- * This implementation returns the ExpireDuration. 0 as default if no
- * configuration is present. -1 in case the configuration can not be converted
- * to a number.
- */
- @Override
- public final long getDefaultExpireDuration() {
- Object durationObject = properties.get(DEFAULT_EXPIRE_DURATION);
- if(durationObject == null){
- return 0;
- } else {
- try {
- return Long.parseLong(durationObject.toString());
- } catch (NumberFormatException e) {
- log.warn("Configuration "+DEFAULT_EXPIRE_DURATION+"="+durationObject+" can not be converted to an Number -> return -1",e);
- return -1;
- }
- }
- }
-
- @Override
- public final EntityMapping.MappingState getDefaultMappedEntityState() {
- Object stateObject = properties.get(DEFAULT_MAPPING_STATE);
- if(stateObject == null){
- return EntityMapping.DEFAULT_MAPPING_STATE;
- } else {
- try {
- return EntityMapping.MappingState.valueOf(stateObject.toString());
- } catch (IllegalArgumentException e) {
- log.warn("Configuration "+DEFAULT_MAPPING_STATE+"="+stateObject+" dose not match any entry in the "+
- EntityMapping.MappingState.class+" Enumeration ( one of "+
- Arrays.toString(EntityMapping.MappingState.values())+") " +
- "-> return the default state "+EntityMapping.DEFAULT_MAPPING_STATE,e);
- return EntityMapping.DEFAULT_MAPPING_STATE;
- }
- }
- }
-
- @Override
- public final Symbol.SymbolState getDefaultSymbolState() {
- Object stateObject = properties.get(DEFAULT_SYMBOL_STATE);
- if(stateObject == null){
- return Symbol.DEFAULT_SYMBOL_STATE;
- } else {
- try {
- return Symbol.SymbolState.valueOf(stateObject.toString());
- } catch (IllegalArgumentException e) {
- log.warn("Configuration "+DEFAULT_SYMBOL_STATE+"="+stateObject+" dose not match any entry in the "+
- Symbol.SymbolState.class+" Enumeration ( one of "+
- Arrays.toString(Symbol.SymbolState.values())+") " +
- "-> return the default state "+Symbol.DEFAULT_SYMBOL_STATE,e);
- return Symbol.DEFAULT_SYMBOL_STATE;
- }
- }
- }
-
- @Override
- public final String getDereferencerType() {
- return properties.get(DEREFERENCER_TYPE).toString();
- }
-
- @Override
- public final String getDescription() {
- return ""+properties.get(DESCRIPTION); //use ""+ because value might be null
- }
-
- @Override
- public final String getId() {
- return properties.get(ID).toString();
- }
-
- @Override
- public final String getName() {
- Object name = properties.get(NAME);
- return name != null ? name.toString() : getId();
- }
-
- @Override
- public final String[] getEntityPrefixes() {
- Object prefixes = properties.get(ENTITY_PREFIX);
- if(prefixes == null){
- return new String[]{};
- } else {
- return (String[])prefixes;
- }
- }
- @Override
- public String getQueryType() {
- Object queryType = properties.get(SEARCHER_TYPE);
- return queryType != null?queryType.toString():null;
- }
- @Override
- public String getQueryUri() {
- return queryUri;
+ public String getId(){
+ return siteConfiguration.getId();
}
@Override
public QueryResultList<Sign> findSigns(FieldQuery query) throws ReferencedSiteException {
List<Sign> results;
- if(cacheStrategy == CacheStrategy.all){
+ if(siteConfiguration.getCacheStrategy() == CacheStrategy.all){
//TODO: check if query can be executed based on the base configuration of the Cache
Cache cache = getCache();
if(cache != null){
@@ -409,30 +300,35 @@ public class ReferencedSiteImpl implemen
}
return new QueryResultListImpl<Sign>(query, results, Sign.class);
} catch (YardException e) {
- if(entitySearcherComponentName==null || isOfflineMode()){
- throw new ReferencedSiteException("Unable to execute query on Cache "+cacheId,e);
+ if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
+ throw new ReferencedSiteException("Unable to execute query on Cache "+siteConfiguration.getCacheId(),e);
} else {
- log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",cacheId,queryUri),e);
+ log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",
+ siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()),e);
}
}
} else {
- if(entitySearcherComponentName==null || isOfflineMode()){
- throw new ReferencedSiteException(String.format("Unable to execute query on Cache %s because it is currently not active",cacheId));
+ if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
+ throw new ReferencedSiteException(String.format("Unable to execute query on Cache %s because it is currently not active",
+ siteConfiguration.getCacheId()));
} else {
- log.warn(String.format("Cache %s currently not active will query remote Site %s as fallback",cacheId,queryUri));
+ log.warn(String.format("Cache %s currently not active will query remote Site %s as fallback",
+ siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()));
}
}
}
QueryResultList<String> entityIds;
if(entitySearcher == null) {
- throw new ReferencedSiteException(String.format("EntitySearcher %s not available for remote site %s!",entitySearcherComponentName,queryUri));
+ throw new ReferencedSiteException(
+ String.format("EntitySearcher %s not available for remote site %s!",siteConfiguration.getEntitySearcherType(),
+ siteConfiguration.getQueryUri()));
}
- ensureOnline(getQueryUri(),entitySearcher.getClass());
+ ensureOnline(siteConfiguration.getQueryUri(),entitySearcher.getClass());
try {
entityIds = entitySearcher.findEntities(query);
} catch (IOException e) {
throw new ReferencedSiteException(String.format("Unable to execute query on remote site %s with entitySearcher %s!",
- queryUri,entitySearcherComponentName), e);
+ siteConfiguration.getQueryUri(),siteConfiguration.getEntitySearcherType()), e);
}
int numResults = entityIds.size();
List<Sign> entities = new ArrayList<Sign>(numResults);
@@ -469,85 +365,102 @@ public class ReferencedSiteImpl implemen
}
@Override
public QueryResultList<Representation> find(FieldQuery query) throws ReferencedSiteException{
- if(cacheStrategy == CacheStrategy.all){
+ if(siteConfiguration.getCacheStrategy() == CacheStrategy.all){
//TODO: check if query can be executed based on the base configuration of the Cache
Cache cache = getCache();
if(cache != null){
try {
return cache.find(query);
} catch (YardException e) {
- if(entitySearcherComponentName==null || isOfflineMode()){
- throw new ReferencedSiteException("Unable to execute query on Cache "+cacheId,e);
+ if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
+ throw new ReferencedSiteException("Unable to execute query on Cache "+siteConfiguration.getCacheId(),e);
} else {
- log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",cacheId,queryUri),e);
+ log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",
+ siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()),e);
}
}
} else {
- if(entitySearcherComponentName==null || isOfflineMode()){
- throw new ReferencedSiteException(String.format("Unable to execute query because Cache %s is currently not active",cacheId));
+ if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
+ throw new ReferencedSiteException(String.format("Unable to execute query because Cache %s is currently not active",
+ siteConfiguration.getCacheId()));
} else {
- log.warn(String.format("Cache %s currently not active will query remote Site %s as fallback",cacheId,queryUri));
+ log.warn(String.format("Cache %s currently not active will query remote Site %s as fallback",
+ siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()));
}
}
}
if(entitySearcher == null){
- throw new ReferencedSiteException(String.format("EntitySearcher %s not available for remote site %s!",entitySearcherComponentName,queryUri));
+ throw new ReferencedSiteException(
+ String.format("EntitySearcher %s not available for remote site %s!",siteConfiguration.getEntitySearcherType(),
+ siteConfiguration.getQueryUri()));
}
- ensureOnline(getQueryUri(), entitySearcher.getClass());
+ ensureOnline(siteConfiguration.getQueryUri(), entitySearcher.getClass());
try {
return entitySearcher.find(query);
} catch (IOException e) {
- throw new ReferencedSiteException("Unable execute Query on remote site "+queryUri,e);
+ throw new ReferencedSiteException("Unable execute Query on remote site "+
+ siteConfiguration.getQueryUri(),e);
}
}
@Override
public QueryResultList<String> findReferences(FieldQuery query) throws ReferencedSiteException {
- if(cacheStrategy == CacheStrategy.all){
+ if(siteConfiguration.getCacheStrategy() == CacheStrategy.all){
//TODO: check if query can be executed based on the base configuration of the Cache
Cache cache = getCache();
if(cache != null){
try {
return cache.findReferences(query);
} catch (YardException e) {
- if(entitySearcherComponentName==null || isOfflineMode()){
- throw new ReferencedSiteException("Unable to execute query on Cache "+cacheId,e);
+ if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
+ throw new ReferencedSiteException("Unable to execute query on Cache "+siteConfiguration.getCacheId(),e);
} else {
- log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",cacheId,queryUri),e);
+ log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",
+ siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()),e);
}
}
} else {
- if(entitySearcherComponentName==null || isOfflineMode()){
- throw new ReferencedSiteException(String.format("Unable to execute query on Cache %s because it is currently not active",cacheId));
+ if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
+ throw new ReferencedSiteException(
+ String.format("Unable to execute query on Cache %s because it is currently not active",
+ siteConfiguration.getCacheId()));
} else {
- log.warn(String.format("Cache %s currently not active will query remote Site %s as fallback",cacheId,queryUri));
+ log.warn(String.format("Cache %s currently not active will query remote Site %s as fallback",
+ siteConfiguration.getCacheId(),siteConfiguration.getQueryUri()));
}
}
}
if(entitySearcher == null){
- throw new ReferencedSiteException(String.format("EntitySearcher %s not available for remote site %s!",entitySearcherComponentName,queryUri));
+ throw new ReferencedSiteException(
+ String.format("EntitySearcher %s not available for remote site %s!",siteConfiguration.getEntitySearcherType(),
+ siteConfiguration.getQueryUri()));
}
- ensureOnline(getQueryUri(), entitySearcher.getClass());
+ ensureOnline(siteConfiguration.getQueryUri(), entitySearcher.getClass());
try {
return entitySearcher.findEntities(query);
} catch (IOException e) {
- throw new ReferencedSiteException("Unable execute Query on remote site "+queryUri,e);
+ throw new ReferencedSiteException("Unable execute Query on remote site "+
+ siteConfiguration.getQueryUri(),e);
}
}
@Override
public InputStream getContent(String id, String contentType) throws ReferencedSiteException {
- if(dereferencerComponentName == null){
- throw new ReferencedSiteException(String.format("Unable to get Content for Entity %s because No dereferencer configured for ReferencedSite %s",
+ if(siteConfiguration.getEntityDereferencerType() == null){
+ throw new ReferencedSiteException(
+ String.format("Unable to get Content for Entity %s because No dereferencer configured for ReferencedSite %s",
id,getId()));
}
if(dereferencer == null){
- throw new ReferencedSiteException(String.format("Dereferencer %s for remote site %s is not available",dereferencerComponentName,accessUri));
+ throw new ReferencedSiteException(
+ String.format("Dereferencer %s for remote site %s is not available",siteConfiguration.getEntityDereferencerType(),
+ siteConfiguration.getAccessUri()));
}
- ensureOnline(getAccessUri(), dereferencer.getClass());
+ ensureOnline(siteConfiguration.getAccessUri(), dereferencer.getClass());
try {
return dereferencer.dereference(id, contentType);
} catch (IOException e) {
- throw new ReferencedSiteException(String.format("Unable to load content for Entity %s and mediaType %s from remote site %s by using dereferencer %s",
- id,contentType,accessUri,entitySearcherComponentName),e);
+ throw new ReferencedSiteException(
+ String.format("Unable to load content for Entity %s and mediaType %s from remote site %s by using dereferencer %s",
+ id,contentType,siteConfiguration.getAccessUri(),siteConfiguration.getEntityDereferencerType()),e);
}
}
@Override
@@ -559,33 +472,35 @@ public class ReferencedSiteImpl implemen
try {
rep = cache.getRepresentation(id);
} catch (YardException e) {
- if (dereferencerComponentName == null || isOfflineMode()) {
- throw new ReferencedSiteException(String.format("Unable to get Represetnation %s form Cache %s", id, cacheId), e);
+ if (siteConfiguration.getEntityDereferencerType() == null || isOfflineMode()) {
+ throw new ReferencedSiteException(String.format("Unable to get Represetnation %s form Cache %s",
+ id, siteConfiguration.getCacheId()), e);
} else {
log.warn(String.format("Unable to get Represetnation %s form Cache %s. Will dereference from remote site %s",
- id, cacheId, getAccessUri()), e);
+ id, siteConfiguration.getCacheId(), siteConfiguration.getAccessUri()), e);
}
}
} else {
- if (dereferencerComponentName == null || isOfflineMode()) {
+ if (siteConfiguration.getEntityDereferencerType() == null || isOfflineMode()) {
throw new ReferencedSiteException(String.format("Unable to get Represetnation %s because configured Cache %s is currently not available",
- id, cacheId));
+ id, siteConfiguration.getCacheId()));
} else {
log.warn(String.format("Cache %s is currently not available. Will use remote site %s to load Representation %s",
- cacheId, dereferencerComponentName, id));
+ siteConfiguration.getCacheId(), siteConfiguration.getEntityDereferencerType(), id));
}
}
if (rep == null) { // no cache or not found in cache
if(dereferencer == null){
throw new ReferencedSiteException(String.format("Entity Dereferencer %s for accessing remote site %s is not available",
- dereferencerComponentName,accessUri));
+ siteConfiguration.getEntityDereferencerType(),siteConfiguration.getAccessUri()));
}
- ensureOnline(getAccessUri(), dereferencer.getClass());
+ ensureOnline(siteConfiguration.getAccessUri(), dereferencer.getClass());
try {
rep = dereferencer.dereference(id);
} catch (IOException e) {
- throw new ReferencedSiteException(String.format("Unable to load Representation for entity %s form remote site %s with dereferencer %s",
- id, accessUri, dereferencerComponentName), e);
+ throw new ReferencedSiteException(
+ String.format("Unable to load Representation for entity %s form remote site %s with dereferencer %s",
+ id, siteConfiguration.getAccessUri(), siteConfiguration.getEntityDereferencerType()), e);
}
//representation loaded from remote site and cache is available
if (rep != null && cache != null) {// -> cache the representation
@@ -597,7 +512,8 @@ public class ReferencedSiteImpl implemen
rep = cache.store(rep);
log.info(String.format(" - cached Representation %s in %d ms", id, (System.currentTimeMillis() - start)));
} catch (YardException e) {
- log.warn(String.format("Unable to cache Represetnation %s in Cache %s! Representation not cached!", id, cacheId), e);
+ log.warn(String.format("Unable to cache Represetnation %s in Cache %s! Representation not cached!",
+ id, siteConfiguration.getCacheId()), e);
}
}
} else {
@@ -606,27 +522,35 @@ public class ReferencedSiteImpl implemen
}
return rep != null ? ModelUtils.createSign(rep, getId()) : null;
}
+ @Override
+ public SiteConfiguration getConfiguration() {
+ return siteConfiguration;
+ }
@Override
public String toString() {
- return getName();
+ return siteConfiguration!= null?siteConfiguration.getName():null;
}
@Override
public int hashCode() {
- return getId().hashCode();
+ return siteConfiguration!=null?getId().hashCode():-1;
}
@Override
public boolean equals(Object obj) {
- return obj instanceof ReferencedSite && ((ReferencedSite)obj).getId().equals(getId());
+ if(obj instanceof ReferencedSite) {
+ SiteConfiguration osc = ((ReferencedSite)obj).getConfiguration();
+ //this will return false if one of the two sites is not activated
+ // -> this should be OK
+ return siteConfiguration != null && osc != null &&
+ getId().equals(osc.getId());
+ } else {
+ return false;
+ }
}
@Override
public FieldMapper getFieldMapper() {
return fieldMappings;
}
- @Override
- public String getCacheId() {
- return cacheId;
- }
/**
* In case {@link CacheStrategy#all} this Method returns the
@@ -636,7 +560,7 @@ public class ReferencedSiteImpl implemen
@Override
public FieldQueryFactory getQueryFactory() {
FieldQueryFactory factory = null;
- if(cacheStrategy == CacheStrategy.all){
+ if(siteConfiguration.getCacheStrategy() == CacheStrategy.all){
Cache cache = getCache();
if(cache != null){
factory = cache.getQueryFactory();
@@ -656,7 +580,7 @@ public class ReferencedSiteImpl implemen
* the configured cache instance is not available.
*/
protected Cache getCache(){
- return cacheStrategy == CacheStrategy.none?null:(Cache)cacheTracker.getService();
+ return siteConfiguration.getCacheStrategy() == CacheStrategy.none?null:(Cache)cacheTracker.getService();
}
/*--------------------------------------------------------------------------
@@ -667,89 +591,60 @@ public class ReferencedSiteImpl implemen
@SuppressWarnings("unchecked")
@Activate
protected void activate(final ComponentContext context) throws ConfigurationException, YardException, InvalidSyntaxException {
- log.info("in "+ReferencedSiteImpl.class+" activate with properties "+context.getProperties());
+ log.debug("in {} activate with properties {}",
+ ReferencedSiteImpl.class.getSimpleName(),context.getProperties());
if(context == null || context.getProperties() == null){
throw new IllegalStateException("No Component Context and/or Dictionary properties object parsed to the acticate methode");
}
this.context = context;
- this.properties = context.getProperties();
- //check and init all required properties!
- accessUri = OsgiUtils.checkProperty(properties,ConfiguredSite.ACCESS_URI).toString();
- //accessURI is the default for the Query URI
- queryUri = OsgiUtils.checkProperty(properties,ConfiguredSite.QUERY_URI,accessUri).toString();
- OsgiUtils.checkProperty(properties,ID);
- dereferencerComponentName = OsgiUtils.checkProperty(context.getProperties(), ConfiguredSite.DEREFERENCER_TYPE).toString();
- if(dereferencerComponentName.isEmpty() || dereferencerComponentName.equals("none")){
- dereferencerComponentName = null;
- }
- entitySearcherComponentName = OsgiUtils.checkProperty(this.properties, ConfiguredSite.SEARCHER_TYPE).toString();
- if(entitySearcherComponentName.isEmpty() || entitySearcherComponentName.equals("none")){
- entitySearcherComponentName = null;
- }
+ //create the SiteConfiguration based on the parsed properties
+ Map<String,Object> config = new HashMap<String,Object>();
+ Dictionary<String,Object> properties = (Dictionary<String,Object>)context.getProperties();
+ //copy the properties to a map
+ for(Enumeration<String> e = properties.keys();e.hasMoreElements();){
+ String key = e.nextElement();
+ config.put(key, properties.get(key));
+ }
+ //NOTE that the constructor also validation of the parsed configuration
+ siteConfiguration = new DefaultSiteConfiguration(config);
+ log.info(" > initialise Referenced Site {}",siteConfiguration.getName());
//if the accessUri is the same as the queryUri and both the dereferencer and
//the entitySearcher uses the same component, than we need only one component
//for both dependencies.
- this.dereferencerEqualsEntitySearcherComponent = accessUri.equals(queryUri)
- && dereferencerComponentName != null &&
- dereferencerComponentName.equals(entitySearcherComponentName);
-
- cacheStrategy = OsgiUtils.checkEnumProperty(CacheStrategy.class, properties, ConfiguredSite.CACHE_STRATEGY);
- //check if the congfig is valid
- if(this.cacheStrategy != CacheStrategy.none){
- //check if the cacheId is configured if cacheStrategy != none
- this.cacheId = OsgiUtils.checkProperty(this.properties, ConfiguredSite.CACHE_ID).toString();
- }
- //check that both dereferencer and searcher are configured if cacheStrategy != all
- if(cacheStrategy != CacheStrategy.all &&
- (dereferencerComponentName==null || entitySearcherComponentName == null)){
- throw new ConfigurationException(ConfiguredSite.CACHE_STRATEGY, String.format("If the EntitySearcher and/or the EntityDereferencer are set to \"none\", than the used CacheStragegy MUST BE \"all\"! (entitySearcher=%s | dereferencer=%s | cacheStrategy=%s",
- dereferencerComponentName==null?"none":dereferencerComponentName,
- entitySearcherComponentName==null?"none":entitySearcherComponentName,
- cacheStrategy));
- }
- //parse the field mappings
- initFieldmappings(context);
+ this.dereferencerEqualsEntitySearcherComponent =
+ //(1) accessURI == queryURI
+ siteConfiguration.getAccessUri() != null &&
+ siteConfiguration.getAccessUri().equals(siteConfiguration.getQueryUri()) &&
+ //(2) entity dereferencer == entity searcher
+ siteConfiguration.getEntityDereferencerType()!= null &&
+ siteConfiguration.getEntityDereferencerType().equals(siteConfiguration.getEntitySearcherType());
+ //init the fieldMapper based on the configuration
+ fieldMappings = new DefaultFieldMapperImpl(ValueConverterFactory.getDefaultInstance());
+ if(siteConfiguration.getFieldMappings() != null){
+ log.debug(" > Initialise configured FieldMappungs");
+ for(String configuredMapping : siteConfiguration.getFieldMappings()){
+ FieldMapping mapping = FieldMappingUtils.parseFieldMapping(configuredMapping);
+ if(mapping != null){
+ log.debug(" - add FieldMapping {}",mapping);
+ fieldMappings.addMapping(mapping);
+ }
+ }
+ }
//now init the referenced Services
initDereferencerAndEntitySearcher();
// If a cache is configured init the ServiceTracker used to manage the
// Reference to the cache!
- if(cacheId != null){
+ if(siteConfiguration.getCacheId() != null){
String cacheFilter = String.format("(&(%s=%s)(%s=%s))",
Constants.OBJECTCLASS,Cache.class.getName(),
- Cache.CACHE_YARD,cacheId);
+ Cache.CACHE_YARD,siteConfiguration.getCacheId());
cacheTracker = new ServiceTracker(context.getBundleContext(),
context.getBundleContext().createFilter(cacheFilter), null);
cacheTracker.open();
}
}
- /**
- * @param context
- * @throws ConfigurationException
- * @throws InvalidSyntaxException
- */
- private void initFieldmappings(final ComponentContext context) throws ConfigurationException, InvalidSyntaxException {
- //create the FieldMappings config
- fieldMappings = new DefaultFieldMapperImpl(ValueConverterFactory.getDefaultInstance());
- Object configuredMappingsObject = properties.get(ConfiguredSite.SITE_FIELD_MAPPINGS);
- log.info(" > Parse FieldMappungs");
- if(configuredMappingsObject != null){
- if(configuredMappingsObject instanceof String[]){
- for(String configuredMapping : (String[])configuredMappingsObject){
- FieldMapping mapping = FieldMappingUtils.parseFieldMapping(configuredMapping);
- if(mapping != null){
- log.info(" - add FieldMapping "+mapping);
- fieldMappings.addMapping(mapping);
- }
- }
- } else { //TODO maybe write an utility method that get values from arrays and collections
- log.warn("Configured Mappings are not parsed as String[] (type="+configuredMappingsObject.getClass()+" value="+configuredMappingsObject+")");
- }
- } else {
- log.info(" <- no FieldMappngs configured");
- }
- }
/**
* Initialise the dereferencer and searcher component as soon as the according
@@ -765,9 +660,9 @@ public class ReferencedSiteImpl implemen
* that can not be used to parse a {@link Filter}.
*/
private void initDereferencerAndEntitySearcher() throws InvalidSyntaxException {
- if(entitySearcherComponentName != null) {
+ if(siteConfiguration.getEntitySearcherType() != null) {
String componentNameFilterString = String.format("(%s=%s)",
- "component.name",entitySearcherComponentName);
+ "component.name",siteConfiguration.getEntitySearcherType());
String filterString = String.format("(&(%s=%s)%s)",
Constants.OBJECTCLASS,ComponentFactory.class.getName(),
componentNameFilterString);
@@ -781,9 +676,9 @@ public class ReferencedSiteImpl implemen
//context.getComponentInstance().dispose();
//throw an exception to avoid an successful activation
}
- if(dereferencerComponentName != null && !this.dereferencerEqualsEntitySearcherComponent){
+ if(siteConfiguration.getEntityDereferencerType() != null && !this.dereferencerEqualsEntitySearcherComponent){
String componentNameFilterString = String.format("(%s=%s)",
- "component.name",dereferencerComponentName);
+ "component.name",siteConfiguration.getEntityDereferencerType());
String filterString = String.format("(&(%s=%s)%s)",
Constants.OBJECTCLASS,ComponentFactory.class.getName(),
componentNameFilterString);
@@ -798,8 +693,8 @@ public class ReferencedSiteImpl implemen
}
/**
* Creates the entity searcher component used by this {@link ReferencedSite}
- * (and configured via the {@link ConfiguredSite#SEARCHER_TYPE} property).<p>
- * If the {@link ConfiguredSite#DEREFERENCER_TYPE} is set to the same vale
+ * (and configured via the {@link SiteConfiguration#ENTITY_SEARCHER_TYPE} property).<p>
+ * If the {@link SiteConfiguration#ENTITY_DEREFERENCER_TYPE} is set to the same vale
* and the {@link #accessUri} also equals the {@link #queryUri}, than the
* component created for the entity searcher is also used as dereferencer.
* @param factory The component factory used to create the
@@ -822,7 +717,7 @@ public class ReferencedSiteImpl implemen
/**
* Creates the entity dereferencer component used by this {@link ReferencedSite}.
* The implementation used as the dereferencer is configured by the
- * {@link ConfiguredSite#DEREFERENCER_TYPE} property.
+ * {@link SiteConfiguration#ENTITY_DEREFERENCER_TYPE} property.
* @param factory the component factory used to create the {@link #dereferencer}
*/
@SuppressWarnings("unchecked")
@@ -860,12 +755,12 @@ public class ReferencedSiteImpl implemen
log.info(String.format("Process ServceEvent for ComponentFactory %s and State REGISTERED",
eventComponentName));
ComponentFactory factory = (ComponentFactory)bundleContext.getService(event.getServiceReference());
- if(dereferencerComponentName != null &&
- dereferencerComponentName.equals(eventComponentName)){
+ if(siteConfiguration.getEntityDereferencerType() != null &&
+ siteConfiguration.getEntityDereferencerType().equals(eventComponentName)){
createDereferencerComponent(factory);
}
- if(entitySearcherComponentName!= null &&
- entitySearcherComponentName.equals(eventComponentName)){
+ if(siteConfiguration.getEntitySearcherType()!= null &&
+ siteConfiguration.getEntitySearcherType().equals(eventComponentName)){
createEntitySearcherComponent(factory);
}
} else {
@@ -879,7 +774,7 @@ public class ReferencedSiteImpl implemen
@Deactivate
protected void deactivate(ComponentContext context) {
- log.info("in "+AbstractEntityDereferencer.class.getSimpleName()+" deactivate with context "+context);
+ log.info("deactivate Referenced Site {}",siteConfiguration.getName());
this.dereferencer = null;
if(this.dereferencerComponentInstance != null){
this.dereferencerComponentInstance.dispose();
@@ -898,17 +793,13 @@ public class ReferencedSiteImpl implemen
context.getBundleContext().removeServiceListener(dereferencerComponentFactoryListener);
dereferencerComponentFactoryListener = null;
}
- this.cacheStrategy = null;
- this.cacheId = null;
if(cacheTracker != null){
cacheTracker.close();
cacheTracker = null;
}
this.fieldMappings = null;
- this.accessUri = null;
- this.queryUri = null;
this.context = null;
- this.properties = null;
+ this.siteConfiguration = null;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/site/AbstractEntityDereferencer.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/site/AbstractEntityDereferencer.java?rev=1091500&r1=1091499&r2=1091500&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/site/AbstractEntityDereferencer.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/site/AbstractEntityDereferencer.java Tue Apr 12 17:09:31 2011
@@ -27,7 +27,7 @@ import java.util.RandomAccess;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Property;
-import org.apache.stanbol.entityhub.servicesapi.site.ConfiguredSite;
+import org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration;
import org.apache.stanbol.entityhub.servicesapi.site.EntityDereferencer;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
@@ -71,7 +71,7 @@ public abstract class AbstractEntityDere
}
//TODO: I am sure, there is some Utility, that supports getting multiple
// values from a OSGI Dictionary
- Object prefixObject = properties.get(ConfiguredSite.ENTITY_PREFIX);
+ Object prefixObject = properties.get(SiteConfiguration.ENTITY_PREFIX);
ArrayList<String> prefixList = new ArrayList<String>();
if (prefixObject == null) {
prefixList = null;