001/*
002 * (C) Copyright 2006-2011 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 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.runtime.model;
023
024/**
025 * Empty implementation for a component.
026 *
027 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
028 */
029public class DefaultComponent implements Component, Adaptable {
030
031    /**
032     * @since 5.6
033     */
034    protected Long lastModified;
035
036    @Override
037    public void activate(ComponentContext context) {
038        setModifiedNow();
039    }
040
041    @Override
042    public void deactivate(ComponentContext context) {
043        setModifiedNow();
044    }
045
046    @Override
047    public void registerExtension(Extension extension) {
048        Object[] contribs = extension.getContributions();
049        if (contribs == null) {
050            return;
051        }
052        for (Object contrib : contribs) {
053            registerContribution(contrib, extension.getExtensionPoint(), extension.getComponent());
054        }
055        setModifiedNow();
056    }
057
058    @Override
059    public void unregisterExtension(Extension extension) {
060        Object[] contribs = extension.getContributions();
061        if (contribs == null) {
062            return;
063        }
064        for (Object contrib : contribs) {
065            unregisterContribution(contrib, extension.getExtensionPoint(), extension.getComponent());
066        }
067        setModifiedNow();
068    }
069
070    public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
071    }
072
073    public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
074    }
075
076    @Override
077    public <T> T getAdapter(Class<T> adapter) {
078        return adapter.cast(this);
079    }
080
081    @Override
082    public int getApplicationStartedOrder() {
083        return 1000;
084    }
085
086    @Override
087    public void applicationStarted(ComponentContext context) {
088        // do nothing by default
089    }
090
091    /**
092     * Sets the last modified date to current date timestamp
093     *
094     * @since 5.6
095     */
096    protected void setModifiedNow() {
097        setLastModified(Long.valueOf(System.currentTimeMillis()));
098    }
099
100    @Override
101    public Long getLastModified() {
102        return lastModified;
103    }
104
105    @Override
106    public void setLastModified(Long lastModified) {
107        this.lastModified = lastModified;
108    }
109}