Home | History | Annotate | Download | only in dom
      1 /*
      2 * Copyright (C) 2012 The Android Open Source Project
      3 *
      4 * Licensed under the Apache License, Version 2.0 (the "License");
      5 * you may not use this file except in compliance with the License.
      6 * You may obtain a copy of the License at
      7 *
      8 *      http://www.apache.org/licenses/LICENSE-2.0
      9 *
     10 * Unless required by applicable law or agreed to in writing, software
     11 * distributed under the License is distributed on an "AS IS" BASIS,
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 * See the License for the specific language governing permissions and
     14 * limitations under the License.
     15 */
     16 package com.motorola.studio.android.model.manifest.dom;
     17 
     18 import java.util.Map;
     19 
     20 import org.eclipse.core.runtime.Assert;
     21 
     22 /**
     23  * Abstract class to be used to create nodes that contains the properties
     24  * "icon", "label" and "name"
     25  */
     26 public abstract class AbstractIconLabelNameNode extends AndroidManifestNode implements
     27         IAndroidManifestProperties
     28 {
     29     static
     30     {
     31         // Adds the node properties to the list
     32         defaultProperties.add(PROP_ICON);
     33         defaultProperties.add(PROP_LABEL);
     34         defaultProperties.add(PROP_NAME);
     35     }
     36 
     37     /**
     38      * The icon property
     39      */
     40     protected String propIcon = null;
     41 
     42     /**
     43      * The label property
     44      */
     45     protected String propLabel = null;
     46 
     47     /**
     48      * The name property
     49      */
     50     protected String propName = null;
     51 
     52     /**
     53      * Default constructor
     54      *
     55      * @param name The name property. It must not be null.
     56      * @param newProperties The new properties that are accepted by the child class
     57      */
     58     protected AbstractIconLabelNameNode(String name)
     59     {
     60         Assert.isLegal(name != null);
     61 
     62         this.propName = name;
     63     }
     64 
     65     /* (non-Javadoc)
     66      * @see com.motorola.studio.android.model.manifest.dom.AndroidManifestNode#isNodeValid()
     67      */
     68     @Override
     69     protected boolean isNodeValid()
     70     {
     71         return propName.trim().length() > 0;
     72     }
     73 
     74     /* (non-Javadoc)
     75      * @see com.motorola.studio.android.model.manifest.dom.AndroidManifestNode#getNodeProperties()
     76      */
     77     @Override
     78     public Map<String, String> getNodeProperties()
     79     {
     80         properties.clear();
     81 
     82         if ((propName != null) && (propName.trim().length() > 0))
     83         {
     84             properties.put(PROP_NAME, propName);
     85         }
     86 
     87         if ((propIcon != null) && (propIcon.trim().length() > 0))
     88         {
     89             properties.put(PROP_ICON, propIcon);
     90         }
     91 
     92         if ((propLabel != null) && (propLabel.trim().length() > 0))
     93         {
     94             properties.put(PROP_LABEL, propLabel);
     95         }
     96 
     97         addAdditionalProperties();
     98 
     99         return properties;
    100     }
    101 
    102     /**
    103      * Adds the additional properties to the properties variable
    104      */
    105     protected abstract void addAdditionalProperties();
    106 
    107     /**
    108      * Gets the icon property value
    109      *
    110      * @return the icon property value
    111      */
    112     public String getIcon()
    113     {
    114         return propIcon;
    115     }
    116 
    117     /**
    118      * Sets the icon property value. Set it to null to remove it.
    119      *
    120      * @param icon the icon property value
    121      */
    122     public void setIcon(String icon)
    123     {
    124         this.propIcon = icon;
    125     }
    126 
    127     /**
    128      * Gets the label property value
    129      *
    130      * @return the label property value
    131      */
    132     public String getLabel()
    133     {
    134         return propLabel;
    135     }
    136 
    137     /**
    138      * Sets the label property value. Set it to null to remove it.
    139      *
    140      * @param label the label property value
    141      */
    142     public void setLabel(String label)
    143     {
    144         this.propLabel = label;
    145     }
    146 
    147     /**
    148      * Gets the name property value
    149      *
    150      * @return the name property value
    151      */
    152     public String getName()
    153     {
    154         return propName;
    155     }
    156 
    157     /**
    158      * Sets the name property value. It must not be set to null.
    159      *
    160      * @param name the name property value
    161      */
    162     public void setName(String name)
    163     {
    164         Assert.isLegal(name != null);
    165         this.propName = name;
    166     }
    167 }
    168