Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interfaces moved from resource to core
- Loading branch information
1 parent
4eb440a
commit b0cc517
Showing
9 changed files
with
414 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/core/java/org/wyona/yanel/core/api/attributes/CreatableV3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.wyona.yanel.core.api.attributes; | ||
|
||
import org.wyona.yanel.core.api.attributes.creatable.ResourceInput; | ||
|
||
/** | ||
* An implementation of CreatableV3 can be created from a ResourceInput. The | ||
* ResourceInput, which specifies the format of the expected input must be | ||
* provided by the CreatableV3 itself. | ||
* | ||
*/ | ||
public interface CreatableV3 { | ||
|
||
/** | ||
* Creates the Instance and assigns values from input. | ||
* @param input - normally it should be validated and valid | ||
* @throws Exception | ||
*/ | ||
public void create(ResourceInput input) throws Exception; | ||
|
||
/** | ||
* Should return a ResourceInput which shows the expected data at for the cerate method. | ||
* @return ResourceInput | ||
* @throws Exception | ||
*/ | ||
public ResourceInput getResourceInputForCreation() throws Exception; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/core/java/org/wyona/yanel/core/api/attributes/DeletableV1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.wyona.yanel.core.api.attributes; | ||
|
||
import org.wyona.yanel.core.api.attributes.creatable.ResourceInput; | ||
|
||
/** | ||
* A Deletable knows how to delete itself. This interface should not be mixed | ||
* with the Modifiable. | ||
* | ||
*/ | ||
public interface DeletableV1 { | ||
/** | ||
* Deletes the instance | ||
* | ||
* @param input | ||
* @throws Exception | ||
*/ | ||
public void delete(ResourceInput input) throws Exception; | ||
|
||
/** | ||
* Values in the input may hint how the deletion should proceed. | ||
* Normally it will be an input with only one item, identifying the resource to delete. | ||
* However, there may be cases when a user is guided through a conversation where additional | ||
* info is needed to perform the delete (e.g. some confirmation input). | ||
* | ||
* @return ResourceInput | ||
* @throws Exception | ||
*/ | ||
public ResourceInput getResourceInputForDeletion() throws Exception; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/core/java/org/wyona/yanel/core/api/attributes/ModifiableV3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.wyona.yanel.core.api.attributes; | ||
|
||
import org.wyona.yanel.core.api.attributes.creatable.ResourceInput; | ||
|
||
/** | ||
* A Modifiable can be modified from a ResourceInput. The ResourceInput, which | ||
* specifies the format of the expected input must be provided by the Modifiable | ||
* itself and must be prefilled with the values of the Object to be modified. | ||
* | ||
*/ | ||
public interface ModifiableV3 { | ||
|
||
/** | ||
* Modifies the instance and assigns values from the input. | ||
* | ||
* @param input | ||
* @throws Exception | ||
*/ | ||
public void modify(ResourceInput input) throws Exception; | ||
|
||
/** | ||
* The ResourceInput must be prefilled with the values of the Resource. This | ||
* resource is used to do modifications and is then passed back to the | ||
* modify method. | ||
* | ||
* @return ResourceInput | ||
* @throws Exception | ||
*/ | ||
public ResourceInput getResourceInputForModification() throws Exception; | ||
|
||
|
||
} |
90 changes: 90 additions & 0 deletions
90
src/core/java/org/wyona/yanel/core/api/attributes/creatable/AbstractResourceInputItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.wyona.yanel.core.api.attributes.creatable; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
/** | ||
* Implements name and validation functionality for a ResourceInputItem. | ||
* | ||
*/ | ||
public abstract class AbstractResourceInputItem implements ResourceInputItem { | ||
|
||
private static Logger log = Logger.getLogger(AbstractResourceInputItem.class); | ||
|
||
private String name; | ||
|
||
private Validator validator = null; | ||
|
||
private ValidationMessage validationMessage; | ||
|
||
/** | ||
* Creates an InputItem with the specified name. | ||
* @param name | ||
*/ | ||
public AbstractResourceInputItem(String name) { | ||
this.name = name; | ||
} | ||
|
||
/* | ||
* @see org.wyona.yanel.core.api.attributes.creatable.ResourceInputItem#getName() | ||
*/ | ||
public final String getName() { | ||
return this.name; | ||
} | ||
|
||
public final void rename( String newName ){ | ||
this.name = newName; | ||
} | ||
|
||
/** | ||
* @return the validator associated with this item | ||
*/ | ||
public final Validator getValidator() { | ||
return validator; | ||
} | ||
|
||
/** | ||
* Set the validator for this item | ||
* @param validator | ||
*/ | ||
public final void setValidator(Validator validator) { | ||
this.validator = validator; | ||
} | ||
|
||
/** | ||
* Validates the value and returns <code>true</code> when the validation is ok. | ||
*/ | ||
public final boolean validate() { | ||
log.debug("Validate item ..."); | ||
validationMessage = new ValidationMessage(getName(), this.getValue(), "Assumed to be valid", true); | ||
if(validator != null){ | ||
ValidationMessage vm = validator.validate(this); | ||
if(vm != null){ | ||
validationMessage = vm; | ||
} | ||
} | ||
|
||
return validationMessage.isValidationOK(); | ||
} | ||
|
||
public ValidationMessage getValidationMessage() { | ||
return validationMessage; | ||
} | ||
|
||
/** | ||
* Removes the validation message and calls doSetValue() | ||
* */ | ||
public final void setValue(Object value) { | ||
removeValidationMessage(); | ||
doSetValue(value); | ||
} | ||
|
||
/** | ||
* Set value only without any additional steps | ||
* */ | ||
public abstract void doSetValue(Object value); | ||
|
||
public final void removeValidationMessage(){ | ||
validationMessage = null; | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/core/java/org/wyona/yanel/core/api/attributes/creatable/ResourceInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.wyona.yanel.core.api.attributes.creatable; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* A ResourceInput holds different ResourceInputItems which specify the ResourceInput's structure. | ||
*/ | ||
public interface ResourceInput { | ||
/** | ||
* Adds an item | ||
* @param item ResourceInputItem | ||
*/ | ||
public void add(ResourceInputItem item); | ||
|
||
/** | ||
* Gets a specific ResourceInputItem by name. | ||
* | ||
* @param name | ||
* @return ResourceInputItem | ||
* @throws Exception | ||
*/ | ||
public ResourceInputItem getItem(String name) throws Exception; | ||
|
||
/** | ||
* Return all items on this ResourceInput. | ||
* @return | ||
* @throws Exception | ||
*/ | ||
public ResourceInputItem [] getItems() throws Exception; | ||
|
||
/** | ||
* Gets the names of all ResourceInputItems | ||
* @return String[] specifying all the names off the input items. | ||
* @throws Exception | ||
*/ | ||
public String[] getItemNames() throws Exception; | ||
|
||
|
||
/** | ||
* Should be called in cases when the validation is not performed directly on each input item. | ||
* It validates <b>only invalid or not yet validated items</b>. | ||
* */ | ||
public boolean validate(); | ||
|
||
/** | ||
* Tells if the input is valid without doing the validation. It simply checks if every item is ok. | ||
* If the item was not validated it is assumed to be invalid. So make sure validate() has been called beforehand. | ||
* | ||
* @return | ||
* */ | ||
public boolean isValid(); | ||
|
||
/** | ||
* @return validation messages for every input item | ||
* */ | ||
public List<ValidationMessage> getValidationMessages(); | ||
} |
76 changes: 76 additions & 0 deletions
76
src/core/java/org/wyona/yanel/core/api/attributes/creatable/ResourceInputItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.wyona.yanel.core.api.attributes.creatable; | ||
|
||
|
||
/** | ||
* Represents a single input item. | ||
*/ | ||
public interface ResourceInputItem { | ||
|
||
public static final int INPUT_TYPE_TEXT = 0; | ||
public static final int INPUT_TYPE_TEXTAREA = 1; | ||
public static final int INPUT_TYPE_HIDDEN = 2; | ||
public static final int INPUT_TYPE_PASSWORD = 3; | ||
public static final int INPUT_TYPE_FILE_UPLOAD = 4; | ||
public static final int INPUT_TYPE_RADIO = 5; | ||
public static final int INPUT_TYPE_CHECK = 6; | ||
public static final int INPUT_TYPE_SELECT = 7; | ||
public static final int INPUT_TYPE_LISTBOX = 8; | ||
public static final int INPUT_TYPE_COLLECTION = 9; | ||
|
||
/** | ||
* Type cane have the following values: | ||
* INPUT_TYPE_TEXT = 0; | ||
* INPUT_TYPE_TEXTAREA = 1; | ||
* INPUT_TYPE_HIDDEN = 2; | ||
* INPUT_TYPE_PASSWORD = 3; | ||
* INPUT_TYPE_FILE_UPLOAD = 4; | ||
* INPUT_TYPE_RADIO = 5; | ||
* INPUT_TYPE_CHECK = 6; | ||
* INPUT_TYPE_SELECT = 7; | ||
* INPUT_TYPE_LISTBOX = 8; | ||
* | ||
* @return type of the InputItem | ||
* | ||
*/ | ||
public int getType(); | ||
|
||
/** | ||
* @return the name of the item. | ||
*/ | ||
public String getName(); | ||
|
||
/** | ||
* Changes the name to the passed in value; | ||
* @param name | ||
*/ | ||
public void rename( String name ); | ||
|
||
|
||
/** | ||
* Depending on the type, this can be very different. A cast will be | ||
* necessary after retrieving the value. | ||
* | ||
* @return the value of the item or <code>null</code> when there is no value | ||
*/ | ||
public Object getValue(); | ||
|
||
/** | ||
* Sets the value of the item. Depending on the items type, different kind | ||
* of values are expected. | ||
* This method must remove the validation message, because it may be inconsistent | ||
* with the new value | ||
* | ||
* @param value of the item or <code>null</code> to reset it | ||
*/ | ||
public void setValue(Object value); | ||
|
||
/** | ||
* Validates the item on the current input and sets the validation message | ||
* */ | ||
public boolean validate(); | ||
|
||
/** | ||
* @return last validation message or <code>null</code> when no validation happend or it is inconsistent | ||
* */ | ||
public ValidationMessage getValidationMessage(); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/core/java/org/wyona/yanel/core/api/attributes/creatable/ResourceInputItemCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.wyona.yanel.core.api.attributes.creatable; | ||
|
||
|
||
/** | ||
* Represents an Item which can have more than one value. The possible values are not predefined.new values can be added and existing values can be removed. | ||
* add a parameter called resource.input.collection.action with value 'add' or | ||
* remove to the request, so that the JellyAdapterForCreatable knows what to to. | ||
*/ | ||
public interface ResourceInputItemCollection extends ResourceInputItem { | ||
public boolean addValue(Object value); | ||
public boolean addValue(int index, Object value); | ||
|
||
public boolean removeValue(Object value); | ||
public Object removeValue(int index); | ||
|
||
public int size(); | ||
|
||
/** | ||
* @return -1 when the index can't be determined, otherwise >= 0 | ||
* */ | ||
public int indexOfValue(Object value); | ||
|
||
/** | ||
* Move the value in the collection | ||
* */ | ||
public boolean moveValue(int fromIndex, int toIndex); | ||
} |
Oops, something went wrong.