All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sdmlib.models.transformations.PlaceHolderDescription Maven / Gradle / Ivy

Go to download

SDMLib is a light weight modeling library. SDMLib intentionally comes without any tool or editor.

There is a newer version: 2.3.2341
Show newest version
/*
   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.util.LinkedHashSet;

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.models.transformations.ChoiceTemplate;
import de.uniks.networkparser.interfaces.SendableEntity;
import org.sdmlib.models.transformations.Template;
import org.sdmlib.models.transformations.Match;
   /**
    * 
    * @see ModelToTextToModelClassModel.java
*/
   public class PlaceHolderDescription 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) {
      getPropertyChangeSupport().removePropertyChangeListener(listener);
      return true;
   }

   // ==========================================================================

   public void removeYou()
   {
      setSubTemplate(null);
      withoutOwners(this.getOwners().toArray(new Template[this.getOwners().size()]));
      withoutMatches(this.getMatches().toArray(new Match[this.getMatches().size()]));
      getPropertyChangeSupport().firePropertyChange("REMOVE_YOU", this, null);
   }

   // ==========================================================================

   public static final String PROPERTY_TEXTFRAGMENT = "textFragment";

   private String textFragment;

   public String getTextFragment()
   {
      return this.textFragment;
   }

   public void setTextFragment(String value)
   {
      if (!StrUtil.stringEquals(this.textFragment, value))
      {
         String oldValue = this.textFragment;
         this.textFragment = value;
         getPropertyChangeSupport().firePropertyChange(PROPERTY_TEXTFRAGMENT, oldValue, value);
      }
   }

   public PlaceHolderDescription withTextFragment(String value)
   {
      setTextFragment(value);
      return this;
   }

   @Override
   public String toString()
   {
      StringBuilder result = new StringBuilder();

      result.append(" ").append(this.getTextFragment());
      result.append(" ").append(this.getValue());
      result.append(" ").append(this.getAttrName());
      result.append(" ").append(this.getPrefix());
      return result.substring(1);
   }

   // ==========================================================================

   public static final String PROPERTY_VALUE = "value";

   private String value;

   public String getValue()
   {
      return this.value;
   }

   public void setValue(String value)
   {
      if (!StrUtil.stringEquals(this.value, value))
      {
         String oldValue = this.value;
         this.value = value;
         getPropertyChangeSupport().firePropertyChange(PROPERTY_VALUE, oldValue, value);
      }
   }

   public PlaceHolderDescription withValue(String value)
   {
      setValue(value);
      return this;
   }

   // ==========================================================================

   public static final String PROPERTY_ATTRNAME = "attrName";

   private String attrName;

   public String getAttrName()
   {
      return this.attrName;
   }

   public void setAttrName(String value)
   {
      if (!StrUtil.stringEquals(this.attrName, value))
      {
         String oldValue = this.attrName;
         this.attrName = value;
         getPropertyChangeSupport().firePropertyChange(PROPERTY_ATTRNAME, oldValue, value);
      }
   }

   public PlaceHolderDescription withAttrName(String value)
   {
      setAttrName(value);
      return this;
   }

   public PlaceHolderDescription with(String fragmentText, String attrName)
   {
      this.setTextFragment(fragmentText);
      this.setAttrName(attrName);

      return this;
   }

   public static final PlaceHolderDescriptionSet EMPTY_SET = new PlaceHolderDescriptionSet();

   // ==========================================================================

   public static final String PROPERTY_ISKEYATTRIBUTE = "isKeyAttribute";

   private boolean isKeyAttribute;

   public boolean getIsKeyAttribute()
   {
      return this.isKeyAttribute;
   }

   public void setIsKeyAttribute(boolean value)
   {
      if (this.isKeyAttribute != value)
      {
         boolean oldValue = this.isKeyAttribute;
         this.isKeyAttribute = value;
         getPropertyChangeSupport().firePropertyChange(PROPERTY_ISKEYATTRIBUTE, oldValue, value);
      }
   }

   public PlaceHolderDescription withIsKeyAttribute(boolean value)
   {
      setIsKeyAttribute(value);
      return this;
   }

   /********************************************************************
    * 
    *              many                       many
    * PlaceHolderDescription ----------------------------------- Template
    *              placeholders                   owners
    * 
*/ public static final String PROPERTY_OWNERS = "owners"; private TemplateSet owners = null; public TemplateSet getOwners() { if (this.owners == null) { return Template.EMPTY_SET; } return this.owners; } public boolean addToOwners(Template value) { boolean changed = false; if (value != null) { if (this.owners == null) { this.owners = new TemplateSet(); } changed = this.owners.add(value); if (changed) { value.withPlaceholders(this); getPropertyChangeSupport().firePropertyChange(PROPERTY_OWNERS, null, value); } } return changed; } public boolean removeFromOwners(Template value) { boolean changed = false; if ((this.owners != null) && (value != null)) { changed = this.owners.remove(value); if (changed) { value.withoutPlaceholders(this); getPropertyChangeSupport().firePropertyChange(PROPERTY_OWNERS, value, null); } } return changed; } public PlaceHolderDescription withOwners(Template... value) { for (Template item : value) { addToOwners(item); } return this; } public PlaceHolderDescription withoutOwners(Template... value) { for (Template item : value) { removeFromOwners(item); } return this; } public void removeAllFromOwners() { LinkedHashSet