[jbosstools-commits] JBoss Tools SVN: r22883 - in branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta: impl and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Jun 18 11:08:53 EDT 2010


Author: scabanovich
Date: 2010-06-18 11:08:53 -0400 (Fri, 18 Jun 2010)
New Revision: 22883

Modified:
   branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintImpl.java
   branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintJavaName.java
   branches/jbosstools-3.1.x/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: branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintImpl.java
===================================================================
--- branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintImpl.java	2010-06-18 14:36:27 UTC (rev 22882)
+++ branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintImpl.java	2010-06-18 15:08:53 UTC (rev 22883)
@@ -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;
     }
@@ -36,4 +46,3 @@
     }
 
 }
-

Modified: branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintJavaName.java
===================================================================
--- branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintJavaName.java	2010-06-18 14:36:27 UTC (rev 22882)
+++ branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/constraint/impl/XAttributeConstraintJavaName.java	2010-06-18 15:08:53 UTC (rev 22883)
@@ -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$
@@ -91,4 +95,3 @@
 
 
 }
-

Modified: branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XAttributeImpl.java
===================================================================
--- branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XAttributeImpl.java	2010-06-18 14:36:27 UTC (rev 22882)
+++ branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XAttributeImpl.java	2010-06-18 15:08:53 UTC (rev 22883)
@@ -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;
@@ -298,4 +304,4 @@
 		this.constraint = constraint;
 	}
 
-}
+}
\ No newline at end of file



More information about the jbosstools-commits mailing list