1 23 24 package org.apache.slide.projector.processor.query; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import org.apache.slide.projector.Context; 30 import org.apache.slide.projector.Processor; 31 import org.apache.slide.projector.Projector; 32 import org.apache.slide.projector.Result; 33 import org.apache.slide.projector.descriptor.ParameterDescriptor; 34 import org.apache.slide.projector.descriptor.ResultDescriptor; 35 import org.apache.slide.projector.descriptor.ResultEntryDescriptor; 36 import org.apache.slide.projector.descriptor.StateDescriptor; 37 import org.apache.slide.projector.descriptor.URIValueDescriptor; 38 import org.apache.slide.projector.i18n.DefaultMessage; 39 import org.apache.slide.projector.i18n.ParameterMessage; 40 import org.apache.slide.projector.value.ArrayValue; 41 import org.apache.slide.projector.value.MapValue; 42 import org.apache.slide.projector.value.URIValue; 43 44 48 public class PropertyQuery implements Processor { 49 private final static String EMPTY = "empty"; 50 private final static String URI = "uri"; 51 private final static String ARRAY = "array"; 52 private final static String MAP = "map"; 53 54 private static ResultDescriptor resultDescriptor = new ResultDescriptor( 55 new StateDescriptor[] { 56 StateDescriptor.OK_DESCRIPTOR, 57 new StateDescriptor(EMPTY, new DefaultMessage("propertyQuery/state/empty"))}, 58 new ResultEntryDescriptor[] { 59 new ResultEntryDescriptor(ARRAY, new ParameterMessage("propertyQuery/array"), ArrayValue.CONTENT_TYPE, false), 60 new ResultEntryDescriptor(MAP, new ParameterMessage("propertyQuery/map"), MapValue.CONTENT_TYPE, false) 61 }); 62 63 private static ParameterDescriptor []parameterDescriptors = new ParameterDescriptor[] { 64 new ParameterDescriptor(URI, new DefaultMessage("propertyQuery/uri"), new URIValueDescriptor()) 65 }; 66 67 public Result process(Map parameter, Context context) throws Exception { 68 ArrayValue properties = Projector.getRepository().getProperties((URIValue)parameter.get(URI), context.getCredentials()); 69 if ( properties.getArray().length == 0 ) return new Result(EMPTY); 70 Result result= new Result(StateDescriptor.OK, ARRAY, properties); 71 Map properyMap = new HashMap (); 72 for ( int i = 0; i < properties.getArray().length; i++ ) { 73 properyMap.put(((MapValue)properties.getArray()[i]).getMap().get("name").toString(), ((MapValue)properties.getArray()[i]).getMap().get("value")); 74 } 75 result.addResultEntry(MAP, new MapValue(properyMap)); 76 return result; 77 } 78 79 public ParameterDescriptor[] getParameterDescriptors() { 80 return parameterDescriptors; 81 } 82 83 public ResultDescriptor getResultDescriptor() { 84 return resultDescriptor; 85 } 86 } | Popular Tags |