Last change
on this file 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.5 KB
|
Rev | Line | |
---|
[77] | 1 | package com.framsticks.parsers; |
---|
| 2 | |
---|
[88] | 3 | import javax.annotation.Nonnull; |
---|
| 4 | |
---|
[77] | 5 | import com.framsticks.params.*; |
---|
[100] | 6 | // import org.apache.logging.log4j.Logger; |
---|
[77] | 7 | |
---|
| 8 | /** |
---|
| 9 | * @author Piotr Sniegowski |
---|
| 10 | */ |
---|
| 11 | public class Loaders { |
---|
| 12 | |
---|
[100] | 13 | // private static final Logger log = LogManager.getLogger(Loaders.class.getName()); |
---|
[77] | 14 | |
---|
[101] | 15 | public static @Nonnull FramsClass loadFramsClass(Source source) throws ConstructionException { |
---|
[87] | 16 | final MultiParamLoader loader = new MultiParamLoader(); |
---|
[77] | 17 | loader.setNewSource(source); |
---|
| 18 | |
---|
[87] | 19 | final FramsClassBuilder builder = FramsClass.build(); |
---|
[77] | 20 | |
---|
[100] | 21 | final Access framsClassAccess = new ReflectionAccess(FramsClassBuilder.class, FramsClass.build().forClass(FramsClassBuilder.class)); |
---|
| 22 | Access paramBuilderAccess = new ReflectionAccess(ParamBuilder.class, FramsClass.build().forClass(ParamBuilder.class)); |
---|
[87] | 23 | framsClassAccess.select(builder); |
---|
[103] | 24 | loader.setAccessProvider(new AccessStash().add(framsClassAccess).add(paramBuilderAccess)); |
---|
[77] | 25 | |
---|
[87] | 26 | loader.addListener(MultiParamLoader.Status.AfterObject, new MultiParamLoader.StatusListener() { |
---|
| 27 | @Override |
---|
| 28 | public void onStatusChange() { |
---|
| 29 | Object object = loader.returnObject(); |
---|
| 30 | if (object instanceof FramsClassBuilder) { |
---|
| 31 | return; |
---|
| 32 | } |
---|
[96] | 33 | framsClassAccess.select(builder).tryAutoAppend(object); |
---|
| 34 | // throw new ConstructionException().msg("failed to interpretate object").arg("object", object); |
---|
[77] | 35 | |
---|
[87] | 36 | } |
---|
| 37 | }); |
---|
| 38 | |
---|
[77] | 39 | try { |
---|
[87] | 40 | loader.go(); |
---|
| 41 | return builder.finish(); |
---|
[77] | 42 | } catch (Exception e) { |
---|
[86] | 43 | throw new ConstructionException().msg("an error occurred while loading class description").arg("before", loader.getCurrentLine()).cause(e); |
---|
[77] | 44 | } |
---|
| 45 | } |
---|
| 46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.