1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.objects.meta

File PropertyMetaClass.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
62
10
1
191
118
13
0.21
6.2
10
1.3

Classes

Class Line # Actions
PropertyMetaClass 47 62 0% 13 10
0.864864986.5%
 

Contributing tests

This file is covered by 26 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.objects.meta;
21   
22    import com.xpn.xwiki.XWikiContext;
23    import com.xpn.xwiki.XWikiException;
24    import com.xpn.xwiki.internal.objects.classes.PropertyClassProvider;
25    import com.xpn.xwiki.internal.objects.meta.PropertyMetaClassInterface;
26    import com.xpn.xwiki.objects.BaseCollection;
27    import com.xpn.xwiki.objects.classes.BaseClass;
28    import com.xpn.xwiki.objects.classes.BooleanClass;
29    import com.xpn.xwiki.objects.classes.NumberClass;
30    import com.xpn.xwiki.objects.classes.PropertyClassInterface;
31    import com.xpn.xwiki.objects.classes.StringClass;
32    import com.xpn.xwiki.objects.classes.TextAreaClass;
33    import com.xpn.xwiki.web.Utils;
34   
35    /**
36    * Default implementation of {@link PropertyMetaClassInterface}. Provides the default set of meta properties all XClass
37    * properties have. Can be extended by adding new meta properties with
38    * {@link #safeput(String, com.xpn.xwiki.objects.PropertyInterface)}.
39    * <p>
40    * NOTE: We implement {@link PropertyClassProvider} in order to be able to use existing meta classes (that extend this
41    * one) as providers while keeping backward compatibility. When defining new property types you should not extend this
42    * class but rather create a new {@link PropertyClassProvider} that creates an instance of this class and adds new meta
43    * properties using {@link #safeput(String, com.xpn.xwiki.objects.PropertyInterface)}.
44    *
45    * @version $Id: 799582c7a1b6eaa3dcc175a3d4a691f9e191ff21 $
46    */
 
47    public class PropertyMetaClass extends BaseClass implements PropertyMetaClassInterface, PropertyClassProvider
48    {
49    /**
50    * Default constructor. Initializes the meta properties that are common to all XClass property types.
51    */
 
52  885 toggle public PropertyMetaClass()
53    {
54    // NOTE: All XClass property types have an additional read-only meta property called 'classType' that is added
55    // automatically when exporting the XClass property to XML. See PropertyClass#toXML().
56   
57  885 StringClass nameClass = new StringClass(this);
58  885 nameClass.setName("name");
59  885 nameClass.setPrettyName("Name");
60  885 nameClass.setUnmodifiable(true);
61  885 nameClass.setSize(40);
62  885 safeput(nameClass.getName(), nameClass);
63   
64  885 BooleanClass disabledClass = new BooleanClass(this);
65  885 disabledClass.setName("disabled");
66  885 disabledClass.setPrettyName("Disabled");
67  885 disabledClass.setDisplayType("yesno");
68  885 disabledClass.setDisplayFormType("checkbox");
69  885 safeput(disabledClass.getName(), disabledClass);
70   
71  885 addPresentationMetaProperties();
72   
73  885 BooleanClass unmodifiableClass = new BooleanClass(this);
74  885 unmodifiableClass.setName("unmodifiable");
75  885 unmodifiableClass.setPrettyName("Unmodifiable");
76  885 unmodifiableClass.setDisplayType(disabledClass.getDisplayType());
77  885 safeput(unmodifiableClass.getName(), unmodifiableClass);
78   
79  885 NumberClass numberClass = new NumberClass(this);
80  885 numberClass.setName("number");
81  885 numberClass.setPrettyName("Number");
82  885 numberClass.setNumberType("integer");
83  885 safeput(numberClass.getName(), numberClass);
84   
85  885 addValidationMetaProperties();
86    }
87   
88    /**
89    * Adds generic meta properties that control how an XClass property is displayed.
90    */
 
91  885 toggle private void addPresentationMetaProperties()
92    {
93  885 StringClass prettyNameClass = new StringClass(this);
94  885 prettyNameClass.setName("prettyName");
95  885 prettyNameClass.setPrettyName("Pretty Name");
96  885 prettyNameClass.setSize(40);
97  885 safeput(prettyNameClass.getName(), prettyNameClass);
98   
99  885 TextAreaClass toolTipClass = new TextAreaClass(this);
100  885 toolTipClass.setName("tooltip");
101  885 toolTipClass.setPrettyName("Tooltip");
102  885 toolTipClass.setSize(60);
103  885 toolTipClass.setRows(5);
104  885 safeput(toolTipClass.getName(), toolTipClass);
105   
106  885 TextAreaClass customDisplayClass = new TextAreaClass(this);
107  885 customDisplayClass.setName("customDisplay");
108  885 customDisplayClass.setPrettyName("Custom Display");
109  885 customDisplayClass.setEditor("Text");
110  885 customDisplayClass.setRows(5);
111  885 customDisplayClass.setSize(80);
112  885 safeput(customDisplayClass.getName(), customDisplayClass);
113    }
114   
115    /**
116    * Adds the meta properties used for validation the XClass property value.
117    */
 
118  885 toggle private void addValidationMetaProperties()
119    {
120  885 StringClass validationRegExpClass = new StringClass(this);
121  885 validationRegExpClass.setName("validationRegExp");
122  885 validationRegExpClass.setPrettyName("Validation Regular Expression");
123  885 validationRegExpClass.setSize(40);
124  885 safeput(validationRegExpClass.getName(), validationRegExpClass);
125   
126  885 StringClass validationMessageClass = new StringClass(this);
127  885 validationMessageClass.setName("validationMessage");
128  885 validationMessageClass.setPrettyName("Validation Message");
129  885 validationMessageClass.setSize(80);
130  885 safeput(validationMessageClass.getName(), validationMessageClass);
131    }
132   
 
133  0 toggle @Override
134    public BaseCollection getObject()
135    {
136  0 return null;
137    }
138   
 
139  0 toggle @Override
140    public void setObject(BaseCollection object)
141    {
142    }
143   
 
144  0 toggle @Override
145    public String toFormString()
146    {
147  0 return null;
148    }
149   
 
150  0 toggle @Override
151    public PropertyMetaClass clone()
152    {
153  0 return (PropertyMetaClass) super.clone();
154    }
155   
156    /**
157    * {@inheritDoc}
158    * <p>
159    * This method is deprecated. Use directly the {@link PropertyClassProvider} if you need a new XClass property
160    * instance.
161    * </p>
162    */
 
163  4 toggle @Override
164    public BaseCollection newObject(XWikiContext context) throws XWikiException
165    {
166  4 PropertyClassInterface instance = null;
167  4 try {
168    // Try to use the corresponding XClass property provider to create the new property instance.
169  4 PropertyClassProvider provider = Utils.getComponent(PropertyClassProvider.class, getName());
170  4 instance = provider.getInstance();
171    } catch (Exception e) {
172    // Fail silently.
173    }
174  4 return instance != null && instance instanceof BaseCollection ? (BaseCollection) instance : super
175    .newObject(context);
176    }
177   
 
178  0 toggle @Override
179    public PropertyClassInterface getInstance()
180    {
181    // Needs to be implemented in derived classes. We didn't make this method abstract to preserve backwards
182    // compatibility.
183  0 return null;
184    }
185   
 
186  37580 toggle @Override
187    public PropertyMetaClassInterface getDefinition()
188    {
189  37580 return this;
190    }
191    }