in src/main/java/org/apache/sling/hapi/impl/HApiUtilImpl.java [225:275]
public HApiType fromResource(ResourceResolver resolver, Resource typeResource) throws RepositoryException {
if (!enabled) {
return null;
}
if (null == typeResource) return null;
ValueMap resProps = typeResource.adaptTo(ValueMap.class);
String name = resProps.get("name", (String) null);
String description = resProps.get("description", (String) null);
String path = typeResource.getPath();
String fqdn = resProps.get("fqdn", (String) null);
// get parameters
Value[] parameterValues = resProps.get("parameters", new Value[]{});
List<String> parameters = new ArrayList<String>(parameterValues.length);
for (Value p : Arrays.asList(parameterValues)) {
parameters.add(p.getString());
}
// Parent weak reference
String parentPath = resProps.get("extends", (String) null);
HApiType parentWeak = new HApiTypeLazyWrapper(this, resolver, this.serverContextPath, parentPath);
// Properties weak reference
Map<String, HApiProperty> properties = new HashMap<String, HApiProperty>();
for (Resource res : typeResource.getChildren()) {
ValueMap resValueMap = res.adaptTo(ValueMap.class);
String propName = res.getName();
String propDescription = resValueMap.get("description", "");
String typeFqdnOrPath = resValueMap.get("type", (String) null);
Resource propTypeResource = getTypeResource(resolver, typeFqdnOrPath);
HApiType propTypeWeak = (null != propTypeResource)
? new HApiTypeLazyWrapper(this, resolver, this.serverContextPath, propTypeResource)
: new AbstractHapiTypeImpl(typeFqdnOrPath);
Boolean propMultiple = resValueMap.get("multiple", false);
HApiProperty prop = new HApiPropertyImpl(propName, propDescription, propTypeWeak, propMultiple);
properties.put(prop.getName(), prop);
}
//
// Create type and add to cache
//
HApiTypeImpl newType = new HApiTypeImpl(name, description, serverContextPath, path, fqdn, parameters, properties, parentWeak, false);
TypesCache.getInstance(this).addType(newType);
LOG.debug("Inserted type {} to cache: {}", newType, TypesCache.getInstance(this));
LOG.debug("Created type {}", newType);
return newType;
}