Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
AbstractSafeObject | 31 | 3 | 0% | 2 | 0 |
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 org.xwiki.script.internal.safe; | |
21 | ||
22 | import org.xwiki.script.wrap.AbstractWrappingObject; | |
23 | ||
24 | /** | |
25 | * Encapsulate an object in a safe way for public scripts. | |
26 | * | |
27 | * @param <T> the type of the wrapped object | |
28 | * @version $Id: 942066d121492dbef92b9926d5de59c153a98ed3 $ | |
29 | * @since 4.0M2 | |
30 | */ | |
31 | public abstract class AbstractSafeObject<T> extends AbstractWrappingObject<T> | |
32 | { | |
33 | /** | |
34 | * The message used in forbidden access exceptions. | |
35 | */ | |
36 | public static final String FORBIDDEN = "Operation forbidden in script proxy"; | |
37 | ||
38 | /** | |
39 | * The provider of instances safe for public scripts. | |
40 | */ | |
41 | protected ScriptSafeProvider<Object> safeProvider; | |
42 | ||
43 | /** | |
44 | * @param wrapped the wrapped object | |
45 | * @param safeProvider the provider of instances safe for public scripts | |
46 | */ | |
47 | 1693 | public AbstractSafeObject(T wrapped, ScriptSafeProvider<?> safeProvider) |
48 | { | |
49 | 1693 | super(wrapped); |
50 | ||
51 | 1693 | this.safeProvider = (ScriptSafeProvider<Object>) safeProvider; |
52 | } | |
53 | ||
54 | /** | |
55 | * @param <S> the type of the object | |
56 | * @param unsafe the unsafe object | |
57 | * @return the safe version of the object | |
58 | */ | |
59 | 959 | protected <S> S safe(Object unsafe) |
60 | { | |
61 | 959 | return this.safeProvider.get(unsafe); |
62 | } | |
63 | } |