All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ujoframework.extensions.PathProperty Maven / Gradle / Ivy

There is a newer version: 1.22
Show newest version
/*
 *  Copyright 2007-2010 Pavel Ponec
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */   
   
package org.ujoframework.extensions;

import java.util.List;
import org.ujoframework.Ujo;
import org.ujoframework.UjoProperty;

/**
 * A PathProperty class is an composite of a UjoProperty objects.
 * The PathProperty class can be used wherever is used UjoProperty - with a one important exception: 
 * do not send the PathProperty object to methods Ujo.readValue(...) and Ujo.writeValue(...) !!!
 * 

You can use the preferred methods UjoManager.setValue(...) / UjoManager.getValue(...) * to write and read a value instead of or use some type safe solution by UjoExt or a method of UjoProperty. *

Note that method isDirect() returns a false in this class. For this reason, the property is not included * in the list returned by Ujo.readProperties(). * * @author Pavel Ponec * @since 0.81 */ public class PathProperty implements UjoProperty { private final UjoProperty[] properties; public PathProperty(List properties) { this(properties.toArray(new UjoProperty[properties.size()])); } public PathProperty(UjoProperty... properties) { this.properties = properties; } /** Get the last property of the current object. The result may not be the direct property. */ @SuppressWarnings("unchecked") final public UjoProperty getLastProperty() { return properties[properties.length - 1]; } /** Get a property from selected positon.. The result may not be the direct property. */ final public UjoProperty getProperty(final int index) { return properties[index]; } /** Returns a count of properties */ final public int getPropertyCount() { return properties.length; } /** Full property name */ public String getName() { StringBuilder result = new StringBuilder(32); for (UjoProperty p : properties) { if (result.length() > 0) { result.append('.'); } result.append(p.getName()); } return result.toString(); } /** Property type */ public Class getType() { return getLastProperty().getType(); } /** Get a semifinal value from an Ujo object by a chain of properties. * If a value (not getLastProperty) is null, then the result is null. */ @SuppressWarnings("unchecked") public Ujo getSemifinalValue(UJO ujo) { Ujo result = ujo; for (int i=0; i descending() { return isAscending() ? new SortingProperty(this, false) : this ; } /** Export all direct properties to the list from parameter. */ @SuppressWarnings("unchecked") public void exportProperties(List result) { for (UjoProperty p : properties) { if (p.isDirect()) { result.add(p); } else { ((PathProperty)p).exportProperties(result); } } } /** Create new composite (indirect) instance. * @since 0.92 */ @SuppressWarnings("unchecked") @Override public UjoProperty add(final UjoProperty property) { UjoProperty[] props = new UjoProperty[properties.length+1]; System.arraycopy(properties, 0, props, 0, properties.length); props[properties.length] = property; return new PathProperty(props); } // ================ STATIC ================ /** Create new instance * @hidden */ public static final PathProperty newInstance(final UjoProperty property) { return new PathProperty(property); } /** Create new instance * @hidden */ public static final PathProperty newInstance ( final UjoProperty property1 , final UjoProperty property2 ) { return new PathProperty(property1, property2); } /** Create new instance * @hidden */ public static final PathProperty newInstance ( final UjoProperty property1 , final UjoProperty property2 , final UjoProperty property3 ) { return new PathProperty(property1, property2, property3); } /** Create new instance * @hidden */ public static final PathProperty newInstance ( final UjoProperty property1 , final UjoProperty property2 , final UjoProperty property3 , final UjoProperty property4 ) { return new PathProperty(property1, property2, property3, property4); } /** Create new instance * @hidden */ @SuppressWarnings("unchecked") public static final PathProperty create(UjoProperty... properties) { return new PathProperty(properties); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy