001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.rice.kew.api.document;
017
018import org.kuali.rice.core.api.CoreConstants;
019import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
020import org.w3c.dom.Element;
021
022import javax.xml.bind.annotation.XmlAccessType;
023import javax.xml.bind.annotation.XmlAccessorType;
024import javax.xml.bind.annotation.XmlAnyElement;
025import javax.xml.bind.annotation.XmlElement;
026import javax.xml.bind.annotation.XmlRootElement;
027import javax.xml.bind.annotation.XmlType;
028import java.util.Collection;
029
030/**
031 * Immutable implementation of the {@code DocumentWithContentContract}.  This class does not have a builder since it is
032 * intended to simply be a wrapper a document and it's content.
033 *
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 */
036@XmlRootElement(name = DocumentWithContent.Constants.ROOT_ELEMENT_NAME)
037@XmlAccessorType(XmlAccessType.NONE)
038@XmlType(name = DocumentWithContent.Constants.TYPE_NAME, propOrder = {
039    DocumentWithContent.Elements.DOCUMENT,
040    DocumentWithContent.Elements.DOCUMENT_CONTENT,
041    CoreConstants.CommonElements.FUTURE_ELEMENTS
042})
043public final class DocumentWithContent extends AbstractDataTransferObject implements DocumentWithContentContract {
044
045    @XmlElement(name = Elements.DOCUMENT, required = true)
046    private final Document document;
047
048    @XmlElement(name = Elements.DOCUMENT_CONTENT, required = true)
049    private final DocumentContent documentContent;
050
051    @SuppressWarnings("unused")
052    @XmlAnyElement
053    private final Collection<Element> _futureElements = null;
054
055    /**
056     * Private constructor used only by JAXB.
057     */
058    private DocumentWithContent() {
059        this.document = null;
060        this.documentContent = null;
061    }
062
063    private DocumentWithContent(Document document, DocumentContent documentContent) {
064        if (document == null) {
065            throw new IllegalArgumentException("document was null");
066        }
067        if (documentContent == null) {
068            throw new IllegalArgumentException("documentContent was null");
069        }
070        this.document = document;
071        this.documentContent = documentContent;
072    }
073
074    public static DocumentWithContent create(Document document, DocumentContent documentContent) {
075        return new DocumentWithContent(document, documentContent);
076    }
077
078    @Override
079    public Document getDocument() {
080        return this.document;
081    }
082
083    @Override
084    public DocumentContent getDocumentContent() {
085        return this.documentContent;
086    }
087
088    /**
089     * Defines some internal constants used on this class.
090     */
091    static class Constants {
092        final static String ROOT_ELEMENT_NAME = "documentWithContent";
093        final static String TYPE_NAME = "DocumentWithContentType";
094    }
095
096    /**
097     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
098     */
099    static class Elements {
100        final static String DOCUMENT = "document";
101        final static String DOCUMENT_CONTENT = "documentContent";
102    }
103
104}