source: java/main/src/main/java/com/framsticks/params/types/ObjectParam.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1package com.framsticks.params.types;
2
3import com.framsticks.params.Access;
4import com.framsticks.params.CastFailure;
5import com.framsticks.params.CompositeParam;
6import com.framsticks.params.ParamBuilder;
7import com.framsticks.params.ReassignResult;
8
9import javax.annotation.concurrent.Immutable;
10
11/**
12 * @author Piotr Sniegowski
13 */
14@Immutable
15public class ObjectParam extends CompositeParam {
16
17        protected final Class<?> storageType;
18
19        public ObjectParam(ParamBuilder builder) {
20                super(builder.fillStorageType(Object.class));
21                storageType = builder.getStorageType();
22        }
23
24        @Override
25        public String computeAccessId() {
26                return containedTypeName;
27        }
28
29        @Override
30        public Class<?> getStorageType() {
31                return storageType;
32        }
33
34        @Override
35        public ReassignResult<Object> reassign(Object newValue, Object oldValue) throws CastFailure {
36                if (newValue != null && !storageType.isInstance(newValue)) {
37                        throw new CastFailure();
38                }
39                return ReassignResult.create(newValue);
40        }
41
42        @Override
43        public Access prepareAccess(Access access) {
44                return access;
45        }
46
47        @Override
48        public String getFramsTypeName() {
49                return "o " + containedTypeName;
50        }
51
52        // @Override
53        // public <T> String serialize(T value) {
54        //      return ParamsUtil.serialize(value);
55        // }
56
57}
Note: See TracBrowser for help on using the repository browser.