001/**
002 * Copyright 2014 The Sculptor Project Team, including the original
003 * author or authors.
004 * 
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 * 
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 * 
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.sculptor.generator.cartridge.builder;
018
019import com.google.inject.Inject;
020import java.util.Collection;
021import org.eclipse.xtext.xbase.lib.Extension;
022import org.eclipse.xtext.xbase.lib.Functions.Function1;
023import org.eclipse.xtext.xbase.lib.IterableExtensions;
024import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
025import org.sculptor.generator.cartridge.builder.BuilderHelper;
026import org.sculptor.generator.cartridge.builder.BuilderTmpl;
027import org.sculptor.generator.chain.ChainOverride;
028import org.sculptor.generator.ext.Helper;
029import org.sculptor.generator.ext.Properties;
030import org.sculptor.generator.template.RootTmpl;
031import sculptormetamodel.Application;
032import sculptormetamodel.DomainObject;
033
034@ChainOverride
035@SuppressWarnings("all")
036public class RootTmplExtension extends RootTmpl {
037  @Inject
038  private BuilderTmpl builderTmpl;
039  
040  @Inject
041  @Extension
042  private BuilderHelper builderHelper;
043  
044  @Inject
045  @Extension
046  private Helper helper;
047  
048  @Inject
049  @Extension
050  private Properties properties;
051  
052  public String root(final Application it) {
053    RootTmpl headObj = getMethodsDispatchHead()[org.sculptor.generator.template.RootTmplMethodIndexes.ROOT_APPLICATION];
054    return headObj._chained_root(it);
055  }
056  
057  public RootTmplExtension(final RootTmpl next, final RootTmpl[] methodsDispatchNext) {
058    super(next);
059  }
060  
061  public String _chained_root(final Application it) {
062    String _xblockexpression = null;
063    {
064      boolean _isDomainObjectToBeGenerated = this.properties.isDomainObjectToBeGenerated();
065      if (_isDomainObjectToBeGenerated) {
066        Collection<DomainObject> _allDomainObjects = this.helper.getAllDomainObjects(it, false);
067        final Function1<DomainObject, Boolean> _function = new Function1<DomainObject, Boolean>() {
068          public Boolean apply(final DomainObject e) {
069            return Boolean.valueOf(RootTmplExtension.this.builderHelper.needsBuilder(e));
070          }
071        };
072        Iterable<DomainObject> _filter = IterableExtensions.<DomainObject>filter(_allDomainObjects, _function);
073        final Procedure1<DomainObject> _function_1 = new Procedure1<DomainObject>() {
074          public void apply(final DomainObject e) {
075            RootTmplExtension.this.builderTmpl.builder(e);
076          }
077        };
078        IterableExtensions.<DomainObject>forEach(_filter, _function_1);
079      }
080      RootTmpl _next = this.getNext();
081      _xblockexpression = _next.root(it);
082    }
083    return _xblockexpression;
084  }
085  
086  public RootTmpl[] _getOverridesDispatchArray() {
087    org.sculptor.generator.template.RootTmpl[] result = new org.sculptor.generator.template.RootTmpl[org.sculptor.generator.template.RootTmplMethodIndexes.NUM_METHODS];
088    result[org.sculptor.generator.template.RootTmplMethodIndexes.ROOT_APPLICATION] = this; 
089    return result;
090  }
091}