Package org.restlet.ext.osgi

Source Code of org.restlet.ext.osgi.ResourceProvider

/*******************************************************************************
* Copyright (c) 2011.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     - initial API and implementation
*******************************************************************************/

package org.restlet.ext.osgi;

import java.util.Dictionary;

import org.osgi.service.component.ComponentContext;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.resource.Finder;
import org.restlet.routing.Template;

/**
* @author bhunt
*
*/
public abstract class ResourceProvider extends RestletProvider implements IResourceProvider
{
  @Override
  public Restlet getInboundRoot(Context context)
  {
    if (finder == null)
      finder = createFinder(context);

    Restlet inboundRoot = super.getInboundRoot(context);
    return inboundRoot != null ? inboundRoot : finder;
  }

  @Override
  public String[] getPaths()
  {
    return paths.clone();
  }

  @Override
  public int getMatchingMode()
  {
    return matchingMode;
  }

  protected void activate(ComponentContext context)
  {
    @SuppressWarnings("unchecked")
    Dictionary<String, Object> properties = context.getProperties();
    paths = (String[]) properties.get("paths");
    matchingMode = (Integer) properties.get("matchingMode");

    if (matchingMode == null)
      matchingMode = Template.MODE_EQUALS;
  }

  protected abstract Finder createFinder(Context context);

  @Override
  protected Restlet getFilteredRestlet()
  {
    return finder;
  }

  private Finder finder;
  private String[] paths;
  private Integer matchingMode;
}
TOP

Related Classes of org.restlet.ext.osgi.ResourceProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.