Coverage Report - org.kuali.rice.kew.api.document.DocumentLink
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentLink
0%
0/15
N/A
1.533
DocumentLink$1
N/A
N/A
1.533
DocumentLink$Builder
0%
0/27
0%
0/8
1.533
DocumentLink$Constants
0%
0/1
N/A
1.533
DocumentLink$Elements
0%
0/1
N/A
1.533
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.api.document;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Collection;
 20  
 
 21  
 import javax.xml.bind.annotation.XmlAccessType;
 22  
 import javax.xml.bind.annotation.XmlAccessorType;
 23  
 import javax.xml.bind.annotation.XmlAnyElement;
 24  
 import javax.xml.bind.annotation.XmlElement;
 25  
 import javax.xml.bind.annotation.XmlRootElement;
 26  
 import javax.xml.bind.annotation.XmlType;
 27  
 
 28  
 import org.apache.commons.lang.StringUtils;
 29  
 import org.kuali.rice.core.api.CoreConstants;
 30  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 31  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 32  
 import org.w3c.dom.Element;
 33  
 
 34  
 @XmlRootElement(name = DocumentLink.Constants.ROOT_ELEMENT_NAME)
 35  
 @XmlAccessorType(XmlAccessType.NONE)
 36  
 @XmlType(name = DocumentLink.Constants.TYPE_NAME, propOrder = {
 37  
             DocumentLink.Elements.ID,
 38  
                 DocumentLink.Elements.ORIGINATING_DOCUMENT_ID,
 39  
                 DocumentLink.Elements.DESTINATION_DOCUMENT_ID,
 40  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 41  
 })
 42  0
 public final class DocumentLink extends AbstractDataTransferObject implements DocumentLinkContract {
 43  
 
 44  
         private static final long serialVersionUID = -1193048221115914280L;
 45  
 
 46  
         @XmlElement(name = Elements.ID, required = false)
 47  
     private final String id;
 48  
 
 49  
     @XmlElement(name = Elements.ORIGINATING_DOCUMENT_ID, required = true)
 50  
     private final String originatingDocumentId;
 51  
     
 52  
     @XmlElement(name = Elements.DESTINATION_DOCUMENT_ID, required = true)
 53  
     private final String destinationDocumentId;
 54  
         
 55  0
     @SuppressWarnings("unused")
 56  
     @XmlAnyElement
 57  
     private final Collection<Element> _futureElements = null;
 58  
 
 59  
     /**
 60  
      * Private constructor used only by JAXB.
 61  
      */
 62  0
     private DocumentLink() {
 63  0
         this.id = null;
 64  0
             this.originatingDocumentId = null;
 65  0
         this.destinationDocumentId = null;
 66  0
     }
 67  
 
 68  0
     private DocumentLink(Builder builder) {
 69  0
         this.id = builder.getId();
 70  0
             this.originatingDocumentId = builder.getOriginatingDocumentId();
 71  0
         this.destinationDocumentId = builder.getDestinationDocumentId();
 72  0
     }
 73  
 
 74  
     @Override
 75  
     public String getId() {
 76  0
         return this.id;
 77  
     }
 78  
     
 79  
     @Override
 80  
     public String getOriginatingDocumentId() {
 81  0
         return this.originatingDocumentId;
 82  
     }
 83  
 
 84  
     @Override
 85  
     public String getDestinationDocumentId() {
 86  0
         return this.destinationDocumentId;
 87  
     }
 88  
 
 89  
     /**
 90  
      * A builder which can be used to construct {@link DocumentLink} instances.  Enforces the constraints of the {@link DocumentLinkContract}.
 91  
      */
 92  0
     public final static class Builder implements Serializable, ModelBuilder, DocumentLinkContract {
 93  
 
 94  
                 private static final long serialVersionUID = -6713990840543140054L;
 95  
 
 96  
                 private String id;
 97  
         private String originatingDocumentId;
 98  
         private String destinationDocumentId;
 99  
 
 100  0
         private Builder(String originatingDocumentId, String destinationDocumentId) {
 101  0
             setOriginatingDocumentId(originatingDocumentId);
 102  0
             setDestinationDocumentId(destinationDocumentId);
 103  0
             if (getOriginatingDocumentId().equals(getDestinationDocumentId())) {
 104  0
                     throw new IllegalArgumentException("originating and destination document ids were the same, cannot link a document with itself");
 105  
             }
 106  0
         }
 107  
 
 108  
         public static Builder create(String originatingDocumentId, String destinationDocumentId) {
 109  0
             return new Builder(originatingDocumentId, destinationDocumentId);
 110  
         }
 111  
 
 112  
         public static Builder create(DocumentLinkContract contract) {
 113  0
             if (contract == null) {
 114  0
                 throw new IllegalArgumentException("contract was null");
 115  
             }
 116  0
             Builder builder = create(contract.getOriginatingDocumentId(), contract.getDestinationDocumentId());
 117  0
             builder.setId(contract.getId());
 118  0
             return builder;
 119  
         }
 120  
 
 121  
         public DocumentLink build() {
 122  0
             return new DocumentLink(this);
 123  
         }
 124  
 
 125  
         @Override
 126  
         public String getId() {
 127  0
             return this.id;
 128  
         }
 129  
         
 130  
         @Override
 131  
         public String getOriginatingDocumentId() {
 132  0
             return this.originatingDocumentId;
 133  
         }
 134  
 
 135  
         @Override
 136  
         public String getDestinationDocumentId() {
 137  0
             return this.destinationDocumentId;
 138  
         }
 139  
 
 140  
         public void setId(String id) {
 141  0
             this.id = id;
 142  0
         }
 143  
 
 144  
         public void setOriginatingDocumentId(String originatingDocumentId) {
 145  0
             if (StringUtils.isBlank(originatingDocumentId)) {
 146  0
                     throw new IllegalArgumentException("originatingDocumentId was null or blank");
 147  
             }
 148  0
             this.originatingDocumentId = originatingDocumentId;
 149  0
         }
 150  
 
 151  
         public void setDestinationDocumentId(String destinationDocumentId) {
 152  0
                 if (StringUtils.isBlank(destinationDocumentId)) {
 153  0
                     throw new IllegalArgumentException("destinationDocumentId was null or blank");
 154  
             }
 155  0
             this.destinationDocumentId = destinationDocumentId;
 156  0
         }
 157  
 
 158  
     }
 159  
 
 160  
     /**
 161  
      * Defines some internal constants used on this class.
 162  
      */
 163  0
     static class Constants {
 164  
         final static String ROOT_ELEMENT_NAME = "documentLink";
 165  
         final static String TYPE_NAME = "DocumentLinkType";
 166  
     }
 167  
 
 168  
     /**
 169  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 170  
      */
 171  0
     static class Elements {
 172  
         final static String ID = "id";
 173  
         final static String ORIGINATING_DOCUMENT_ID = "originatingDocumentId";
 174  
         final static String DESTINATION_DOCUMENT_ID = "destinationDocumentId";
 175  
     }
 176  
 
 177  
 }