Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
Copyright (c) 2013 zuendorf
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.sdmlib.models.transformations;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import org.sdmlib.CGUtil;
import org.sdmlib.StrUtil;
import org.sdmlib.models.transformations.util.MatchSet;
import org.sdmlib.models.transformations.util.PlaceHolderDescriptionSet;
import org.sdmlib.models.transformations.util.TemplateSet;
import org.sdmlib.serialization.PropertyChangeInterface;
import org.sdmlib.storyboards.GenericCreator;
import org.sdmlib.storyboards.GenericIdMap;
import de.uniks.networkparser.IdMap;
import de.uniks.networkparser.interfaces.SendableEntity;
import de.uniks.networkparser.interfaces.SendableEntityCreator;
import org.sdmlib.models.transformations.ChoiceTemplate;
import org.sdmlib.models.transformations.PlaceHolderDescription;
import org.sdmlib.models.transformations.Match;
/**
*
* @see ModelToTextToModelClassModel.java
*/
public class Template implements PropertyChangeInterface, SendableEntity
{
// ==========================================================================
protected PropertyChangeSupport listeners = new PropertyChangeSupport(this);
@Override
public PropertyChangeSupport getPropertyChangeSupport()
{
return listeners;
}
public boolean addPropertyChangeListener(PropertyChangeListener listener)
{
getPropertyChangeSupport().addPropertyChangeListener(listener);
return true;
}
public boolean addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
getPropertyChangeSupport().addPropertyChangeListener(propertyName, listener);
return true;
}
public boolean removePropertyChangeListener(PropertyChangeListener listener) {
if (listeners != null) {
listeners.removePropertyChangeListener(listener);
}
return true;
}
public boolean removePropertyChangeListener(String property,
PropertyChangeListener listener) {
if (listeners != null) {
listeners.removePropertyChangeListener(property, listener);
}
return true;
}
// ==========================================================================
public void removeYou()
{
setChooser(null);
withoutPlaceholders(this.getPlaceholders().toArray(new PlaceHolderDescription[this.getPlaceholders().size()]));
withoutMatches(this.getMatches().toArray(new Match[this.getMatches().size()]));
withoutParents(this.getParents().toArray(new PlaceHolderDescription[this.getParents().size()]));
firePropertyChange("REMOVE_YOU", this, null);
}
// ==========================================================================
public static final String PROPERTY_TEMPLATETEXT = "templateText";
private String templateText = "";
public String getTemplateText()
{
return this.templateText;
}
public void setTemplateText(String value)
{
if (!StrUtil.stringEquals(this.templateText, value))
{
String oldValue = this.templateText;
this.templateText = value;
getPropertyChangeSupport().firePropertyChange(PROPERTY_TEMPLATETEXT, oldValue, value);
}
}
public Template withTemplateText(String value)
{
setTemplateText(value);
return this;
}
@Override
public String toString()
{
StringBuilder s = new StringBuilder();
s.append(" ").append(this.getTemplateText());
s.append(" ").append(this.getModelClassName());
s.append(" ").append(this.getExpandedText());
s.append(" ").append(this.getListStart());
s.append(" ").append(this.getListSeparator());
s.append(" ").append(this.getListEnd());
s.append(" ").append(this.getName());
return s.substring(1);
}
public Template withSimple(String propertyName)
{
return with("_", "_", propertyName);
}
public Template withReplacements(String... placeholderAttrNamePairs)
{
for (int i = 0; i + 2 <= placeholderAttrNamePairs.length; i += 2)
{
this.createPlaceholders().withTextFragment(placeholderAttrNamePairs[i]).withAttrName(placeholderAttrNamePairs[i + 1]);
}
return this;
}
public Template with(String templateText, String... placeholderAttrNamePairs)
{
this.setTemplateText(templateText);
this.withReplacements(placeholderAttrNamePairs);
return this;
}
public Template withList(String start, String separator, String end)
{
this.setListStart(start);
this.setListSeparator(separator);
this.setListEnd(end);
return this;
}
// ==========================================================================
public static final String PROPERTY_MODELOBJECT = "modelObject";
private Object modelObject;
public Object getModelObject()
{
return this.modelObject;
}
public void setModelObject(Object value)
{
if (this.modelObject != value)
{
Object oldValue = this.modelObject;
this.modelObject = value;
getPropertyChangeSupport().firePropertyChange(PROPERTY_MODELOBJECT, oldValue, value);
}
}
public Template withModelObject(Object value)
{
setModelObject(value);
return this;
}
// ==========================================================================
public static final String PROPERTY_MODELCLASSNAME = "modelClassName";
private String modelClassName;
public String getModelClassName()
{
return this.modelClassName;
}
public void setModelClassName(String value)
{
if (!StrUtil.stringEquals(this.modelClassName, value))
{
String oldValue = this.modelClassName;
this.modelClassName = value;
getPropertyChangeSupport().firePropertyChange(PROPERTY_MODELCLASSNAME, oldValue, value);
}
}
public Template withModelClassName(String value)
{
setModelClassName(value);
return this;
}
public Template createPlaceHolderAndSubTemplate()
{
PlaceHolderDescription placeholder = this.createPlaceholders();
Template subTemplate = placeholder.createSubTemplate();
return subTemplate;
}
// ==========================================================================
public static final String PROPERTY_EXPANDEDTEXT = "expandedText";
private String expandedText;
protected IdMap idMap;
public String getExpandedText()
{
return this.expandedText;
}
public void setExpandedText(String value)
{
if (!StrUtil.stringEquals(this.expandedText, value))
{
String oldValue = this.expandedText;
this.expandedText = value;
getPropertyChangeSupport().firePropertyChange(PROPERTY_EXPANDEDTEXT, oldValue, value);
}
}
public Template withExpandedText(String value)
{
setExpandedText(value);
return this;
}
protected int currentPosInExpandedText = 0;
protected String constFragmentFollowingAfterList;
public int getValueStartPos()
{
return currentPosInExpandedText;
}
public Template withValueStartPos(int valueStartPos)
{
this.currentPosInExpandedText = valueStartPos;
return this;
}
public Match parseOnceNew()
{
this.currentPosInExpandedText = 0;
return parseOnce();
}
public MatchSet parse()
{
MatchSet result = new MatchSet();
if (!isList())
{
Match subMatch = parseOnce();
if (subMatch != null)
{
result.add(subMatch);
}
}
else
{
int oldValueStartPos = 0;
// look for list start
int listStartPos = this.getExpandedText().indexOf(this.getListStart(), currentPosInExpandedText);
if (listStartPos >= 0)
{
currentPosInExpandedText = currentPosInExpandedText + getListStart().length();
LinkedHashSet