001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
018 *
019 * $Id: URLServiceComponent.java 28924 2008-01-10 14:04:05Z sfermigier $
020 */
021
022package org.nuxeo.ecm.platform.ui.web.rest.services;
023
024import org.nuxeo.ecm.platform.ui.web.rest.api.URLPolicyService;
025import org.nuxeo.ecm.platform.ui.web.rest.descriptors.URLPatternDescriptor;
026import org.nuxeo.runtime.model.ComponentContext;
027import org.nuxeo.runtime.model.ComponentInstance;
028import org.nuxeo.runtime.model.DefaultComponent;
029
030/**
031 * Component registering url policies and document view codecs.
032 *
033 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
034 */
035public class URLServiceComponent extends DefaultComponent {
036
037    public static final String NAME = URLServiceComponent.class.getName();
038
039    public static final String URL_PATTERNS_EXTENSION_POINT = "urlpatterns";
040
041    protected URLPolicyService urlPolicyService;
042
043    @Override
044    public void activate(ComponentContext context) {
045        urlPolicyService = new URLPolicyServiceImpl();
046    }
047
048    @Override
049    public void deactivate(ComponentContext context) {
050        urlPolicyService.clear();
051        urlPolicyService = null;
052    }
053
054    @Override
055    @SuppressWarnings("unchecked")
056    public <T> T getAdapter(Class<T> adapter) {
057        if (adapter.isAssignableFrom(URLPolicyService.class)) {
058            return (T) urlPolicyService;
059        }
060        return null;
061    }
062
063    @Override
064    public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
065        if (URL_PATTERNS_EXTENSION_POINT.equals(extensionPoint)) {
066            urlPolicyService.addPatternDescriptor((URLPatternDescriptor) contribution);
067        }
068    }
069
070    @Override
071    public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
072        if (URL_PATTERNS_EXTENSION_POINT.equals(extensionPoint)) {
073            urlPolicyService.removePatternDescriptor((URLPatternDescriptor) contribution);
074        }
075    }
076
077}