Author: objectiser
Date: 2008-08-27 11:20:34 -0400 (Wed, 27 Aug 2008)
New Revision: 281
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/util/PropertyUtil.java
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/Messages.properties
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/PerformAction.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/SetStateAction.java
Log:
Added checks for 'parentProperty' on PerformAction to ensure that the property is
writable and is of the correct type. Refactored property checking into separate utility
class and updated SetStateAction to use this.
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/Messages.properties
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/Messages.properties 2008-08-27
13:37:24 UTC (rev 280)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/Messages.properties 2008-08-27
15:20:34 UTC (rev 281)
@@ -20,6 +20,7 @@
_CANNOT_INITIATE_NON_ROOT=Cannot 'initiate' non-root service descriptor for
category '{0}' and name '{1}'
_CANNOT_SESSION_BASED_ACTIONS_WITH_ROUTER=Cannot define MessageRouterAction with session
based actions in service descriptor
_IF_ORDER_WRONG=IfAction must have an 'if' path, followed by zero or more
'elseif' paths and ending with an optional 'else' path
+_INVALID_PROPERTY_TYPE=Property '{0}' on class '{1}' must be of type
'{2}'
_MISMATCH_SESSION_CLASS=Session class mismatch with service descriptor for category
'{0}' and name '{1}'
_MULTIPLE_JOINS=Action has multiple joins
_MUST_DEFINE_SINGLE_WHILE_PATH=While action must have a single 'while' path
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/PerformAction.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/PerformAction.java 2008-08-27
13:37:24 UTC (rev 280)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/PerformAction.java 2008-08-27
15:20:34 UTC (rev 281)
@@ -18,6 +18,7 @@
package org.jboss.tools.overlord.cdl.jbossesb.model.actions;
import org.jboss.tools.overlord.cdl.jbossesb.model.*;
+import org.jboss.tools.overlord.cdl.jbossesb.model.util.PropertyUtil;
import org.scribble.model.*;
import org.scribble.conversation.model.*;
@@ -33,6 +34,7 @@
public static final String RETURN_SERVICE_NAME = "returnServiceName";
public static final String RETURN_SERVICE_CATEGORY = "returnServiceCategory";
public static final String BIND_DETAILS = "bindDetails";
+ public static final String PARENT_PROPERTY = "parentProperty";
/**
* The constructor for the action.
@@ -120,6 +122,7 @@
ret.add(RETURN_SERVICE_NAME);
ret.add(RETURN_SERVICE_CATEGORY);
ret.add(BIND_DETAILS);
+ ret.add(PARENT_PROPERTY);
return(ret);
}
@@ -143,6 +146,40 @@
"_NOT_FOUND_PERFORM_CREATE_SESSION",
new String[]{}), null);
}
+
+ // Check if performed service has relevant bind
+ // and parent properties
+ if (m_service.getSessionClass() != null &&
+ hasProperty(PARENT_PROPERTY)) {
+ String parentProperty=getPropertyValue(PARENT_PROPERTY);
+
+ if (PropertyUtil.hasWritableProperty(m_service.getSessionClass(),
+ parentProperty) == false) {
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.cdl.jbossesb.model.actions.Messages"),
+ "_NOT_WRITABLE_PROPERTY",
+ new String[]{parentProperty,
+ m_service.getSessionClass().getName()}), null);
+ }
+
+
+ Class<?> parentCls=PropertyUtil.getPropertyType(
+ m_service.getSessionClass(), parentProperty);
+
+ if (parentCls != null && getService() != null &&
+ getService().getSessionClass() != null &&
+ parentCls != getService().getSessionClass()) {
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.cdl.jbossesb.model.actions.Messages"),
+ "_INVALID_PROPERTY_TYPE",
+ new String[]{parentProperty,
+ m_service.getSessionClass().getName(),
+ getService().getSessionClass().getName()}), null);
+ }
+
+ }
}
}
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/SetStateAction.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/SetStateAction.java 2008-08-27
13:37:24 UTC (rev 280)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/actions/SetStateAction.java 2008-08-27
15:20:34 UTC (rev 281)
@@ -20,6 +20,7 @@
import java.util.logging.Logger;
import org.jboss.tools.overlord.cdl.jbossesb.model.*;
+import org.jboss.tools.overlord.cdl.jbossesb.model.util.PropertyUtil;
import org.scribble.model.*;
/**
@@ -89,67 +90,46 @@
java.util.StringTokenizer st=new java.util.StringTokenizer(variable, ".");
- while (st.hasMoreTokens()) {
+ while (cls != null && st.hasMoreTokens()) {
String token=st.nextToken();
if (cls != null) {
- try {
- java.beans.BeanInfo bi=java.beans.Introspector.getBeanInfo(cls);
+ if (PropertyUtil.isProperty(cls, token) == false) {
- java.beans.PropertyDescriptor[] pds=bi.getPropertyDescriptors();
- java.beans.PropertyDescriptor pd=null;
-
- for (int i=0; pd == null && pds != null &&
- i < pds.length; i++) {
- if (pds[i].getName().equals(token)) {
- pd = pds[i];
- }
- }
-
- if (pd == null) {
-
- if (variable.equals(token)) {
- l.error(this, org.scribble.util.MessageUtil.format(
- java.util.PropertyResourceBundle.getBundle(
- "org.jboss.tools.overlord.cdl.jbossesb.model.actions.Messages"),
- "_NOT_FOUND_VARIABLE",
- new String[]{variable, cls.getName()}), null);
- } else {
- l.error(this, org.scribble.util.MessageUtil.format(
- java.util.PropertyResourceBundle.getBundle(
- "org.jboss.tools.overlord.cdl.jbossesb.model.actions.Messages"),
- "_NOT_FOUND_VARIABLE_PROPERTY",
- new String[]{variable, token, cls.getName()}), null);
- }
- } else if (st.hasMoreTokens()) {
- // Check property can be read
- if (pd.getReadMethod() == null) {
- l.error(this, org.scribble.util.MessageUtil.format(
- java.util.PropertyResourceBundle.getBundle(
- "org.jboss.tools.overlord.cdl.jbossesb.model.actions.Messages"),
- "_NOT_READABLE_PROPERTY",
- new String[]{pd.getName(), cls.getName()}), null);
- }
+ if (variable.equals(token)) {
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.cdl.jbossesb.model.actions.Messages"),
+ "_NOT_FOUND_VARIABLE",
+ new String[]{variable, cls.getName()}), null);
} else {
- // Check property can be written
- if (pd.getWriteMethod() == null) {
- l.error(this, org.scribble.util.MessageUtil.format(
- java.util.PropertyResourceBundle.getBundle(
- "org.jboss.tools.overlord.cdl.jbossesb.model.actions.Messages"),
- "_NOT_WRITABLE_PROPERTY",
- new String[]{pd.getName(), cls.getName()}), null);
- }
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.cdl.jbossesb.model.actions.Messages"),
+ "_NOT_FOUND_VARIABLE_PROPERTY",
+ new String[]{variable, token, cls.getName()}), null);
}
-
- if (pd != null) {
- cls = pd.getPropertyType();
+ } else if (st.hasMoreTokens()) {
+ // Check property can be read
+ if (!PropertyUtil.hasReadableProperty(cls, token)) {
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.cdl.jbossesb.model.actions.Messages"),
+ "_NOT_READABLE_PROPERTY",
+ new String[]{token, cls.getName()}), null);
}
- } catch(Exception e) {
- logger.log(java.util.logging.Level.SEVERE,
- "Failed to check if variable '"+
- variable+"' exists on session class '"+
- cls+"'", e);
+ } else {
+ // Check property can be written
+ if (!PropertyUtil.hasWritableProperty(cls, token)) {
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.cdl.jbossesb.model.actions.Messages"),
+ "_NOT_WRITABLE_PROPERTY",
+ new String[]{token, cls.getName()}), null);
+ }
}
+
+ cls = PropertyUtil.getPropertyType(cls, token);
}
}
}
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/util/PropertyUtil.java
===================================================================
---
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/util/PropertyUtil.java
(rev 0)
+++
cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.jbossesb/src/java/org/jboss/tools/overlord/cdl/jbossesb/model/util/PropertyUtil.java 2008-08-27
15:20:34 UTC (rev 281)
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2005-8 Pi4 Technologies Ltd
+ *
+ * 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.
+ *
+ *
+ * Change History:
+ * 27 Aug 2008 : Initial version created by gary
+ */
+package org.jboss.tools.overlord.cdl.jbossesb.model.util;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class PropertyUtil {
+
+ /**
+ * This method determines whether the supplied class has
+ * a writable property associated with the specified name.
+ *
+ * @param type The class to be checked
+ * @param prop The property
+ * @return Whether the class has a writable property
+ */
+ public static boolean isProperty(Class<?> type, String prop) {
+ boolean ret=false;
+
+ java.beans.PropertyDescriptor pd=getPropertyDescriptor(type, prop);
+ if (pd != null) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method determines whether the supplied class has
+ * a writable property associated with the specified name.
+ *
+ * @param type The class to be checked
+ * @param prop The property
+ * @return Whether the class has a writable property
+ */
+ public static boolean hasWritableProperty(Class<?> type, String prop) {
+ boolean ret=false;
+
+ java.beans.PropertyDescriptor pd=getPropertyDescriptor(type, prop);
+ if (pd != null && pd.getWriteMethod() != null) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method determines whether the supplied class has
+ * a readable property associated with the specified name.
+ *
+ * @param type The class to be checked
+ * @param prop The property
+ * @return Whether the class has a readable property
+ */
+ public static boolean hasReadableProperty(Class<?> type, String prop) {
+ boolean ret=false;
+
+ java.beans.PropertyDescriptor pd=getPropertyDescriptor(type, prop);
+ if (pd != null && pd.getReadMethod() != null) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the type of the property associated
+ * with the supplied class and property name.
+ *
+ * @param type The class to be checked
+ * @param prop The property
+ * @return The type of the property, or null if not found
+ */
+ public static Class<?> getPropertyType(Class<?> type, String prop) {
+ Class<?> ret=null;
+
+ java.beans.PropertyDescriptor pd=getPropertyDescriptor(type, prop);
+ if (pd != null) {
+ ret = pd.getPropertyType();
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the property descriptor with the
+ * supplied name on the supplied class.
+ *
+ * @param type The class
+ * @param prop The property name
+ * @return The property descriptor, or null if not found
+ */
+ protected static java.beans.PropertyDescriptor getPropertyDescriptor(Class<?>
type, String prop) {
+ java.beans.PropertyDescriptor ret=null;
+
+ try {
+ java.beans.BeanInfo bi=java.beans.Introspector.getBeanInfo(type);
+
+ java.beans.PropertyDescriptor[] pds=bi.getPropertyDescriptors();
+
+ for (int i=0; ret == null && pds != null &&
+ i < pds.length; i++) {
+ if (pds[i].getName().equals(prop)) {
+ ret = pds[i];
+ }
+ }
+
+ } catch(Exception e) {
+ logger.log(Level.SEVERE, "Failed to find property '"+prop+
+ "' on class '"+type+"'", e);
+ }
+
+ return(ret);
+ }
+
+ private static Logger logger =
Logger.getLogger("org.jboss.tools.overlord.cdl.jbossesb.model.util");
+}