Change-Id: I72248e1bb8423f24194cc69b63c3623732e2a065
Issue-ID: AAI-712
Signed-off-by: burdziak <olaf.burdziakowski@nokia.com>
*/
package org.onap.aai.introspection;
*/
package org.onap.aai.introspection;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import java.util.Map.Entry;
public class MoxyStrategy extends Introspector {
import java.util.Map.Entry;
public class MoxyStrategy extends Introspector {
+
+ private static final EELFLogger LOGGER2 = EELFManager.getInstance().getLogger(MoxyStrategy.class);
+
private DynamicEntity internalObject = null;
private DynamicType internalType = null;
private DynamicJAXBContext jaxbContext = null;
private DynamicEntity internalObject = null;
private DynamicType internalType = null;
private DynamicJAXBContext jaxbContext = null;
private Set<String> requiredProperties = null;
private boolean isInitialized = false;
private Set<String> requiredProperties = null;
private boolean isInitialized = false;
protected MoxyStrategy(Object obj) {
super(obj);
/* must look up the correct jaxbcontext for this object */
protected MoxyStrategy(Object obj) {
super(obj);
/* must look up the correct jaxbcontext for this object */
marshaller = jaxbContext.createMarshaller();
unmarshaller = jaxbContext.createUnmarshaller();
} catch (JAXBException e) {
marshaller = jaxbContext.createMarshaller();
unmarshaller = jaxbContext.createUnmarshaller();
} catch (JAXBException e) {
+ LOGGER2.error(e.getMessage(),e);
private void init() {
isInitialized = true;
private void init() {
isInitialized = true;
}
props = Collections.unmodifiableSet(props);
this.properties = props;
}
props = Collections.unmodifiableSet(props);
this.properties = props;
Set<String> requiredProps = new LinkedHashSet<>();
requiredProps = new LinkedHashSet<>();
for (DatabaseMapping dm : cd.getMappings()) {
Set<String> requiredProps = new LinkedHashSet<>();
requiredProps = new LinkedHashSet<>();
for (DatabaseMapping dm : cd.getMappings()) {
- if (dm.getField() instanceof XMLField) {
+ if (dm.getField() instanceof XMLField) {
XMLField x = (XMLField)dm.getField();
XMLField x = (XMLField)dm.getField();
if (x.isRequired()) {
requiredProps.add(this.removeXPathDescriptor(x.getName()));
}
if (x.isRequired()) {
requiredProps.add(this.removeXPathDescriptor(x.getName()));
}
}
requiredProps = Collections.unmodifiableSet(requiredProps);
this.requiredProperties = requiredProps;
}
requiredProps = Collections.unmodifiableSet(requiredProps);
this.requiredProperties = requiredProps;
Set<String> keys = new LinkedHashSet<>();
Set<String> keys = new LinkedHashSet<>();
for (String name : internalType.getDescriptor().getPrimaryKeyFieldNames()) {
keys.add(this.removeXPathDescriptor(name));
}
keys = Collections.unmodifiableSet(keys);
this.keys = keys;
for (String name : internalType.getDescriptor().getPrimaryKeyFieldNames()) {
keys.add(this.removeXPathDescriptor(name));
}
keys = Collections.unmodifiableSet(keys);
this.keys = keys;
@Override
public boolean hasProperty(String name) {
String convertedName = convertPropertyName(name);
@Override
public boolean hasProperty(String name) {
String convertedName = convertPropertyName(name);
- return internalType.containsProperty(convertedName);
+ return internalType.containsProperty(convertedName);
@Override
public Object get(String name) {
return internalObject.get(name);
@Override
public Object get(String name) {
return internalObject.get(name);
@Override
public void set(String name, Object obj) throws IllegalArgumentException {
@Override
public void set(String name, Object obj) throws IllegalArgumentException {
internalObject.set(name, obj);
}
internalObject.set(name, obj);
}
}
return this.properties;
}
return this.properties;
@Override
public Map<PropertyMetadata, String> getPropertyMetadata(String prop) {
String propName = this.convertPropertyName(prop);
@Override
public Map<PropertyMetadata, String> getPropertyMetadata(String prop) {
String propName = this.convertPropertyName(prop);
PropertyMetadata.valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, (String)entry.getKey())), (String)entry.getValue());
}
}
PropertyMetadata.valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, (String)entry.getKey())), (String)entry.getValue());
}
}
public String getJavaClassName() {
return internalObject.getClass().getName();
}
public String getJavaClassName() {
return internalObject.getClass().getName();
}
@Override
public Class<?> getClass(String name) {
@Override
public Class<?> getClass(String name) {
if (internalType.getPropertyType(name) == null) {
if (cd.getMappingForAttributeName(name) instanceof XMLCompositeDirectCollectionMapping) {
resultClass = cd.getMappingForAttributeName(name).getContainerPolicy().getContainerClass();
if (internalType.getPropertyType(name) == null) {
if (cd.getMappingForAttributeName(name) instanceof XMLCompositeDirectCollectionMapping) {
resultClass = cd.getMappingForAttributeName(name).getContainerPolicy().getContainerClass();
} else if (cd.getMappingForAttributeName(name) instanceof XMLCompositeCollectionMapping) {
resultClass = cd.getMappingForAttributeName(name).getContainerPolicy().getContainerClass();
} else {
} else if (cd.getMappingForAttributeName(name) instanceof XMLCompositeCollectionMapping) {
resultClass = cd.getMappingForAttributeName(name).getContainerPolicy().getContainerClass();
} else {
}
} catch (DynamicException e) {
//property doesn't exist
}
} catch (DynamicException e) {
//property doesn't exist
+ LOGGER2.error(e.getMessage(),e);
resultClass = cd.getMappingForAttributeName(name).getReferenceDescriptor().getJavaClass();
}
}
resultClass = cd.getMappingForAttributeName(name).getReferenceDescriptor().getJavaClass();
}
}
public Object getUnderlyingObject() {
return this.internalObject;
}
public Object getUnderlyingObject() {
return this.internalObject;
}
@Override
public String getChildName() {
@Override
public String getChildName() {
String className = internalObject.getClass().getSimpleName();
String lowerHyphen = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, className);
String className = internalObject.getClass().getSimpleName();
String lowerHyphen = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, className);
if (this.isContainer()) {
lowerHyphen = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,this.getGenericTypeClass(this.getProperties().iterator().next()).getSimpleName());
}
if (this.isContainer()) {
lowerHyphen = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,this.getGenericTypeClass(this.getProperties().iterator().next()).getSimpleName());
}
@Override
public String getName() {
String className = internalObject.getClass().getSimpleName();
@Override
public String getName() {
String className = internalObject.getClass().getSimpleName();
if (this.isContainer()) {
lowerHyphen = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,this.getGenericTypeClass(this.getProperties().get(0)).getSimpleName());
}*/
if (this.isContainer()) {
lowerHyphen = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,this.getGenericTypeClass(this.getProperties().get(0)).getSimpleName());
}*/
@Override
public String getObjectId() throws UnsupportedEncodingException {
String result = "";
@Override
public String getObjectId() throws UnsupportedEncodingException {
String result = "";
if (this.isContainer()) {
result += "/" + this.getName();
} else {
if (this.isContainer()) {
result += "/" + this.getName();
} else {
if (container != null) {
result += "/" + container;
}
result += "/" + this.getDbName() + "/" + this.findKey();
if (container != null) {
result += "/" + container;
}
result += "/" + this.getDbName() + "/" + this.findKey();
@Override
protected String findKey() throws UnsupportedEncodingException {
Set<String> keys = null;
@Override
protected String findKey() throws UnsupportedEncodingException {
Set<String> keys = null;
String value = UriUtils.encode(this.getValue(key).toString(), "UTF-8");
results.add(value);
}
String value = UriUtils.encode(this.getValue(key).toString(), "UTF-8");
results.add(value);
}
return Joiner.on("/").join(results);
}
return Joiner.on("/").join(results);
}
@Override
public String preProcessKey (String key) {
String result = "";
@Override
public String preProcessKey (String key) {
String result = "";
String[] split = key.split("/");
int i = 0;
for (i = split.length-1; i >= 0; i--) {
String[] split = key.split("/");
int i = 0;
for (i = split.length-1; i >= 0; i--) {
if (jaxbContext.getDynamicType(split[i]) != null) {
break;
if (jaxbContext.getDynamicType(split[i]) != null) {
break;
}
result = Joiner.on("/").join(Arrays.copyOfRange(split, 0, i));
}
result = Joiner.on("/").join(Arrays.copyOfRange(split, 0, i));
@Override
public String marshal(MarshallerProperties properties) {
StringWriter result = new StringWriter();
@Override
public String marshal(MarshallerProperties properties) {
StringWriter result = new StringWriter();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, properties.getFormatted());
marshaller.marshal(this.internalObject, result);
} catch (JAXBException e) {
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, properties.getFormatted());
marshaller.marshal(this.internalObject, result);
} catch (JAXBException e) {
+ LOGGER2.error(e.getMessage(),e);
}
return result.toString();
}
}
return result.toString();
}
@Override
public Object clone() {
Object result = null;
@Override
public Object clone() {
Object result = null;
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
result = unmarshaller.unmarshal(new StreamSource(new StringReader(this.marshal(true))), this.internalObject.getClass()).getValue();
} catch (JAXBException e) {
result = unmarshaller.unmarshal(new StreamSource(new StringReader(this.marshal(true))), this.internalObject.getClass()).getValue();
} catch (JAXBException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
+ LOGGER2.error(e.getMessage(),e);
}
result = IntrospectorFactory.newInstance(getModelType(), result);
return result;
}
result = IntrospectorFactory.newInstance(getModelType(), result);
return result;