📄 .#maptojava.java.1.26
字号:
if (thisName.equals ("mapping")) { propertyTable = new PropertyTable (); propertyTable.addProperties (thisNode.getChildNodes (PROPERTY_TAG), mapName); if (generatorHandler != null) { addGenerators (thisNode.getChildNodes (GENERATOR_TAG), mapName); XmlNode n = getOneNode (thisNode, CLASS_GENERATOR_TAG, mapName); if (n != null) { makeClasses = false; addGenerator (n, mapName); } else TypeMapper.setObjectMap (new JavaClassGenerator ("",' ',"").getTypeMap ()); } recurseOnChildList (thisNode.getChildNodes (), mapName); setCompositeLinks (); XmlNode cls_imp = getOneNode (thisNode, CLASS_IMPLEMENTS_TAG, mapName); if (cls_imp != null) toImplement = getAttribute (cls_imp, "implements"); //generateAll (); } else if (thisName.equals ("map-to")) { String currentTableName = getAttribute (thisNode, "table"); // also need to make factories if (!currentTableName.equals ("")) currentClass.setTableName (currentTableName); else { // try "query" String query = getAttribute (thisNode, "query"); if (!query.equals("")) { currentClass.setQuery(query); currentClass.setVersioned(false); } else { // try xml.. String xmlName = getAttribute (thisNode, "xml"); // also need to make factories currentClass.setXmlNodeName (xmlName); // "" is OK will be ignored.. } } } else if (thisName.equals ("class-view")) { String formatName = getAttribute (thisNode, "format"); String viewName = getAttribute (thisNode, "name"); if (!Checks.exists(formatName)) throw new SchemaException ("ephman.abra.tools.missingreqd", new Object[]{"'format'", "node <class-view>"}); if (!Checks.exists(viewName)) throw new SchemaException ("ephman.abra.tools.missingreqd", new Object[]{"'name'", "node <class-view>"}); JView jv = currentClass.getView (formatName); if (jv == null) { jv = new JView (viewName, formatName); currentClass.addView (jv); } else { //jv.setFormatName (formatName); jv.setViewName (viewName); } } else if (thisName.equals ("class")) { // System.out.println (thisNode.toXml ()); String fullClassName = getAttribute (thisNode, "name"); // System.out.println ("Transforming " + fullClassName); int split_index = fullClassName.lastIndexOf ('.'); String currentClassName = split_index == -1 ? fullClassName : fullClassName.substring (split_index + 1); String packageName = split_index == -1 ? "" : fullClassName.substring (0, split_index); String extendsClass = getAttribute (thisNode, "extends"); String impl = getAttribute (thisNode, "implements"); String view = getAttribute (thisNode, "view"); String descendant = getAttribute (thisNode, "descendant"); String endDate = getAttribute (thisNode, "end-date"); String cache_type = getAttribute (thisNode, "cache-type"); String abstractDef = getAttribute (thisNode, "abstract"); String inlineOnly = getAttribute (thisNode, "inline-only"); currentClass = new JClass (currentClassName, packageName); currentClass.setSchemaFileName (mapName); currentClass.setImplements (impl); currentClass.setViewName (view); currentClass.setDescendantName (descendant); currentClass.setAbstract (abstractDef != null && abstractDef.equalsIgnoreCase ("true")); currentClass.setInlineOnly (inlineOnly != null && inlineOnly.equalsIgnoreCase ("true")); currentClass.setVersioned (!cache_type.equals ("persistent")); currentClass.setEndDate (endDate != null && endDate.equalsIgnoreCase ("true")); String primaryKey = getAttribute (thisNode, "identity"); currentClass.setPrimaryKeyJava (primaryKey); if (getAttribute (thisNode, "many-to-many").equals ("true")) { currentClass.setManyToMany (); // many-to-many classes do not need version numbers currentClass.setVersioned(false); } currentClass.setParentClassName (extendsClass); recurseOnChildList (thisNode.getChildNodes (), mapName); JClass prevEntry = (JClass)classTree.get (fullClassName); if (prevEntry != null) Debugger.trace ("ERROR: class - " + fullClassName + " in " + prevEntry.getSchemaFileName () + "\n\tbeing replaced by class in file " + currentClass.getSchemaFileName (), Debugger.ERROR); classTree.put (fullClassName, currentClass); if (generatorHandler != null) generatorHandler.addDefault (currentClass); } else if (thisName.equals ("field")) { // System.out.println (thisNode.toXml ()); String fieldName = getAttribute (thisNode, "name"); String fieldType = getAttribute (thisNode, "type"); TypeMap typeMap = TypeMapper.getType (fieldType); if (typeMap.isComposite ()) currentField = new JCompositeField (); else currentField = new JField (); // TODO: check here that valid collection type is supplied String collectionType = getAttribute (thisNode, "collection"); if ((collectionType != null) && (collectionType.length() > 0)) { currentField.setCollection(true); currentField.setCollectionType(collectionType); } currentField.setJavaName (fieldName); currentField.setMapFileType (fieldType); currentField.setDkType (typeMap); // setObjectType (currentField, fieldType); String reqd = getAttribute (thisNode, "required"); if (reqd != null && reqd.equals ("true")) currentField.setRequired (); String len = getAttribute (thisNode, "len"); currentField.setLength (len); inFieldNode = true; recurseOnChildList (thisNode.getChildNodes (), mapName); inFieldNode = false; if (currentField.getJavaName ().equals (currentClass.getPrimaryKeyJava ())) currentClass.setPrimaryKey (currentField.getSqlName ());//set the java name // currentField.setSqlType (findSqlType (fieldType, reqd, len, currentClass.getSchemaFileName ())); currentClass.addField (currentField); } else if (thisName.equals ("sql")) { // System.out.println (thisNode.toXml ()); String tmpName = getAttribute (thisNode, "name"); if (tmpName != null && !tmpName.equals("")) currentField.setSqlName (tmpName); String un = getAttribute (thisNode, "unique"); currentField.setUnique (un != null && un.equals ("true")); currentField.setConstraintName (getAttribute (thisNode, "constraint-name")); currentField.setConstraint (getAttribute (thisNode, "constraint")); if (currentField instanceof JCompositeField) { JCompositeField jcf = (JCompositeField)currentField; String inl = getAttribute (thisNode, "inline"); if (inl != null && inl.equals ("true")) { jcf.setInline (); jcf.setPrefix (getAttribute (thisNode, "prefix")); } } } else if (thisName.equals ("description")) { if (!inFieldNode) currentClass.setClassDescription(thisNode.getText ()); else currentField.setDescription (thisNode.getText ()); } else if (thisName.equals("xml")) { String el = getAttribute (thisNode, "node"); currentField._xmlAttribute = el.equals("attribute"); el = getAttribute (thisNode, "marshal"); //System.out.println ("'" + el + "'"); currentField._noMarshal = (el.equals("false")); //System.out.println (currentField._noMarshal); } else if (thisName.equals("view")) { String viewFormat = getAttribute (thisNode, "foreign-view"); boolean asView = true; if (!Checks.exists (viewFormat)) { viewFormat = getAttribute (thisNode, "foreign-field"); asView = false; if (!Checks.exists (viewFormat)) asView = true; } Vector formats = Tokenizer.tokenize (getAttribute (thisNode, "in"), ",", "'"); for (int i=0; formats != null && i < formats.size (); i++) { String formatName = (String)formats.elementAt (i); currentClass.addToView (formatName, currentField, viewFormat, asView); } } else if (thisName.equals("constraint")) { String name = getAttribute (thisNode, "name"); String type = getAttribute (thisNode, "type"); String cons = thisNode.getText (); //thisNode.getChildNodes().item(0).getNodeValue().trim (); currentClass.addConstraint (new JConstraint (name, type, cons)); } else if (thisName.equals("index")) { String name = getAttribute (thisNode, "name"); String cons = thisNode.getText (); //thisNode.getChildNodes().item(0).getNodeValue().trim (); currentClass.addIndex (new JIndex (name, cons)); } else if (!ignoreTags.contains (thisName)) { Debugger.trace ("node type " + thisName + " is being saved - " + (inFieldNode ? "fieldLevel" : "classLevel"), Debugger.ALL); if (generatorHandler != null) { if (inFieldNode) generatorHandler.handleFieldLevelNode (thisName, propertyTable.replaceAll (thisNode.getHashedAttributes ()), currentClass, currentField); else generatorHandler.handleClassLevelNode (thisName, propertyTable.replaceAll (thisNode.getHashedAttributes ()), currentClass); } // ?? bad } } public void generateAll () throws IOException, SchemaException { System.out.print ("Database is set to "); System.out.println (FactoryGenerator.DB_NAME); ClassGenerator class_gen = new JavaClassGenerator (outdir, fileSeperator.charAt(0), toImplement); FactoryGenerator fact_gen = new FactoryGenerator (outdir, fileSeperator.charAt (0), facImp, useProcs); TypeMapper.setDbMap (fact_gen.getTypeMap (), fact_gen.DB_NAME); // ValidatorGenerator val_gen = new ValidatorGenerator (outdir, fileSeperator); SchemaGenerator sch_gen = null; if (this.makeSchema) { if (!isTopLevelDirectory (outSchema)) outSchema = outdir + fileSeperator + outSchema; sch_gen = new SchemaGenerator (outSchema); } Iterator cls = classTree.values().iterator(); while (cls.hasNext()) { JClass currentClass = (JClass)cls.next(); if (this.makeClasses && !currentClass.isManyToMany()) class_gen.generate (currentClass); //if (this.makeValidators && !currentClass.isManyToMany()) //val_gen.generate (currentClass); generatorHandler.generate (currentClass); if (currentClass.isLeaf () && !currentClass.isInlineOnly ()) { //System.out.println (currentClass.getClassName () + " is a leaf."); if (this.makeFactories) { //System.out.println ("\tgenerating factory"); fact_gen.generate (currentClass); } if (this.makeSchema && !currentClass.isQuery()) { sch_gen.generate (currentClass); } } } if (sch_gen != null) sch_gen.close (); generatorHandler.close (); // close all generators } private void setCompositeLinks () { Iterator cls = classTree.values().iterator(); while (cls.hasNext()) { JClass currentClass = (JClass)cls.next(); JClass superClass = (JClass)classTree.get (currentClass.getParentClassName ()); currentClass.setParentClass (superClass); currentClass.resetFieldIteration(); while (currentClass.hasMoreFields()) { JField jf = currentClass.getNextField(); if (jf instanceof JCompositeField) // link composite field ((JCompositeField)jf).setJClass ((JClass)classTree.get (jf.getObjectType ())); } if (currentClass.isLeaf ()) { Vector allFields = new Vector (currentClass.getAllFields ().values()); for (int i = 0; i < allFields.size (); i++) { JField jf = (JField)allFields.elementAt (i); if (currentClass.getPrimaryKeyJava ().equals (jf.getJavaName ())) currentClass.setPrimaryKey (jf.getSqlName ()); } } } // now set all views to be right.. cls = classTree.values().iterator(); while (cls.hasNext()) { JClass currentClass = (JClass)cls.next(); Iterator views = currentClass.getViewList (); while (views.hasNext ()) { JView view = (JView)views.next (); String name = view.getFormatName (); JClass jc = currentClass.getParentClass (); JView jv = null; while (jc != null && jv == null) { jv = jc.getView (name); jc = jc.getParentClass (); } view.setSuperView (jv); } } } public XmlNode getOneNode (XmlNode thisNode, String tagToGet, String mapName) throws SchemaException { XmlNode result = null; Vector v = thisNode.getChildNodes (tagToGet); if (v != null && v.size () > 0) { if (v.size () == 1) { result = (XmlNode)v.elementAt (0); } else throw new SchemaException ("Too many <" +tagToGet+ "> tags only one allowed", mapName); } return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -