Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.sporniket.libre.javabeans.generator.core;
  
  import java.util.HashMap;
  import java.util.Map;
  
Implementation for property having type="enum:...".

© Copyright 2012-2013 David Sporn


This file is part of The Sporniket Javabeans Library – core.

The Sporniket Javabeans Library – core is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The Sporniket Javabeans Library – core is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with The Sporniket Javabeans Library – core. If not, see http://www.gnu.org/licenses/. 2


Author(s):
David SPORN
Version:
13.01.01
Since:
13.01.01
 
 public class PropertyGeneratorTypeMap implements PropertyGenerator
 {
Template of the name of the template file for generating the enum.
0
"notNull" or "isolated"
1
"basic", "boundable" or "vetoable"
 
 	private static final String FILE_NAME_TEMPLATE__MAP = "template_property_map_{0}_{1}.txt";

For a map property, the interface is always "Map".
 
 	private static final String INTERFACE_NAME__MAP = "Map";

Template for computing the name of the template file.
 
Registry pairing a template file name and the template (in other words, it's a cache).
 
Compute template name.

Parameters:
collectionMode
mode
Returns:
 
 	private String getTemplateName(String collectionModePropertyMode mode)
 	{
 		Object[] _params =
 		{
 				collectionModemode.value()
 		};
 		return .format(_params);
 	}

Return the specified template from the cache or from loading it if it is not in the cache yet.

Parameters:
templateName
Returns:
Throws:
java.io.IOException
 
	private MessageFormat getTemplate(String templateNamethrows IOException
	{
		MessageFormat _result = null;
		if (!.containsKey(templateName))
		{
			_result = MessageFormatLoader.load(getClass().getResourceAsStream(templateName));
			.put(templateName_result);
		}
		else
		{
			_result = .get(templateName);
		}
		return _result;
	}
	public void outputPropertyJavaCode(PrintWriter outPropertyType propertyTypeProperty propertyBean beanPackage pack,
			BeanSet set)
	{
		// prepare template parameters
		PropertyTypeMap _propertyType = (PropertyTypeMappropertyType;
		String _templateName = getTemplateName(_propertyType.getMode(), property.getMode());
		try
		{
			MessageFormat _template = getTemplate(_templateName);
			Name _name = Name.createFromJavabeanPropertyName(property.getName());
			String _sees = JavadocUtils.generateSee(property);
			String _description = (null != property.getAnnotation()) ? JavadocUtils.concatenateStringArray(property.getAnnotation()
					.getDescription()) : "";
			String _summary = (null != property.getAnnotation()) ? property.getAnnotation().getSummary() : "";
			Object[] _params =
			{
					_name.getAllCaps(),
					_description,
					_sees,
					_summary,
					_propertyType.getImplementation(),
					_propertyType.getParametrizationKey(),
					_propertyType.getParametrizationValue(),
					bean.getName()
			};
			out.println(_template.format(_params));
		}
		catch (IOException _exception)
		{
			throw new IllegalStateException("Error loading template " + _templateName);
		}
	}
New to GrepCode? Check out our FAQ X