Skip to content

Commit

Permalink
MODE-1339 Ported text sequencer to 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Horia Chiorean committed Jan 20, 2012
1 parent 30f3dcd commit 6950557
Show file tree
Hide file tree
Showing 29 changed files with 1,240 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public static class Default {
* The default value of the {@link FieldName#ANONYMOUS_ROLES} field is a list with 'admin' as the role.
*/
public static final Set<String> ANONYMOUS_ROLES = Collections.unmodifiableSet(new HashSet<String>(
Arrays.asList(new String[] {ModeShapeRoles.ADMIN})));
Arrays.asList(new String[] {ModeShapeRoles.ADMIN})));

/**
* The default value of the {@link FieldName#USE_ANONYMOUS_ON_FAILED_LOGINS} field is '{@value} '.
Expand Down Expand Up @@ -482,13 +482,13 @@ public static RepositoryConfiguration read( InputStream stream,
* file, or a string containg the actual JSON content.
*
* @param resourcePathOrJsonContentString the path to a file on the file system, the path to a classpath resource file or the
* JSON content string; may not be null
* JSON content string; may not be null
* @return the parsed repository configuration; never null
* @throws ParsingException if the content could not be parsed as a valid JSON document
* @throws FileNotFoundException if the file could not be found
*/
public static RepositoryConfiguration read( String resourcePathOrJsonContentString )
throws ParsingException, FileNotFoundException {
throws ParsingException, FileNotFoundException {
FileLookup factory = FileLookupFactory.newInstance();
InputStream stream = factory.lookupFile(resourcePathOrJsonContentString, Thread.currentThread().getContextClassLoader());
if (stream == null) {
Expand Down Expand Up @@ -664,9 +664,7 @@ public BinaryStore getBinaryStore() {
Default.CACHE_TRANSACTION_MANAGER_LOOKUP);
store = new InfinispanBinaryStore();
}
if (store == null) {
store = TransientBinaryStore.get();
}
if (store == null) store = TransientBinaryStore.get();
store.setMinimumBinarySizeInBytes(getMinimumBinarySizeInBytes());
return store;
}
Expand Down Expand Up @@ -706,9 +704,7 @@ public Set<String> getPredefinedWorkspaceNames() {
List<?> predefined = workspaces.getArray(FieldName.PREDEFINED);
if (predefined != null) {
for (Object value : predefined) {
if (value instanceof String) {
names.add((String)value);
}
if (value instanceof String) names.add((String)value);
}
}
}
Expand Down Expand Up @@ -779,9 +775,7 @@ public AnonymousSecurity getAnonymous() {
return null;
}
}
if (anonymous == null) {
anonymous = Schematic.newDocument();
}
if (anonymous == null) anonymous = Schematic.newDocument();
return new AnonymousSecurity(anonymous);
}

Expand All @@ -806,9 +800,7 @@ protected void validateCustomProviders( Problems problems ) {

private boolean isIncludedInCustomProviders( String classname ) {
for (Component component : getCustomProviders()) {
if (classname.equals(component.getClassname())) {
return true;
}
if (classname.equals(component.getClassname())) return true;
}
return false;
}
Expand Down Expand Up @@ -859,9 +851,7 @@ protected AnonymousSecurity( Document anonymous ) {
public Set<String> getAnonymousRoles() {
Set<String> names = new HashSet<String>();
Collection<?> roles = anonymous.getArray(FieldName.ANONYMOUS_ROLES);
if (roles == null) {
roles = Default.ANONYMOUS_ROLES;
}
if (roles == null) roles = Default.ANONYMOUS_ROLES;
if (roles != null) {
for (Object value : roles) {
if (value instanceof String) {
Expand Down Expand Up @@ -1114,11 +1104,8 @@ private String aliasesStringFrom( Map<String, String> classnamesByAlias ) {
StringBuilder aliases = new StringBuilder();
boolean first = true;
for (String validAlias : classnamesByAlias.keySet()) {
if (first) {
first = false;
} else {
aliases.append(", ");
}
if (first) first = false;
else aliases.append(", ");
aliases.append('"').append(validAlias).append('"');
}
return aliases.toString();
Expand All @@ -1130,18 +1117,14 @@ protected Map<String, Object> readProperties( Document document,
Set<String> skipFields = new HashSet<String>(Arrays.asList(skipFieldNames));
for (Field field : document.fields()) {
String name = field.getName();
if (skipFields.contains(name)) {
continue;
}
if (skipFields.contains(name)) continue;
props.put(name, field.getValue());
}
return props;
}

protected CacheContainer getCacheContainer() throws IOException, NamingException {
if (this.cacheContainer != null) {
return this.cacheContainer;
}
if (this.cacheContainer != null) return this.cacheContainer;

CacheContainer container = null;
// First try finding the cache configuration ...
Expand Down Expand Up @@ -1228,7 +1211,7 @@ public Editor edit() {
return Schematic.editDocument(this.doc, true);
}

/**
/***
* Validate this configuration against the JSON Schema.
*
* @return the validation results; never null
Expand Down Expand Up @@ -1257,7 +1240,7 @@ public Problems validate() {
return problems;
}

/**
/***
* Validate this configuration if the supplied changes were made to this. Note that this does <i>not</i> actually change this
* configuration.
*
Expand Down Expand Up @@ -1347,23 +1330,13 @@ public int hashCode() {

@Override
public boolean equals( Object obj ) {
if (obj == this) {
return true;
}
if (obj == this) return true;
if (obj instanceof Component) {
Component that = (Component)obj;
if (!this.getClassname().equals(that.getClassname())) {
return false;
}
if (!this.getName().equals(that.getName())) {
return false;
}
if (!ObjectUtil.isEqualWithNulls(this.getClasspath(), that.getClasspath())) {
return false;
}
if (!this.getDocument().equals(that.getDocument())) {
return false;
}
if (!this.getClassname().equals(that.getClassname())) return false;
if (!this.getName().equals(that.getName())) return false;
if (!ObjectUtil.isEqualWithNulls(this.getClasspath(), that.getClasspath())) return false;
if (!this.getDocument().equals(that.getDocument())) return false;
return true;
}
return false;
Expand Down Expand Up @@ -1435,7 +1408,7 @@ private void setTypeFields( Object instance, Document document ) {
//locate the field instance on which the value will be set
java.lang.reflect.Field instanceField = findField(instance.getClass(), fieldName);
if (instanceField == null) {
Logger.getLogger(getClass()).error(JcrI18n.missingFieldOnInstance,
Logger.getLogger(getClass()).warn(JcrI18n.missingFieldOnInstance,
fieldName,
getClassname());
continue;
Expand All @@ -1451,6 +1424,7 @@ private void setTypeFields( Object instance, Document document ) {
convertedFieldValue = innerInstance;
}

//this is very ! tricky because it does not throw an exception - ever
ReflectionUtil.setValue(instance, fieldName, convertedFieldValue);
} catch (Throwable e) {
Logger.getLogger(getClass()).error(e,
Expand All @@ -1470,24 +1444,26 @@ private void setTypeFields( Object instance, Document document ) {
*
* @param expectedType the {@link Class} of the field on which the value should be set
* @param value a generic value coming from a document. Can be a simple value, another {@link Document} or {@link Array}
* @return the converted value, which should be compatible with the expected type.
*
* @throws Exception if anything will fail during the conversion process
*/
@SuppressWarnings( "unchecked" )
private Object convertValueToType(Class<?> expectedType, Object value) throws Exception {
//lists
//lists are converted to ArrayList
if (List.class.isAssignableFrom(expectedType)) {
return valueToCollection(value, ArrayList.class);
}
//sets
//sets are converted to HashSet
if (Set.class.isAssignableFrom(expectedType)) {
return valueToCollection(value, HashSet.class);
}
//arrays
//arrays are converted as-is
if (expectedType.isArray()) {
return valueToArray(expectedType.getComponentType(), value);
}

//maps
//maps are converted to hashmap
if (Map.class.isAssignableFrom(expectedType)) {
//only string keys are supported atm
return valueToMap(value);
Expand All @@ -1497,6 +1473,7 @@ private Object convertValueToType(Class<?> expectedType, Object value) throws Ex
return value;
}

@SuppressWarnings( "unchecked" )
private Object valueToMap(Object value ) throws Exception {
if (value instanceof Document) {
Map mapValue = HashMap.class.newInstance();
Expand Down Expand Up @@ -1527,6 +1504,7 @@ private Object valueToArray( Class<?> arrayComponentType, Object value) throws E
return array;
}

@SuppressWarnings( "unchecked" )
private <T extends Collection> T valueToCollection ( Object value, Class<T> collectionClass) throws Exception {
boolean valueIsArray = value instanceof Array;
T collection = collectionClass.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ protected InputStream getRepositoryConfigStream() {
* @throws RepositoryException if anything fails
*/
protected Node createNodeWithContentFromFile( String nodePath, String filePath ) throws RepositoryException {
Node file = rootNode.addNode(nodePath);
Node content = file.addNode(JcrConstants.JCR_CONTENT);
Node parent = rootNode;
for (String pathSegment: nodePath.split("/")) {
parent = parent.addNode(pathSegment);
}
Node content = parent.addNode(JcrConstants.JCR_CONTENT);
content.setProperty(JcrConstants.JCR_DATA, ((javax.jcr.Session)session).getValueFactory().createBinary(resourceStream(filePath)));
session.save();
return file;
return parent;
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<module>sequencers/modeshape-sequencer-java</module>
<module>sequencers/modeshape-sequencer-ddl</module>
<module>sequencers/modeshape-sequencer-mp3</module>
<module>sequencers/modeshape-sequencer-text</module>
</modules>
<properties>
<rootDir>${project.basedir}</rootDir>
Expand Down Expand Up @@ -62,7 +63,6 @@
<module>extensions/modeshape-sequencer-msoffice</module>
<module>extensions/modeshape-sequencer-sramp</module>
<module>extensions/modeshape-sequencer-teiid</module>
<module>extensions/modeshape-sequencer-text</module>
<module>extensions/modeshape-sequencer-xml</module>
<module>extensions/modeshape-sequencer-xsd</module>
<module>extensions/modeshape-sequencer-wsdl</module>
Expand All @@ -75,7 +75,6 @@
<module>extensions/modeshape-connector-jcr</module>
<module>extensions/modeshape-connector-store-jpa</module>
<module>extensions/modeshape-connector-jdbc-metadata</module>
<module>extensions/modeshape-mimetype-detector-aperture</module>
<module>extensions/modeshape-extractor-tika</module>
<!-- Order is important (web before JDBC before jbossas) -->
<module>web</module>
Expand Down
Loading

0 comments on commit 6950557

Please sign in to comment.