Package com.astamuse.asta4d

Examples of com.astamuse.asta4d.Context


        }
        readySnippetCount = readySnippetCount - blockedSnippetCount;

        String renderDeclaration;
        Renderer renderer;
        Context context = Context.getCurrentThreadContext();
        Configuration conf = Configuration.getConfiguration();
        final SnippetInvoker invoker = conf.getSnippetInvoker();

        String refId;
        Element renderTarget;
        for (Element element : snippetList) {
            if (!conf.isSkipSnippetExecution()) {
                // for a faked snippet node which is created by template
                // analyzing process, the render target element should be its
                // child.
                if (element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE).equals(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE_FAKE)) {
                    renderTarget = element.children().first();
                } else {
                    renderTarget = element;
                }
                context.setCurrentRenderingElement(renderTarget);
                renderDeclaration = element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_RENDER);
                refId = element.attr(ExtNodeConstants.ATTR_SNIPPET_REF);
                try {
                    if (element.hasAttr(ExtNodeConstants.SNIPPET_NODE_ATTR_PARALLEL)) {
                        ConcurrentRenderHelper crHelper = ConcurrentRenderHelper.getInstance(context, doc);
                        final Context newContext = context.clone();
                        final String declaration = renderDeclaration;
                        crHelper.submitWithContext(newContext, declaration, refId, new Callable<Renderer>() {
                            @Override
                            public Renderer call() throws Exception {
                                return invoker.invoke(declaration);
View Full Code Here


    private ApplicationContext applicationContext;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Context templateContext = Context.getCurrentThreadContext();
        if (templateContext == null) {
            templateContext = applicationContext.getBean(WebApplicationContext.class);
            Context.setCurrentThreadContext(templateContext);
        }
        templateContext.init();
        WebApplicationContext webContext = (WebApplicationContext) templateContext;
        webContext.setRequest(request);
        webContext.setResponse(response);
        return true;
    }
View Full Code Here

        return true;
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        Context templateContext = Context.getCurrentThreadContext();
        if (templateContext != null) {
            templateContext.clear();
        }
        super.afterCompletion(request, response, handler, ex);
    }
View Full Code Here

    private ApplicationContext beanCtx = null;

    private RequestDispatcher dispatcher = new RequestDispatcher();

    public void init() {
        Context templateContext = Context.getCurrentThreadContext();
        if (templateContext == null) {
            templateContext = beanCtx.getBean(WebApplicationContext.class);
            Context.setCurrentThreadContext(templateContext);
        }
        UrlMappingRuleHelper helper = new UrlMappingRuleHelper();
View Full Code Here

        }
        return newList;
    }

    public final static <S, T> List<Future<T>> transformToFuture(final Iterable<S> sourceList, final ParallelRowConvertor<S, T> convertor) {
        final Context context = Context.getCurrentThreadContext();
        final Configuration conf = context.getConfiguration();
        Boolean isInParallelConverting = context.getData(ParallelListConversionMark);

        if (isInParallelConverting != null) {// recursive converting
            switch (conf.getParallelRecursivePolicyForListRendering()) {
            case EXCEPTION:
                throw new RuntimeException(
                        "Parallel list converting is forbidden (by default) to avoid deadlock. You can change this policy by Configuration.setParallelRecursivePolicyForListRendering().");
            case CURRENT_THREAD:
                List<T> list = transform(sourceList, (RowConvertor<S, T>) convertor);
                return transform(list, new RowConvertor<T, Future<T>>() {
                    @Override
                    public Future<T> convert(int rowIndex, final T obj) {
                        return new Future<T>() {
                            @Override
                            public boolean cancel(boolean mayInterruptIfRunning) {
                                return false;
                            }

                            @Override
                            public boolean isCancelled() {
                                return false;
                            }

                            @Override
                            public boolean isDone() {
                                return true;
                            }

                            @Override
                            public T get() throws InterruptedException, ExecutionException {
                                return obj;
                            }

                            @Override
                            public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
                                return obj;
                            }
                        };
                    }
                });
            case NEW_THREAD:
                ExecutorService executor = ParallelFallbackExecutor;
                List<Future<T>> futureList = new LinkedList<>();
                int index = 0;
                for (S obj : sourceList) {
                    futureList.add(convertor.invoke(executor, index, obj));
                    index++;
                }
                return futureList;
            default:
                return Collections.emptyList();
            }
        } else {// not in recursive converting
            Context newContext = context.clone();
            newContext.setData(ParallelListConversionMark, Boolean.TRUE);
            try {
                return Context.with(newContext, new Callable<List<Future<T>>>() {
                    @Override
                    public List<Future<T>> call() throws Exception {
                        ExecutorService executor = conf.getListExecutorFactory().getExecutorService();
View Full Code Here

        }
        throw new InvalidMessageException("key[" + key + "] not found.", ex);
    }

    private static ResourceBundle getResourceBundle(String resourceName, Locale locale) {
        Context context = Context.getCurrentThreadContext();
        if (!context.getConfiguration().isCacheEnable()) {
            ResourceBundle.clearCache();
        }
        if (locale != null || LocaleUtils.isAvailableLocale(locale)) {
            return ResourceBundle.getBundle(resourceName, locale);
        }
        Locale currentLocale = context.getCurrentLocale();
        if (currentLocale != null || LocaleUtils.isAvailableLocale(currentLocale)) {
            return ResourceBundle.getBundle(resourceName, currentLocale);
        }
        return ResourceBundle.getBundle(resourceName);
    }
View Full Code Here

    private final static String InstanceListCacheKey = SnippetInitializeInterceptor.class + "##InstanceListCacheKey##";

    @Override
    public boolean beforeProcess(SnippetExecutionHolder execution) throws Exception {

        Context context = Context.getCurrentThreadContext();
        List<Object> snippetList = context.getData(InstanceListCacheKey);
        if (snippetList == null) {
            snippetList = new ArrayList<>();
            context.setData(InstanceListCacheKey, snippetList);
        }

        Object target = execution.getInstance();
        boolean inialized = false;
View Full Code Here

        }
        return null;
    }

    private Map<String, Object> getCacheMap(String key) {
        Context context = Context.getCurrentThreadContext();
        Map<String, Object> map = context.getData(key);
        if (map == null) {
            map = new HashMap<>();
            context.setData(key, map);
        }
        return map;
    }
View Full Code Here

        }
        readySnippetCount = readySnippetCount - blockedSnippetCount;

        String renderDeclaration;
        Renderer renderer;
        Context context = Context.getCurrentThreadContext();
        Configuration conf = context.getConfiguration();
        final SnippetInvoker invoker = conf.getSnippetInvoker();

        String refId;
        Element renderTarget;
        for (Element element : snippetList) {
            if (!conf.isSkipSnippetExecution()) {
                // for a faked snippet node which is created by template
                // analyzing process, the render target element should be its
                // child.
                if (element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE).equals(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE_FAKE)) {
                    renderTarget = element.children().first();
                } else {
                    renderTarget = element;
                }
                context.setCurrentRenderingElement(renderTarget);
                renderDeclaration = element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_RENDER);
                refId = element.attr(ExtNodeConstants.ATTR_SNIPPET_REF);
                if (element.hasAttr(ExtNodeConstants.SNIPPET_NODE_ATTR_PARALLEL)) {
                    ConcurrentRenderHelper crHelper = ConcurrentRenderHelper.getInstance(context, doc);
                    final Context newContext = context.clone();
                    final String declaration = renderDeclaration;
                    crHelper.submitWithContext(newContext, refId, new Callable<Renderer>() {
                        @Override
                        public Renderer call() throws Exception {
                            return invoker.invoke(declaration);
View Full Code Here

     * @throws DataOperationException
     */
    public final static void injectToInstance(Object instance) throws DataOperationException {
        try {

            Context context = Context.getCurrentThreadContext();
            InstanceWireTarget target = getInstanceTarget(instance);
            ContextDataFinder dataFinder = context.getConfiguration().getContextDataFinder();
            Object value;
            for (FieldInfo fi : target.setFieldList) {
                value = dataFinder.findDataInContext(context, fi.scope, fi.name, fi.type);
                FieldUtils.writeField(fi.field, instance, value, true);
            }
View Full Code Here

TOP

Related Classes of com.astamuse.asta4d.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.