Author: scabanovich
Date: 2010-05-17 06:20:56 -0400 (Mon, 17 May 2010)
New Revision: 22114
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintJavaName.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XAttributeImpl.java
Log:
https://jira.jboss.org/browse/JBIDE-6295
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintImpl.java 2010-05-17
09:29:51 UTC (rev 22113)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintImpl.java 2010-05-17
10:20:56 UTC (rev 22114)
@@ -11,13 +11,23 @@
package org.jboss.tools.common.meta.constraint.impl;
import org.w3c.dom.*;
+import org.jboss.tools.common.meta.XAttribute;
import org.jboss.tools.common.meta.constraint.*;
import org.jboss.tools.common.meta.impl.*;
public class XAttributeConstraintImpl extends XMetaElementImpl implements
XAttributeConstraint {
+ /**
+ * It happens that some data useful for constraint, e.g. that attribute is required,
+ * is contained at the attribute object.
+ */
+ protected XAttribute attribute;
public XAttributeConstraintImpl() {}
+ public void setAttribute(XAttribute attribute) {
+ this.attribute = attribute;
+ }
+
public boolean accepts(String value){
return true;
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintJavaName.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintJavaName.java 2010-05-17
09:29:51 UTC (rev 22113)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintJavaName.java 2010-05-17
10:20:56 UTC (rev 22114)
@@ -65,7 +65,7 @@
}
public String getError(String value) {
- return (value.length() == 0) ? ModelMessages.CONSTRAINT_NONEMPTY :
+ return (value.length() == 0) ? (isRequired() ? ModelMessages.CONSTRAINT_NONEMPTY
: null) :
accepts(value) ? null :
(keytable.contains(value)) ? ModelMessages.CONSTRAINT_NO_JAVA_KEYWORD :
(!allowPrimitiveTypes && primitiveSet.contains(value)) ?
ModelMessages.CONSTRAINT_NO_JAVA_KEYWORD :
@@ -73,6 +73,10 @@
ModelMessages.CONSTRAINT_JAVA_NAME;
}
+ boolean isRequired() {
+ return attribute != null &&
"always".equals(attribute.getProperty("save")); //$NON-NLS-1$
//$NON-NLS-2$
+ }
+
public String getCorrectedValue(String value) {
if(value == null || value.length() == 0) return null;
if(XModelObjectConstants.TRUE.equals(getProperties().getProperty("acceptIncorrect")))
return value; //$NON-NLS-1$
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XAttributeImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XAttributeImpl.java 2010-05-17
09:29:51 UTC (rev 22113)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XAttributeImpl.java 2010-05-17
10:20:56 UTC (rev 22114)
@@ -23,7 +23,7 @@
protected XAttributeEditor m_Editor;
protected String m_DefValue;
protected boolean m_Visible;
- protected ConstraintHolder constraint = new ConstraintHolder();
+ protected ConstraintHolder constraint = new ConstraintHolder(this);
protected boolean m_Required;
protected boolean m_Editable;
protected boolean trimmable;
@@ -256,11 +256,14 @@
}
class ConstraintHolder {
+ XAttributeImpl attribute;
private XAttributeConstraint constraint;
private String loader;
private Element element;
- public ConstraintHolder() {}
+ public ConstraintHolder(XAttributeImpl attribute) {
+ this.attribute = attribute;
+ }
public void init(String loader, Element element) {
this.loader = loader;
@@ -291,6 +294,9 @@
}
if(constraint == null) constraint = new XAttributeConstraintImpl();
+ if(constraint instanceof XAttributeConstraintImpl) {
+ ((XAttributeConstraintImpl)constraint).setAttribute(attribute);
+ }
if(element != null)
((XAttributeConstraintImpl)constraint).load(element);
loader = null;