Coverage Report - org.kuali.rice.core.api.style.Style
 
Classes in this File Line Coverage Branch Coverage Complexity
Style
100%
24/24
N/A
1.167
Style$1
N/A
N/A
1.167
Style$Builder
100%
36/36
100%
4/4
1.167
Style$Constants
0%
0/1
N/A
1.167
Style$Elements
0%
0/1
N/A
1.167
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.core.api.style;
 18  
 
 19  
 import java.io.Serializable;
 20  
 import java.util.Collection;
 21  
 
 22  
 import javax.xml.bind.annotation.XmlAccessType;
 23  
 import javax.xml.bind.annotation.XmlAccessorType;
 24  
 import javax.xml.bind.annotation.XmlAnyElement;
 25  
 import javax.xml.bind.annotation.XmlElement;
 26  
 import javax.xml.bind.annotation.XmlRootElement;
 27  
 import javax.xml.bind.annotation.XmlType;
 28  
 
 29  
 import org.apache.commons.lang.StringUtils;
 30  
 import org.kuali.rice.core.api.CoreConstants;
 31  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 32  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 33  
 import org.w3c.dom.Element;
 34  
 
 35  
 /**
 36  
  * An immutable representation of a Style.  A style is essentially a block of
 37  
  * XML containing and XSL stylesheet. These can be used in various places for
 38  
  * the transformation of XML data from one form to another.
 39  
  * 
 40  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 41  
  *
 42  
  */
 43  
 @XmlRootElement(name = Style.Constants.ROOT_ELEMENT_NAME)
 44  
 @XmlAccessorType(XmlAccessType.NONE)
 45  
 @XmlType(name = Style.Constants.TYPE_NAME, propOrder = {
 46  
                 Style.Elements.STYLE_ID,
 47  
                 Style.Elements.NAME,
 48  
                 Style.Elements.XML_CONTENT,
 49  
                 Style.Elements.ACTIVE,
 50  
         CoreConstants.CommonElements.VERSION_NUMBER,
 51  
         CoreConstants.CommonElements.OBJECT_ID,
 52  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 53  
 })
 54  4
 public final class Style extends AbstractDataTransferObject implements StyleContract {
 55  
 
 56  
         private static final long serialVersionUID = -26426318682076660L;
 57  
         
 58  
         @XmlElement(name = Elements.STYLE_ID, required = false)
 59  
         private final Long styleId;
 60  
         
 61  
         @XmlElement(name = Elements.NAME, required = true)
 62  
     private final String name;
 63  
         
 64  
         @XmlElement(name = Elements.XML_CONTENT, required = false)
 65  
     private final String xmlContent;
 66  
         
 67  
         @XmlElement(name = Elements.ACTIVE, required = true)
 68  
     private final boolean active;
 69  
     
 70  
         @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 71  
     private final Long versionNumber;
 72  
         
 73  
         @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 74  
         private final String objectId;
 75  
 
 76  6
     @SuppressWarnings("unused")
 77  
     @XmlAnyElement
 78  
     private final Collection<Element> _futureElements = null;
 79  
         
 80  
     /**
 81  
      * Private constructor used only by JAXB.
 82  
      */
 83  2
     private Style() {
 84  2
             this.styleId = null;
 85  2
             this.name = null;
 86  2
             this.xmlContent = null;
 87  2
             this.active = false;
 88  2
             this.versionNumber = null;
 89  2
             this.objectId = null;
 90  2
     }
 91  
     
 92  4
     private Style(Builder builder) {
 93  4
             this.styleId = builder.getStyleId();
 94  4
             this.name = builder.getName();
 95  4
             this.xmlContent = builder.getXmlContent();
 96  4
             this.active = builder.isActive();
 97  4
             this.versionNumber = builder.getVersionNumber();
 98  4
             this.objectId = builder.getObjectId();
 99  4
     }
 100  
 
 101  
     @Override
 102  
     public Long getStyleId() {
 103  2
                 return this.styleId;
 104  
         }
 105  
 
 106  
     @Override
 107  
     public String getName() {
 108  2
                 return this.name;
 109  
         }
 110  
 
 111  
     @Override
 112  
     public String getXmlContent() {
 113  2
                 return this.xmlContent;
 114  
         }
 115  
         
 116  
     @Override
 117  
     public boolean isActive() {
 118  2
                 return this.active;
 119  
         }
 120  
         
 121  
         @Override
 122  
         public Long getVersionNumber() {
 123  2
                 return this.versionNumber;
 124  
         }
 125  
         
 126  
         @Override
 127  
         public String getObjectId() {
 128  2
                 return this.objectId;
 129  
         }
 130  
 
 131  
         /**
 132  
          * A builder which can be used to construct {@link Style} instances.
 133  
          * Enforces the constraints of the {@link StyleContract}.
 134  
          * 
 135  
          * @author Kuali Rice Team (rice.collab@kuali.org)
 136  
          *
 137  
          */
 138  4
         public static final class Builder implements StyleContract, ModelBuilder, Serializable  {
 139  
             
 140  
             private static final long serialVersionUID = -219369603932108436L;
 141  
             
 142  
                 private Long styleId;
 143  
         private String name;
 144  
         private String xmlContent;
 145  
         private boolean active;
 146  
         private Long versionNumber;
 147  
         private String objectId;
 148  
         
 149  8
         private Builder(String name) {
 150  8
                 setName(name);
 151  5
                 setActive(true);
 152  5
         }
 153  
         
 154  
         /**
 155  
          * Creates a style builder with the given required values.  The builder
 156  
          * is the only means by which a {@link Style} object should be created.
 157  
          * 
 158  
          * <p>Will default the active flag to true.
 159  
          * 
 160  
          * @param name the name of the style to create, must not be null or blank
 161  
          * 
 162  
          * @return a builder with the required values already initialized
 163  
          * 
 164  
          * @throws IllegalArgumentException if the given name is null or blank
 165  
          */
 166  
         public static Builder create(String name) {
 167  8
                 return new Builder(name);
 168  
         }
 169  
         
 170  
         /**
 171  
          * Creates a populates a builder with the data on the given StyleContract.
 172  
          * This is similar in nature to a "copy constructor" for Style.
 173  
          * 
 174  
          * @param contract an object implementing the StyleContract from which
 175  
          * to copy property values
 176  
          *  
 177  
          * @return a builder with the values from the contract already initialized
 178  
          * 
 179  
          * @throws IllegalArgumentException if the given contract is null
 180  
          */
 181  
         public static Builder create(StyleContract contract) {
 182  4
                 if (contract == null) {
 183  1
                         throw new IllegalArgumentException("contract was null");
 184  
                 }
 185  3
                 Builder builder = create(contract.getName());
 186  3
                 builder.setStyleId(contract.getStyleId());
 187  3
                 builder.setXmlContent(contract.getXmlContent());
 188  3
                 builder.setActive(contract.isActive());
 189  3
                 builder.setVersionNumber(contract.getVersionNumber());
 190  3
                 builder.setObjectId(contract.getObjectId());
 191  3
                 return builder;
 192  
         }
 193  
         
 194  
         @Override
 195  
         public Style build() {
 196  4
                 return new Style(this);
 197  
         }
 198  
 
 199  
         @Override
 200  
                 public Long getStyleId() {
 201  4
                         return this.styleId;
 202  
                 }
 203  
 
 204  
         /**
 205  
          * Sets the styleId for the style that will be returned by this builder.
 206  
          * 
 207  
          * @param styleId the styleId to set
 208  
          */
 209  
                 public void setStyleId(Long styleId) {
 210  3
                         this.styleId = styleId;
 211  3
                 }
 212  
 
 213  
                 @Override
 214  
                 public String getName() {
 215  4
                         return this.name;
 216  
                 }
 217  
 
 218  
                 /**
 219  
          * Sets the name for the style that will be returned by this builder.
 220  
          * The name must not be blank or null.
 221  
          * 
 222  
          * @param name the name to set on this builder, must not be null or
 223  
          * blank
 224  
          * 
 225  
          * @throws IllegalArgumentException if the given name is null or blank
 226  
          */
 227  
                 public void setName(String name) {
 228  11
                         if (StringUtils.isBlank(name)) {
 229  6
                                 throw new IllegalArgumentException("name is blank");
 230  
                         }
 231  5
                         this.name = name;
 232  5
                 }
 233  
 
 234  
                 @Override
 235  
                 public String getXmlContent() {
 236  4
                         return this.xmlContent;
 237  
                 }
 238  
 
 239  
                 /**
 240  
                  * Sets the XML content for the style that will be returned by this
 241  
                  * builder.
 242  
                  * 
 243  
                  * @param xmlContent the xmlContent to set on this builder
 244  
                  */
 245  
                 public void setXmlContent(String xmlContent) {
 246  3
                         this.xmlContent = xmlContent;
 247  3
                 }
 248  
 
 249  
                 @Override
 250  
                 public boolean isActive() {
 251  4
                         return this.active;
 252  
                 }
 253  
 
 254  
                 /**
 255  
          * Sets the active flag for the style that will be returned by this
 256  
          * builder.
 257  
          * 
 258  
          * @param active the active flag to set
 259  
          */
 260  
                 public void setActive(boolean active) {
 261  8
                         this.active = active;
 262  8
                 }
 263  
 
 264  
                 @Override
 265  
                 public Long getVersionNumber() {
 266  4
                         return this.versionNumber;
 267  
                 }
 268  
 
 269  
                 /**
 270  
          * Sets the version number for the style that will be returned by this
 271  
          * builder.
 272  
          * 
 273  
          * <p>In general, this value should not be manually set on the builder,
 274  
          * but rather copied from an existing {@link StyleContract} when
 275  
          * invoking {@link Builder#create(StyleContract)}.
 276  
          * 
 277  
          * @param versionNumber the version number to set
 278  
          */
 279  
                 public void setVersionNumber(Long versionNumber) {
 280  3
                         this.versionNumber = versionNumber;
 281  3
                 }
 282  
 
 283  
                 @Override
 284  
                 public String getObjectId() {
 285  4
                         return objectId;
 286  
                 }
 287  
                 
 288  
                 /**
 289  
          * Sets the globally unique object ID for the style that will be
 290  
          * returned by this builder.
 291  
          * 
 292  
          * <p>In general, this value should not be manually set on the builder,
 293  
          * but rather copied from an existing {@link StyleContract} when
 294  
          * invoking {@link Builder#create(StyleContract)}.
 295  
          * 
 296  
          * @param objectId the object ID to set
 297  
          */
 298  
                 public void setObjectId(String objectId) {
 299  3
                         this.objectId = objectId;
 300  3
                 }
 301  
             
 302  
     }
 303  
 
 304  
     /**
 305  
      * Defines some internal constants used on this class.
 306  
      */
 307  0
     static class Constants {
 308  
         final static String ROOT_ELEMENT_NAME = "style";
 309  
         final static String TYPE_NAME = "StyleType";
 310  
     }
 311  
 
 312  
     /**
 313  
      * A private class which exposes constants which define the XML element names to use
 314  
      * when this object is marshalled to XML.
 315  
      */
 316  0
     static class Elements {
 317  
         final static String STYLE_ID = "styleId";
 318  
         final static String NAME = "name";
 319  
         final static String XML_CONTENT = "xmlContent";
 320  
         final static String ACTIVE = "active";
 321  
     }
 322  
 
 323  
 }