use of org.jvnet.hk2.config.ConfigModel in project Payara by payara.
the class AllModelsImplementingTest method checkResources.
@Test
public void checkResources() throws ClassNotFoundException {
ServiceLocator habitat = getHabitat();
Resources resources = habitat.<Domain>getService(Domain.class).getResources();
Dom dom = Dom.unwrap(resources);
List<ConfigModel> models = dom.document.getAllModelsImplementing(Resource.class);
for (ConfigModel model : models) {
Logger.getAnonymousLogger().fine(model.targetTypeName);
}
assertTrue(models.size() > 0);
}
use of org.jvnet.hk2.config.ConfigModel in project Payara by payara.
the class ResourcesGeneratorBase method generateSingle.
/**
* Generate REST resource for a single config model.
*/
@Override
public void generateSingle(ConfigModel model, DomDocument domDocument) {
configModelVisited(model);
// processRedirectsAnnotation(model); // TODO need to extract info from RestRedirect Annotations
String serverConfigName = ResourceUtil.getUnqualifiedTypeName(model.targetTypeName);
String beanName = getBeanName(serverConfigName);
String className = getClassName(beanName);
if (alreadyGenerated(className)) {
return;
}
String baseClassName = "TemplateRestResource";
String resourcePath = null;
if (beanName.equals("Domain")) {
baseClassName = "org.glassfish.admin.rest.resources.GlassFishDomainResource";
resourcePath = "domain";
}
ClassWriter classWriter = getClassWriter(className, baseClassName, resourcePath);
if (classWriter != null) {
generateCommandResources(beanName, classWriter);
generateGetDeleteCommandMethod(beanName, classWriter);
generateCustomResourceMapping(beanName, classWriter);
for (String elementName : model.getElementNames()) {
ConfigModel.Property childElement = model.getElement(elementName);
if (elementName.equals("*")) {
ConfigModel.Node node = (ConfigModel.Node) childElement;
ConfigModel childModel = node.getModel();
List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, domDocument);
for (ConfigModel subChildConfigModel : subChildConfigModels) {
if (ResourceUtil.isOnlyATag(childModel) || ResourceUtil.isOnlyATag(subChildConfigModel) || subChildConfigModel.getAttributeNames().isEmpty() || hasSingletonAnnotation(subChildConfigModel)) {
String childResourceClassName = getClassName(ResourceUtil.getUnqualifiedTypeName(subChildConfigModel.targetTypeName));
String childPath = subChildConfigModel.getTagName();
classWriter.createGetChildResource(childPath, childResourceClassName);
generateSingle(subChildConfigModel, domDocument);
} else {
processNonLeafChildConfigModel(subChildConfigModel, childElement, domDocument, classWriter);
}
}
} else if (childElement.isLeaf()) {
if (childElement.isCollection()) {
// handle the CollectionLeaf config objects.
// JVM Options is an example of CollectionLeaf object.
String childResourceBeanName = getBeanName(elementName);
String childResourceClassName = getClassName(childResourceBeanName);
classWriter.createGetChildResource(elementName, childResourceClassName);
// create resource class
generateCollectionLeafResource(childResourceBeanName);
} else {
String childResourceBeanName = getBeanName(elementName);
String childResourceClassName = getClassName(childResourceBeanName);
classWriter.createGetChildResource(elementName, childResourceClassName);
// create resource class
generateLeafResource(childResourceBeanName);
}
} else {
// => !childElement.isLeaf()
processNonLeafChildElement(elementName, childElement, domDocument, classWriter);
}
}
classWriter.done();
}
}
use of org.jvnet.hk2.config.ConfigModel in project Payara by payara.
the class ClientGenerator method processElements.
protected Set<String> processElements(ClientClassWriter writer, ConfigModel model) {
Set<String> processed = new HashSet<String>();
for (String elementName : model.getElementNames()) {
if (processed.contains(elementName)) {
continue;
}
processed.add(elementName);
ConfigModel.Property childElement = model.getElement(elementName);
if (elementName.equals("*")) {
ConfigModel.Node node = (ConfigModel.Node) childElement;
ConfigModel childModel = node.getModel();
List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, document);
for (ConfigModel subChildConfigModel : subChildConfigModels) {
if (ResourceUtil.isOnlyATag(childModel)) {
String childResourceClassName = ResourceUtil.getUnqualifiedTypeName(subChildConfigModel.targetTypeName);
writer.createGetChildResource(subChildConfigModel, childResourceClassName, childResourceClassName);
generateSingle(subChildConfigModel);
} else {
processNonLeafChildConfigModel(writer, subChildConfigModel, childElement);
}
}
} else if (childElement.isLeaf()) {
if (processed.contains(childElement.xmlName)) {
continue;
}
processed.add(childElement.xmlName);
if (childElement.isCollection()) {
// generateCollectionLeafResource
System.out.println("generateCollectionLeafResource for " + elementName + " off of " + model.getTagName());
generateCollectionLeafResource(writer, childElement.xmlName);
} else {
System.out.println("generateLeafResource for " + elementName + " off of " + model.getTagName());
// generateSingle(document.getModelByElementName(elementName));
generateLeafResource(writer, childElement.xmlName);
}
} else {
processNonLeafChildElement(writer, elementName, childElement);
}
}
return processed;
}
use of org.jvnet.hk2.config.ConfigModel in project Payara by payara.
the class ClientGenerator method processAttributes.
protected void processAttributes(ClientClassWriter writer, ConfigModel model, Set<String> processed) {
Class clazz = model.getProxyType();
for (Method method : clazz.getMethods()) {
String methodName = method.getName();
Attribute a = method.getAnnotation(Attribute.class);
Param p = method.getAnnotation(Param.class);
if ((a != null) || (p != null)) {
String type = "String";
if (a != null) {
type = a.dataType().getName();
}
if (methodName.startsWith("get") || methodName.startsWith("set")) {
methodName = methodName.substring(3);
}
String fieldName = Util.lowerCaseFirstLetter(methodName);
if (processed.contains(fieldName)) {
continue;
}
processed.add(fieldName);
writer.generateGettersAndSetters(type, methodName, fieldName);
}
}
}
use of org.jvnet.hk2.config.ConfigModel in project Payara by payara.
the class BaseProvider method getResourceLinks.
protected Map<String, String> getResourceLinks(Dom dom) {
Map<String, String> links = new TreeMap<String, String>();
Set<String> elementNames = dom.model.getElementNames();
for (String elementName : elementNames) {
// for each element
if (elementName.equals("*")) {
ConfigModel.Node node = (ConfigModel.Node) dom.model.getElement(elementName);
ConfigModel childModel = node.getModel();
List<ConfigModel> lcm = ResourceUtil.getRealChildConfigModels(childModel, dom.document);
Collections.sort(lcm, new ConfigModelComparator());
if (lcm != null) {
Collections.sort(lcm, new ConfigModelComparator());
for (ConfigModel cmodel : lcm) {
links.put(cmodel.getTagName(), ProviderUtil.getElementLink(uriInfo.get(), cmodel.getTagName()));
}
}
} else {
links.put(elementName, ProviderUtil.getElementLink(uriInfo.get(), elementName));
}
}
return links;
}
Aggregations