예제 #1
0
 /**
  * Resolves the state corresponding to a property.
  *
  * @param name the property name
  * @return the resolved state
  * @throws PropertyResolverException if the name is invalid
  */
 @Override
 @SuppressWarnings({"deprecation"})
 public PropertyState resolve(String name) {
   PropertyState state;
   IMObject object = root;
   ArchetypeDescriptor archetype = this.archetype;
   int index;
   while ((index = name.indexOf(".")) != -1) {
     String nodeName = name.substring(0, index);
     NodeDescriptor node = archetype.getNodeDescriptor(nodeName);
     if (node == null) {
       throw new NodeResolverException(InvalidProperty, name);
     }
     Object value = getValue(object, node);
     if (value == null) {
       // object missing.
       object = null;
       break;
     } else if (!(value instanceof IMObject)) {
       throw new NodeResolverException(InvalidObject, name);
     }
     object = (IMObject) value;
     archetype = service.getArchetypeDescriptor(object.getArchetypeId());
     name = name.substring(index + 1);
   }
   if (object != null) {
     NodeDescriptor leafNode = archetype.getNodeDescriptor(name);
     Object value;
     if (leafNode == null) {
       if ("displayName".equals(name)) {
         value = archetype.getDisplayName();
       } else if ("shortName".equals(name)) {
         value = object.getArchetypeId().getShortName();
       } else if ("uid".equals(name)) {
         value = object.getId();
       } else {
         throw new NodeResolverException(InvalidProperty, name);
       }
     } else {
       value = getValue(object, leafNode);
     }
     state = new PropertyState(object, archetype, name, leafNode, value);
   } else {
     state = new PropertyState();
   }
   return state;
 }
예제 #2
0
 /**
  * Constructs a {@link NodeResolver}.
  *
  * @param root the root object
  * @param service the archetype service
  */
 public NodeResolver(IMObject root, IArchetypeService service) {
   this.root = root;
   archetype = service.getArchetypeDescriptor(root.getArchetypeId());
   this.service = service;
 }