blob: f7ab8b7ceb1862a30bcb59d1c6a089990c21251e [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007, 2009 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Contributors:
* Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.core.internal.context.persistence;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode;
import org.eclipse.jpt.core.resource.persistence.XmlProperty;
import org.eclipse.jpt.core.utility.TextRange;
/**
* Straightforward implementation of the persistence unit property.
* Notifies the persistence unit of any changes to the property.
*/
public class GenericPersistenceUnitProperty
extends AbstractXmlContextNode
implements PersistenceUnit.Property
{
protected XmlProperty xmlProperty;
protected String name;
protected String value;
public GenericPersistenceUnitProperty(PersistenceUnit parent, XmlProperty xmlProperty) {
super(parent);
this.initialize(xmlProperty);
}
protected void initialize(XmlProperty xp) {
this.xmlProperty = xp;
this.name = xp.getName();
this.value = xp.getValue();
}
@Override
public PersistenceUnit getParent() {
return (PersistenceUnit) super.getParent();
}
// ********** name **********
public String getName() {
return this.name;
}
public void setName(String name) {
String old = this.name;
this.name = name;
this.xmlProperty.setName(name);
this.firePropertyChanged(NAME_PROPERTY, old, name);
}
// ********** value **********
public String getValue() {
return this.value;
}
public void setValue(String value) {
String old = this.value;
this.value = value;
this.xmlProperty.setValue(value);
this.firePropertyChanged(VALUE_PROPERTY, old, value);
}
// ********** updating **********
public void update(XmlProperty xp) {
this.xmlProperty = xp;
this.setName(xp.getName());
this.setValue(xp.getValue());
}
// ********** validation **********
public TextRange getValidationTextRange() {
return this.xmlProperty.getValidationTextRange();
}
// ********** misc **********
@Override
public void toString(StringBuilder sb) {
sb.append(this.name);
sb.append(" = "); //$NON-NLS-1$
sb.append(this.value);
}
}