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 */
020
021package org.nuxeo.ecm.core.api.blobholder;
022
023import java.io.Serializable;
024import java.util.ArrayList;
025import java.util.Calendar;
026import java.util.List;
027import java.util.Map;
028
029import org.nuxeo.ecm.core.api.Blob;
030
031/**
032 * {@link BlobHolder} implementation that simply wraps a detached {@link Blob}.
033 *
034 * @author tiry
035 */
036public class SimpleBlobHolder extends AbstractBlobHolder {
037
038    protected List<Blob> blobs;
039
040    protected Calendar creationDate;
041
042    public SimpleBlobHolder() {
043        // Empty constructor
044    }
045
046    public SimpleBlobHolder(List<Blob> blobs) {
047        init(blobs);
048    }
049
050    public SimpleBlobHolder(Blob blob) {
051        blobs = new ArrayList<Blob>();
052        blobs.add(blob);
053        init(blobs);
054    }
055
056    protected void init(List<Blob> blobs) {
057        this.blobs = blobs;
058        creationDate = Calendar.getInstance();
059    }
060
061    @Override
062    public Blob getBlob() {
063        if (blobs == null || blobs.size() == 0) {
064            return null;
065        } else {
066            return blobs.get(0);
067        }
068    }
069
070    @Override
071    public List<Blob> getBlobs() {
072        return blobs;
073    }
074
075    @Override
076    protected String getBasePath() {
077        return "";
078    }
079
080    @Override
081    public Calendar getModificationDate() {
082        return creationDate;
083    }
084
085    @Override
086    public Serializable getProperty(String name) {
087        return null;
088    }
089
090    @Override
091    public Map<String, Serializable> getProperties() {
092        return null;
093    }
094
095}