Java源码示例:com.sun.tools.internal.xjc.model.CPropertyInfo
示例1
public void build(XSComplexType ct) {
XSContentType contentType = ct.getContentType();
builder.recordBindingMode(ct, FALLBACK_CONTENT);
BIProperty prop = BIProperty.getCustomization(ct);
CPropertyInfo p;
if(contentType.asEmpty()!=null) {
p = prop.createValueProperty("Content",false,ct,CBuiltinLeafInfo.STRING,null);
} else {
RawTypeSet ts = RawTypeSetBuilder.build(contentType.asParticle(),false);
p = prop.createReferenceProperty("Content", false, ct, ts, true, false, true, false);
}
selector.getCurrentBean().addProperty(p);
// adds attributes and we are through.
green.attContainer(ct);
}
示例2
private void generate( ClassOutlineImpl outline, CPropertyInfo prop ) {
// add isSetXXX and unsetXXX.
MethodWriter writer = outline.createMethodWriter();
JCodeModel codeModel = outline.parent().getCodeModel();
FieldAccessor acc = core.create(JExpr._this());
if( generateIsSetMethod ) {
// [RESULT] boolean isSetXXX()
JExpression hasSetValue = acc.hasSetValue();
if( hasSetValue==null ) {
// this field renderer doesn't support the isSet/unset methods generation.
// issue an error
throw new UnsupportedOperationException();
}
writer.declareMethod(codeModel.BOOLEAN,"isSet"+this.prop.getName(true))
.body()._return( hasSetValue );
}
if( generateUnSetMethod ) {
// [RESULT] void unsetXXX()
acc.unsetValues(
writer.declareMethod(codeModel.VOID,"unset"+this.prop.getName(true)).body() );
}
}
示例3
public void build(XSComplexType ct) {
XSContentType contentType = ct.getContentType();
builder.recordBindingMode(ct, FALLBACK_CONTENT);
BIProperty prop = BIProperty.getCustomization(ct);
CPropertyInfo p;
if(contentType.asEmpty()!=null) {
p = prop.createValueProperty("Content",false,ct,CBuiltinLeafInfo.STRING,null);
} else {
RawTypeSet ts = RawTypeSetBuilder.build(contentType.asParticle(),false);
p = prop.createReferenceProperty("Content", false, ct, ts, true, false, true, false);
}
selector.getCurrentBean().addProperty(p);
// adds attributes and we are through.
green.attContainer(ct);
}
示例4
public void build(XSComplexType ct) {
XSContentType contentType = ct.getContentType();
builder.recordBindingMode(ct, FALLBACK_CONTENT);
BIProperty prop = BIProperty.getCustomization(ct);
CPropertyInfo p;
if(contentType.asEmpty()!=null) {
p = prop.createValueProperty("Content",false,ct,CBuiltinLeafInfo.STRING,null);
} else {
RawTypeSet ts = RawTypeSetBuilder.build(contentType.asParticle(),false);
p = prop.createReferenceProperty("Content", false, ct, ts, true, false, true, false);
}
selector.getCurrentBean().addProperty(p);
// adds attributes and we are through.
green.attContainer(ct);
}
示例5
ConstField( ClassOutlineImpl outline, CPropertyInfo prop ) {
super(outline,prop);
// we only support value constraints for a single-value property.
assert !prop.isCollection();
JPrimitiveType ptype = implType.boxify().getPrimitiveType();
// generate the constant
JExpression defaultValue = null;
if(prop.defaultValue!=null)
defaultValue = prop.defaultValue.compute(outline.parent());
$ref = outline.ref.field(JMod.PUBLIC|JMod.STATIC|JMod.FINAL,
ptype!=null?ptype:implType, prop.getName(true), defaultValue );
$ref.javadoc().append(prop.javadoc);
annotate($ref);
}
示例6
private void generate( ClassOutlineImpl outline, CPropertyInfo prop ) {
// add isSetXXX and unsetXXX.
MethodWriter writer = outline.createMethodWriter();
JCodeModel codeModel = outline.parent().getCodeModel();
FieldAccessor acc = core.create(JExpr._this());
if( generateIsSetMethod ) {
// [RESULT] boolean isSetXXX()
JExpression hasSetValue = acc.hasSetValue();
if( hasSetValue==null ) {
// this field renderer doesn't support the isSet/unset methods generation.
// issue an error
throw new UnsupportedOperationException();
}
writer.declareMethod(codeModel.BOOLEAN,"isSet"+this.prop.getName(true))
.body()._return( hasSetValue );
}
if( generateUnSetMethod ) {
// [RESULT] void unsetXXX()
acc.unsetValues(
writer.declareMethod(codeModel.VOID,"unset"+this.prop.getName(true)).body() );
}
}
示例7
ConstField( ClassOutlineImpl outline, CPropertyInfo prop ) {
super(outline,prop);
// we only support value constraints for a single-value property.
assert !prop.isCollection();
JPrimitiveType ptype = implType.boxify().getPrimitiveType();
// generate the constant
JExpression defaultValue = null;
if(prop.defaultValue!=null)
defaultValue = prop.defaultValue.compute(outline.parent());
$ref = outline.ref.field(JMod.PUBLIC|JMod.STATIC|JMod.FINAL,
ptype!=null?ptype:implType, prop.getName(true), defaultValue );
$ref.javadoc().append(prop.javadoc);
annotate($ref);
}
示例8
private void generate( ClassOutlineImpl outline, CPropertyInfo prop ) {
// add isSetXXX and unsetXXX.
MethodWriter writer = outline.createMethodWriter();
JCodeModel codeModel = outline.parent().getCodeModel();
FieldAccessor acc = core.create(JExpr._this());
if( generateIsSetMethod ) {
// [RESULT] boolean isSetXXX()
JExpression hasSetValue = acc.hasSetValue();
if( hasSetValue==null ) {
// this field renderer doesn't support the isSet/unset methods generation.
// issue an error
throw new UnsupportedOperationException();
}
writer.declareMethod(codeModel.BOOLEAN,"isSet"+this.prop.getName(true))
.body()._return( hasSetValue );
}
if( generateUnSetMethod ) {
// [RESULT] void unsetXXX()
acc.unsetValues(
writer.declareMethod(codeModel.VOID,"unset"+this.prop.getName(true)).body() );
}
}
示例9
ConstField( ClassOutlineImpl outline, CPropertyInfo prop ) {
super(outline,prop);
// we only support value constraints for a single-value property.
assert !prop.isCollection();
JPrimitiveType ptype = implType.boxify().getPrimitiveType();
// generate the constant
JExpression defaultValue = null;
if(prop.defaultValue!=null)
defaultValue = prop.defaultValue.compute(outline.parent());
$ref = outline.ref.field(JMod.PUBLIC|JMod.STATIC|JMod.FINAL,
ptype!=null?ptype:implType, prop.getName(true), defaultValue );
$ref.javadoc().append(prop.javadoc);
annotate($ref);
}
示例10
/**
* If the given component has {@link BIInlineBinaryData} customization,
* reflect that to the specified property.
*/
public static void handle(XSComponent source, CPropertyInfo prop) {
BIInlineBinaryData inline = Ring.get(BGMBuilder.class).getBindInfo(source).get(BIInlineBinaryData.class);
if(inline!=null) {
prop.inlineBinaryData = true;
inline.markAsAcknowledged();
}
}
示例11
protected IsSetField( ClassOutlineImpl outline, CPropertyInfo prop,
FieldOutline core, boolean unsetMethod, boolean issetMethod ) {
super(outline,prop);
this.core = core;
this.generateIsSetMethod = issetMethod;
this.generateUnSetMethod = unsetMethod;
generate(outline,prop);
}
示例12
protected CPropertyInfo createAttribute(
String elementName, String attributeName, String attributeType,
String[] enums, short attributeUse, String defaultValue )
throws SAXException {
boolean required = attributeUse==USE_REQUIRED;
// get the attribute-property declaration
BIElement edecl = bindInfo.element(elementName);
BIAttribute decl=null;
if(edecl!=null) decl=edecl.attribute(attributeName);
String propName;
if(decl==null) propName = model.getNameConverter().toPropertyName(attributeName);
else propName = decl.getPropertyName();
QName qname = new QName("",attributeName);
// if no declaration is specified, just wrap it by
// a FieldItem and let the normalizer handle its content.
TypeUse use;
if(decl!=null && decl.getConversion()!=null)
use = decl.getConversion().getTransducer();
else
use = builtinConversions.get(attributeType);
CPropertyInfo r = new CAttributePropertyInfo(
propName, null,null/*TODO*/, copyLocator(), qname, use, null, required );
if(defaultValue!=null)
r.defaultValue = CDefaultValue.create( use, new XmlString(defaultValue) );
return r;
}
示例13
protected AbstractField( ClassOutlineImpl outline, CPropertyInfo prop ) {
this.outline = outline;
this.prop = prop;
this.codeModel = outline.parent().getCodeModel();
this.implType = getType(IMPLEMENTATION);
this.exposedType = getType(Aspect.EXPOSED);
}
示例14
/**
* Returns contents to be added to javadoc.
*/
protected final List<Object> listPossibleTypes( CPropertyInfo prop ) {
List<Object> r = new ArrayList<Object>();
for( CTypeInfo tt : prop.ref() ) {
JType t = tt.getType().toType(outline.parent(),Aspect.EXPOSED);
if( t.isPrimitive() || t.isArray() )
r.add(t.fullName());
else {
r.add(t);
r.add("\n");
}
}
return r;
}
示例15
/**
* Reads fields of the super class and includes them
* to name collision tests.
*/
void readSuperClass( CClassInfo base ) {
for( ; base!=null; base=base.getBaseClass() ) {
for( CPropertyInfo p : base.getProperties() )
occupiedLabels.put(p.getName(true),p);
}
}
示例16
/**
* Determines the FieldRenderer used for the given FieldUse,
* then generates the field declaration and accessor methods.
*
* The <code>fields</code> map will be updated with the newly
* created FieldRenderer.
*/
private FieldOutline generateFieldDecl(ClassOutlineImpl cc, CPropertyInfo prop) {
FieldRenderer fr = prop.realization;
if (fr == null) // none is specified. use the default factory
{
fr = model.options.getFieldRendererFactory().getDefault();
}
FieldOutline field = fr.generate(cc, prop);
fields.put(prop, field);
return field;
}
示例17
/**
* If the given component has {@link BIInlineBinaryData} customization,
* reflect that to the specified property.
*/
public static void handle(XSComponent source, CPropertyInfo prop) {
BIInlineBinaryData inline = Ring.get(BGMBuilder.class).getBindInfo(source).get(BIInlineBinaryData.class);
if(inline!=null) {
prop.inlineBinaryData = true;
inline.markAsAcknowledged();
}
}
示例18
/**
* @param coreList
* A concrete class that implements the List interface.
* An instance of this class will be used to store data
* for this field.
*/
protected ContentListField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) {
// the JAXB runtime picks ArrayList if the signature is List,
// so don't do eager allocation if it's ArrayList.
// otherwise we need to do eager allocation so that the collection type specified by the user
// will be used.
super(context, prop, false);
this.coreList = coreList;
generate();
}
示例19
/**
* Attribute use always becomes a property.
*/
public void attributeUse(XSAttributeUse use) {
boolean hasFixedValue = use.getFixedValue()!=null;
BIProperty pc = BIProperty.getCustomization(use);
// map to a constant property ?
boolean toConstant = pc.isConstantProperty() && hasFixedValue;
TypeUse attType = bindAttDecl(use.getDecl());
CPropertyInfo prop = pc.createAttributeProperty( use, attType );
if(toConstant) {
prop.defaultValue = CDefaultValue.create(attType,use.getFixedValue());
prop.realization = builder.fieldRendererFactory.getConst(prop.realization);
} else
if(!attType.isCollection() && (prop.baseType == null ? true : !prop.baseType.isPrimitive())) {
// don't support a collection default value. That's difficult to do.
// primitive types default value is problematic too - we can't check whether it has been set or no ( ==null) isn't possible TODO: emit a waring in these cases
if(use.getDefaultValue()!=null) {
// this attribute use has a default value.
// the item type is guaranteed to be a leaf type... or TODO: is it really so?
// don't support default values if it's a list
prop.defaultValue = CDefaultValue.create(attType,use.getDefaultValue());
} else
if(use.getFixedValue()!=null) {
prop.defaultValue = CDefaultValue.create(attType,use.getFixedValue());
}
} else if(prop.baseType != null && prop.baseType.isPrimitive()) {
ErrorReporter errorReporter = Ring.get(ErrorReporter.class);
errorReporter.warning(prop.getLocator(), Messages.WARN_DEFAULT_VALUE_PRIMITIVE_TYPE, prop.baseType.name());
}
getCurrentBean().addProperty(prop);
}
示例20
protected CPropertyInfo createAttribute(
String elementName, String attributeName, String attributeType,
String[] enums, short attributeUse, String defaultValue )
throws SAXException {
boolean required = attributeUse==USE_REQUIRED;
// get the attribute-property declaration
BIElement edecl = bindInfo.element(elementName);
BIAttribute decl=null;
if(edecl!=null) decl=edecl.attribute(attributeName);
String propName;
if(decl==null) propName = model.getNameConverter().toPropertyName(attributeName);
else propName = decl.getPropertyName();
QName qname = new QName("",attributeName);
// if no declaration is specified, just wrap it by
// a FieldItem and let the normalizer handle its content.
TypeUse use;
if(decl!=null && decl.getConversion()!=null)
use = decl.getConversion().getTransducer();
else
use = builtinConversions.get(attributeType);
CPropertyInfo r = new CAttributePropertyInfo(
propName, null,null/*TODO*/, copyLocator(), qname, use, null, required );
if(defaultValue!=null)
r.defaultValue = CDefaultValue.create( use, new XmlString(defaultValue) );
return r;
}
示例21
protected CPropertyInfo createAttribute(
String elementName, String attributeName, String attributeType,
String[] enums, short attributeUse, String defaultValue )
throws SAXException {
boolean required = attributeUse==USE_REQUIRED;
// get the attribute-property declaration
BIElement edecl = bindInfo.element(elementName);
BIAttribute decl=null;
if(edecl!=null) decl=edecl.attribute(attributeName);
String propName;
if(decl==null) propName = model.getNameConverter().toPropertyName(attributeName);
else propName = decl.getPropertyName();
QName qname = new QName("",attributeName);
// if no declaration is specified, just wrap it by
// a FieldItem and let the normalizer handle its content.
TypeUse use;
if(decl!=null && decl.getConversion()!=null)
use = decl.getConversion().getTransducer();
else
use = builtinConversions.get(attributeType);
CPropertyInfo r = new CAttributePropertyInfo(
propName, null,null/*TODO*/, copyLocator(), qname, use, null, required );
if(defaultValue!=null)
r.defaultValue = CDefaultValue.create( use, new XmlString(defaultValue) );
return r;
}
示例22
/**
* Attribute use always becomes a property.
*/
public void attributeUse(XSAttributeUse use) {
boolean hasFixedValue = use.getFixedValue()!=null;
BIProperty pc = BIProperty.getCustomization(use);
// map to a constant property ?
boolean toConstant = pc.isConstantProperty() && hasFixedValue;
TypeUse attType = bindAttDecl(use.getDecl());
CPropertyInfo prop = pc.createAttributeProperty( use, attType );
if(toConstant) {
prop.defaultValue = CDefaultValue.create(attType,use.getFixedValue());
prop.realization = builder.fieldRendererFactory.getConst(prop.realization);
} else
if(!attType.isCollection() && (prop.baseType == null ? true : !prop.baseType.isPrimitive())) {
// don't support a collection default value. That's difficult to do.
// primitive types default value is problematic too - we can't check whether it has been set or no ( ==null) isn't possible TODO: emit a waring in these cases
if(use.getDefaultValue()!=null) {
// this attribute use has a default value.
// the item type is guaranteed to be a leaf type... or TODO: is it really so?
// don't support default values if it's a list
prop.defaultValue = CDefaultValue.create(attType,use.getDefaultValue());
} else
if(use.getFixedValue()!=null) {
prop.defaultValue = CDefaultValue.create(attType,use.getFixedValue());
}
} else if(prop.baseType != null && prop.baseType.isPrimitive()) {
ErrorReporter errorReporter = Ring.get(ErrorReporter.class);
errorReporter.warning(prop.getLocator(), Messages.WARN_DEFAULT_VALUE_PRIMITIVE_TYPE, prop.baseType.name());
}
getCurrentBean().addProperty(prop);
}
示例23
/**
* @param coreList
* A concrete class that implements the List interface.
* An instance of this class will be used to store data
* for this field.
*/
protected NoExtendedContentField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) {
// the JAXB runtime picks ArrayList if the signature is List,
// so don't do eager allocation if it's ArrayList.
// otherwise we need to do eager allocation so that the collection type specified by the user
// will be used.
super(context, prop, false);
this.coreList = coreList;
generate();
}
示例24
public CPropertyInfo createElementOrReferenceProperty(
String defaultName, boolean forConstant, XSParticle source,
RawTypeSet types) {
boolean generateRef;
switch(types.canBeTypeRefs) {
case CAN_BE_TYPEREF:
case SHOULD_BE_TYPEREF:
// it's up to the use
Boolean b = generateElementProperty();
if(b==null) // follow XJC recommendation
generateRef = types.canBeTypeRefs== RawTypeSet.Mode.CAN_BE_TYPEREF;
else // use the value user gave us
generateRef = b;
break;
case MUST_BE_REFERENCE:
generateRef = true;
break;
default:
throw new AssertionError();
}
if(generateRef) {
return createReferenceProperty(defaultName,forConstant,source,types, false, false, false, false);
} else {
return createElementProperty(defaultName,forConstant,source,types);
}
}
示例25
/**
* Reads fields of the super class and includes them
* to name collision tests.
*/
void readSuperClass( CClassInfo base ) {
for( ; base!=null; base=base.getBaseClass() ) {
for( CPropertyInfo p : base.getProperties() )
occupiedLabels.put(p.getName(true),p);
}
}
示例26
/**
* @param coreList
* A concrete class that implements the List interface.
* An instance of this class will be used to store data
* for this field.
*/
protected ContentListField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) {
// the JAXB runtime picks ArrayList if the signature is List,
// so don't do eager allocation if it's ArrayList.
// otherwise we need to do eager allocation so that the collection type specified by the user
// will be used.
super(context, prop, false);
this.coreList = coreList;
generate();
}
示例27
private boolean checkPropertyCollision(CPropertyInfo p1, CPropertyInfo p2) {
if(!p1.getName(true).equals(p2.getName(true)))
return false;
errorReceiver.error(p1.locator,Messages.DUPLICATE_PROPERTY.format(p1.getName(true)));
errorReceiver.error(p2.locator,Messages.ERR_RELEVANT_LOCATION.format());
return true;
}
示例28
/**
* Gets all the {@link FieldOutline}s newly declared
* in this class.
*/
public final FieldOutline[] getDeclaredFields() {
List<CPropertyInfo> props = target.getProperties();
FieldOutline[] fr = new FieldOutline[props.size()];
for( int i=0; i<fr.length; i++ )
fr[i] = parent().getField(props.get(i));
return fr;
}
示例29
/**
* Gets all the {@link FieldOutline}s newly declared
* in this class.
*/
public final FieldOutline[] getDeclaredFields() {
List<CPropertyInfo> props = target.getProperties();
FieldOutline[] fr = new FieldOutline[props.size()];
for( int i=0; i<fr.length; i++ )
fr[i] = parent().getField(props.get(i));
return fr;
}
示例30
private FieldRenderer decideRenderer(ClassOutlineImpl outline, CPropertyInfo prop) {
if (prop instanceof CReferencePropertyInfo) {
CReferencePropertyInfo p = (CReferencePropertyInfo)prop;
if (p.isDummy()) {
return frf.getDummyList(outline.parent().getCodeModel().ref(ArrayList.class));
}
if (p.isContent() && (p.isMixedExtendedCust())) {
return frf.getContentList(outline.parent().getCodeModel().ref(ArrayList.class).narrow(Serializable.class));
}
}
if(!prop.isCollection()) {
// non-collection field
// TODO: check for bidning info for optionalPrimitiveType=boxed or
// noHasMethod=false and noDeletedMethod=false
if(prop.isUnboxable())
// this one uses a primitive type as much as possible
return frf.getRequiredUnboxed();
else
// otherwise use the default non-collection field
return frf.getSingle();
}
if( defaultCollectionFieldRenderer==null ) {
return frf.getList(outline.parent().getCodeModel().ref(ArrayList.class));
}
// this field is a collection field.
// use untyped list as the default. This is consistent
// to the JAXB spec.
return defaultCollectionFieldRenderer;
}