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  @Override
053  public String root(final Application it) {
054    RootTmpl headObj = getMethodsDispatchHead()[org.sculptor.generator.template.RootTmplMethodIndexes.ROOT_APPLICATION];
055    return headObj._chained_root(it);
056  }
057  
058  public RootTmplExtension(final RootTmpl next, final RootTmpl[] methodsDispatchNext) {
059    super(next);
060  }
061  
062  public String _chained_root(final Application it) {
063    String _xblockexpression = null;
064    {
065      boolean _isDomainObjectToBeGenerated = this.properties.isDomainObjectToBeGenerated();
066      if (_isDomainObjectToBeGenerated) {
067        Collection<DomainObject> _allDomainObjects = this.helper.getAllDomainObjects(it, false);
068        final Function1<DomainObject, Boolean> _function = new Function1<DomainObject, Boolean>() {
069          @Override
070          public Boolean apply(final DomainObject e) {
071            return Boolean.valueOf(RootTmplExtension.this.builderHelper.needsBuilder(e));
072          }
073        };
074        Iterable<DomainObject> _filter = IterableExtensions.<DomainObject>filter(_allDomainObjects, _function);
075        final Procedure1<DomainObject> _function_1 = new Procedure1<DomainObject>() {
076          @Override
077          public void apply(final DomainObject e) {
078            RootTmplExtension.this.builderTmpl.builder(e);
079          }
080        };
081        IterableExtensions.<DomainObject>forEach(_filter, _function_1);
082      }
083      RootTmpl _next = this.getNext();
084      _xblockexpression = _next.root(it);
085    }
086    return _xblockexpression;
087  }
088  
089  public RootTmpl[] _getOverridesDispatchArray() {
090    org.sculptor.generator.template.RootTmpl[] result = new org.sculptor.generator.template.RootTmpl[org.sculptor.generator.template.RootTmplMethodIndexes.NUM_METHODS];
091    result[org.sculptor.generator.template.RootTmplMethodIndexes.ROOT_APPLICATION] = this; 
092    return result;
093  }
094}