org.wso2.developerstudio.eclipse.esb.impl.NamespacedPropertyImpl.java Source code

Java tutorial

Introduction

Here is the source code for org.wso2.developerstudio.eclipse.esb.impl.NamespacedPropertyImpl.java

Source

/*
 * Copyright 2009-2010 WSO2, Inc. (http://wso2.com)
 *
 * Licensed 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 org.wso2.developerstudio.eclipse.esb.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.w3c.dom.Element;
import org.wso2.developerstudio.eclipse.esb.EsbPackage;
import org.wso2.developerstudio.eclipse.esb.NamespacedProperty;
import org.wso2.developerstudio.eclipse.esb.util.ObjectValidator;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Namespaced Property</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.wso2.developerstudio.eclipse.esb.impl.NamespacedPropertyImpl#getPrettyName <em>Pretty Name</em>}</li>
 *   <li>{@link org.wso2.developerstudio.eclipse.esb.impl.NamespacedPropertyImpl#getPropertyName <em>Property Name</em>}</li>
 *   <li>{@link org.wso2.developerstudio.eclipse.esb.impl.NamespacedPropertyImpl#getPropertyValue <em>Property Value</em>}</li>
 *   <li>{@link org.wso2.developerstudio.eclipse.esb.impl.NamespacedPropertyImpl#getNamespaces <em>Namespaces</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class NamespacedPropertyImpl extends ModelObjectImpl implements NamespacedProperty {
    /**
     * The default value of the '{@link #getPrettyName() <em>Pretty Name</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getPrettyName()
     * @generated
     * @ordered
     */
    protected static final String PRETTY_NAME_EDEFAULT = "Namespaced Property";

    /**
     * The cached value of the '{@link #getPrettyName() <em>Pretty Name</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getPrettyName()
     * @generated
     * @ordered
     */
    protected String prettyName = PRETTY_NAME_EDEFAULT;

    /**
     * The default value of the '{@link #getPropertyName() <em>Property Name</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getPropertyName()
     * @generated
     * @ordered
     */
    protected static final String PROPERTY_NAME_EDEFAULT = "propertyName";

    /**
     * The cached value of the '{@link #getPropertyName() <em>Property Name</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getPropertyName()
     * @generated
     * @ordered
     */
    protected String propertyName = PROPERTY_NAME_EDEFAULT;

    /**
     * The default value of the '{@link #getPropertyValue() <em>Property Value</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getPropertyValue()
     * @generated NOT
     * @ordered
     */
    protected static final String PROPERTY_VALUE_EDEFAULT = "";

    /**
     * The cached value of the '{@link #getPropertyValue() <em>Property Value</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getPropertyValue()
     * @generated
     * @ordered
     */
    protected String propertyValue = PROPERTY_VALUE_EDEFAULT;

    /**
     * The cached value of the '{@link #getNamespaces() <em>Namespaces</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getNamespaces()
     * @generated
     * @ordered
     */
    protected Map<String, String> namespaces;

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     */
    protected NamespacedPropertyImpl() {
        super();

        setNamespaces(new HashMap<String, String>());
    }

    /**
     * {@inheritDoc}
     */
    public void doLoad(Element self) throws Exception {
        if (self.hasAttribute(getPropertyName())) {
            setPropertyValue(self.getAttribute(getPropertyName()));
        }

        // Clear namespace declarations.
        getNamespaces().clear();

        // Load all declared additional namespaces on this element.
        Map<String, String> additionalNamespaces = extractNamespaces(self);
        if (!StringUtils.isBlank(self.getPrefix())) {
            // Do not include the namespace corresponding to current element itself.
            additionalNamespaces.remove(self.getPrefix());
        }
        getNamespaces().putAll(additionalNamespaces);

        super.doLoad(self);
    }

    /**
     * {@inheritDoc}
     */
    public Element doSave(Element parent) throws Exception {
        parent.setAttribute(getPropertyName(), getPropertyValue());
        for (Map.Entry<String, String> entry : getNamespaces().entrySet()) {
            parent.setAttribute(String.format("xmlns:%s", entry.getKey()), entry.getValue());
        }
        addComments(parent);
        return parent;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */

    @Override
    protected EClass eStaticClass() {
        return EsbPackage.Literals.NAMESPACED_PROPERTY;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public String getPrettyName() {
        return prettyName;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setPrettyName(String newPrettyName) {
        String oldPrettyName = prettyName;
        prettyName = newPrettyName;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, EsbPackage.NAMESPACED_PROPERTY__PRETTY_NAME,
                    oldPrettyName, prettyName));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public String getPropertyName() {
        return propertyName;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setPropertyName(String newPropertyName) {
        String oldPropertyName = propertyName;
        propertyName = newPropertyName;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, EsbPackage.NAMESPACED_PROPERTY__PROPERTY_NAME,
                    oldPropertyName, propertyName));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public String getPropertyValue() {
        return propertyValue;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setPropertyValue(String newPropertyValue) {
        String oldPropertyValue = propertyValue;
        propertyValue = newPropertyValue;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, EsbPackage.NAMESPACED_PROPERTY__PROPERTY_VALUE,
                    oldPropertyValue, propertyValue));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public Map<String, String> getNamespaces() {
        return namespaces;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setNamespaces(Map<String, String> newNamespaces) {
        Map<String, String> oldNamespaces = namespaces;
        namespaces = newNamespaces;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, EsbPackage.NAMESPACED_PROPERTY__NAMESPACES,
                    oldNamespaces, namespaces));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */

    @Override
    public Object eGet(int featureID, boolean resolve, boolean coreType) {
        switch (featureID) {
        case EsbPackage.NAMESPACED_PROPERTY__PRETTY_NAME:
            return getPrettyName();
        case EsbPackage.NAMESPACED_PROPERTY__PROPERTY_NAME:
            return getPropertyName();
        case EsbPackage.NAMESPACED_PROPERTY__PROPERTY_VALUE:
            return getPropertyValue();
        case EsbPackage.NAMESPACED_PROPERTY__NAMESPACES:
            return getNamespaces();
        }
        return super.eGet(featureID, resolve, coreType);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @SuppressWarnings("unchecked")
    @Override

    public void eSet(int featureID, Object newValue) {
        switch (featureID) {
        case EsbPackage.NAMESPACED_PROPERTY__PRETTY_NAME:
            setPrettyName((String) newValue);
            return;
        case EsbPackage.NAMESPACED_PROPERTY__PROPERTY_NAME:
            setPropertyName((String) newValue);
            return;
        case EsbPackage.NAMESPACED_PROPERTY__PROPERTY_VALUE:
            setPropertyValue((String) newValue);
            return;
        case EsbPackage.NAMESPACED_PROPERTY__NAMESPACES:
            setNamespaces((Map<String, String>) newValue);
            return;
        }
        super.eSet(featureID, newValue);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */

    @Override
    public void eUnset(int featureID) {
        switch (featureID) {
        case EsbPackage.NAMESPACED_PROPERTY__PRETTY_NAME:
            setPrettyName(PRETTY_NAME_EDEFAULT);
            return;
        case EsbPackage.NAMESPACED_PROPERTY__PROPERTY_NAME:
            setPropertyName(PROPERTY_NAME_EDEFAULT);
            return;
        case EsbPackage.NAMESPACED_PROPERTY__PROPERTY_VALUE:
            setPropertyValue(PROPERTY_VALUE_EDEFAULT);
            return;
        case EsbPackage.NAMESPACED_PROPERTY__NAMESPACES:
            setNamespaces((Map<String, String>) null);
            return;
        }
        super.eUnset(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */

    @Override
    public boolean eIsSet(int featureID) {
        switch (featureID) {
        case EsbPackage.NAMESPACED_PROPERTY__PRETTY_NAME:
            return PRETTY_NAME_EDEFAULT == null ? prettyName != null : !PRETTY_NAME_EDEFAULT.equals(prettyName);
        case EsbPackage.NAMESPACED_PROPERTY__PROPERTY_NAME:
            return PROPERTY_NAME_EDEFAULT == null ? propertyName != null
                    : !PROPERTY_NAME_EDEFAULT.equals(propertyName);
        case EsbPackage.NAMESPACED_PROPERTY__PROPERTY_VALUE:
            return PROPERTY_VALUE_EDEFAULT == null ? propertyValue != null
                    : !PROPERTY_VALUE_EDEFAULT.equals(propertyValue);
        case EsbPackage.NAMESPACED_PROPERTY__NAMESPACES:
            return namespaces != null;
        }
        return super.eIsSet(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     */

    public String toString() {
        if (eIsProxy())
            return super.toString();
        StringBuffer result = new StringBuffer();
        result.append(getPropertyValue());
        return result.toString();
    }

    public Map<String, ObjectValidator> validate() {
        // TODO Auto-generated method stub
        return null;
    }

} //NamespacedPropertyImpl