protected void log(Object object, int level, StringBuffer log) { ClassProperties props = OwsUtils.getClassProperties(object.getClass()); for (String prop : props.properties()) { if ("class".equalsIgnoreCase(prop)) continue; Object value = OwsUtils.get(object, prop); log.append("\n"); for (int i = 0; i < level; i++) log.append("\t"); log.append(prop).append(" = ").append(value); } } }
/** * Reflectively puts a key, value into a Map property. * * @param object The target object. * @param property The Map property. * @param key The key to place into the map. * @param value The value to place into the map. * @throws IllegalArgumentException If the property specified is not a map * @throws NullPointerException If the property specifies is null */ public static void put(Object object, String property, Object key, Object value) { Object o = get(object, property); if (o == null) { throw new NullPointerException("Property " + property + " is null"); } if (!(o instanceof Map)) { throw new IllegalArgumentException("Property " + property + " is not a map"); } ((Map) o).put(key, value); }
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { String ref = null; if ( OwsUtils.getter( clazz, "name", String.class ) != null ) { ref = (String) OwsUtils.get( source, "name"); } else if ( OwsUtils.getter( clazz, "id", String.class ) != null ) { ref = (String) OwsUtils.get( source, "id"); } else { throw new RuntimeException( "Could not determine identifier for: " + clazz.getName()); } writer.startNode( "name" ); writer.setValue(ref); writer.endNode(); encodeLink(encode(ref), writer); }
private Collection<Object> getCollectionProperty(Object input, String colPropName) { Object colProp = OwsUtils.get(input, colPropName); if (null == colProp) { return null; } if (colProp.getClass().isArray()) { int length = Array.getLength(colProp); List<Object> array = new ArrayList<Object>(length); for (int j = 0; j < length; j++) { array.add(Array.get(colProp, j)); } colProp = array; } if (!(colProp instanceof Collection)) { throw new IllegalArgumentException( "Specified property " + colPropName + " is not a collection or array: " + colProp); } @SuppressWarnings("unchecked") Collection<Object> col = (Collection<Object>) colProp; return col; }
Object value; try { value = OwsUtils.get(obj, p); } catch (Exception e) {
public void marshal( Object source, HierarchicalStreamWriter writer, MarshallingContext context) { String ref; // Special case for layer list, to handle the non-workspace-specific // endpoint for layers if (clazz.equals(LayerInfo.class) && OwsUtils.getter(clazz, "prefixedName", String.class) != null && RequestInfo.get() != null && !RequestInfo.get().getPagePath().contains("/workspaces/")) { ref = (String) OwsUtils.get(source, "prefixedName"); } else if (OwsUtils.getter(clazz, "name", String.class) != null) { ref = (String) OwsUtils.get(source, "name"); } else if (OwsUtils.getter(clazz, "id", String.class) != null) { ref = (String) OwsUtils.get(source, "id"); } else if (OwsUtils.getter(clazz, "id", Long.class) != null) { // For some reason Importer objects have Long ids so this catches that // case ref = OwsUtils.get(source, "id").toString(); } else { throw new RuntimeException( "Could not determine identifier for: " + clazz.getName()); } writer.startNode("name"); writer.setValue(ref); writer.endNode(); encodeLink(encode(ref), writer); }
@Override public boolean apply(T input) { return name.equals(OwsUtils.get(input, "name")); } });
for ( String p : cp.properties() ) { if ( "Class".equals( p ) ) continue; Object value = OwsUtils.get(object, p); if ( value == null ) { value = "null";
protected void setId(Object o) { if (OwsUtils.get(o, "id") == null) { String uid = new UID().toString(); OwsUtils.set(o, "id", o.getClass().getSimpleName() + "-" + uid); } } }
protected void setId(Object o) { if (OwsUtils.get(o, "id") == null) { String uid = new UID().toString(); OwsUtils.set(o, "id", o.getClass().getSimpleName() + "-" + uid); } } }
@Override public int compare(Object o1, Object o2) { Object v1 = OwsUtils.get(o1, sortOrder.getPropertyName().getPropertyName()); Object v2 = OwsUtils.get(o2, sortOrder.getPropertyName().getPropertyName()); if (v1 == null) { if (v2 == null) { return 0; } else { return -1; } } else if (v2 == null) { return 1; } Comparable c1 = (Comparable) v1; Comparable c2 = (Comparable) v2; return c1.compareTo(c2); } };
if (props.length > 1) { for (int i = 0; i < props.length - 1 && object != null; i++) { object = get(object, props[i]);
value = OwsUtils.get(input, propName);
public void testSimple() throws Exception { Foo foo = new Foo(); foo.setA("a"); assertEquals("a", OwsUtils.get(foo, "a")); assertNull(OwsUtils.get(foo, "b")); OwsUtils.set(foo, "b", 5); assertEquals(5, OwsUtils.get(foo, "b")); assertEquals(0f, OwsUtils.get(foo, "c")); OwsUtils.set(foo, "c", 5f); assertEquals(5f, OwsUtils.get(foo, "c")); }
String id = (String) OwsUtils.get(source, "id"); if (id != null && !referenceByName) { writer.startNode("id"); } else { String name = (String) OwsUtils.get(source, "name"); WorkspaceInfo workspace = (WorkspaceInfo) OwsUtils.get(source, "workspace"); if (workspace != null) { wsName = workspace.getName(); prefixedName = (String) OwsUtils.get(source, "prefixedName"); if (prefixedName != null && prefixedName.indexOf(":") > 0) { wsName = prefixedName.substring(0, prefixedName.indexOf(":"));
public void testExtended() throws Exception { Bar bar = new Bar(); assertNull(OwsUtils.get(bar, "foo")); assertNull(OwsUtils.get(bar, "foo.a")); Foo foo = new Foo(); bar.setFoo(foo); assertEquals(foo, OwsUtils.get(bar, "foo")); assertNull(OwsUtils.get(bar, "foo.a")); foo.setA("abc"); assertEquals("abc", OwsUtils.get(bar, "foo.a")); OwsUtils.set(bar, "foo.b", 123); assertEquals(123, OwsUtils.get(bar, "foo.b")); }
static String getBaseURL(Operation operation) { Object firstParam = operation.getParameters()[0]; String baseURL = Converters.convert(OwsUtils.get(firstParam, "baseUrl"), String.class); if (baseURL == null) { throw new IllegalArgumentException("Cannot extract base URL from " + firstParam); } return baseURL; }
public WFSException init(Object request) { if (request != null) { // wfs 2.0 has more requirements for exception codes and handles if (OwsUtils.has(request, "version")) { Object ver = OwsUtils.get(request, "version"); Version version = Version.negotiate(ver != null ? ver.toString() : null); if (version != null && version.compareTo(Version.V_20) < 0) { return this; // not 2.0 } } if (locator == null && OwsUtils.has(request, "handle")) { // check the request object locator = (String) OwsUtils.get(request, "handle"); } if (locator == null) { locator = determineDefaultLocator(request); } if (code == null) { code = Code.OperationProcessingFailed.name(); } } return this; }
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { // could be a proxy, unwrap it source = CatalogImpl.unwrap(source); // gets its id String id = (String) OwsUtils.get(source, "id"); writer.startNode("id"); writer.setValue(id); writer.endNode(); }
ConfigChangeEvent newChangeEvent(Info subj, Type type) { String name = (String) (OwsUtils.has(subj, "name") ? OwsUtils.get(subj, "name") : null); WorkspaceInfo ws = (WorkspaceInfo) (OwsUtils.has(subj, "workspace") ? OwsUtils.get(subj, "workspace") : null); StoreInfo store = (StoreInfo) (OwsUtils.has(subj, "store") ? OwsUtils.get(subj, "store") : null); ConfigChangeEvent ev = new ConfigChangeEvent(subj.getId(), name, subj.getClass(), type); if (ws != null) { ev.setWorkspaceId(ws.getId()); } if (store != null) { ev.setStoreId(store.getId()); } if (subj instanceof ResourceInfo) { ev.setNativeName(((ResourceInfo) subj).getNativeName()); } return ev; }