List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname)
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a UserRequest object from a JDOM element. * * @param element The UserRequest JDOM element. * @return A UserRequest object./*w ww . jav a 2 s .c om*/ * @throws ReaderException */ protected final UserRequest getUserRequest(Element element) throws ReaderException { // user element of the UserRequest element Element userElement = element.getChild(USER); if (userElement == null) { String error = "user element not found in userRequest element"; throw new ReaderException(error); } User user = getUser(userElement); // password element of the userRequest element Element passwordElement = element.getChild(PASSWORD); if (passwordElement == null) { String error = "password element not found in userRequest element"; throw new ReaderException(error); } String password = passwordElement.getText(); return new UserRequest(user, password.toCharArray()); }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a PosixDetails object from a JDOM element. * * @param element The PosixDetails JDOM element. * @return A PosixDetails object./*from w w w .ja v a 2 s .c o m*/ * @throws ReaderException */ protected final PosixDetails getPosixDetails(Element element) throws ReaderException { if (element == null) { String error = "null posixDetails element"; throw new ReaderException(error); } // userName Element userNameElement = element.getChild(USERNAME); if (userNameElement == null) { String error = "posixDetails missing required element username"; throw new ReaderException(error); } String username = userNameElement.getText(); // uid Element uidElement = element.getChild(UID); if (uidElement == null) { String error = "posixDetails missing required element uid"; throw new ReaderException(error); } long uid; try { uid = Long.valueOf(uidElement.getText()); } catch (NumberFormatException e) { String error = "Cannot parse posixDetails uid to a long"; throw new ReaderException(error); } // gid Element gidElement = element.getChild(GID); if (gidElement == null) { String error = "posixDetails missing required element gid"; throw new ReaderException(error); } long gid; try { gid = Long.valueOf(gidElement.getText()); } catch (NumberFormatException e) { String error = "Cannot parse posixDetails gid to a long"; throw new ReaderException(error); } // homeDirectory Element homeDirElement = element.getChild(HOME_DIRECTORY); if (homeDirElement == null) { String error = "posixDetails missing required element homeDirectory"; throw new ReaderException(error); } String homeDirectory = homeDirElement.getText(); return new PosixDetails(username, uid, gid, homeDirectory); }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a PersonalDetails object from a JDOM element. * * @param element The PersonalDetails JDOM element. * @return A PersonalDetails object.//from www . ja v a2s . c om * @throws ReaderException */ protected final PersonalDetails getPersonalDetails(Element element) throws ReaderException { if (element == null) { String error = "null personalDetails element"; throw new ReaderException(error); } // firstName Element firstNameElement = element.getChild(FIRST_NAME); if (firstNameElement == null) { String error = "personalDetails missing required element firstName"; throw new ReaderException(error); } String firstName = firstNameElement.getText(); // lastName Element lastNameElement = element.getChild(LAST_NAME); if (lastNameElement == null) { String error = "personalDetails missing required element lastName"; throw new ReaderException(error); } String lastName = lastNameElement.getText(); PersonalDetails details = new PersonalDetails(firstName, lastName); // email Element emailElement = element.getChild(EMAIL); if (emailElement != null) { details.email = emailElement.getText(); } // address Element addressElement = element.getChild(ADDRESS); if (addressElement != null) { details.address = addressElement.getText(); } // institute Element instituteElement = element.getChild(INSTITUTE); if (instituteElement != null) { details.institute = instituteElement.getText(); } // city Element cityElement = element.getChild(CITY); if (cityElement != null) { details.city = cityElement.getText(); } // country Element countryElement = element.getChild(COUNTRY); if (countryElement != null) { details.country = countryElement.getText(); } return details; }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a UserRequest object from a JDOM element. * * @param element The UserRequest JDOM element. * @return A UserRequest object./*w w w .j a v a2 s . co m*/ * @throws ReaderException */ protected final Group getGroup(Element element) throws ReaderException { String uri = element.getAttributeValue(URI); if (uri == null) { String error = "group missing required uri attribute"; throw new ReaderException(error); } // Group owner User user = null; Element ownerElement = element.getChild(OWNER); if (ownerElement != null) { // Owner user Element userElement = ownerElement.getChild(USER); if (userElement == null) { String error = "owner missing required user element"; throw new ReaderException(error); } user = getUser(userElement); } GroupURI groupURI = new GroupURI(uri); Group group = new Group(groupURI); // set owner field setField(group, user, OWNER); // description Element descriptionElement = element.getChild(DESCRIPTION); if (descriptionElement != null) { group.description = descriptionElement.getText(); } // lastModified Element lastModifiedElement = element.getChild(LAST_MODIFIED); if (lastModifiedElement != null) { try { DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC); group.lastModified = df.parse(lastModifiedElement.getText()); } catch (ParseException e) { String error = "Unable to parse group lastModified because " + e.getMessage(); throw new ReaderException(error); } } // properties Element propertiesElement = element.getChild(PROPERTIES); if (propertiesElement != null) { List<Element> propertyElements = propertiesElement.getChildren(PROPERTY); for (Element propertyElement : propertyElements) { group.getProperties().add(getGroupProperty(propertyElement)); } } // groupMembers Element groupMembersElement = element.getChild(GROUP_MEMBERS); if (groupMembersElement != null) { List<Element> groupElements = groupMembersElement.getChildren(GROUP); for (Element groupMember : groupElements) { group.getGroupMembers().add(getGroup(groupMember)); } } // userMembers Element userMembersElement = element.getChild(USER_MEMBERS); if (userMembersElement != null) { List<Element> userElements = userMembersElement.getChildren(USER); for (Element userMember : userElements) { group.getUserMembers().add(getUser(userMember)); } } // groupAdmins Element groupAdminsElement = element.getChild(GROUP_ADMINS); if (groupAdminsElement != null) { List<Element> groupElements = groupAdminsElement.getChildren(GROUP); for (Element groupMember : groupElements) { group.getGroupAdmins().add(getGroup(groupMember)); } } // userAdmins Element userAdminsElement = element.getChild(USER_ADMINS); if (userAdminsElement != null) { List<Element> userElements = userAdminsElement.getChildren(USER); for (Element userMember : userElements) { group.getUserAdmins().add(getUser(userMember)); } } return group; }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
private void setInternalID(User user, Element element) throws ReaderException { Element uriElement = element.getChild(URI); if (uriElement == null) { String error = "expected uri element not found in internalID element"; throw new ReaderException(error); }//w w w . ja v a 2s. c o m String text = uriElement.getText(); URI uri; try { uri = new URI(text); } catch (URISyntaxException e) { throw new ReaderException("Invalid InternalID URI " + text, e); } InternalID internalID = new InternalID(uri); setField(user, internalID, ID); }
From source file:ca.nrc.cadc.caom2.xml.ArtifactAccessReader.java
License:Open Source License
public ArtifactAccess read(Reader reader) throws IOException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); }//w ww. j a v a2 s . c o m Document document; try { document = XmlUtil.buildDocument(reader); } catch (JDOMException ex) { throw new IllegalArgumentException("invalid input document", ex); } // Root element and namespace of the Document Element root = document.getRootElement(); if (!ENAMES.artifactAccess.name().equals(root.getName())) { throw new IllegalArgumentException( "invalid root element: " + root.getName() + " expected: " + ENAMES.artifactAccess); } Artifact a = getArtifact(root.getChild(ENAMES.artifact.name())); ArtifactAccess ret = new ArtifactAccess(a); ret.isPublic = getBoolean(root.getChildTextTrim(ENAMES.isPublic.name())); getGroupList(ret.getReadGroups(), ENAMES.readGroups.name(), root.getChildren(ENAMES.readGroups.name())); return ret; }
From source file:ca.nrc.cadc.reg.CapabilitiesReader.java
License:Open Source License
private Interface buildInterface(final Element intfElement) { AccessURL accessURL = this.parseAccessURL(intfElement.getChild("accessURL")); URI securityMethod = this.parseSecurityMethod(intfElement.getChild("securityMethod")); String roleString = intfElement.getAttributeValue("role"); Interface intf = new Interface(accessURL, securityMethod); intf.role = roleString;//from ww w .j av a2 s . com return intf; }
From source file:ca.nrc.cadc.vosi.TableReader.java
License:Open Source License
static TableDesc toTable(String schemaName, Element te, Namespace xsi) { String tn = te.getChildTextTrim("name"); TableDesc td = new TableDesc(schemaName, tn); List<Element> cols = te.getChildren("column"); for (Element ce : cols) { String cn = ce.getChildTextTrim("name"); Element dte = ce.getChild("dataType"); String dtt = dte.getAttributeValue("type", xsi); String dtv = dte.getTextTrim(); if (TAP_TYPE.equals(dtt)) dtv = "adql:" + dtv; else if (VOT_TYPE.equals(dtt)) dtv = "vot:" + dtv; Integer arraysize = null; String as = dte.getAttributeValue("size"); if (as != null) arraysize = new Integer(as); ColumnDesc cd = new ColumnDesc(tn, cn, dtv, arraysize); td.getColumnDescs().add(cd);/*from ww w .j av a 2s . c om*/ } List<Element> keys = te.getChildren("foreignKey"); int i = 1; for (Element fk : keys) { String keyID = tn + "_key" + i; String tt = fk.getChildTextTrim("targetTable"); KeyDesc kd = new KeyDesc(keyID, tn, tt); List<Element> fkcols = fk.getChildren("fkColumn"); for (Element fkc : fkcols) { String fc = fkc.getChildTextTrim("fromColumn"); String tc = fkc.getChildTextTrim("targetColumn"); KeyColumnDesc kcd = new KeyColumnDesc(keyID, fc, tc); kd.getKeyColumnDescs().add(kcd); } td.getKeyDescs().add(kd); } return td; }
From source file:cager.parser.test.SimpleTest2.java
License:Open Source License
private void trataNodo(SimpleNode astNode, Element segmento, int nivel, String contexto) { int numChildren = astNode.jjtGetNumChildren(); //TODO Solucionar referencias a Namespaces Namespace xmi = Namespace.getNamespace("xmi", "http://www.omg.org/XMI"); String contextoLocal = ""; contextoLocal = contexto;//from ww w .j a v a2 s . co m String strNombre = ""; for (int i = 0; i < numChildren; i++) { strNombre = ((SimpleNode) astNode.jjtGetChild(i)).getName(); if (astNode.jjtGetChild(i).getClass() == ASTProcDeclaration.class) { for (int j = 0; j < nivel; j++) System.out.print("\t"); //logger.info("1. ->"+astNode.jjtGetChild(i).getClass().toString()+" - "+strNombre+" - "+" Nivel: "+nivel); System.out.println("1. ->" + astNode.jjtGetChild(i).getClass().toString() + " - " + strNombre + " - " + " Nivel: " + nivel); Element codeElement = new Element("codeElement"); codeElement.setAttribute("id", "id." + idCount, xmi); hsmMethodUnits.put(strNombre, idCount); hsmMethodUnitsObj.put(idCount, codeElement); contextoLocal = strNombre; idCount++; codeElement.setAttribute("name", strNombre); codeElement.setAttribute("type", "code:MethodUnit", xmi); //TODO: Comprobar que tipo de method es: Enumeration MethodKind codeElement.setAttribute("kind", "method"); ASTProcDeclaration astProcDecl = (ASTProcDeclaration) astNode.jjtGetChild(i); String contenido = astProcDecl.allText(true); Element sourceElement = new Element("source"); sourceElement.setAttribute("id", "id." + idCount, xmi); idCount++; sourceElement.setAttribute("language", "VisualBasic"); sourceElement.setAttribute("snippet", contenido); codeElement.addContent(sourceElement); segmento.getChild("model").getChild("codeElement").addContent(codeElement); //<source xmi:id="id.41" language="Hla" snippet="Field5[1] -> Acc_Type[0]"/> //Buscar Parmetros para signature codeElement.addContent(TratarSignature((SimpleNode) astNode.jjtGetChild(i), strNombre)); } else if (astNode.jjtGetChild(i) instanceof ASTName) { if (astNode instanceof ASTDeclare && astNode.jjtGetChild(i).jjtGetParent().jjtGetChild(0).equals(astNode.jjtGetChild(i))) { //TODO: Revisar si esto es lgico. ASTDeclare astDeclare = (ASTDeclare) astNode; Element codeElement = new Element("codeElement"); codeElement.setAttribute("id", "id." + idCount, xmi); hsmMethodUnits.put(strNombre, idCount); hsmMethodUnitsObj.put(idCount, codeElement); contextoLocal = strNombre; idCount++; codeElement.setAttribute("name", strNombre); codeElement.setAttribute("export", astDeclare.getFirstToken().toString().toLowerCase()); codeElement.setAttribute("type", "code:MethodUnit", xmi); //TODO: Comprobar que tipo de method es: Enumeration MethodKind codeElement.setAttribute("kind", "method"); String contenido = astDeclare.allText(true); Element sourceElement = new Element("source"); sourceElement.setAttribute("id", "id." + idCount, xmi); idCount++; sourceElement.setAttribute("language", "VisualBasic"); sourceElement.setAttribute("snippet", contenido); codeElement.addContent(sourceElement); segmento.getChild("model").getChild("codeElement").addContent(codeElement); //Buscar Parmetros para signature codeElement.addContent(TratarSignature(astNode, strNombre)); } else if (astNode instanceof ASTVarDecl) { ASTDeclaration astDeclaration = null; String exportVal = null; if (astNode.jjtGetParent() instanceof ASTDeclaration) { astDeclaration = (ASTDeclaration) astNode.jjtGetParent(); exportVal = astDeclaration.getFirstToken().toString().toLowerCase(); } Element codeElement = new Element("codeElement"); codeElement.setAttribute("id", "id." + idCount, xmi); String tipo = null; //Buscamos el tipo de la variable declarada recorriendo todos los hijos buscando el ASTTypeName for (int n = 0; n < astNode.jjtGetNumChildren() && tipo == null; n++) { if (astNode.jjtGetChild(n) instanceof ASTTypeName) { tipo = ((SimpleNode) ((SimpleNode) astNode.jjtGetChild(n)).jjtGetChild(0)).getName(); } } //Si no se ha encontrado comprobamos si es una declaracin mltiple y buscamos el tipo if (tipo == null) { SimpleNode Padre = (SimpleNode) astNode.jjtGetParent(); for (int t = 0; t < Padre.jjtGetNumChildren() && tipo == null; t++) { SimpleNode Hijo = (SimpleNode) Padre.jjtGetChild(t); for (int n = 0; n < Hijo.jjtGetNumChildren(); n++) { if (Hijo.jjtGetChild(n) instanceof ASTTypeName) { tipo = ((SimpleNode) ((SimpleNode) Hijo.jjtGetChild(n)).jjtGetChild(0)) .getName(); } } } } hsmStorableUnits.put(strNombre, idCount); hsmStorableUnitsObj.put(idCount, codeElement); Integer numeroTipo = hsmLanguajeUnitDataType.get(tipo); if (numeroTipo == null) { numeroTipo = 13; } /* if(numeroTipo == null){ numeroTipo = idCount; Element enumerated = new Element("codeElement"); enumerated.setAttribute("id", "id."+numeroTipo, xmi); //enumerated.setAttribute("type", "code:ClassUnit", xmi); enumerated.setAttribute("type", "code:StringType", xmi); enumerated.setAttribute("name", tipo); hsmLanguajeUnitDataType.put(tipo, numeroTipo); idCount++; //Aadimos el enumerated a la lista de tipos elementoTipos.addContent(enumerated); } */ idCount++; codeElement.setAttribute("name", strNombre); //StorableUnit no permite atributo export //if(exportVal != null) codeElement.setAttribute("export", exportVal); codeElement.setAttribute("type", "code:StorableUnit", xmi); codeElement.setAttribute("type", "id." + numeroTipo); if (contextoLocal == "") { codeElement.setAttribute("kind", "global"); segmento.getChild("model").getChild("codeElement").addContent(codeElement); } else { codeElement.setAttribute("kind", "local"); Element elementAux = hsmMethodUnitsObj.get(hsmMethodUnits.get(contextoLocal));//.getChild("codeElement"); elementAux.addContent(codeElement); } } } trataNodo((SimpleNode) astNode.jjtGetChild(i), segmento, nivel + 1, contextoLocal); } }
From source file:cager.parser.test.SimpleTest2.java
License:Open Source License
private void trataNodo2(SimpleNode astNode, Element segmento, int nivel, int nivelAcumulado, String contexto) { int numChildren = astNode.jjtGetNumChildren(); //TODO Solucionar referencias a Namespaces Namespace xmi = Namespace.getNamespace("xmi", "http://www.omg.org/XMI"); SimpleNode snHijo = new SimpleNode(0); String strNombre = ""; String contextoLocal = ""; contextoLocal = contexto;//from w w w.j av a2s . c o m strNombre = astNode.getName(); // if (strNombre!= null && contextoLocal.compareTo(strNombre)!=0) idName = 0; if (hsmMethodUnits.get(strNombre) != null) { // if (contextoLocal.compareTo(strNombre)!=0) idName = 0; contextoLocal = strNombre; } String espacios = ""; for (int j = 0; j < nivelAcumulado; j++) espacios += " "; //logger.info(espacios+"Trata nodo : "+nivel+" - "+numChildren+" -> "+astNode.getClass().getName()+" "+astNode.toString()); System.out.println(espacios + "Trata nodo : " + nivel + " - " + numChildren + " -> " + astNode.getClass().getName() + " " + astNode.toString()); // Recorre todos los hijos del ASTNode for (int i = 0; i < numChildren; i++) { strNombre = ((SimpleNode) astNode.jjtGetChild(i)).getName(); if ((SimpleNode) astNode.jjtGetChild(i) instanceof ASTAssignment) { //Preparamos el ActionElement Element actionElement = new Element("codeElement"); idAction = idCount; idCount++; actionElement.setAttribute("id", "id." + idAction, xmi); actionElement.setAttribute("type", "action:ActionElement", xmi); if (this.debuggMode) actionElement.setAttribute("debug", astNode.jjtGetChild(i).toString()); actionElement.setAttribute("name", "a" + idName); //actionElement.setAttribute("name",contexto+"_"+idName); idName++; espacios = ""; for (int j = 0; j < nivelAcumulado; j++) espacios += " "; //Recorre todos los nodos del ASTAssignment for (int k = 0; k < ((SimpleNode) astNode.jjtGetChild(i)).jjtGetNumChildren(); k++) { snHijo = (SimpleNode) (astNode.jjtGetChild(i)).jjtGetChild(k); //Tratamos el hijo ASTPrimaryExpresion if (snHijo instanceof ASTPrimaryExpression) { SimpleNode snNieto; //Recorre todos los hijos del ASTPrimaryExpression for (int l = 0; l < snHijo.jjtGetNumChildren(); l++) { snNieto = (SimpleNode) snHijo.jjtGetChild(l); String nombreCompleto = ""; for (int m = 0; m < snHijo.jjtGetNumChildren(); m++) { if (m > 0) nombreCompleto += "."; nombreCompleto += ((SimpleNode) snHijo.jjtGetChild(m)).getName(); } //Comprobamos si se trata de un StorableUnit reconocido if (hsmStorableUnits.get(nombreCompleto) != null) { //<actionRelation xmi:id="id.46" xmi:type="action:Writes" to="id.39"/> Element actionRelation = new Element("actionRelation"); actionRelation.setAttribute("id", "id." + idCount, xmi); idCount++; actionRelation.setAttribute("type", "action:Writes", xmi); actionRelation.setAttribute("to", "id." + String.valueOf(hsmStorableUnits.get(nombreCompleto))); actionRelation.setAttribute("from", "id." + idAction); actionElement.addContent(actionRelation); //TODO: Revisar qu hacemos con las referencias a tributos de Objetos (Objeto.atributo = ...) ASTName y ASTName //salir //TODO: Tomamos solo uno de los ASTNames hasta que sepamos cmo hacer con las properties de un objeto. break; } else { //logger.info("Detectado un StorabeUnit nuevo!!!! Qu hacemos?"); System.out.println( "Detectado un StorabeUnit nuevo!!!! Que hacemos?: " + snNieto.getName()); //Optamos temporalmente por aadirlo como StorableUnit global. //TODO: Revisar qu hacer en estos casos, ya que el parser no trata los "Begin" //Comprobamos si a Element codeElement = new Element("codeElement"); codeElement.setAttribute("id", "id." + idCount, xmi); hsmStorableUnits.put(nombreCompleto, idCount); hsmStorableUnitsObj.put(idCount, codeElement); idCount++; codeElement.setAttribute("name", nombreCompleto); codeElement.setAttribute("type", "code:StorableUnit", xmi); codeElement.setAttribute("type", ""); //codeElement.setAttribute("kind", "external");//TODO: Ver cmo tratar ste caso, variables utilizadas no definidas. //Para MethodUnit no hay external codeElement.setAttribute("kind", "unknown"); segmento.getChild("model").getChild("codeElement").addContent(codeElement); //Aadimos el Action:Writes //TODO: Qu hacemos con los properties de un objeto. Element actionRelation = new Element("actionRelation"); actionRelation.setAttribute("id", "id." + idCount, xmi); idCount++; actionRelation.setAttribute("type", "action:Writes", xmi); actionRelation.setAttribute("to", "id." + String.valueOf(hsmStorableUnits.get(nombreCompleto))); actionRelation.setAttribute("from", "id." + idAction); actionElement.addContent(actionRelation); //salir //TODO: Tomamos solo uno de los ASTNames hasta que sepamos cmo hacer con las properties de un objeto. break; //l=snHijo.jjtGetNumChildren(); } } //FIN hijos ASTPrimaryExpression //Tratamos el caso de ASTExpression } else if (snHijo instanceof ASTExpression) { SimpleNode snNieto; //Recorre todos los hijos del ASTExpression for (int l = 0; l < snHijo.jjtGetNumChildren(); l++) { snNieto = (SimpleNode) snHijo.jjtGetChild(l); //Si el hijo es un ASTName if (snNieto instanceof ASTName) { //Comprobamos si es un storableUnit reconocido if (hsmStorableUnits.get(snNieto.getName()) != null) { Element actionRelation = new Element("actionRelation"); actionRelation.setAttribute("id", "id." + idCount, xmi); idCount++; actionRelation.setAttribute("type", "action:Reads", xmi); actionRelation.setAttribute("to", "id." + String.valueOf(hsmStorableUnits.get(snNieto.getName()))); actionRelation.setAttribute("from", "id." + idAction); actionElement.addContent(actionRelation); //TODO: Revisar qu hacemos con las referencias atributos de Objetos (Objeto.atributo = ...) ASTName y ASTName //Si no es un storableUnit reconocido } else { //logger.info("Encontrado un Hijo de ASTExpression que no es ASTName"); System.out.println("Encontrado un Hijo de ASTExpression que no es ASTName"); } //FIN Comprobar si se conoce el storableUnit //Si el hijo es ASTBinOp } else if (snNieto instanceof ASTBinOp) { //Si el hijo es ASTName if (snNieto.jjtGetChild(0) instanceof ASTName) { strNombre = ((SimpleNode) (snNieto).jjtGetChild(0)).getName(); //Tratamos la llamada a mtodo //Si la MethodUnit no estaba registrada if (hsmMethodUnits.get(strNombre) == null && strNombre != null) { //idCount++; //Se da de alta como nueva MethodUnit Element nuevaFuncion = new Element("codeElement"); nuevaFuncion.setAttribute("id", "id." + idCount, xmi); hsmMethodUnits.put(strNombre, idCount); hsmMethodUnitsObj.put(idCount, nuevaFuncion); //logger.info("METODO: "+strNombre+": "+idCount); System.out.println("METODO: " + strNombre + ": " + idCount); idCount++; nuevaFuncion.setAttribute("name", "" + strNombre); nuevaFuncion.setAttribute("type", "code:MethodUnit", xmi); //nuevaFuncion.setAttribute("kind", "system"); //TODO: Ver cmo tratar ste caso, funciones llamadas no definidas. //nuevaFuncion.setAttribute("kind", "unknown"); //TODO: Ver cmo tratar ste caso, funciones llamadas no definidas. //nuevaFuncion.setAttribute("kind", "external"); //Tratamos los mtodos no conocidos como de tipo exteral. //Para los MethodUnit no hay external nuevaFuncion.setAttribute("kind", "unknown"); segmento.getChild("model").getChild("codeElement").addContent(nuevaFuncion); //Se registra el actionRelation (Call) Element actionRelation = new Element("actionRelation"); actionRelation.setAttribute("id", "id." + idCount, xmi); actionRelation.setAttribute("type", "action:Calls", xmi); actionRelation.setAttribute("to", "id." + String.valueOf(hsmMethodUnits.get(strNombre))); // actionRelation.setAttribute("from","id."+String.valueOf(idCount)); actionRelation.setAttribute("from", "id." + idAction); idCount++; actionElement.addContent(actionRelation); //segmento.getChild("model").getChild("codeElement").addContent(codeElement); //Si el MethodUnit ya existia } else { //Se registra el actionRelation (Call) Element actionRelation = new Element("actionRelation"); actionRelation.setAttribute("id", "id." + idCount, xmi); actionRelation.setAttribute("type", "action:Calls", xmi); actionRelation.setAttribute("to", "id." + String.valueOf(hsmMethodUnits.get(strNombre))); actionRelation.setAttribute("from", "id." + String.valueOf(idAction)); idCount++; actionElement.addContent(actionRelation); } //FIN Tratamiento la llamada a mtodo } //FIN Tratar hijo ASTName //TODO Hijos que no sean ASTName (Otro ASTBinOp contatenaciones // EJEMPLO -> AFOROS.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\BaseDatos.mdb;Persist Security Info=False" } //FIN Tratamiento tipos de hijos de ASTExpression } //FIN Recorrido de hijos de ASTExpression } //FIN Tratamiento tipos de hijos de ASTAssignment } //FIN Recorrido de hijos de ASTAssignment if (contextoLocal == "") { actionElement.setAttribute("kind", "global"); segmento.getChild("model").getChild("codeElement").addContent(actionElement); } else { actionElement.setAttribute("kind", "local"); Element elementAux = hsmMethodUnitsObj.get(hsmMethodUnits.get(contextoLocal));//.getChild("codeElement"); elementAux.addContent(actionElement); } } else if ((SimpleNode) astNode.jjtGetChild(i) instanceof ASTStatement) { ASTStatement astStatement = (ASTStatement) astNode.jjtGetChild(i); astStatement.getClass().getName(); //System.out.println("SENTENCIA!!"+astStatement.getClass().getName()); /* switch (astStatement.getClass().getName()) { case "ASTIfStatement": System.out.println("SENTENCIA IF encontrada!!"+astStatement.getClass().getName()); break; case "ASTCaseStatment": System.out.println("SENTENCIA CASE encontrada!!"+astStatement.getClass().getName()); break; case "ASTDoWhileStatement": System.out.println("SENTENCIA DOWHILE encontrada!!"+astStatement.getClass().getName()); break; case "ASTForEachStatement": System.out.println("SENTENCIA FOREACH encontrada!!"+astStatement.getClass().getName()); break; case "ASTForWhileWendStatement": System.out.println("SENTENCIA FORWHILE encontrada!!"+astStatement.getClass().getName()); break; case "ASTWithStatement": System.out.println("SENTENCIA WITH encontrada!!"+astStatement.getClass().getName()); break; default: break; } */ if (astStatement.getClass().getName().compareTo("cager.parser.ASTIfStatement") == 0) { System.out.println("SENTENCIA IF encontrada!!" + astStatement.getClass().getName()); System.out.println(((ASTIfStatement) astStatement).toString()); //Preparamos el ActionElement Element actionElement = new Element("codeElement"); idCount++; idAction = idCount; idCount++; actionElement.setAttribute("id", "id." + idAction, xmi); actionElement.setAttribute("type", "action:ActionElement", xmi); actionElement.setAttribute("name", "a" + idName); //actionElement.setAttribute("name",contexto+"_"+idName); idName++; actionElement.setAttribute("kind", "Condition"); if (contextoLocal == "") { //actionElement.setAttribute("kind", "global"); segmento.getChild("model").getChild("codeElement").addContent(actionElement); } else { //actionElement.setAttribute("kind", "local"); Element elementAux = hsmMethodUnitsObj.get(hsmMethodUnits.get(contextoLocal)); elementAux.addContent(actionElement); } TratarASTIfStatement(astStatement, actionElement); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTCaseStatment") == 0) { System.out.println("SENTENCIA CASE encontrada!!" + astStatement.getClass().getName()); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTForStatement") == 0) { System.out.println("SENTENCIA FOR encontrada!!" + astStatement.getClass().getName()); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTDoWhileStatement") == 0) { System.out.println("SENTENCIA DOWHILE encontrada!!" + astStatement.getClass().getName()); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTWhileWendStatement") == 0) { System.out.println("SENTENCIA WHILEWEND encontrada!!" + astStatement.getClass().getName()); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTForEachStatement") == 0) { System.out.println("SENTENCIA FOREACH encontrada!!" + astStatement.getClass().getName()); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTWithStatement") == 0) { System.out.println("SENTENCIA WITH encontrada!!" + astStatement.getClass().getName()); } else { System.out.println("SENTENCIA encontrada SIN DETERMINAR!!" + astStatement.getClass().getName()); } } trataNodo2((SimpleNode) astNode.jjtGetChild(i), segmento, nivel + 1, nivel + nivelAcumulado, contextoLocal); } }