protected ElementMappingImpl(JAXBModelImpl parent, CElementInfo elementInfo) { super(parent,elementInfo); TypeUse t = clazz.getContentType(); if(clazz.getProperty().isCollection()) t = TypeUseFactory.makeCollection(t); CAdapter a = clazz.getProperty().getAdapter(); if(a!=null) t = TypeUseFactory.adapt(t,a); taa = new TypeAndAnnotationImpl(parent.outline,t); }
/*package*/ void add( CElementInfo ei ) { NClass clazz = null; if(ei.getScope()!=null) clazz = ei.getScope().getClazz(); Map<QName,CElementInfo> m = elementMappings.get(clazz); if(m==null) elementMappings.put(clazz, m = new LinkedHashMap<QName, CElementInfo>()); m.put(ei.getElementName(),ei); }
/** * 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; }
protected CTypeRef toTypeRef(CElementPropertyInfo ep) { assert !target.isCollection(); CAdapter a = target.getProperty().getAdapter(); if(a!=null && ep!=null) ep.setAdapter(a); return new CTypeRef(target.getContentType(),decl); }
JType exposedElementType = ei.toType(outline,exposed); JType exposedType = ei.getContentInMemoryType().toType(outline,exposed); JType implType = ei.getContentInMemoryType().toType(outline,impl); String namespaceURI = ei.getElementName().getNamespaceURI(); String localPart = ei.getElementName().getLocalPart(); if(ei.getScope()!=null) scope = outline.getClazz(ei.getScope()).implClass; if(ei.isAbstract()) { CElementInfo existing = elementFactoryNames.put(ei.getSqueezedName(),ei); if( existing!=null ) { outline.getErrorReceiver().error(existing.getLocator(), Messages.OBJECT_FACTORY_CONFLICT.format(ei.getSqueezedName())); outline.getErrorReceiver().error(ei.getLocator(), Messages.OBJECT_FACTORY_CONFLICT_RELATED.format()); return; m = objectFactory.method( JMod.PUBLIC, exposedElementType, "create" + ei.getSqueezedName() ); JVar $value = m.param(exposedType,"value"); if(!ei.hasClass()) { exp.arg(getQNameInvocation(ei)); exp.arg(declaredType); if(ei.getSubstitutionHead()!=null) { QName n = ei.getSubstitutionHead().getElementName(); xemw.substitutionHeadNamespace(n.getNamespaceURI());
parent.getContainer( ei.parent, Aspect.EXPOSED ), ei.shortName(), ei.getLocator() )); this.parent = parent; parent.elements.put(ei,this); 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()));
protected RawTypeSet.Mode canBeType(RawTypeSet parent) { // if element substitution can occur, no way it can be mapped to a list of types if(decl.getSubstitutables().size()>1) return RawTypeSet.Mode.MUST_BE_REFERENCE; // BIXSubstitutable also simulates this effect. Useful for separate compilation BIXSubstitutable subst = builder.getBindInfo(decl).get(BIXSubstitutable.class); if(subst!=null) { subst.markAsAcknowledged(); return RawTypeSet.Mode.MUST_BE_REFERENCE; } // we have no place to put an adater if this thing maps to a type CElementPropertyInfo p = target.getProperty(); // if we have an adapter or IDness, which requires special // annotation, and there's more than one element, // we have no place to put the special annotation, so we need JAXBElement. if((parent.refs.size()>1 || !parent.mul.isAtMostOnce()) && p.id()!=ID.NONE) return RawTypeSet.Mode.MUST_BE_REFERENCE; if(parent.refs.size() > 1 && p.getAdapter() != null) return RawTypeSet.Mode.MUST_BE_REFERENCE; if(target.hasClass()) // if the CElementInfo was explicitly bound to a class (which happen if and only if // the user requested so, then map that to reference property so that the user sees a class return RawTypeSet.Mode.CAN_BE_TYPEREF; else return RawTypeSet.Mode.SHOULD_BE_TYPEREF; }
} else { CElementInfo eref = (CElementInfo)ref; if(!eref.getSubstitutionMembers().isEmpty()) return null; // elements with a substitution group isn't qualified for the wrapper style fr, eref.getElementName()));
private JInvocation getCopyOfElementInfoInvocation( final FieldOutline fieldOutline, final CElementInfo element ) final JType elementType = element.toType( fieldOutline.parent().parent(), Aspect.IMPLEMENTATION ); final JType[] signature = if ( element.hasClass() ) methodName = "copyOf" + element.shortName(); element.getContentType().toType( fieldOutline.parent().parent(), Aspect.IMPLEMENTATION ) ) + "Element"; if ( element.hasClass() ) fieldOutline, element.getContentType(), elementNotNull._then(), JExpr.cast( element.getContentType().toType( fieldOutline.parent().parent(), Aspect.IMPLEMENTATION ), JExpr.invoke( e, "getValue" ) ), true ) ); elementNotNull._then().add( copy.invoke( "setNil" ).arg( e.invoke( "isNil" ) ) ); if ( !element.hasClass() ) fieldOutline, element.getContentType(), elementNotNull._then(), JExpr.cast( element.getContentType().toType( fieldOutline.parent().parent(), Aspect.IMPLEMENTATION ), copy.invoke( "getValue" ) ), true ) ) );
if (!elementInfo.getSubstitutionMembers().isEmpty()) { logger.error("[" + ((CClassInfo) propertyInfo.parent()).getName() + propertyInfo.getName(true) + "] is a single hetero reference containing element [" + elementInfo.getSqueezedName() + "] which is a substitution group head. See issue #95."); } else { itemPropertyInfo.getTypes().addAll( context.getGetTypes().getTypes(context, ((CElementInfo) element).getProperty()));
private JExpression getElementCopyExpression( final FieldOutline fieldOutline, final CElementInfo type, final JBlock block, final JExpression sourceExpr ) { block.directStatement( "// CElementInfo: " + type.toType( fieldOutline.parent().parent(), Aspect.IMPLEMENTATION ).binaryName() ); return this.getCopyOfElementInfoInvocation( fieldOutline, type ).arg( sourceExpr ); }
public int compare( final CElementInfo o1, final CElementInfo o2 ) { final JClass javaClass1; final JClass javaClass2; if ( this.hasClass ) { javaClass1 = (JClass) o1.toType( this.outline, Aspect.IMPLEMENTATION ); javaClass2 = (JClass) o2.toType( this.outline, Aspect.IMPLEMENTATION ); } else { javaClass1 = (JClass) o1.getContentType().toType( this.outline, Aspect.IMPLEMENTATION ); javaClass2 = (JClass) o2.getContentType().toType( this.outline, Aspect.IMPLEMENTATION ); } int ret = 0; if ( !javaClass1.binaryName().equals( javaClass2.binaryName() ) ) { if ( javaClass1.isAssignableFrom( javaClass2 ) ) { ret = -1; } else if ( javaClass2.isAssignableFrom( javaClass1 ) ) { ret = 1; } } return ret; }
XSSchemaSet schemaSet = outline.getModel().schemaComponent; for (CElementInfo elementInfo : outline.getModel().getAllElements()) { QName name = elementInfo.getElementName(); XSComponent elementDecl; if (elementInfo.getSchemaComponent() != null) { // it's strange but elements seem not to have this filled-in... elementDecl = elementInfo.getSchemaComponent(); } else { elementDecl = schemaSet.getElementDecl(name.getNamespaceURI(), name.getLocalPart()); print("*** Raw element found: " + elementInfo.getElementName()); JDefinedClass objectFactory = outline.getPackageContext(elementInfo._package()).objectFactory(); boolean methodFound = false; // finding method corresponding to the given element for (JMethod method : objectFactory.methods()) {
JAXBModelImpl(Outline outline) { this.model = outline.getModel(); this.outline = outline; for (CClassInfo ci : model.beans().values()) { if(!ci.isElement()) continue; byXmlName.put(ci.getElementName(),new BeanMappingImpl(this,ci)); } for (CElementInfo ei : model.getElementMappings(null).values()) { byXmlName.put(ei.getElementName(),new ElementMappingImpl(this,ei)); } }
/** * Returns all <i>used</i> JPackages. * * A JPackage is considered as "used" if a ClassItem or * a InterfaceItem resides in that package. * * This value is dynamically calculated every time because * one can freely remove ClassItem/InterfaceItem. * * @return * Given the same input, the order of packages in the array * is always the same regardless of the environment. */ public final JPackage[] getUsedPackages( Aspect aspect ) { Set<JPackage> s = new TreeSet<JPackage>(); for( CClassInfo bean : model.beans().values() ) { JClassContainer cont = getContainer(bean.parent(),aspect); if(cont.isPackage()) s.add( (JPackage)cont ); } for( CElementInfo e : model.getElementMappings(null).values() ) { // at the first glance you might think we should be iterating all elements, // not just global ones, but if you think about it, local ones live inside // another class, so those packages are already enumerated when we were // walking over CClassInfos. s.add( e._package() ); } return s.toArray(new JPackage[s.size()]); }
public ElementOutlineImpl getElement(CElementInfo ei) { ElementOutlineImpl def = elements.get(ei); if (def == null && ei.hasClass()) { // create one. in the constructor it adds itself to the elements. def = new ElementOutlineImpl(this, ei); } return def; }
@Override protected String getLocalName(CElementInfo info) { return info.shortName(); }
/** Returns raw schema name for simpleType property. May return null for other types. */ public final QName rawName() { if (fr instanceof ElementAdapter) { CElementInfo eInfo = ((ElementAdapter)fr).ei; if ((eInfo != null) && (eInfo.getProperty() != null)) { return eInfo.getProperty().getTypes().get(0).getTypeName(); } } return null; }
/** * Returns the "squeezed name" of this element. * * @see CClassInfo#getSqueezedName() */ @XmlElement public String getSqueezedName() { if(squeezedName!=null) return squeezedName; StringBuilder b = new StringBuilder(); CClassInfo s = getScope(); if(s!=null) b.append(s.getSqueezedName()); if(className!=null) b.append(className); else b.append( model.getNameConverter().toClassName(tagName.getLocalPart())); return b.toString(); }
public static Set<JType> getPossibleTypes(Outline outline, Aspect aspect, CTypeInfo typeInfo) { final Set<JType> types = new HashSet<JType>(); types.add(typeInfo.getType().toType(outline, aspect)); if (typeInfo instanceof CElementInfo) { final CElementInfo elementInfo = (CElementInfo) typeInfo; for (CElementInfo substitutionMember : elementInfo .getSubstitutionMembers()) { types.addAll(getPossibleTypes(outline, aspect, substitutionMember)); } } return types; }