private static Attribute createAttribute(Map<String, String> beanAttr) throws InternalErrorException { if (beanAttr == null) return null; Attribute attribute = new Attribute(); attribute.setId(Integer.valueOf(beanAttr.get("id")).intValue()); attribute.setFriendlyName(BeansUtils.eraseEscaping(beanAttr.get("friendlyName"))); attribute.setNamespace(BeansUtils.eraseEscaping(beanAttr.get("namespace"))); attribute.setType(BeansUtils.eraseEscaping(beanAttr.get("type"))); attribute.setValue( BeansUtils.stringToAttributeValue( BeansUtils.eraseEscaping(beanAttr.get("value")), attribute.getType())); return attribute; }
/** * Called by Java2XML * * @return Attributes with enough information to be saved to a project file */ public List getAttributes() { ArrayList persistentAttributes = new ArrayList(); for (int i = 0; i < super.getAttributeCount(); i++) { // if(super.getAttributeType(i)==AttributeType.GEOMETRY) continue; Attribute attribute = new Attribute(); attribute.setName(super.getAttributeName(i)); attribute.setType(super.getAttributeType(i).toString()); attribute.setColumn(getColumnByAttribute(super.getAttributeName(i))); attribute.setAccessType((String) attributeAccess.get(i)); persistentAttributes.add(attribute); } return persistentAttributes; }
private void loadAttributesFromClass(Class<?> componentClass) { PropertyDescriptor[] descriptors = null; try { descriptors = Introspector.getBeanInfo(componentClass).getPropertyDescriptors(); } catch (IntrospectionException e) { logger.error("Could not get a list with attributes of class" + componentClass); attributes = Collections.emptyMap(); } attributes = new TreeMap<String, Attribute>(); // not all attributes of given class are needed Set<String> excludeSet = getExcludeSet(); Attribute attribute = null; // create list of all attributes and their types for (PropertyDescriptor descriptor : descriptors) { if (!excludeSet.contains(descriptor.getName())) { attribute = new Attribute(descriptor.getName()); attribute.setType(descriptor.getPropertyType()); attributes.put(descriptor.getName(), attribute); } } }
void insertAttribute(String line) { int indexL, indexR; String type; // Treating string and declaring a string tokenizer line.replace("{", " {"); // line.replace ("["," ["); // System.out.println (" > Processing line: "+ line ); StringTokenizer st = new StringTokenizer(line, " [{\t"); // Disregarding the first token. It is @attribute st.nextToken(); Attribute at = new Attribute(); at.setName(st.nextToken().trim()); // System.out.println ( " > Attribute name: "+ at.getName() ); // Next action depends on the type of attribute: continuous or nominal if (!st.hasMoreTokens()) { // Parsing a nominal attribute with no definition of values // System.out.println (" > Parsing nominal attribute without values "); at.setType(Attribute.NOMINAL); } else if (line.indexOf("{") != -1) { // Parsing a nominal attribute // System.out.println (" > Parsing nominal attribute with values: "+line ); at.setType(Attribute.NOMINAL); at.setFixedBounds(true); indexL = line.indexOf("{"); indexR = line.indexOf("}"); // System.out.println ( " > The Nominal values are: " + line.substring( indexL+1, indexR) // ); StringTokenizer st2 = new StringTokenizer(line.substring(indexL + 1, indexR), ","); while (st2.hasMoreTokens()) { at.addNominalValue(st2.nextToken().trim()); } } else { // Parsing an integer or real type = st.nextToken().trim(); // System.out.println (" > Parsing "+ type + " attributes"); if (type.equalsIgnoreCase("integer")) at.setType(Attribute.INTEGER); if (type.equalsIgnoreCase("real")) at.setType(Attribute.REAL); indexL = line.indexOf("["); indexR = line.indexOf("]"); if (indexL != -1 && indexR != -1) { // System.out.println ( " > The real values are: " + line.substring( indexL+1, indexR) // ); StringTokenizer st2 = new StringTokenizer(line.substring(indexL + 1, indexR), ","); double min = Double.parseDouble(st2.nextToken().trim()); double max = Double.parseDouble(st2.nextToken().trim()); at.setBounds(min, max); } } Attributes.addAttribute(at); } // end insertAttribute