Java tutorial
/* * Copyright 2007-2008 the original author or authors. * * 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 ae.config.field; import static org.apache.commons.lang.StringUtils.capitalize; import static org.apache.commons.lang.StringUtils.isBlank; import java.util.List; import ae.config.ActiveEntity; import ae.config.Project; import com.google.common.collect.Lists; public abstract class AbstractMetaField<F extends AbstractMetaField<F>> implements MetaField<F> { private final ActiveEntity ae; private String name; private String property; private final List<FieldMetaConstraint> constraints = Lists.newLinkedList(); protected AbstractMetaField(final ActiveEntity ae) { if (ae == null) { throw new NullPointerException("ae"); } this.ae = ae; } @Override public Project getProject() { return this.ae.getProject(); } @Override public ActiveEntity getAe() { return this.ae; } @Override public String getName() { return this.name; } protected void setName(final String field) { this.name = field; } @Override public String getDescriptorClass() { return getCapitallizedField() + "Field"; } @Override public String getProperty() { return this.property; } @Override public void setProperty(final String mappedName) { this.property = mappedName; } @Override public void addConstraint(final FieldMetaConstraint constraint) { this.constraints.add(constraint); } @Override public void prepareField(final String name) { if (name == null) { throw new NullPointerException("name"); } if (isBlank(getName())) { setName(name); } if (isBlank(getProperty())) { setProperty(getName()); } } public String getCapitallizedField() { return capitalize(getName()); } @Override public List<FieldMetaConstraint> getConstraints() { return this.constraints; } @Override public boolean isConstraintsDefined() { return this.constraints != null && !this.constraints.isEmpty(); } @Override public String toString() { return this.name; } @Override public boolean isBoolean() { return false; } @Override public boolean isEnum() { return false; } @Override public boolean isCollection() { return false; } @Override public String getPath() { return getAe().getClassName() + '.' + getName(); } @Override @SuppressWarnings("unchecked") public F asMetaField() { return (F) this; } }