
com.squeakysand.jcr.SimpleValue Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2010-2011 Craig S. Dickson (http://craigsdickson.com)
*
* 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 com.squeakysand.jcr;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class SimpleValue implements Value {
private static final Logger LOG = LoggerFactory.getLogger(SimpleNode.class);
public static SimpleValue asSimpleValue(Value value) {
SimpleValue result = null;
try {
if (value != null) {
if (value instanceof SimpleValue) {
result = (SimpleValue) value;
} else {
SimpleProperty.Type type = SimpleProperty.Type.getType(value.getType());
switch (type) {
case STRING:
String stringValue = value.getString();
result = new StringValue(stringValue);
break;
default:
}
}
}
} catch (ValueFormatException e) {
LOG.error(e.getMessage(), e);
} catch (IllegalStateException e) {
LOG.error(e.getMessage(), e);
} catch (RepositoryException e) {
LOG.error(e.getMessage(), e);
}
return result;
}
private SimpleProperty.Type type;
public SimpleValue(SimpleProperty.Type type) {
this.type = type;
}
@Override
public int getType() {
return type.getId();
}
@Override
public boolean equals(Object obj) {
boolean result = false;
if (obj != null && obj instanceof Value) {
SimpleValue otherValue = SimpleValue.asSimpleValue((Value)obj);
if (type == otherValue.type) {
try {
if (getString().equals(otherValue.getString())) {
result = true;
}
} catch (ValueFormatException e) {
LOG.error(e.getMessage(), e);
} catch (IllegalStateException e) {
LOG.error(e.getMessage(), e);
} catch (RepositoryException e) {
LOG.error(e.getMessage(), e);
}
}
}
return result;
}
@Override
public int hashCode() {
int hash = 7;
hash = 41 * hash + (this.type != null ? this.type.hashCode() : 0);
return hash;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy