group components;

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

component(componentInfo) ::= <<
// ---------- Attention: Generated code, please do not modify! -----------  

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package <componentInfo.packageName>;

<componentInfo.imports:import(); separator="\n">
import org.apache.myfaces.tobago.internal.util.ArrayUtils;
import org.apache.myfaces.tobago.internal.util.StringUtils;
import org.apache.myfaces.tobago.internal.util.Deprecation;
import org.apache.myfaces.tobago.renderkit.MarginValues;
import org.apache.myfaces.tobago.renderkit.SpacingValues;
import org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer;
import javax.el.ELException;
import javax.faces.FacesException;
import java.util.ArrayList;
import java.util.List;
import javax.el.MethodExpression;
import javax.el.ValueExpression;

/** 
 <if(componentInfo.description)>
 <componentInfo.description>
 <endif>
  * UIComponent class, generated from template {@code component2.0.stg} with class
  * {@link <componentInfo.sourceClass>}.
   <if(componentInfo.deprecated)>
   @deprecated
   <endif>
 */
<if(componentInfo.deprecated)>
@Deprecated

<endif>
public class <componentInfo.className>
    extends <componentInfo.superClassName> <first(componentInfo.interfaces):{ n | implements <n>}><rest(componentInfo.interfaces):{ n |, <n>}> {

  <if(componentInfo.componentType)>
  public static final String COMPONENT_TYPE = "<componentInfo.componentType>";

  <endif>
  <if(componentInfo.componentFamily)>
  public static final String COMPONENT_FAMILY = "<componentInfo.componentFamily>";

  <endif>
  <componentInfo.transientProperties:field(); separator="\n">

  <if(componentInfo.properties)>
  enum PropertyKeys {
    <componentInfo.nonTransientProperties:enumName(); separator="\n">
  }
  <endif>

  <if(componentInfo.componentFamily)>
  public String getFamily() {
    return COMPONENT_FAMILY;
  }

  <endif>
  <componentInfo.properties:{ p | <p:(p.propertyTemplate)()>}; separator="\n">

  <if(componentInfo.transientProperties)>
  public Object saveState(FacesContext context) {
    <componentInfo.transientProperties:{ p | <p:resetField()>}; separator="\n">
    return super.saveState(context);
  }
  <endif>

}
>>

import() ::= <<
import <it>;
>>

createDescription(property) ::= <<
<if(property.description)>
/**
<property.description>
<if(property.defaultValue)>
\<br /\>Default: \<code\><property.defaultValue>\</code\>
<endif>
<if(property.allowedValues)>
\<br /\>Allowed Values: \<code\><property.allowedValues:allowedValue(); separator=",">\</code\>
<endif>

<if(property.deprecated)>
@deprecated
<endif>
*/
<endif>
>>

checkDeprecated(property) ::= <<
<if(property.deprecated)>
@Deprecated
<endif>
>>

logDeprecated(property) ::= <<
<if(property.deprecated)>
  Deprecation.LOG.error("The attribute '<property.propertyName>' of '<componentInfo.className>' is deprecated. "
      + "Please refer the documentation for further information.");
<endif>
>>

allowedValue() ::= <<
<it>
>>

IntegerProperty(property) ::= <<

<createDescription(property)>
<checkDeprecated(property)>
public <property.type> get<property.upperCamelCaseName>() {
  <if(property.transient)>
  if (<property.propertyName> != null) {
    return <property.propertyName>;
  }
  <else>
  Number value  = (Number) getStateHelper().eval(PropertyKeys.<property.propertyName>);
  if (value != null) {
    return value.intValue();
  }
  <endif>
  <if(property.defaultCode)>
  return <property.defaultCode>;
  <else>
  return null;
  <endif>
}

<checkDeprecated(property)>
public void set<property.upperCamelCaseName>(<property.type> <property.propertyName>) {
  <logDeprecated(property)>
  <if(property.transient)>
  this.<property.propertyName> = <property.propertyName>;
  <else>
  getStateHelper().put(PropertyKeys.<property.propertyName>, <property.propertyName>);
  <endif>
}
>>

ObjectProperty(property) ::= <<

<createDescription(property)>
<checkDeprecated(property)>
public <property.type> get<property.upperCamelCaseName>() {
  <if(property.transient)>
  if (<property.propertyName> != null) {
    return <property.propertyName>;
  }
  <else>
  return getStateHelper().eval(PropertyKeys.<property.propertyName>);
  <endif>
}

<checkDeprecated(property)>
public void set<property.upperCamelCaseName>(<property.type> <property.propertyName>) {
  <logDeprecated(property)>
  <if(property.transient)>
  this.<property.propertyName> = <property.propertyName>;
  <else>
  getStateHelper().put(PropertyKeys.<property.propertyName>, <property.propertyName>);
  <endif>
}
>>

StringArrayProperty(property) ::= <<

<createDescription(property)>
<checkDeprecated(property)>
public String[] get<property.upperCamelCaseName>() {
  Object strArray = getStateHelper().eval(PropertyKeys.<property.propertyName>);
  if (strArray != null) {
    if (strArray instanceof String[]) {
      return (String[]) strArray;
    } else if (strArray instanceof String) {
      String[] strings = StringUtils.split((String) strArray, ", ");
      List\<String\> result = new ArrayList\<String\>(strings.length);
      for (String string : strings) {
        if (string.trim().length() != 0) {
          result.add(string.trim());
        }
      }
      return result.toArray(new String[result.size()]);
    } else if (strArray == null) {
      return org.apache.myfaces.tobago.internal.util.ArrayUtils.EMPTY_STRING_ARRAY;
    } else {
      return new String[]{strArray.toString()};
    }
  }
  return org.apache.myfaces.tobago.internal.util.ArrayUtils.EMPTY_STRING_ARRAY;
}

<checkDeprecated(property)>
public void set<property.upperCamelCaseName>(String[] <property.propertyName>) {
  <logDeprecated(property)>
  getStateHelper().put(PropertyKeys.<property.propertyName>, <property.propertyName>);
}
>>

booleanProperty(property) ::= <<

<createDescription(property)>
<checkDeprecated(property)>
public boolean is<property.upperCamelCaseName>() {
  <if(property.transient)>
  if (<property.propertyName> != null) {
    return <property.propertyName>;
  }
  <else>
  Boolean bool = (Boolean) getStateHelper().eval(PropertyKeys.<property.propertyName>);
  if (bool != null) {
    return bool;
  }
  <endif>
  <if(property.defaultCode)>
  return <property.defaultCode>;
  <else>
  return false;
  <endif>
}

<checkDeprecated(property)>
public void set<property.upperCamelCaseName>(boolean <property.propertyName>) {
  <logDeprecated(property)>
  <if(property.transient)>
  this.<property.propertyName> = <property.propertyName>;
  <else>
  getStateHelper().put(PropertyKeys.<property.propertyName>, <property.propertyName>);
  <endif>
}
>>

BooleanProperty(property) ::= <<

<createDescription(property)>
<checkDeprecated(property)>
public Boolean get<property.upperCamelCaseName>() {
  <if(property.transient)>
  if (<property.propertyName> != null) {
    return <property.propertyName>;
  }
  <else>
  Boolean bool = (Boolean) getStateHelper().eval(PropertyKeys.<property.propertyName>);
  if (bool != null) {
    return bool;
  }
  <endif>
  <if(property.defaultCode)>
  return <property.defaultCode>;
  <else>
  return null;
  <endif>
}

<checkDeprecated(property)>
public void set<property.upperCamelCaseName>(Boolean <property.propertyName>) {
  <logDeprecated(property)>
  <if(property.transient)>
  this.<property.propertyName> = <property.propertyName>;
  <else>
  getStateHelper().put(PropertyKeys.<property.propertyName>, <property.propertyName>);
  <endif>
}
>>

SeverityProperty(property) ::= <<
<NormalProperty(property)>
>>

TextAlignProperty(property) ::= <<
<NormalProperty(property)>
>>

SuggestFilterProperty(property) ::= <<
<NormalProperty(property)>
>>

DisplayProperty(property) ::= <<
<NormalProperty(property)>
>>

OrderByProperty(property) ::= <<
<NormalProperty(property)>
>>

WizardProperty(property) ::= <<
<NormalProperty(property)>
>>

StringProperty(property) ::= <<
<NormalProperty(property)>
>>

CharacterProperty(property) ::= <<
<NormalProperty(property)>
>>

MethodExpressionProperty(property) ::= <<

/**
 * @deprecated since 2.0.0
 */
@Deprecated
public javax.faces.el.MethodBinding get<property.upperCamelCaseName>() {
  javax.el.MethodExpression expression = get<property.upperCamelCaseName>Expression();
  if (expression instanceof MethodBindingToMethodExpression) {
    return ((MethodBindingToMethodExpression)expression).getMethodBinding();
  }
  if (expression != null) {
     return new MethodExpressionToMethodBinding(expression);
  }
  return null;
}

/**
 * @deprecated since 2.0.0
 */
@Deprecated
public void set<property.upperCamelCaseName>(javax.faces.el.MethodBinding <property.propertyName>) {
  if (<property.propertyName> != null) {
    set<property.upperCamelCaseName>Expression(new MethodBindingToMethodExpression(<property.propertyName>));
  } else {
    set<property.upperCamelCaseName>Expression(null);
  }
}

public <property.type> get<property.upperCamelCaseName>Expression() {
  return (<property.type>) getStateHelper().eval(PropertyKeys.<property.propertyName>);
}

public void set<property.upperCamelCaseName>Expression(<property.type> <property.propertyName>) {
  getStateHelper().put(PropertyKeys.<property.propertyName>, <property.propertyName>);
}

>>

NormalProperty(property) ::= <<

<createDescription(property)>
<checkDeprecated(property)>
public <property.type> get<property.upperCamelCaseName>() {
  <if(property.transient)>
  if (<property.propertyName> != null) {
    return <property.propertyName>;
  }
  <else>
  <if(property.defaultCode)>
  <property.type> <property.propertyName> = (<property.type>) getStateHelper().eval(PropertyKeys.<property.propertyName>);
  if (<property.propertyName> != null) {
    return <property.propertyName>;
  }
  <else>
  return (<property.type>) getStateHelper().eval(PropertyKeys.<property.propertyName>);
  <endif>
  <endif>
  <if(property.defaultCode)>
  return <property.defaultCode>;
  <endif>
}

<checkDeprecated(property)>
public void set<property.upperCamelCaseName>(<property.type> <property.propertyName>) {
  <logDeprecated(property)>
  <if(property.transient)>
  <else>
  getStateHelper().put(PropertyKeys.<property.propertyName>, <property.propertyName>);
  <endif>
}
>>

MeasureProperty(property) ::= <<

<createDescription(property)>
<checkDeprecated(property)>
public <property.type> get<property.upperCamelCaseName>() {
  <if(property.transient)>
  if (<property.propertyName> != null) {
    return <property.propertyName>;
  }
  <else>
  Object object = getStateHelper().eval(PropertyKeys.<property.propertyName>);
  if (object != null) {
     return Measure.valueOf(object);
  }
  <endif>
  <if(property.defaultCode)>
  return <property.defaultCode>;
  <else>
  return null;
  <endif>
}

<checkDeprecated(property)>
public void set<property.upperCamelCaseName>(<property.type> <property.propertyName>) {
  <logDeprecated(property)>
  <if(property.transient)>
  this.<property.propertyName> = <property.propertyName>;
  <else>
  getStateHelper().put(PropertyKeys.<property.propertyName>, <property.propertyName>);
  <endif>
}
>>

MarkupProperty(property) ::= <<

<checkDeprecated(property)>
public <property.type> get<property.upperCamelCaseName>() {
  <if(property.transient)>
  if (<property.propertyName> != null) {
    return <property.propertyName>;
  }
  <else>
  Object object = getStateHelper().eval(PropertyKeys.<property.propertyName>);
  if (object != null) {
    return Markup.valueOf(object);
  }
  <endif>
  return null;
}

<checkDeprecated(property)>
public void set<property.upperCamelCaseName>(<property.type> <property.propertyName>) {
  <logDeprecated(property)>
  <if(property.transient)>
  this.<property.propertyName> = <property.propertyName>;
  <else>
  getStateHelper().put(PropertyKeys.<property.propertyName>, <property.propertyName>);
  <endif>
}
>>

enumName() ::= <<
<it.propertyName>,
>>

field() ::= <<
private <it.internalType> <it.propertyName>;
>>

resetField() ::= <<
<it.propertyName> = null;
>>
