blob: 84ffbf31e77b8d3efb3dedae6669da843693da8a [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.sling.nosql.couchbase.resourceprovider.impl;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceProvider;
import org.apache.sling.api.resource.ResourceProviderFactory;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.nosql.couchbase.client.CouchbaseClient;
import org.apache.sling.nosql.generic.adapter.NoSqlAdapter;
import org.apache.sling.nosql.generic.resource.AbstractNoSqlResourceProviderFactory;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.event.EventAdmin;
/**
* {@link ResourceProviderFactory} implementation that uses couchbase as
* persistence.
*/
@Component(immediate = true)
@Service(value = ResourceProviderFactory.class)
public class CouchbaseNoSqlResourceProviderFactory extends AbstractNoSqlResourceProviderFactory {
/**
* Couchbase Client ID for Couchbase Resource Provier
*/
public static final String COUCHBASE_CLIENT_ID = "sling-resourceprovider-couchbase";
@Property(label = "Cache Key Prefix", description = "Prefix for caching keys.", value = CouchbaseNoSqlResourceProviderFactory.CACHE_KEY_PREFIX_DEFAULT)
static final String CACHE_KEY_PREFIX_PROPERTY = "cacheKeyPrefix";
private static final String CACHE_KEY_PREFIX_DEFAULT = "sling-resource:";
@Property(label = "Root paths", description = "Root paths for resource provider.", cardinality = Integer.MAX_VALUE)
static final String PROVIDER_ROOTS_PROPERTY = ResourceProvider.ROOTS;
@Reference(target = "(" + CouchbaseClient.CLIENT_ID_PROPERTY + "=" + COUCHBASE_CLIENT_ID + ")")
private CouchbaseClient couchbaseClient;
@Reference
private EventAdmin eventAdmin;
private NoSqlAdapter noSqlAdapter;
@Activate
private void activate(ComponentContext componentContext, Map<String, Object> config) {
String cacheKeyPrefix = PropertiesUtil
.toString(config.get(CACHE_KEY_PREFIX_PROPERTY), CACHE_KEY_PREFIX_DEFAULT);
noSqlAdapter = new CouchbaseNoSqlAdapter(couchbaseClient, cacheKeyPrefix);
}
@Override
protected NoSqlAdapter getNoSqlAdapter() {
return noSqlAdapter;
}
@Override
protected EventAdmin getEventAdmin() {
return eventAdmin;
}
}