1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.objects.meta

File PropertyMetaClass.java

 

Coverage histogram

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

Code metrics

2
67
10
1
197
123
13
0.19
6.7
10
1.3

Classes

Class Line # Actions
PropertyMetaClass 47 67 0% 13 10
0.8734177487.3%
 

Contributing tests

This file is covered by 28 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: 9999420ba2a8ac65556119d8e008539925eb3cb8 $
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  1200 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  1200 StringClass nameClass = new StringClass(this);
58  1200 nameClass.setName("name");
59  1200 nameClass.setPrettyName("Name");
60  1200 nameClass.setUnmodifiable(true);
61  1200 nameClass.setSize(40);
62  1200 safeput(nameClass.getName(), nameClass);
63   
64  1200 BooleanClass disabledClass = new BooleanClass(this);
65  1200 disabledClass.setName("disabled");
66  1200 disabledClass.setPrettyName("Disabled");
67  1200 disabledClass.setDisplayType("yesno");
68  1200 disabledClass.setDisplayFormType("checkbox");
69  1200 safeput(disabledClass.getName(), disabledClass);
70   
71  1200 addPresentationMetaProperties();
72   
73  1200 BooleanClass unmodifiableClass = new BooleanClass(this);
74  1200 unmodifiableClass.setName("unmodifiable");
75  1200 unmodifiableClass.setPrettyName("Unmodifiable");
76  1200 unmodifiableClass.setDisplayType(disabledClass.getDisplayType());
77  1200 safeput(unmodifiableClass.getName(), unmodifiableClass);
78   
79  1200 NumberClass numberClass = new NumberClass(this);
80  1200 numberClass.setName("number");
81  1200 numberClass.setPrettyName("Number");
82  1200 numberClass.setNumberType("integer");
83  1200 safeput(numberClass.getName(), numberClass);
84   
85  1200 addValidationMetaProperties();
86    }
87   
88    /**
89    * Adds generic meta properties that control how an XClass property is displayed.
90    */
 
91  1200 toggle private void addPresentationMetaProperties()
92    {
93  1200 StringClass prettyNameClass = new StringClass(this);
94  1200 prettyNameClass.setName("prettyName");
95  1200 prettyNameClass.setPrettyName("Pretty Name");
96  1200 prettyNameClass.setSize(40);
97  1200 safeput(prettyNameClass.getName(), prettyNameClass);
98   
99  1200 StringClass hintClass = new StringClass(this);
100  1200 hintClass.setName("hint");
101  1200 hintClass.setPrettyName("Hint");
102  1200 hintClass.setSize(40);
103  1200 safeput(hintClass.getName(), hintClass);
104   
105  1200 TextAreaClass toolTipClass = new TextAreaClass(this);
106  1200 toolTipClass.setName("tooltip");
107  1200 toolTipClass.setPrettyName("Tooltip");
108  1200 toolTipClass.setSize(60);
109  1200 toolTipClass.setRows(5);
110  1200 safeput(toolTipClass.getName(), toolTipClass);
111   
112  1200 TextAreaClass customDisplayClass = new TextAreaClass(this);
113  1200 customDisplayClass.setName("customDisplay");
114  1200 customDisplayClass.setPrettyName("Custom Display");
115  1200 customDisplayClass.setEditor("Text");
116  1200 customDisplayClass.setRows(5);
117  1200 customDisplayClass.setSize(80);
118  1200 safeput(customDisplayClass.getName(), customDisplayClass);
119    }
120   
121    /**
122    * Adds the meta properties used for validation the XClass property value.
123    */
 
124  1200 toggle private void addValidationMetaProperties()
125    {
126  1200 StringClass validationRegExpClass = new StringClass(this);
127  1200 validationRegExpClass.setName("validationRegExp");
128  1200 validationRegExpClass.setPrettyName("Validation Regular Expression");
129  1200 validationRegExpClass.setSize(40);
130  1200 safeput(validationRegExpClass.getName(), validationRegExpClass);
131   
132  1200 StringClass validationMessageClass = new StringClass(this);
133  1200 validationMessageClass.setName("validationMessage");
134  1200 validationMessageClass.setPrettyName("Validation Message");
135  1200 validationMessageClass.setSize(80);
136  1200 safeput(validationMessageClass.getName(), validationMessageClass);
137    }
138   
 
139  0 toggle @Override
140    public BaseCollection getObject()
141    {
142  0 return null;
143    }
144   
 
145  0 toggle @Override
146    public void setObject(BaseCollection object)
147    {
148    }
149   
 
150  0 toggle @Override
151    public String toFormString()
152    {
153  0 return null;
154    }
155   
 
156  0 toggle @Override
157    public PropertyMetaClass clone()
158    {
159  0 return (PropertyMetaClass) super.clone();
160    }
161   
162    /**
163    * {@inheritDoc}
164    * <p>
165    * This method is deprecated. Use directly the {@link PropertyClassProvider} if you need a new XClass property
166    * instance.
167    * </p>
168    */
 
169  49 toggle @Override
170    public BaseCollection newObject(XWikiContext context) throws XWikiException
171    {
172  49 PropertyClassInterface instance = null;
173  49 try {
174    // Try to use the corresponding XClass property provider to create the new property instance.
175  49 PropertyClassProvider provider = Utils.getComponent(PropertyClassProvider.class, getName());
176  49 instance = provider.getInstance();
177    } catch (Exception e) {
178    // Fail silently.
179    }
180  49 return instance != null && instance instanceof BaseCollection ? (BaseCollection) instance : super
181    .newObject(context);
182    }
183   
 
184  0 toggle @Override
185    public PropertyClassInterface getInstance()
186    {
187    // Needs to be implemented in derived classes. We didn't make this method abstract to preserve backwards
188    // compatibility.
189  0 return null;
190    }
191   
 
192  89723 toggle @Override
193    public PropertyMetaClassInterface getDefinition()
194    {
195  89723 return this;
196    }
197    }