/** * Operation parser. Parse the Operation of a CLASS and recursively adds it to the inputed CLASS * before giving back control to the Classe parser. * * @param c The Classe * @return The Classe with the operations * @throws InvalidUMLException */ private Classe parse_operations(Classe c) throws InvalidUMLException { Classe classe = c; Operation operation; ArrayList<Argument> arguments; String name, type; read_token(); // Terminate the operations parsing when there is a semicolon; if (this.current_token.equals(";")) { return classe; } else if (valid_identifier(this.current_token) && !classe.get_operations().isEmpty()) { // Throw an exception if the current token is a valid identifier and the operations array is // not empty. // It means that we are missing a comma. throw new InvalidUMLException("Missing `,` between multiple OPERATIONS"); } else if (this.current_token.equals(",")) { // Read the comma read_token(); } if (!valid_identifier(this.current_token)) throw new InvalidUMLException("Invalid OPERATIONS IDENTIFIER"); name = this.current_token; read_token(); if (!this.current_token.equals("(")) throw new InvalidUMLException("Expecting `(`"); // If the parenthesis is not closed right after the opened one, we need to parse the arguments if (!peek_token().equals(")")) { arguments = parse_arguments(); } else { arguments = new ArrayList<Argument>(); } // Read the closing parenthesis read_token(); // Read the colon read_token(); if (!this.current_token.equals(":")) throw new InvalidUMLException("Expecting `:`"); // Validate the type read_token(); if (!valid_identifier(this.current_token)) throw new InvalidUMLException("Invalid OPERATION type IDENTIFIER"); type = this.current_token; // Create the operation and add it to the class operation = new Operation(name, type, arguments); classe.add_operation(operation); return parse_operations(classe); }
private void constrClasseFormu( Programme prog, StringBuffer buf, int indent, String msg, String p_pere, Argument arg) { this.constrLabelFormu(prog, buf, indent, msg, p_pere, arg); Classe cl = (Classe) arg.getClasse(prog); String p_zone = "p_" + arg.nom; p_zone = Divers.remplacer(p_zone, ".", "_"); int nb_prop = cl.proprietes.size() - cl.compterMode("OUT"); Divers.ecrire(buf, p_zone + "=new JPanel(new GridLayout(" + (2 * nb_prop) + "," + 1 + ")); "); Divers.ecrire(buf, p_pere + ".add(" + p_zone + ");"); for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Variable> iter = cl.proprietes.iterator(); iter.hasNext(); ) { Variable prop = (Variable) iter.next(); if (prop.isOut()) continue; String msg1 = prog.quote(prop.nom); Argument arg1 = new Argument(arg.nom + "." + prop.nom, prop.type, arg.mode); constrFormu(prog, buf, indent, msg1, p_zone, arg1); } }
/** * Attribute parser. Parse the attribute of a CLASS and recursively adds them to the CLASS in * input before sending back the control to the class parser. * * @param c The Classe * @return The Classe with the attributes * @throws InvalidUMLException */ private Classe parse_attributes(Classe c) throws InvalidUMLException { Classe classe = c; Attribute attribute; String name, type; // Return the classe, we are done with attributes if (peek_token().equals("OPERATIONS")) return classe; read_token(); if (valid_identifier(this.current_token) && !classe.get_attributes().isEmpty()) { // Throw an exception if the current token is a valid identifier and the operations array is // not empty. // It means that we are missing a comma. throw new InvalidUMLException("Missing `,` between multiple ATTRIBUTES"); } // Read the next token if it is a comma. if (this.current_token.equals(",")) read_token(); // Validate the identifier if (!valid_identifier(this.current_token)) throw new InvalidUMLException("Invalid ATTRIBUTES IDENTIFIER"); // Set the name of the attribute name = this.current_token; read_token(); if (!this.current_token.equals(":")) throw new InvalidUMLException("Expecting `:` after ATTRIBUTE name"); read_token(); if (!valid_identifier(this.current_token)) throw new InvalidUMLException("Invalid TYPE IDENTIFIER"); type = this.current_token; // Create attribute attribute = new Attribute(name, type); classe.add_attribute(attribute); return parse_attributes(classe); }
private void constrTabClasseFormu( Programme prog, StringBuffer buf, int indent, String msg, String p_pere, Argument arg) { this.constrLabelFormu(prog, buf, indent, msg, p_pere, arg); Classe cl = (Classe) arg.getClasseOfTab(prog); Divers.indenter(buf, indent); String p_zone = "p_" + arg.nom; p_zone = Divers.remplacer(p_zone, ".", "_"); String zone = "zone_" + arg.nom; zone = Divers.remplacer(zone, ".", "_"); int nb_prop = cl.proprietes.size() - cl.compterMode("OUT"); Divers.ecrire(buf, p_zone + "=new JPanel(new GridLayout(" + 2 + "," + nb_prop + ")); "); Divers.ecrire(buf, p_pere + ".add(" + p_zone + ");"); for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Variable> iter = cl.proprietes.iterator(); iter.hasNext(); ) { Variable prop = (Variable) iter.next(); if (prop.isOut()) continue; String msg1 = prog.quote(prop.nom); String label1 = "new JLabel(" + msg1 + ")"; Divers.indenter(buf, indent); Divers.ecrire(buf, p_zone + ".add(" + label1 + ");"); } for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Variable> iter = cl.proprietes.iterator(); iter.hasNext(); ) { Variable prop = (Variable) iter.next(); if (prop.isOut()) continue; instr_pere.addVariable(new Variable("ii", "ENTIER")); if (prop.isSimple()) { Argument arg1 = new Argument(arg.nom + "." + prop.nom, "TAB_" + prop.type, arg.mode); String msg1 = null; constrTabFormu(prog, buf, indent, msg1, p_zone, arg1, "ii"); } if (prop.isTabSimple()) { Argument arg1 = new Argument(arg.nom + "." + prop.nom, "MAT_" + prop.getTypeOfTab(), arg.mode); String msg1 = null; constrMatFormu(prog, buf, indent, msg1, p_zone, arg1); } } }
/** * Constructs the object from the current row in the resultSet. * * @param resultSet the resultSet to operate on, already pointing to the correct row. Not null. * @param a possible offset in the columns to be considered (if previous columns contain other * objects), or 0 for no offset. * @param criteria The criteria which created the result set. If set, the attributes to set in the * data object are determined from the select columns in the criteria; if no matching column * can be found, null is returned. If not set, all of the table's columns are read from the * result set in the order defined in the table definition. * @return the mapped object, not null. * @throws TorqueException when reading fields from the RecordSet fails or if a Criteria is passed * which contains select columns other than the columns in the classe table. */ public Classe processRow(ResultSet resultSet, int offset, CriteriaInterface<?> criteria) throws TorqueException { Classe classe = new Classe(); try { classe.setLoading(true); if (criteria == null) { classe.setClasseId(getClasseId(resultSet, offset + 1)); classe.setNom(getNom(resultSet, offset + 2)); } else { // try to get columns to be mapped // from criteria's select columns boolean columnMapped = false; int totalOffset = offset + 1; List<Column> selectColumns = criteria.getSelectColumns(); List<Column> columnsWithoutOffset = selectColumns.subList(offset, selectColumns.size()); for (Column column : columnsWithoutOffset) { if (BaseClassePeer.CLASSE_ID.getSqlExpression().equals(column.getSqlExpression())) { classe.setClasseId(getClasseId(resultSet, totalOffset)); columnMapped = true; } else if (BaseClassePeer.NOM.getSqlExpression().equals(column.getSqlExpression())) { classe.setNom(getNom(resultSet, totalOffset)); columnMapped = true; } totalOffset++; } if (!columnMapped) { log.debug("no columns to map found in criteria, " + "returning null"); return null; } } classe.setNew(false); classe.setModified(false); } finally { classe.setLoading(false); } return classe; }