private void writeGetPort(Port port, JType retType, JDefinedClass cls) { JMethod m = cls.method(JMod.PUBLIC, retType, port.getPortGetter()); JDocComment methodDoc = m.javadoc(); if (port.getJavaDoc() != null) { methodDoc.add(port.getJavaDoc()); } JCommentPart ret = methodDoc.addReturn(); JCommentPart paramDoc = methodDoc.addParam("features"); paramDoc.append("A list of "); paramDoc.append("{@link " + WebServiceFeature.class.getName() + "}"); paramDoc.append("to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values."); ret.add("returns " + retType.name()); m.varParam(WebServiceFeature.class, "features"); JBlock body = m.body(); StringBuilder statement = new StringBuilder("return "); statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), "); statement.append(retType.name()); statement.append(".class, features);"); body.directStatement(statement.toString()); writeWebEndpoint(port, m); }
private void writeDefaultGetPort(Port port, JType retType, JDefinedClass cls) { String portGetter = port.getPortGetter(); JMethod m = cls.method(JMod.PUBLIC, retType, portGetter); JDocComment methodDoc = m.javadoc(); if (port.getJavaDoc() != null) { methodDoc.add(port.getJavaDoc()); } JCommentPart ret = methodDoc.addReturn(); ret.add("returns " + retType.name()); JBlock body = m.body(); StringBuilder statement = new StringBuilder("return "); statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), "); statement.append(retType.name()); statement.append(".class);"); body.directStatement(statement.toString()); writeWebEndpoint(port, m); }
private void writeMember(JDefinedClass cls, TypeMirror paramType, String paramName) { if (cls == null) return; String accessorName =BindingHelper.mangleNameToPropertyName(paramName); String getterPrefix = paramType.toString().equals("boolean")? "is" : "get"; JType propType = getType(paramType); JMethod m = cls.method(JMod.PUBLIC, propType, getterPrefix+ accessorName); JDocComment methodDoc = m.javadoc(); JCommentPart ret = methodDoc.addReturn(); ret.add("returns "+propType.name()); JBlock body = m.body(); body._return( JExpr._this().ref(paramName) ); m = cls.method(JMod.PUBLIC, cm.VOID, "set"+accessorName); JVar param = m.param(propType, paramName); methodDoc = m.javadoc(); JCommentPart part = methodDoc.addParam(paramName); part.add("the value for the "+ paramName+" property"); body = m.body(); body.assign( JExpr._this().ref(paramName), param ); }
/** * return a JFieldVar that represents the QName field for the given information. * * if it doesn't exist, create a static field in the class and store a new JFieldVar. */ private JExpression getQNameInvocation(CElementInfo ei) { QName name = ei.getElementName(); if(qnameMap.containsKey(name)) { return qnameMap.get(name); } if(qnameMap.size()>1024) // stop gap measure to avoid 'code too large' error in javac. return createQName(name); // [RESULT] // private static final QName _XYZ_NAME = new QName("uri", "local"); JFieldVar qnameField = objectFactory.field( JMod.PRIVATE | JMod.STATIC | JMod.FINAL, QName.class, '_' + ei.getSqueezedName() + "_QNAME", createQName(name)); qnameMap.put(name, qnameField); return qnameField; }
public boolean run( Outline outline, Options opt, ErrorHandler errorHandler ) { for( ClassOutline ci : outline.getClasses() ) { JDefinedClass impl = ci.implClass; if (ci.getSuperClass() == null) { JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName); $loc.annotate(XmlLocation.class); $loc.annotate(XmlTransient.class); impl._implements(Locatable.class); impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc); JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation"); JVar $newLoc = setter.param(Locator.class, "newLocator"); setter.body().assign($loc, $newLoc); } } return true; }
private void writeGetPort(Port port, JType retType, JDefinedClass cls) { JMethod m = cls.method(JMod.PUBLIC, retType, port.getPortGetter()); JDocComment methodDoc = m.javadoc(); if (port.getJavaDoc() != null) methodDoc.add(port.getJavaDoc()); JCommentPart ret = methodDoc.addReturn(); JCommentPart paramDoc = methodDoc.addParam("features"); paramDoc.append("A list of "); paramDoc.append("{@link " + WebServiceFeature.class.getName() + "}"); paramDoc.append("to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values."); ret.add("returns " + retType.name()); m.varParam(WebServiceFeature.class, "features"); JBlock body = m.body(); StringBuffer statement = new StringBuffer("return "); statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), "); statement.append(retType.name()); statement.append(".class, features);"); body.directStatement(statement.toString()); writeWebEndpoint(port, m); }
private void writeDefaultGetPort(Port port, JType retType, JDefinedClass cls) { String portGetter = port.getPortGetter(); JMethod m = cls.method(JMod.PUBLIC, retType, portGetter); JDocComment methodDoc = m.javadoc(); if (port.getJavaDoc() != null) methodDoc.add(port.getJavaDoc()); JCommentPart ret = methodDoc.addReturn(); ret.add("returns " + retType.name()); JBlock body = m.body(); StringBuffer statement = new StringBuffer("return "); statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), "); statement.append(retType.name()); statement.append(".class);"); body.directStatement(statement.toString()); writeWebEndpoint(port, m); }
protected final void generateArray() { field = outline.implClass.field( JMod.PROTECTED, getCoreListType(), prop.getName(false) ); annotate(field); // generate the rest of accessors generateAccessors(); }
protected final void generate() { // for the collectionType customization to take effect, the field needs to be strongly typed, // not just List<Foo>. field = outline.implClass.field( JMod.PROTECTED, listT, prop.getName(false) ); if(eagerInstanciation) field.init(newCoreList()); annotate(field); // generate the rest of accessors generateAccessors(); }
private void generateInternalGetter() { internalGetter = outline.implClass.method(JMod.PROTECTED,listT,"_get"+prop.getName(true)); if(!eagerInstanciation) { // if eagerly instanciated, the field can't be null fixNullRef(internalGetter.body()); } internalGetter.body()._return(field); }
/** * Generates an attribute wildcard property on a class. */ private void generateAttributeWildcard(ClassOutlineImpl cc) { String FIELD_NAME = "otherAttributes"; String METHOD_SEED = model.getNameConverter().toClassName(FIELD_NAME); JClass mapType = codeModel.ref(Map.class).narrow(QName.class, String.class); JClass mapImpl = codeModel.ref(HashMap.class).narrow(QName.class, String.class); // [RESULT] // Map<QName,String> m = new HashMap<QName,String>(); JFieldVar $ref = cc.implClass.field(JMod.PRIVATE, mapType, FIELD_NAME, JExpr._new(mapImpl)); $ref.annotate2(XmlAnyAttributeWriter.class); MethodWriter writer = cc.createMethodWriter(); JMethod $get = writer.declareMethod(mapType, "get" + METHOD_SEED); $get.javadoc().append( "Gets a map that contains attributes that aren't bound to any typed property on this class.\n\n" + "<p>\n" + "the map is keyed by the name of the attribute and \n" + "the value is the string value of the attribute.\n" + "\n" + "the map returned by this method is live, and you can add new attribute\n" + "by updating the map directly. Because of this design, there's no setter.\n"); $get.javadoc().addReturn().append("always non-null"); $get.body()._return($ref); }
ElementOutlineImpl(BeanGenerator parent, CElementInfo ei) { super(ei, parent.getClassFactory().createClass( parent.getContainer( ei.parent, Aspect.EXPOSED ), ei.shortName(), ei.getLocator() )); this.parent = parent; parent.elements.put(ei,this); JCodeModel cm = parent.getCodeModel(); implClass._extends( cm.ref(JAXBElement.class).narrow( target.getContentInMemoryType().toType(parent,Aspect.EXPOSED).boxify())); if(ei.hasClass()) { JType implType = ei.getContentInMemoryType().toType(parent,Aspect.IMPLEMENTATION); JExpression declaredType = JExpr.cast(cm.ref(Class.class),implType.boxify().dotclass()); // why do we have to cast? JClass scope=null; if(ei.getScope()!=null) scope = parent.getClazz(ei.getScope()).implRef; JExpression scopeClass = scope==null?JExpr._null():scope.dotclass(); JFieldVar valField = implClass.field(JMod.PROTECTED|JMod.FINAL|JMod.STATIC,QName.class,"NAME",createQName(cm,ei.getElementName())); // take this opportunity to generate a constructor in the element class JMethod cons = implClass.constructor(JMod.PUBLIC); cons.body().invoke("super") .arg(valField) .arg(declaredType) .arg(scopeClass) .arg(cons.param(implType,"value")); // generate no-arg constructor in the element class (bug #391; section 5.6.2 in JAXB spec 2.1) JMethod noArgCons = implClass.constructor(JMod.PUBLIC); noArgCons.body().invoke("super") .arg(valField) .arg(declaredType) .arg(scopeClass) .arg(JExpr._null()); } }
DualObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) { this.publicOFG = new PublicObjectFactoryGenerator(outline,model,targetPackage); this.privateOFG = new PrivateObjectFactoryGenerator(outline,model,targetPackage); // put the marker so that we can detect missing jaxb.properties publicOFG.getObjectFactory().field(JMod.PRIVATE|JMod.STATIC|JMod.FINAL, Void.class, "_useJAXBProperties", JExpr._null()); }