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.mongodb;
018
019import javax.inject.Inject;
020import org.eclipse.xtend2.lib.StringConcatenation;
021import org.eclipse.xtext.xbase.lib.Extension;
022import org.sculptor.generator.cartridge.mongodb.MongoDbProperties;
023import org.sculptor.generator.chain.ChainOverride;
024import org.sculptor.generator.ext.Helper;
025import org.sculptor.generator.template.domain.DomainObjectConstructorTmpl;
026import sculptormetamodel.NamedElement;
027
028@ChainOverride
029@SuppressWarnings("all")
030public class DomainObjectConstructorTmplExtension extends DomainObjectConstructorTmpl {
031  @Inject
032  @Extension
033  private MongoDbProperties mongoDbProperties;
034  
035  @Inject
036  @Extension
037  private Helper helper;
038  
039  @Override
040  public String propertyConstructorBaseParameterAssignmentForUnownedOneReference(final NamedElement it) {
041    DomainObjectConstructorTmpl headObj = getMethodsDispatchHead()[org.sculptor.generator.template.domain.DomainObjectConstructorTmplMethodIndexes.PROPERTYCONSTRUCTORBASEPARAMETERASSIGNMENTFORUNOWNEDONEREFERENCE_NAMEDELEMENT];
042    return headObj._chained_propertyConstructorBaseParameterAssignmentForUnownedOneReference(it);
043  }
044  
045  public DomainObjectConstructorTmplExtension(final DomainObjectConstructorTmpl next, final DomainObjectConstructorTmpl[] methodsDispatchNext) {
046    super(next);
047  }
048  
049  public String _chained_propertyConstructorBaseParameterAssignmentForUnownedOneReference(final NamedElement it) {
050    StringConcatenation _builder = new StringConcatenation();
051    {
052      boolean _mongoDb = this.mongoDbProperties.mongoDb();
053      if (_mongoDb) {
054        _builder.append("this.");
055        String _name = it.getName();
056        _builder.append(_name, "");
057        String _unownedReferenceSuffix = this.helper.unownedReferenceSuffix(it);
058        _builder.append(_unownedReferenceSuffix, "");
059        _builder.append(" = (");
060        String _name_1 = it.getName();
061        _builder.append(_name_1, "");
062        _builder.append(" == null ? null : ");
063        String _name_2 = it.getName();
064        _builder.append(_name_2, "");
065        _builder.append(".getId());");
066        _builder.newLineIfNotEmpty();
067        _builder.append("this.");
068        String _name_3 = it.getName();
069        _builder.append(_name_3, "");
070        _builder.append(" = ");
071        String _name_4 = it.getName();
072        _builder.append(_name_4, "");
073        _builder.append(";");
074        _builder.newLineIfNotEmpty();
075        _builder.append("this.");
076        String _name_5 = it.getName();
077        _builder.append(_name_5, "");
078        _builder.append("IsLoaded = true;");
079        _builder.newLineIfNotEmpty();
080      } else {
081        DomainObjectConstructorTmpl _next = this.getNext();
082        String _propertyConstructorBaseParameterAssignmentForUnownedOneReference = _next.propertyConstructorBaseParameterAssignmentForUnownedOneReference(it);
083        _builder.append(_propertyConstructorBaseParameterAssignmentForUnownedOneReference, "");
084        _builder.newLineIfNotEmpty();
085      }
086    }
087    return _builder.toString();
088  }
089  
090  public DomainObjectConstructorTmpl[] _getOverridesDispatchArray() {
091    org.sculptor.generator.template.domain.DomainObjectConstructorTmpl[] result = new org.sculptor.generator.template.domain.DomainObjectConstructorTmpl[org.sculptor.generator.template.domain.DomainObjectConstructorTmplMethodIndexes.NUM_METHODS];
092    result[org.sculptor.generator.template.domain.DomainObjectConstructorTmplMethodIndexes.PROPERTYCONSTRUCTORBASEPARAMETERASSIGNMENTFORUNOWNEDONEREFERENCE_NAMEDELEMENT] = this; 
093    return result;
094  }
095}