-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started API and implementation for user friendly access to node type …
…definition and manipulation #1
- Loading branch information
1 parent
d150d11
commit 4c670f9
Showing
14 changed files
with
316 additions
and
23 deletions.
There are no files selected for viewing
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
10 changes: 8 additions & 2 deletions
10
src/main/java/com/dc2f/dstore/hierachynodestore/WorkingTree.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 |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package com.dc2f.dstore.hierachynodestore; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import com.dc2f.dstore.hierachynodestore.nodetype.NodeTypeAccessor; | ||
|
||
|
||
public interface WorkingTree { | ||
WorkingTreeNode getRootNode(); | ||
@Nonnull WorkingTreeNode getRootNode(); | ||
|
||
Commit commit(String message); | ||
@Nonnull Commit commit(String message); | ||
|
||
@Nonnull NodeTypeAccessor getNodeTypeAccessor(); | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/dc2f/dstore/hierachynodestore/exception/NodeStoreException.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,16 @@ | ||
package com.dc2f.dstore.hierachynodestore.exception; | ||
|
||
/** | ||
* generic exception from your node store. | ||
*/ | ||
public class NodeStoreException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
|
||
public NodeStoreException(String message) { | ||
this(message, null); | ||
} | ||
public NodeStoreException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
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
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/dc2f/dstore/hierachynodestore/impl/nodetype/NodeTypeAccessorImpl.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,24 @@ | ||
package com.dc2f.dstore.hierachynodestore.impl.nodetype; | ||
|
||
import java.util.Collection; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import com.dc2f.dstore.hierachynodestore.impl.WorkingTreeImpl; | ||
import com.dc2f.dstore.hierachynodestore.nodetype.NodeTypeAccessor; | ||
import com.dc2f.dstore.hierachynodestore.nodetype.NodeTypeDefinition; | ||
|
||
|
||
public class NodeTypeAccessorImpl implements NodeTypeAccessor { | ||
@SuppressWarnings("unused") | ||
private @Nonnull WorkingTreeImpl workingTreeImpl; | ||
|
||
public NodeTypeAccessorImpl(@Nonnull WorkingTreeImpl workingTreeImpl) { | ||
this.workingTreeImpl = workingTreeImpl; | ||
} | ||
|
||
@Override | ||
public @Nonnull Collection<NodeTypeDefinition> listNodeTypeDefinitions() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/dc2f/dstore/hierachynodestore/impl/nodetype/NodeTypeDefinitionImpl.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,53 @@ | ||
package com.dc2f.dstore.hierachynodestore.impl.nodetype; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import com.dc2f.dstore.hierachynodestore.WorkingTreeNode; | ||
import com.dc2f.dstore.hierachynodestore.nodetype.NodeTypeDefinition; | ||
import com.dc2f.dstore.hierachynodestore.nodetype.PropertyDefinition; | ||
import com.dc2f.dstore.storage.Property; | ||
|
||
import static com.dc2f.utils.NullUtils.assertNotNull; | ||
|
||
public class NodeTypeDefinitionImpl implements NodeTypeDefinition { | ||
public static final @Nonnull String PROPERTY_NAME = ":name"; | ||
|
||
private @Nonnull WorkingTreeNode node; | ||
|
||
public NodeTypeDefinitionImpl(@Nonnull WorkingTreeNode node) { | ||
// TODO assert node type? | ||
this.node = node; | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public Collection<PropertyDefinition> listPropertyDefinitions() { | ||
List<PropertyDefinition> ret = new ArrayList<>(); | ||
for (WorkingTreeNode child : node.getChildren()) { | ||
ret.add(new PropertyDefinitionImpl(assertNotNull(child))); | ||
} | ||
return assertNotNull(Collections.unmodifiableCollection(ret)); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public PropertyDefinition addPropertyDefinition(@Nonnull String name) { | ||
WorkingTreeNode propertyNode = node.addChild(); | ||
propertyNode.setProperty(PROPERTY_NAME, new Property(name)); | ||
return new PropertyDefinitionImpl(propertyNode); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public Collection<NodeTypeDefinition> listAllowedChildNodeTypes() { | ||
// FIXME implement me :) | ||
return new ArrayList<>(); | ||
} | ||
|
||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/com/dc2f/dstore/hierachynodestore/impl/nodetype/PropertyDefinitionImpl.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,72 @@ | ||
package com.dc2f.dstore.hierachynodestore.impl.nodetype; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import com.dc2f.dstore.hierachynodestore.WorkingTreeNode; | ||
import com.dc2f.dstore.hierachynodestore.exception.NodeStoreException; | ||
import com.dc2f.dstore.hierachynodestore.nodetype.PropertyDefinition; | ||
import com.dc2f.dstore.storage.Property; | ||
import com.dc2f.dstore.storage.Property.PropertyType; | ||
|
||
import static com.dc2f.utils.NullUtils.assertNotNull; | ||
|
||
public class PropertyDefinitionImpl implements PropertyDefinition { | ||
public static final @Nonnull String PROPERTY_NAME = NodeTypeDefinitionImpl.PROPERTY_NAME; | ||
public static final @Nonnull String PROPERTY_TYPE = ":type"; | ||
public static final @Nonnull String PROPERTY_REQUIRED = ":required"; | ||
public static final @Nonnull String PROPERTY_INDEXED = ":indexed"; | ||
|
||
private WorkingTreeNode node; | ||
|
||
public PropertyDefinitionImpl(@Nonnull WorkingTreeNode node) { | ||
this.node = node; | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public String getName() { | ||
// a property definition must always have a name.. | ||
return assertNotNull(node.getProperty(PROPERTY_NAME)).getString(); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public PropertyType getType() { | ||
// property definition must always have a type. | ||
Property typeProperty = assertNotNull(node.getProperty(PROPERTY_TYPE)); | ||
PropertyType propertyType = PropertyType.valueOf(typeProperty.getString()); | ||
if (propertyType == null) { | ||
throw new NodeStoreException("Illegal property type {" + typeProperty.getString() + "}"); | ||
} | ||
return propertyType; | ||
} | ||
|
||
@Override | ||
public void setRequired(boolean isRequired) { | ||
node.setProperty(PROPERTY_REQUIRED, new Property(new Boolean(isRequired))); | ||
} | ||
|
||
@Override | ||
public boolean isRequired() { | ||
Property requiredProperty = node.getProperty(PROPERTY_REQUIRED); | ||
if (requiredProperty == null) { | ||
return false; | ||
} | ||
return requiredProperty.getBoolean(); | ||
} | ||
|
||
@Override | ||
public void setIndexed(boolean isIndexed) { | ||
node.setProperty(PROPERTY_INDEXED, new Property(new Boolean(isIndexed))); | ||
} | ||
|
||
@Override | ||
public boolean isIndexed() { | ||
Property indexedProperty = node.getProperty(PROPERTY_INDEXED); | ||
if (indexedProperty == null) { | ||
return false; | ||
} | ||
return indexedProperty.getBoolean(); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/dc2f/dstore/hierachynodestore/nodetype/NodeTypeAccessor.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,25 @@ | ||
package com.dc2f.dstore.hierachynodestore.nodetype; | ||
|
||
import java.util.Collection; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import com.dc2f.dstore.hierachynodestore.WorkingTree; | ||
|
||
/** | ||
* Convenience interface to access node types in a working tree of a repository. Allows reflection and editing | ||
* of node types. | ||
* | ||
* | ||
* @see WorkingTree#getNodeTypeAccessor() | ||
*/ | ||
public interface NodeTypeAccessor { | ||
/** | ||
* find all node type definitions in the current working tree and return them. | ||
* TODO: really all, or just those within /:nodetypes/ ?? | ||
* @return list of all node type definnitions. | ||
*/ | ||
@Nonnull Collection<NodeTypeDefinition> listNodeTypeDefinitions(); | ||
|
||
|
||
} |
Oops, something went wrong.