public PropertyAction(RADProperty<?> aProperty) { super(); property = (RADProperty<Object>) aProperty; String name = (String) aProperty.getValue("actionName"); // NOI18N if (name == null) { StringBuilder sb = new StringBuilder(aProperty.getName()); sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); name = sb.toString(); } putValue(Action.NAME, name); }
/** * Adds to the given list of property descriptors the mapped properties, ie. properties that have * a getter method taking a single String value as a parameter. * * @param clazz to introspect * @param result is the list to add to */ protected static void addMappedProperties(Class clazz, List<InternalEventPropDescriptor> result) { Set<String> uniquePropertyNames = new HashSet<String>(); Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { String methodName = methods[i].getName(); if (!methodName.startsWith("get")) { continue; } String inferredName = methodName.substring(3, methodName.length()); if (inferredName.length() == 0) { continue; } Class<?> parameterTypes[] = methods[i].getParameterTypes(); if (parameterTypes.length != 1) { continue; } if (parameterTypes[0] != String.class) { continue; } String newInferredName = null; // Leave uppercase inferred names such as URL if (inferredName.length() >= 2) { if ((Character.isUpperCase(inferredName.charAt(0))) && (Character.isUpperCase(inferredName.charAt(1)))) { newInferredName = inferredName; } } // camelCase the inferred name if (newInferredName == null) { newInferredName = Character.toString(Character.toLowerCase(inferredName.charAt(0))); if (inferredName.length() > 1) { newInferredName += inferredName.substring(1, inferredName.length()); } } inferredName = newInferredName; // if the property inferred name already exists, don't supply it if (uniquePropertyNames.contains(inferredName)) { continue; } result.add( new InternalEventPropDescriptor(inferredName, methods[i], EventPropertyType.MAPPED)); uniquePropertyNames.add(inferredName); } }
/** * Set the fields from the ProjectionClass * * @param projClass projection class to use */ private void setFieldsWithClassParams(ProjectionClass projClass) { // set the projection in the JComboBox String want = projClass.toString(); for (int i = 0; i < projClassCB.getItemCount(); i++) { ProjectionClass pc = (ProjectionClass) projClassCB.getItemAt(i); if (pc.toString().equals(want)) { projClassCB.setSelectedItem((Object) pc); break; } } // set the parameter fields paramPanel.removeAll(); paramPanel.setVisible(0 < projClass.paramList.size()); List widgets = new ArrayList(); for (int i = 0; i < projClass.paramList.size(); i++) { ProjectionParam pp = (ProjectionParam) projClass.paramList.get(i); // construct the label String name = pp.name; String text = ""; // Create a decent looking label for (int cIdx = 0; cIdx < name.length(); cIdx++) { char c = name.charAt(cIdx); if (cIdx == 0) { c = Character.toUpperCase(c); } else { if (Character.isUpperCase(c)) { text += " "; c = Character.toLowerCase(c); } } text += c; } widgets.add(GuiUtils.rLabel(text + ": ")); // text input field JTextField tf = new JTextField(); pp.setTextField(tf); tf.setColumns(12); widgets.add(tf); } GuiUtils.tmpInsets = new Insets(4, 4, 4, 4); JPanel widgetPanel = GuiUtils.doLayout(widgets, 2, GuiUtils.WT_N, GuiUtils.WT_N); paramPanel.add("North", widgetPanel); paramPanel.add("Center", GuiUtils.filler()); }
private static String getGetterSetterMethodName(String propertyName, String operation) { StringWriter writer = new StringWriter(); writer.write(operation); writer.write(Character.toUpperCase(propertyName.charAt(0))); writer.write(propertyName.substring(1)); return writer.toString(); }
/** * Returns true if two names match without regard to case or the presence of '-' or '_' * characters. * * @param beanName The name of the bean property to compare * @param elementName The name of the element to compare * @return True if the names match */ public static boolean namesMatch(String beanName, String elementName) { int beanNameLen = beanName.length(); int elementNameLen = elementName.length(); int elementPos = 0; int beanPos = 0; // Keep looping until you hit the end of either of the strings while ((elementPos < elementNameLen) && (beanPos < beanNameLen)) { // If the next character in the bean name is a '-' or a '/', skip it char beanCh = Character.toLowerCase(beanName.charAt(beanPos)); if ((beanCh == '-') || (beanCh == '_')) { beanPos++; continue; } // If the next character in the element name is a '-' or a '/', skip it char elementCh = Character.toLowerCase(elementName.charAt(elementPos)); if ((elementCh == '-') || (elementCh == '_')) { elementPos++; continue; } // If the characters don't match, the names don't match if (elementCh != beanCh) return false; elementPos++; beanPos++; } // You hit the end of both names at the same time, the names match if ((elementPos == elementNameLen) && (beanPos == beanNameLen)) { return true; } return false; }
public void keyReleased(KeyEvent e) { char ch = e.getKeyChar(); if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)) return; int pos = m_editor.getCaretPosition(); String str = m_editor.getText(); if (str.length() == 0) return; for (int k = 0; k < m_comboBox.getItemCount(); k++) { String item = m_comboBox.getItemAt(k).toString(); if (item.startsWith(str)) { m_editor.setText(item); m_editor.setCaretPosition(item.length()); m_editor.moveCaretPosition(pos); m_comboBox.setSelectedItem(item); break; } } }
private Object createObject( Node node, String name, String classPackage, String type, String value, boolean setProperty) { Bean parentBean = null; if (beansStack.size() > 0) parentBean = (Bean) beansStack.peek(); Object object = null; // param is either an XSD type or a bean, // check if it can be converted to an XSD type XSDatatype dt = null; try { dt = DatatypeFactory.getTypeByName(type); } catch (DatatypeException dte) { // the type is not a valid XSD data type } // convert null value to default if ((dt != null) && (value == null)) { Class objType = dt.getJavaObjectType(); if (objType == String.class) value = ""; else if ((objType == java.math.BigInteger.class) || (objType == Long.class) || (objType == Integer.class) || (objType == Short.class) || (objType == Byte.class)) value = "0"; else if ((objType == java.math.BigDecimal.class) || (objType == Double.class) || (objType == Float.class)) value = "0.0"; else if (objType == Boolean.class) value = "false"; else if (objType == java.util.Date.class) value = DateUtils.getCurrentDate(); else if (objType == java.util.Calendar.class) value = DateUtils.getCurrentDateTime(); } // check whether the type was converted to an XSD datatype if ((dt != null) && dt.isValid(value, null)) { // create and return an XSD Java object (e.g. String, Integer, Boolean, etc) object = dt.createJavaObject(value, null); if (object instanceof java.util.Calendar) { // check that the object is truly a Calendar // because DatatypeFactory converts xsd:date // types to GregorianCalendar instead of Date. if (type.equals("date")) { java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd"); try { object = df.parse(value); } catch (java.text.ParseException pe) { object = new java.util.Date(); } } } } else { // Create a bean object if (topLevelBean == null) topLevelBean = parentBean; object = pushBeanOnStack(classPackage, type); // Check fields to see if this property is the 'value' for the object Field[] fields = object.getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { if (fields[i].isAnnotationPresent(ObjectXmlAsValue.class)) { try { StringBuffer fieldName = new StringBuffer(fields[i].getName()); char c = fieldName.charAt(0); if (c >= 'a' && c <= 'z') { c += 'A' - 'a'; } fieldName.setCharAt(0, c); fieldName.insert(0, "set"); Method method = object .getClass() .getMethod(fieldName.toString(), new Class[] {fields[i].getType()}); method.invoke(object, value); break; } catch (Exception e) { System.err.println(e.getMessage()); } } } NamedNodeMap nodeAttrs = node.getAttributes(); // iterate attributes and set field values for property attributes for (int i = 0; i < nodeAttrs.getLength(); i++) { String nodePrefix = nodeAttrs.item(i).getPrefix(); if (nodePrefix.equals(nsPrefix)) { String nodeName = nodeAttrs.item(i).getLocalName(); String nodeValue = nodeAttrs.item(i).getNodeValue(); try { Field field = object.getClass().getDeclaredField(nodeName); if (field.isAnnotationPresent(ObjectXmlAsAttribute.class)) { StringBuffer fieldName = new StringBuffer(field.getName()); char c = fieldName.charAt(0); if (c >= 'a' && c <= 'z') { c += 'A' - 'a'; } fieldName.setCharAt(0, c); fieldName.insert(0, "set"); Method method = object.getClass().getMethod(fieldName.toString(), new Class[] {field.getType()}); if (field.getType() == String.class) method.invoke(object, nodeValue); else if (field.getType() == Boolean.TYPE) method.invoke(object, StringUtils.strToBool(nodeValue, "true")); else if (field.getType() == Byte.TYPE) method.invoke(object, Byte.valueOf(nodeValue).byteValue()); else if (field.getType() == Character.TYPE) method.invoke(object, Character.valueOf(nodeValue.charAt(0))); else if (field.getType() == Double.TYPE) method.invoke(object, Double.valueOf(nodeValue).doubleValue()); else if (field.getType() == Float.TYPE) method.invoke(object, Float.valueOf(nodeValue).floatValue()); else if (field.getType() == Integer.TYPE) method.invoke(object, Integer.valueOf(nodeValue).intValue()); else if (field.getType() == Long.TYPE) method.invoke(object, Long.valueOf(nodeValue).longValue()); else if (field.getType() == Short.TYPE) method.invoke(object, Short.valueOf(nodeValue).shortValue()); } } catch (Exception e) { System.err.println(e.getMessage()); } } } } if ((parentBean != null) && (setProperty)) { parentBean.setProperty(name, object); } return object; }
public void setPattern(String globPattern) { char[] gPat = globPattern.toCharArray(); char[] rPat = new char[gPat.length * 2]; boolean isWin32 = (File.separatorChar == '\\'); boolean inBrackets = false; int j = 0; this.globPattern = globPattern; if (isWin32) { // On windows, a pattern ending with *.* is equal to ending with * int len = gPat.length; if (globPattern.endsWith("*.*")) { len -= 2; } for (int i = 0; i < len; i++) { switch (gPat[i]) { case '*': rPat[j++] = '.'; rPat[j++] = '*'; break; case '?': rPat[j++] = '.'; break; case '\\': rPat[j++] = '\\'; rPat[j++] = '\\'; break; default: if ("+()^$.{}[]".indexOf(gPat[i]) >= 0) { rPat[j++] = '\\'; } rPat[j++] = gPat[i]; break; } } } else { for (int i = 0; i < gPat.length; i++) { switch (gPat[i]) { case '*': if (!inBrackets) { rPat[j++] = '.'; } rPat[j++] = '*'; break; case '?': rPat[j++] = inBrackets ? '?' : '.'; break; case '[': inBrackets = true; rPat[j++] = gPat[i]; if (i < gPat.length - 1) { switch (gPat[i + 1]) { case '!': case '^': rPat[j++] = '^'; i++; break; case ']': rPat[j++] = gPat[++i]; break; } } break; case ']': rPat[j++] = gPat[i]; inBrackets = false; break; case '\\': if (i == 0 && gPat.length > 1 && gPat[1] == '~') { rPat[j++] = gPat[++i]; } else { rPat[j++] = '\\'; if (i < gPat.length - 1 && "*?[]".indexOf(gPat[i + 1]) >= 0) { rPat[j++] = gPat[++i]; } else { rPat[j++] = '\\'; } } break; default: // if ("+()|^$.{}<>".indexOf(gPat[i]) >= 0) { if (!Character.isLetterOrDigit(gPat[i])) { rPat[j++] = '\\'; } rPat[j++] = gPat[i]; break; } } } this.pattern = Pattern.compile(new String(rPat, 0, j), Pattern.CASE_INSENSITIVE); }