private void addSetRootMethod() { Method m = SourceFactory.newMethod("setRoot", TypeFactory.newVoidType(pack)); m.setAccessLevel(AccessLevel.PUBLIC); Type t = TypeFactory.newReferenceType( pack, "de.realityinabox.databinding.libs.XMLElement", "XMLElement"); m.addArgument(SourceFactory.newVariable("root", t)); m.addSourceLine("this._root = root;"); addMethod(m); }
private void addStartElementMethod() { Method m = SourceFactory.newMethod("startElement", TypeFactory.newVoidType(pack)); m.setAccessLevel(AccessLevel.PUBLIC); Type t = TypeFactory.newReferenceType(pack, "java.lang.String", "String"); m.addArgument(SourceFactory.newVariable("namespaceURI", t)); m.addArgument(SourceFactory.newVariable("localName", t)); m.addArgument(SourceFactory.newVariable("qName", t)); t = TypeFactory.newReferenceType(pack, "org.xml.sax.Attributes", "Attributes"); m.addArgument(SourceFactory.newVariable("atts", t)); m.addException( TypeFactory.newReferenceType(pack, "org.xml.sax.SAXException", "SAXException")); m.addSourceLine("super.startElement(namespaceURI, localName, qName, atts);"); m.addSourceLine("if (_root != null) return;"); // ... MyHandlerClass.defaultStartElementCode(m, "_root"); m.addSourceLine("_parseStack.push(_root);"); addMethod(m); }
private void addGetRootMethod() { Method m = SourceFactory.newMethod( "getRoot", TypeFactory.newReferenceType( pack, "de.realityinabox.databinding.libs.XMLElement", "XMLElement")); m.setAccessLevel(AccessLevel.PUBLIC); m.addSourceLine("return _root;"); addMethod(m); }
private void addGetParseStackMethod() { Method m = SourceFactory.newMethod( "getParseStack", TypeFactory.newReferenceType( pack, "de.realityinabox.databinding.libs.ParseStack", "ParseStack")); m.setAccessLevel(AccessLevel.PUBLIC); m.addSourceLine("return _parseStack;"); addMethod(m); }
public void addKeyLookup(KeyType keyType, ReferenceType valueType) { String mapName = Tools.toJavaName(keyType.getKeyName(), true); GenericType mapType = TypeFactory.newGenericType(pack, "java.util.Map", "Map"); mapType.addTypeArgument( TypeFactory.newTypeArgument(TypeFactory.newReferenceType(pack, keyType.getJavaName(), ""))); mapType.addTypeArgument(TypeFactory.newTypeArgument(valueType)); Field mapField = SourceFactory.newField("map" + mapName + "Keys", mapType); mapField.setDefaultExpression( "new java.util.HashMap<" + keyType.getJavaName() + "," + valueType.getJavaName() + ">()"); addField(mapField); }
public DocumentClass(XMLPackage pack) { super(pack, null, "XMLDocument"); this.pack = pack; addSuperInterface( TypeFactory.newReferenceType( pack, "de.realityinabox.databinding.libs.Document", "Document")); addField( SourceFactory.newField( "_root", TypeFactory.newReferenceType( pack, "de.realityinabox.databinding.libs.XMLElement", "XMLElement"))); addField( SourceFactory.newField( "_parseStack", TypeFactory.newReferenceType( pack, "de.realityinabox.databinding.libs.ParseStack", "ParseStack"))); addConstructor(); addGetParseStackMethod(); addGetElementFactoryMethod(); addGetRootMethod(); addSetRootMethod(); addNestedClass(new ContentInterceptorClass()); }
private void addConstructor() { Constructor c = SourceFactory.newConstructor(this); c.addSourceLine("_root = null;"); c.addSourceLine("_parseStack = new de.realityinabox.databinding.libs.ParseStack();"); c.addSourceLine("_parseStack.setHandler(new ContentInterceptor());"); }
private void addStartDocumentMethod() { Method m = SourceFactory.newMethod("startDocument", TypeFactory.newVoidType(pack)); m.setAccessLevel(AccessLevel.PUBLIC); m.addSourceLine("_root = null;"); addMethod(m); }