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 *     bstefanescu
018 */
019package org.nuxeo.runtime.model.persistence;
020
021import org.nuxeo.runtime.model.persistence.fs.FileSystemStorage;
022
023/**
024 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
025 */
026public abstract class AbstractContribution implements Contribution {
027
028    protected String id;
029
030    protected boolean loaded;
031
032    protected final String name;
033
034    protected String description;
035
036    protected boolean disabled;
037
038    protected AbstractContribution(String name) {
039        this.name = name;
040    }
041
042    @Override
043    public String getId() {
044        if (id == null) {
045            id = ContributionPersistenceComponent.getComponentName(getName());
046        }
047        return id;
048    }
049
050    protected void load() {
051        if (!loaded) {
052            FileSystemStorage.loadMetadata(this);
053            loaded = true;
054        }
055    }
056
057    @Override
058    public String getName() {
059        return name;
060    }
061
062    @Override
063    public String getDescription() {
064        load();
065        return description;
066    }
067
068    @Override
069    public void setDescription(String description) {
070        this.description = description;
071    }
072
073    @Override
074    public boolean isDisabled() {
075        load();
076        return disabled;
077    }
078
079    @Override
080    public void setDisabled(boolean isDisabled) {
081        this.disabled = isDisabled;
082    }
083
084}