Java源码示例:com.sun.codemodel.internal.JDefinedClass
示例1
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);
}
示例2
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
if (sc == null) return null;
JDefinedClass c;
try {
String v = DOMUtil.getAttribute(sc,"name");
if(v==null) return null;
c = codeModel._class(v);
c.hide();
} catch (JClassAlreadyExistsException e) {
c = e.getExistingClass();
}
return c;
}
示例3
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 );
}
示例4
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
if (sc == null) return null;
JDefinedClass c;
try {
String v = DOMUtil.getAttribute(sc,"name");
if(v==null) return null;
c = codeModel._class(v);
c.hide();
} catch (JClassAlreadyExistsException e) {
c = e.getExistingClass();
}
return c;
}
示例5
public TypeUse getTypeUse(XSSimpleType owner) {
if(typeUse!=null)
return typeUse;
JCodeModel cm = getCodeModel();
JDefinedClass a;
try {
a = cm._class(adapter);
a.hide(); // we assume this is given by the user
a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(
cm.ref(type)));
} catch (JClassAlreadyExistsException e) {
a = e.getExistingClass();
}
// TODO: it's not correct to say that it adapts from String,
// but OTOH I don't think we can compute that.
typeUse = TypeUseFactory.adapt(
CBuiltinLeafInfo.STRING,
new CAdapter(a));
return typeUse;
}
示例6
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 );
}
示例7
/**
* Generates the minimum {@link JDefinedClass} skeleton
* without filling in its body.
*/
private ClassOutlineImpl generateClassDef(CClassInfo bean) {
ImplStructureStrategy.Result r = model.strategy.createClasses(this, bean);
JClass implRef;
if (bean.getUserSpecifiedImplClass() != null) {
// create a place holder for a user-specified class.
JDefinedClass usr;
try {
usr = codeModel._class(bean.getUserSpecifiedImplClass());
// but hide that file so that it won't be generated.
usr.hide();
} catch (JClassAlreadyExistsException e) {
// it's OK for this to collide.
usr = e.getExistingClass();
}
usr._extends(r.implementation);
implRef = usr;
} else {
implRef = r.implementation;
}
return new ClassOutlineImpl(this, bean, r.exposed, r.implementation, implRef);
}
示例8
public TypeUse getTypeUse(XSSimpleType owner) {
if(typeUse!=null)
return typeUse;
JCodeModel cm = getCodeModel();
JDefinedClass a;
try {
a = cm._class(adapter);
a.hide(); // we assume this is given by the user
a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(
cm.ref(type)));
} catch (JClassAlreadyExistsException e) {
a = e.getExistingClass();
}
// TODO: it's not correct to say that it adapts from String,
// but OTOH I don't think we can compute that.
typeUse = TypeUseFactory.adapt(
CBuiltinLeafInfo.STRING,
new CAdapter(a));
return typeUse;
}
示例9
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
if (sc == null) return null;
JDefinedClass c;
try {
String v = DOMUtil.getAttribute(sc,"name");
if(v==null) return null;
c = codeModel._class(v);
c.hide();
} catch (JClassAlreadyExistsException e) {
c = e.getExistingClass();
}
return c;
}
示例10
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
if (sc == null) return null;
JDefinedClass c;
try {
String v = DOMUtil.getAttribute(sc,"name");
if(v==null) return null;
c = codeModel._class(v);
c.hide();
} catch (JClassAlreadyExistsException e) {
c = e.getExistingClass();
}
return c;
}
示例11
/**
* Generates the minimum {@link JDefinedClass} skeleton
* without filling in its body.
*/
private ClassOutlineImpl generateClassDef(CClassInfo bean) {
ImplStructureStrategy.Result r = model.strategy.createClasses(this, bean);
JClass implRef;
if (bean.getUserSpecifiedImplClass() != null) {
// create a place holder for a user-specified class.
JDefinedClass usr;
try {
usr = codeModel._class(bean.getUserSpecifiedImplClass());
// but hide that file so that it won't be generated.
usr.hide();
} catch (JClassAlreadyExistsException e) {
// it's OK for this to collide.
usr = e.getExistingClass();
}
usr._extends(r.implementation);
implRef = usr;
} else {
implRef = r.implementation;
}
return new ClassOutlineImpl(this, bean, r.exposed, r.implementation, implRef);
}
示例12
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;
}
示例13
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;
}
示例14
private static JClass pickOne(Set<JClass> s) {
// we may have more than one candidates at this point.
// any user-defined generated types should have
// precedence over system-defined existing types.
//
// so try to return such a type if any.
for (JClass c : s)
if (c instanceof JDefinedClass)
return c;
// we can do more if we like. for example,
// we can avoid types in the RI runtime.
// but for now, just return the first one.
return s.iterator().next();
}
示例15
private void writeClassLoaderBaseResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JBlock staticBlock = cls.init();
JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
JTryBlock tryBlock = staticBlock._try();
tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(".")).arg(wsdlLocation));
JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
JVar murlVar = catchBlock.param("murl");
catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(murlVar));
staticBlock.assign(urlField, urlVar);
staticBlock.assign(exField, exVar);
}
示例16
private void writeClassLoaderResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JBlock staticBlock = cls.init();
staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getClassLoader").invoke("getResource").arg(wsdlLocation));
JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
"Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
staticBlock.assign(exField, exVar);
}
示例17
/**
* Create a dummy class to recover from an error.
*
* We won't generate the code, so the client will never see this class
* getting generated.
*/
private JDefinedClass createDummyClass(JClassContainer parent) {
try {
return parent._class("$$$garbage$$$"+(ticketMaster++));
} catch( JClassAlreadyExistsException ee ) {
return ee.getExistingClass();
}
}
示例18
private static JClass pickOne(Set<JClass> s) {
// we may have more than one candidates at this point.
// any user-defined generated types should have
// precedence over system-defined existing types.
//
// so try to return such a type if any.
for (JClass c : s)
if (c instanceof JDefinedClass)
return c;
// we can do more if we like. for example,
// we can avoid types in the RI runtime.
// but for now, just return the first one.
return s.iterator().next();
}
示例19
protected JDefinedClass getCMClass(String className, com.sun.codemodel.internal.ClassType type) {
JDefinedClass cls;
try {
cls = cm._class(className, type);
} catch (com.sun.codemodel.internal.JClassAlreadyExistsException e){
cls = cm._getClass(className);
}
return cls;
}
示例20
JDefinedClass getClazz(ClassType t) {
if (clazz != null) return clazz;
try {
JCodeModel codeModel = Ring.get(JCodeModel.class);
clazz = codeModel._class(name, t);
clazz.hide();
return clazz;
} catch (JClassAlreadyExistsException e) {
return e.getExistingClass();
}
}
示例21
private void writeClassLoaderBaseResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JBlock staticBlock = cls.init();
JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
JTryBlock tryBlock = staticBlock._try();
tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(".")).arg(wsdlLocation));
JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
JVar murlVar = catchBlock.param("murl");
catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(murlVar));
staticBlock.assign(urlField, urlVar);
staticBlock.assign(exField, exVar);
}
示例22
private void writeXmlTypeDeclaration(JDefinedClass cls, String typeName, String namespaceUri,
Collection<MemberInfo> members) {
if (cls == null)
return;
JAnnotationUse xmlTypeAnn = cls.annotate(cm.ref(XmlType.class));
xmlTypeAnn.param("name", typeName);
xmlTypeAnn.param("namespace", namespaceUri);
if (members.size() > 1) {
JAnnotationArrayMember paramArray = xmlTypeAnn.paramArray("propOrder");
for (MemberInfo memInfo : members) {
paramArray.param(memInfo.getParamName());
}
}
}
示例23
private void writeClassLoaderResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JBlock staticBlock = cls.init();
staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getClassLoader").invoke("getResource").arg(wsdlLocation));
JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
"Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
staticBlock.assign(exField, exVar);
}
示例24
protected JDefinedClass getClass(String className, ClassType type) throws JClassAlreadyExistsException {
JDefinedClass cls;
try {
cls = cm._class(className, type);
} catch (JClassAlreadyExistsException e){
cls = cm._getClass(className);
if (cls == null) {
throw e;
}
}
return cls;
}
示例25
private static JClass pickOne(Set<JClass> s) {
// we may have more than one candidates at this point.
// any user-defined generated types should have
// precedence over system-defined existing types.
//
// so try to return such a type if any.
for (JClass c : s)
if (c instanceof JDefinedClass)
return c;
// we can do more if we like. for example,
// we can avoid types in the RI runtime.
// but for now, just return the first one.
return s.iterator().next();
}
示例26
protected JDefinedClass getClass(String className, ClassType type) throws JClassAlreadyExistsException {
JDefinedClass cls;
try {
cls = cm._class(className, type);
} catch (JClassAlreadyExistsException e){
cls = cm._getClass(className);
if (cls == null) {
throw e;
}
}
return cls;
}
示例27
private void writeXmlElementDeclaration(JDefinedClass cls, String elementName, String namespaceUri) {
if (cls == null)
return;
JAnnotationUse xmlRootElementAnn = cls.annotate(XmlRootElement.class);
xmlRootElementAnn.param("name", elementName);
if (namespaceUri.length() > 0) {
xmlRootElementAnn.param("namespace", namespaceUri);
}
JAnnotationUse xmlAccessorTypeAnn = cls.annotate(cm.ref(XmlAccessorType.class));
xmlAccessorTypeAnn.param("value", XmlAccessType.FIELD);
}
示例28
private void writeAbsWSDLLocation(JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JBlock staticBlock = cls.init();
JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
JTryBlock tryBlock = staticBlock._try();
tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(wsdlLocation));
JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
catchBlock.param("ex");
catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(JExpr.ref("ex")));
staticBlock.assign(urlField, urlVar);
staticBlock.assign(exField, exVar);
}
示例29
private void writeXmlTypeDeclaration(JDefinedClass cls, String typeName, String namespaceUri,
Collection<MemberInfo> members) {
if (cls == null)
return;
JAnnotationUse xmlTypeAnn = cls.annotate(cm.ref(XmlType.class));
xmlTypeAnn.param("name", typeName);
xmlTypeAnn.param("namespace", namespaceUri);
if (members.size() > 1) {
JAnnotationArrayMember paramArray = xmlTypeAnn.paramArray("propOrder");
for (MemberInfo memInfo : members) {
paramArray.param(memInfo.getParamName());
}
}
}
示例30
private void writeClassLoaderResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JBlock staticBlock = cls.init();
staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getClassLoader").invoke("getResource").arg(wsdlLocation));
JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
"Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
staticBlock.assign(exField, exVar);
}