Clover icon

Magnolia REST Content Delivery 2.1

  1. Project Clover database Fri Mar 16 2018 18:21:08 CET
  2. Package info.magnolia.rest.delivery.jcr.decorator

File ReadOnlyProperty.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
47% of files have more coverage

Code metrics

20
34
11
1
210
139
22
0.65
3.09
11
2
30.1% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
ReadOnlyProperty 54 34 30.1% 22 65
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /**
2    * This file Copyright (c) 2018 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.rest.delivery.jcr.decorator;
35   
36    import java.math.BigDecimal;
37    import java.util.Arrays;
38   
39    import javax.jcr.Binary;
40    import javax.jcr.Item;
41    import javax.jcr.Node;
42    import javax.jcr.RepositoryException;
43    import javax.jcr.Session;
44    import javax.jcr.Value;
45    import javax.jcr.ValueFormatException;
46    import javax.jcr.nodetype.PropertyDefinition;
47   
48    import org.apache.commons.lang3.StringUtils;
49    import org.apache.jackrabbit.commons.AbstractProperty;
50   
51    /**
52    * Read only {@link javax.jcr.Property} implementation.
53    */
 
54    public class ReadOnlyProperty extends AbstractProperty {
55   
56    private final String name;
57    private boolean multiple;
58    private Value[] values = new Value[0];
59    private Node parent;
60   
 
61  0 toggle public ReadOnlyProperty(String name, Value[] values, Node parent) {
62  0 this.name = name;
63  0 this.values = values;
64  0 this.parent = parent;
65  0 this.multiple = true;
66    }
67   
 
68  0 toggle public ReadOnlyProperty(String name, Value value, Node parent) {
69  0 this(name, new Value[] { value }, parent);
70  0 this.multiple = false;
71    }
72   
 
73    toggle @Override
74    public String getName() {
75    return name;
76    }
77   
 
78    toggle @Override
79    public Node getParent() throws RepositoryException {
80    return parent;
81    }
82   
 
83    toggle @Override
84    public Session getSession() throws RepositoryException {
85    return parent.getSession();
86    }
87   
 
88    toggle @Override
89    public Binary getBinary() throws RepositoryException {
90    return getValue().getBinary();
91    }
92   
 
93    toggle @Override
94    public BigDecimal getDecimal() throws RepositoryException {
95    return getValue().getDecimal();
96    }
97   
 
98  0 toggle @Override
99    public String getString() throws RepositoryException {
100  0 return getValue() != null ? getValue().getString() : null;
101    }
102   
 
103    toggle @Override
104    public int getType() throws RepositoryException {
105    return values[0].getType();
106    }
107   
 
108  0 toggle @Override
109    public Value getValue() throws ValueFormatException {
110  0 if (isMultiple()) {
111  0 throw new ValueFormatException("Cannot call getValue() on a multi-value property.");
112    }
113  0 return values[0];
114    }
115   
 
116  0 toggle @Override
117    public Value[] getValues() throws ValueFormatException {
118  0 if (isMultiple()) {
119  0 return values;
120    }
121  0 throw new ValueFormatException("Cannot call getValues() on a single-value property.");
122    }
123   
 
124    toggle @Override
125    public long[] getLengths() throws RepositoryException {
126    throw new UnsupportedOperationException("Not implemented.");
127    }
128   
 
129    toggle @Override
130    public PropertyDefinition getDefinition() throws RepositoryException {
131    throw new UnsupportedOperationException("Not implemented.");
132    }
133   
 
134    toggle @Override
135    public Node getNode() throws RepositoryException {
136    return parent;
137    }
138   
 
139    toggle @Override
140    public void setValue(Binary value) throws RepositoryException {
141    throw new UnsupportedOperationException("Not implemented.");
142    }
143   
 
144    toggle @Override
145    public void setValue(BigDecimal value) throws RepositoryException {
146    throw new UnsupportedOperationException("Not implemented.");
147    }
148   
 
149    toggle @Override
150    public boolean isMultiple() {
151    return multiple;
152    }
153   
 
154    toggle @Override
155    public boolean isModified() {
156    return false;
157    }
158   
 
159    toggle @Override
160    public boolean isNew() {
161    return false;
162    }
163   
 
164  0 toggle @Override
165    public boolean isSame(Item otherItem) throws RepositoryException {
166  0 throw new UnsupportedOperationException("Not implemented.");
167    }
168   
 
169  0 toggle @Override
170    public void refresh(boolean keepChanges) throws RepositoryException {
171   
172    }
173   
 
174  0 toggle @Override
175    public void save() throws RepositoryException {
176  0 throw new UnsupportedOperationException("Not implemented.");
177    }
178   
 
179  0 toggle @Override
180    public String toString() {
181  0 String valueString;
182  0 if (isMultiple()) {
183  0 valueString = StringUtils.join(values, ", ");
184    } else {
185  0 valueString = values.length == 0 ? "" : values[0].toString();
186    }
187  0 return super.toString() + ": " + valueString;
188    }
189   
 
190  0 toggle @Override
191    public boolean equals(Object o) {
192  0 if (this == o) return true;
193  0 if (o == null || getClass() != o.getClass()) return false;
194   
195  0 ReadOnlyProperty that = (ReadOnlyProperty) o;
196   
197  0 if (isMultiple() != that.isMultiple()) return false;
198  0 if (!getName().equals(that.getName())) return false;
199    // Probably incorrect - comparing Object[] arrays with Arrays.equals
200  0 return Arrays.equals(values, that.values);
201    }
202   
 
203  0 toggle @Override
204    public int hashCode() {
205  0 int result = getName().hashCode();
206  0 result = 31 * result + (isMultiple() ? 1 : 0);
207  0 result = 31 * result + Arrays.hashCode(values);
208  0 return result;
209    }
210    }