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