private void writeXmlSeeAlso(JDefinedClass cls) { if (model.getJAXBModel().getS2JJAXBModel() != null) { List<JClass> objectFactories = model.getJAXBModel().getS2JJAXBModel().getAllObjectFactories(); //if there are no object facotires, dont generate @XmlSeeAlso if (objectFactories.isEmpty()) { return; } JAnnotationUse xmlSeeAlso = cls.annotate(cm.ref(XmlSeeAlso.class)); JAnnotationArrayMember paramArray = xmlSeeAlso.paramArray("value"); for (JClass of : objectFactories) { paramArray = paramArray.param(of); } } }
private static LinkedList<FieldsOfSubType> getFieldsOfSubTypes(Class<?> thisType, StubTypeTreeRepository typeTreeRepository) { LinkedList<FieldsOfSubType> fieldsOfAllSubTypes = new LinkedList<FieldsOfSubType>(); if (!thisType.isAnnotationPresent(XmlSeeAlso.class)) { return fieldsOfAllSubTypes; } List<Class<?>> subTypes = getSubTypes(thisType); registerToStubTypeTree(thisType, typeTreeRepository, subTypes); for (Class<?> subType : subTypes) { FieldsOfSubType fieldsOfSubType = new FieldsOfSubType(subType); fieldsOfSubType.addAll(Arrays.asList(subType.getDeclaredFields())); LinkedList<FieldsOfSubType> fieldsOfGrandSonType = getFieldsOfSubTypes(subType, typeTreeRepository); fieldsOfAllSubTypes.add(fieldsOfSubType); fieldsOfAllSubTypes.addAll(fieldsOfGrandSonType); } return fieldsOfAllSubTypes; }
/** * Traverse XML data object hierarchy and collect all descendants of a root class. * * @param rootClass root class of type hierarchy * @param clazz type class to be processed * @param classes set to collect type classes */ public static void collectXmlTypes(Class<?> rootClass, Class<?> clazz, Set<Class<?>> classes) { if (classes.contains(clazz)) { return; } if (clazz != rootClass && rootClass.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) { classes.add(clazz); } XmlSeeAlso xmlSeeAlso = clazz.getAnnotation(XmlSeeAlso.class); if (xmlSeeAlso != null) { Collection<Class<?>> referencedClasses = new HashSet<>(Arrays.<Class<?>>asList(xmlSeeAlso.value())); for (Class<?> referencedClass : referencedClasses) { collectXmlTypes(rootClass, referencedClass, classes); } } }
private void writeXmlSeeAlso(JDefinedClass cls) { if (model.getJAXBModel().getS2JJAXBModel() != null) { List<JClass> objectFactories = model.getJAXBModel().getS2JJAXBModel().getAllObjectFactories(); //if there are no object facotires, dont generate @XmlSeeAlso if(objectFactories.size() == 0) return; JAnnotationUse xmlSeeAlso = cls.annotate(cm.ref(XmlSeeAlso.class)); JAnnotationArrayMember paramArray = xmlSeeAlso.paramArray("value"); for (JClass of : objectFactories) { paramArray = paramArray.param(of); } } }
private static MutableLocatable<?> valueForMutableLocatable(Class<?> clazz) throws Exception { Class<?> currentClass = clazz; while (true) { if (Modifier.isAbstract(currentClass.getModifiers())) { XmlSeeAlso annotation = currentClass.getAnnotation(XmlSeeAlso.class); Assert.assertNotNull(annotation, String.format("Missing @%s annotation on %s.", XmlSeeAlso.class.getSimpleName(), currentClass)); currentClass = (Class<?>) annotation.value()[0]; } else { return (MutableLocatable<?>) currentClass.getConstructor().newInstance(); } } }
private static List<Class<?>> getSubTypes(Class<?> thisType) { List<Class<?>> subTypes = new ArrayList<Class<?>>(); for (Class<?> subType : thisType.getAnnotation(XmlSeeAlso.class).value()) { if (thisType.isAssignableFrom(subType)) { subTypes.add(subType); } } return subTypes; }
static AnnotationDesc create(Class cls) { AnnotationDescImpl aDesc = new AnnotationDescImpl(); // XMLSeeAlso is part of JAXB 2.1.2. // The assumption is that this is a prereq for JAXWS 2.1; thus // we can safely reference this class XmlSeeAlso xmlSeeAlso = (XmlSeeAlso) getAnnotation(cls, XmlSeeAlso.class); if (xmlSeeAlso != null) { aDesc._XmlSeeAlsoClasses = xmlSeeAlso.value(); } QName qName = XMLRootElementUtil.getXmlRootElementQName(cls); if (qName != null) { aDesc._hasXmlRootElement = true; aDesc._XmlRootElementName = qName.getLocalPart(); aDesc._XmlRootElementNamespace = qName.getNamespaceURI(); } qName = XMLRootElementUtil.getXmlTypeQName(cls); if (qName != null) { aDesc._hasXmlType = true; aDesc._XmlTypeName = qName.getLocalPart(); aDesc._XmlTypeNamespace = qName.getNamespaceURI(); } return aDesc; }
/** * Create new <tt>XmlSeeAlso</tt> annotation. * @param file Javassist file to work with * @param types The class to refer to * @return The annotation */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private static Annotation xmlSeeAlso(final ClassFile file, final Collection<Class<?>> types) { final Annotation annotation = new Annotation( XmlSeeAlso.class.getName(), file.getConstPool() ); final ArrayMemberValue member = new ArrayMemberValue( file.getConstPool() ); final ClassMemberValue[] values = new ClassMemberValue[types.size()]; int pos = 0; for (final Class<?> type : types) { values[pos] = new ClassMemberValue( type.getName(), file.getConstPool() ); pos += 1; } member.setValue(values); annotation.addMemberValue("value", member); Logger.debug( JaxbGroup.class, "#xmlSeeAlso(.., %d classes): annotation created", types.size() ); return annotation; }
void processClass(Class clazz) { classUsesWebMethod = new HashSet<Class>(); determineWebMethodUse(clazz); WebService webService = getAnnotation(clazz, WebService.class); QName portTypeName = getPortTypeName(clazz, targetNamespace, metadataReader); // String portTypeLocalName = clazz.getSimpleName(); // if (webService.name().length() >0) // portTypeLocalName = webService.name(); // // targetNamespace = webService.targetNamespace(); packageName = ""; if (clazz.getPackage() != null) packageName = clazz.getPackage().getName(); // if (targetNamespace.length() == 0) { // targetNamespace = getNamespace(packageName); // } // model.setTargetNamespace(targetNamespace); // QName portTypeName = new QName(targetNamespace, portTypeLocalName); targetNamespace = portTypeName.getNamespaceURI(); model.setPortTypeName(portTypeName); model.setTargetNamespace(targetNamespace); model.defaultSchemaNamespaceSuffix = config.getMappingInfo().getDefaultSchemaNamespaceSuffix(); model.setWSDLLocation(webService.wsdlLocation()); SOAPBinding soapBinding = getAnnotation(clazz, SOAPBinding.class); if (soapBinding != null) { if (soapBinding.style() == SOAPBinding.Style.RPC && soapBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) { throw new RuntimeModelerException("runtime.modeler.invalid.soapbinding.parameterstyle", soapBinding, clazz); } isWrapped = soapBinding.parameterStyle()== WRAPPED; } defaultBinding = createBinding(soapBinding); /* * if clazz != portClass then there is an SEI. If there is an * SEI, then all methods should be processed. However, if there is * no SEI, and the implementation class uses at least one * WebMethod annotation, then only methods with this annotation * will be processed. */ /* if (clazz == portClass) { WebMethod webMethod; for (Method method : clazz.getMethods()) { webMethod = getPrivMethodAnnotation(method, WebMethod.class); if (webMethod != null && !webMethod.exclude()) { usesWebMethod = true; break; } } }*/ for (Method method : clazz.getMethods()) { if (!clazz.isInterface()) { // if clazz is SEI, then all methods are web methods if (method.getDeclaringClass() == Object.class) continue; if (!getBooleanSystemProperty("com.sun.xml.internal.ws.legacyWebMethod")) { // legacy webMethod computation behaviour to be used if (!isWebMethodBySpec(method, clazz)) continue; } else { if (!isWebMethod(method)) continue; } } // TODO: binding can be null. We need to figure out how to post-process // RuntimeModel to link to WSDLModel processMethod(method); } //Add additional jaxb classes referenced by {@link XmlSeeAlso} XmlSeeAlso xmlSeeAlso = getAnnotation(clazz, XmlSeeAlso.class); if(xmlSeeAlso != null) model.addAdditionalClasses(xmlSeeAlso.value()); }
void processClass(Class clazz) { WebService webService = getPrivClassAnnotation(clazz, WebService.class); String portTypeLocalName = clazz.getSimpleName(); if (webService.name().length() >0) portTypeLocalName = webService.name(); targetNamespace = webService.targetNamespace(); packageName = ""; if (clazz.getPackage() != null) packageName = clazz.getPackage().getName(); if (targetNamespace.length() == 0) { targetNamespace = getNamespace(packageName); } model.setTargetNamespace(targetNamespace); QName portTypeName = new QName(targetNamespace, portTypeLocalName); model.setPortTypeName(portTypeName); model.setWSDLLocation(webService.wsdlLocation()); SOAPBinding soapBinding = getPrivClassAnnotation(clazz, SOAPBinding.class); if (soapBinding != null) { if (soapBinding.style() == SOAPBinding.Style.RPC && soapBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) { throw new RuntimeModelerException("runtime.modeler.invalid.soapbinding.parameterstyle", soapBinding, clazz); } isWrapped = soapBinding.parameterStyle()== WRAPPED; } defaultBinding = createBinding(soapBinding); /* * if clazz != portClass then there is an SEI. If there is an * SEI, then all methods should be processed. However, if there is * no SEI, and the implementation class uses at least one * WebMethod annotation, then only methods with this annotation * will be processed. */ /* if (clazz == portClass) { WebMethod webMethod; for (Method method : clazz.getMethods()) { webMethod = getPrivMethodAnnotation(method, WebMethod.class); if (webMethod != null && !webMethod.exclude()) { usesWebMethod = true; break; } } }*/ for (Method method : clazz.getMethods()) { if (!clazz.isInterface()) { // if clazz is SEI, then all methods are web methods if (!isWebMethodBySpec(method, clazz)) { continue; } } // TODO: binding can be null. We need to figure out how to post-process // RuntimeModel to link to WSDLModel processMethod(method); } //Add additional jaxb classes referenced by {@link XmlSeeAlso} XmlSeeAlso xmlSeeAlso = getPrivClassAnnotation(clazz, XmlSeeAlso.class); if(xmlSeeAlso != null) model.addAdditionalClasses(xmlSeeAlso.value()); }
@Override public void visit(AttributeCategory attributeCategory) { XmlSeeAlso annotation = BaseChildEditorElement.class.getAnnotation(XmlSeeAlso.class); addMenuEntry(manager, annotation, attributeCategory); }
@Override public void visit(Group group) { XmlSeeAlso annotation = BaseFieldEditorElement.class.getAnnotation(XmlSeeAlso.class); addMenuEntry(manager, annotation, group); }
@Override public void visit(Horizontal horizontal) { XmlSeeAlso annotation = BaseFieldEditorElement.class.getAnnotation(XmlSeeAlso.class); addMenuEntry(manager, annotation, horizontal); }
@Override public void visit(Namespace namespace) { XmlSeeAlso annotation = EditorElement.class.getAnnotation(XmlSeeAlso.class); addMenuEntry(manager, annotation, namespace); }
@Override public void visit(Nested nested) { XmlSeeAlso annotation = BaseChildEditorElement.class.getAnnotation(XmlSeeAlso.class); addMenuEntry(manager, annotation, nested); }
private void addMenuEntry(IMenuManager manager, XmlSeeAlso annotation, final Object object) { for (final Class<?> extended : annotation.value()) { if (Modifier.isAbstract(extended.getModifiers())) { XmlSeeAlso innerAnnotation = extended.getAnnotation(XmlSeeAlso.class); if (innerAnnotation != null) { MenuManager subMenu = new MenuManager(extended.getSimpleName(), extended.getCanonicalName()); manager.add(subMenu); addMenuEntry(subMenu, innerAnnotation, object); } } else { manager.add(new Action() { @Override public void run() { try { if (object instanceof Nested) { ((Nested) object).getChildElements().add((BaseChildEditorElement) extended.newInstance()); } else if (object instanceof Namespace) { ((Namespace) object).getComponents().add((EditorElement) extended.newInstance()); } else if (object instanceof Group) { ((Group) object).getChilds().add((BaseFieldEditorElement) extended.newInstance()); } else if (object instanceof Horizontal) { ((Horizontal) object).getChilds().add((BaseFieldEditorElement) extended.newInstance()); } else if (object instanceof AttributeCategory) { ((AttributeCategory) object).getChilds().add((BaseFieldEditorElement) extended.newInstance()); } viewer.refresh(); } catch (InstantiationException | IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public String getText() { return "Add " + extended.getSimpleName(); } }); } } }