You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/03/10 10:02:31 UTC
[15/51] [abbrv] [partial] [OLINGO-192] rename java packages
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmParameter.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmParameter.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmParameter.java
new file mode 100644
index 0000000..b1d551b
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmParameter.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmMapping;
+import org.apache.olingo.commons.api.edm.EdmParameter;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+
+public abstract class AbstractEdmParameter extends EdmElementImpl implements EdmParameter {
+
+ private final FullQualifiedName paramType;
+
+ private EdmType typeImpl;
+
+ public AbstractEdmParameter(final Edm edm, final String name, final FullQualifiedName paramType) {
+ super(edm, name);
+ this.paramType = paramType;
+ }
+
+ @Override
+ public EdmType getType() {
+ if (typeImpl == null) {
+ if (EdmPrimitiveType.EDM_NAMESPACE.equals(paramType.getNamespace())) {
+ try {
+ typeImpl = EdmPrimitiveTypeKind.valueOf(paramType.getName()).getEdmPrimitiveTypeInstance();
+ } catch (IllegalArgumentException e) {
+ throw new EdmException("Cannot find type with name: " + paramType, e);
+ }
+ } else {
+ typeImpl = edm.getComplexType(paramType);
+ if (typeImpl == null) {
+ typeImpl = edm.getEntityType(paramType);
+ if (typeImpl == null) {
+ typeImpl = edm.getEnumType(paramType);
+ if (typeImpl == null) {
+ typeImpl = edm.getTypeDefinition(paramType);
+ if (typeImpl == null) {
+ throw new EdmException("Cannot find type with name: " + paramType);
+ }
+ }
+ }
+ }
+ }
+ }
+ return typeImpl;
+ }
+
+ @Override
+ public abstract boolean isCollection();
+
+ @Override
+ public abstract EdmMapping getMapping();
+
+ @Override
+ public abstract Boolean isNullable();
+
+ @Override
+ public abstract Integer getMaxLength();
+
+ @Override
+ public abstract Integer getPrecision();
+
+ @Override
+ public abstract Integer getScale();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmProperty.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmProperty.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmProperty.java
new file mode 100644
index 0000000..11e0365
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmProperty.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+
+public abstract class AbstractEdmProperty extends EdmElementImpl implements EdmProperty {
+
+ private EdmType propertyType;
+
+ public AbstractEdmProperty(final Edm edm, final String name) {
+ super(edm, name);
+ }
+
+ protected abstract FullQualifiedName getTypeFQN();
+
+ @Override
+ public boolean isPrimitive() {
+ return EdmPrimitiveType.EDM_NAMESPACE.equals(getTypeFQN().getNamespace());
+ }
+
+ @Override
+ public EdmType getType() {
+ if (propertyType == null) {
+ final FullQualifiedName typeName = getTypeFQN();
+ if (isPrimitive()) {
+ try {
+ propertyType = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance();
+ } catch (IllegalArgumentException e) {
+ throw new EdmException("Cannot find type with name: " + typeName, e);
+ }
+ } else {
+ propertyType = edm.getComplexType(typeName);
+ if (propertyType == null) {
+ propertyType = edm.getEnumType(typeName);
+ if (propertyType == null) {
+ propertyType = edm.getTypeDefinition(typeName);
+ if (propertyType == null) {
+ throw new EdmException("Cannot find type with name: " + typeName);
+ }
+ }
+ }
+ }
+ }
+
+ return propertyType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReturnType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReturnType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReturnType.java
new file mode 100644
index 0000000..a6a6a84
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReturnType.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+
+public abstract class AbstractEdmReturnType implements EdmReturnType {
+
+ private final Edm edm;
+
+ private final FullQualifiedName typeName;
+
+ private EdmType typeImpl;
+
+ public AbstractEdmReturnType(final Edm edm, final FullQualifiedName typeName) {
+ this.edm = edm;
+ this.typeName = typeName;
+ }
+
+ @Override
+ public EdmType getType() {
+ if (typeImpl == null) {
+ if (EdmPrimitiveType.EDM_NAMESPACE.equals(typeName.getNamespace())) {
+ try {
+ typeImpl = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance();
+ } catch (IllegalArgumentException e) {
+ throw new EdmException("Cannot find type with name: " + typeName, e);
+ }
+ } else {
+ typeImpl = edm.getComplexType(typeName);
+ if (typeImpl == null) {
+ typeImpl = edm.getEntityType(typeName);
+ if (typeImpl == null) {
+ typeImpl = edm.getEnumType(typeName);
+ if (typeImpl == null) {
+ typeImpl = edm.getTypeDefinition(typeName);
+ if (typeImpl == null) {
+ throw new EdmException("Cant find type with name: " + typeName);
+ }
+ }
+ }
+ }
+ }
+ }
+ return typeImpl;
+ }
+
+ @Override
+ public abstract Boolean isNullable();
+
+ @Override
+ public abstract Integer getMaxLength();
+
+ @Override
+ public abstract Integer getPrecision();
+
+ @Override
+ public abstract Integer getScale();
+
+ @Override
+ public abstract boolean isCollection();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java
new file mode 100644
index 0000000..d48fda4
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmElement;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmStructuredType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+
+public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements EdmStructuredType {
+
+ protected EdmStructuredType baseType;
+
+ private List<String> propertyNames;
+
+ private List<String> navigationPropertyNames;
+
+ public AbstractEdmStructuredType(final Edm edm, final FullQualifiedName fqn, final EdmTypeKind kind,
+ final FullQualifiedName baseTypeName) {
+
+ super(edm, fqn, kind);
+ }
+
+ protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName);
+
+ protected abstract Map<String, EdmProperty> getProperties();
+
+ protected abstract Map<String, EdmNavigationProperty> getNavigationProperties();
+
+ @Override
+ public List<String> getPropertyNames() {
+ if (propertyNames == null) {
+ propertyNames = new ArrayList<String>();
+ if (baseType != null) {
+ propertyNames.addAll(baseType.getPropertyNames());
+ }
+ propertyNames.addAll(getProperties().keySet());
+ }
+ return propertyNames;
+ }
+
+ @Override
+ public List<String> getNavigationPropertyNames() {
+ if (navigationPropertyNames == null) {
+ navigationPropertyNames = new ArrayList<String>();
+ if (baseType != null) {
+ navigationPropertyNames.addAll(baseType.getNavigationPropertyNames());
+ }
+ navigationPropertyNames.addAll(getNavigationProperties().keySet());
+ }
+ return navigationPropertyNames;
+ }
+
+ @Override
+ public EdmElement getProperty(final String name) {
+ EdmElement property = getStructuralProperty(name);
+ if (property == null) {
+ property = getNavigationProperty(name);
+ }
+ return property;
+ }
+
+ @Override
+ public EdmProperty getStructuralProperty(final String name) {
+ EdmProperty property = null;
+ if (baseType != null) {
+ property = baseType.getStructuralProperty(name);
+ }
+ if (property == null) {
+ property = getProperties().get(name);
+ }
+ return property;
+ }
+
+ @Override
+ public EdmNavigationProperty getNavigationProperty(final String name) {
+ EdmNavigationProperty property = null;
+ if (baseType != null) {
+ property = baseType.getNavigationProperty(name);
+ }
+ if (property == null) {
+ property = getNavigationProperties().get(name);
+ }
+ return property;
+ }
+
+ @Override
+ public boolean compatibleTo(final EdmType targetType) {
+ EdmStructuredType sourceType = this;
+ if (targetType == null) {
+ throw new EdmException("Target type must not be null");
+ }
+ while (!sourceType.getName().equals(targetType.getName())
+ || !sourceType.getNamespace().equals(targetType.getNamespace())) {
+
+ sourceType = sourceType.getBaseType();
+ if (sourceType == null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmTypeDefinition.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmTypeDefinition.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmTypeDefinition.java
new file mode 100644
index 0000000..9ce14de
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmTypeDefinition.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+
+public abstract class AbstractEdmTypeDefinition extends EdmNamedImpl implements EdmTypeDefinition {
+
+ private final String namespace;
+
+ public AbstractEdmTypeDefinition(final Edm edm, final FullQualifiedName typeDefinitionName) {
+ super(edm, typeDefinitionName.getName());
+ this.namespace = typeDefinitionName.getNamespace();
+ }
+
+ @Override
+ public abstract EdmPrimitiveType getUnderlyingType();
+
+ @Override
+ public boolean isCompatible(final EdmPrimitiveType primitiveType) {
+ return getUnderlyingType().isCompatible(primitiveType);
+ }
+
+ @Override
+ public Class<?> getDefaultType() {
+ return getUnderlyingType().getDefaultType();
+ }
+
+ @Override
+ public boolean validate(final String value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode) {
+
+ return getUnderlyingType().validate(value, isNullable, maxLength, precision, scale, isUnicode);
+ }
+
+ @Override
+ public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
+
+ return getUnderlyingType().
+ valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
+ }
+
+ @Override
+ public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode) throws EdmPrimitiveTypeException {
+
+ return getUnderlyingType().valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
+ }
+
+ @Override
+ public String toUriLiteral(final String literal) {
+ return getUnderlyingType().toUriLiteral(literal);
+ }
+
+ @Override
+ public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
+ return getUnderlyingType().fromUriLiteral(literal);
+ }
+
+ @Override
+ public String getNamespace() {
+ return namespace;
+ }
+
+ @Override
+ public EdmTypeKind getKind() {
+ return EdmTypeKind.DEFINITION;
+ }
+
+ @Override
+ public abstract Integer getMaxLength();
+
+ @Override
+ public abstract Integer getPrecision();
+
+ @Override
+ public abstract Integer getScale();
+
+ @Override
+ public abstract Boolean isUnicode();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/ActionMapKey.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/ActionMapKey.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/ActionMapKey.java
new file mode 100644
index 0000000..7e1874a
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/ActionMapKey.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+
+public class ActionMapKey {
+
+ private final FullQualifiedName actionName;
+
+ private final FullQualifiedName bindingParameterTypeName;
+
+ private final Boolean isBindingParameterCollection;
+
+ public ActionMapKey(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName,
+ final Boolean isBindingParameterCollection) {
+
+ if (actionName == null || bindingParameterTypeName == null || isBindingParameterCollection == null) {
+ throw new EdmException("Action name, binding parameter type and binding parameter collection "
+ + "must not be null for bound actions");
+ }
+ this.actionName = actionName;
+ this.bindingParameterTypeName = bindingParameterTypeName;
+ this.isBindingParameterCollection = isBindingParameterCollection;
+ }
+
+ @Override
+ public int hashCode() {
+ final String forHash = actionName.toString()
+ + bindingParameterTypeName.toString()
+ + isBindingParameterCollection.toString();
+ return forHash.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if ((obj == null) || !(obj instanceof ActionMapKey)) {
+ return false;
+ }
+ final ActionMapKey other = (ActionMapKey) obj;
+ if (actionName.equals(other.actionName) && bindingParameterTypeName.equals(other.bindingParameterTypeName)
+ && isBindingParameterCollection.equals(other.isBindingParameterCollection)) {
+ return true;
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmActionImportInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmActionImportInfoImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmActionImportInfoImpl.java
new file mode 100644
index 0000000..798cb4d
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmActionImportInfoImpl.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import java.net.URI;
+
+import org.apache.olingo.commons.api.edm.EdmActionImportInfo;
+import org.apache.olingo.commons.api.edm.EdmException;
+
+public class EdmActionImportInfoImpl extends EdmOperationImportInfoImpl implements EdmActionImportInfo {
+
+ private String actionImportName;
+
+ public EdmActionImportInfoImpl(final String entityContainerName, final String actionImportName) {
+ super(entityContainerName);
+ this.actionImportName = actionImportName;
+ }
+
+ @Override
+ public String getActionImportName() {
+ return actionImportName;
+ }
+
+ @Override
+ public URI getActionImportUri() {
+ throw new EdmException("Not yet implemented");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmElementImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmElementImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmElementImpl.java
new file mode 100644
index 0000000..1653a8f
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmElementImpl.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmElement;
+
+public abstract class EdmElementImpl extends EdmNamedImpl implements EdmElement {
+
+ public EdmElementImpl(final Edm edm, final String name) {
+ super(edm, name);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetInfoImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetInfoImpl.java
new file mode 100644
index 0000000..9bbf568
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetInfoImpl.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import java.net.URI;
+
+import org.apache.olingo.commons.api.edm.EdmEntitySetInfo;
+import org.apache.olingo.commons.api.edm.EdmException;
+
+public class EdmEntitySetInfoImpl implements EdmEntitySetInfo {
+
+ private final String entityContainerName;
+
+ private final String entitySetName;
+
+ public EdmEntitySetInfoImpl(final String entityContainerName, final String entitySetName) {
+ this.entityContainerName = entityContainerName;
+ this.entitySetName = entitySetName;
+ }
+
+ @Override
+ public String getEntityContainerName() {
+ return entityContainerName;
+ }
+
+ @Override
+ public String getEntitySetName() {
+ return entitySetName;
+ }
+
+ @Override
+ public URI getEntitySetUri() {
+ throw new EdmException("Not yet implemented");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportInfoImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportInfoImpl.java
new file mode 100644
index 0000000..a2f52d6
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportInfoImpl.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import java.net.URI;
+
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmFunctionImportInfo;
+
+public class EdmFunctionImportInfoImpl extends EdmOperationImportInfoImpl implements EdmFunctionImportInfo {
+
+ private String functionImportName;
+
+ public EdmFunctionImportInfoImpl(final String entityContainerName, final String functionImportName) {
+ super(entityContainerName);
+ this.functionImportName = functionImportName;
+ }
+
+ @Override
+ public String getFunctionImportName() {
+ return functionImportName;
+ }
+
+ @Override
+ public URI getFunctionImportUri() {
+ throw new EdmException("Not yet implemented");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmMemberImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmMemberImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmMemberImpl.java
new file mode 100644
index 0000000..79be011
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmMemberImpl.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmMember;
+
+public class EdmMemberImpl extends EdmNamedImpl implements EdmMember {
+
+ private final String value;
+
+ public EdmMemberImpl(final Edm edm, final String name, final String value) {
+ super(edm, name);
+ this.value = value;
+ }
+
+ @Override
+ public String getValue() {
+ return value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNamedImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNamedImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNamedImpl.java
new file mode 100644
index 0000000..8f82d56
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNamedImpl.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmNamed;
+
+public abstract class EdmNamedImpl implements EdmNamed {
+
+ protected final Edm edm;
+
+ private final String name;
+
+ public EdmNamedImpl(final Edm edm, final String name) {
+ this.edm = edm;
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOperationImportInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOperationImportInfoImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOperationImportInfoImpl.java
new file mode 100644
index 0000000..5c73b61
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOperationImportInfoImpl.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.EdmOperationImportInfo;
+
+public abstract class EdmOperationImportInfoImpl implements EdmOperationImportInfo {
+
+ protected String entityContainerName;
+
+ public EdmOperationImportInfoImpl(final String entityContainerName) {
+ this.entityContainerName = entityContainerName;
+ }
+
+ @Override
+ public String getEntityContainerName() {
+ return this.entityContainerName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmSingletonInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmSingletonInfoImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmSingletonInfoImpl.java
new file mode 100644
index 0000000..6fa6489
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmSingletonInfoImpl.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import java.net.URI;
+
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmSingletonInfo;
+
+public class EdmSingletonInfoImpl implements EdmSingletonInfo {
+
+ private final String entityContainerName;
+
+ private final String singletonName;
+
+ public EdmSingletonInfoImpl(final String entityContainerName, final String singletonName) {
+ this.entityContainerName = entityContainerName;
+ this.singletonName = singletonName;
+ }
+
+ @Override
+ public String getEntityContainerName() {
+ return entityContainerName;
+ }
+
+ @Override
+ public String getSingletonName() {
+ return singletonName;
+ }
+
+ @Override
+ public URI getEntitySetUri() {
+ throw new EdmException("Not yet implemented");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmStructuredTypeHelper.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmStructuredTypeHelper.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmStructuredTypeHelper.java
new file mode 100644
index 0000000..e1226dd
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmStructuredTypeHelper.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+
+public interface EdmStructuredTypeHelper {
+
+ Map<String, EdmProperty> getProperties();
+
+ Map<String, EdmNavigationProperty> getNavigationProperties();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java
new file mode 100644
index 0000000..7fc2808
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+
+public class EdmTypeImpl extends EdmNamedImpl implements EdmType {
+
+ protected final FullQualifiedName fqn;
+
+ protected final EdmTypeKind kind;
+
+ public EdmTypeImpl(final Edm edm, final FullQualifiedName fqn, final EdmTypeKind kind) {
+ super(edm, fqn.getName());
+ this.fqn = fqn;
+ this.kind = kind;
+ }
+
+ @Override
+ public String getNamespace() {
+ return fqn.getNamespace();
+ }
+
+ @Override
+ public EdmTypeKind getKind() {
+ return kind;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/FunctionMapKey.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/FunctionMapKey.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/FunctionMapKey.java
new file mode 100644
index 0000000..a9193a3
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/FunctionMapKey.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+
+public class FunctionMapKey {
+
+ private final FullQualifiedName functionName;
+
+ private final FullQualifiedName bindingParameterTypeName;
+
+ private final Boolean isBindingParameterCollection;
+
+ private final List<String> parameterNames;
+
+ public FunctionMapKey(final FullQualifiedName functionName, final FullQualifiedName bindingParameterTypeName,
+ final Boolean isBindingParameterCollection, final List<String> parameterNames) {
+
+ this.functionName = functionName;
+ if (bindingParameterTypeName != null && isBindingParameterCollection == null) {
+ throw new EdmException(
+ "Indicator that the bindingparameter is a collection must not be null if its an bound function.");
+ }
+ this.bindingParameterTypeName = bindingParameterTypeName;
+ this.isBindingParameterCollection = isBindingParameterCollection;
+ this.parameterNames = new ArrayList<String>();
+ if (parameterNames != null) {
+ this.parameterNames.addAll(parameterNames);
+ Collections.sort(this.parameterNames);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ String hash = functionName.toString();
+
+ if (bindingParameterTypeName != null) {
+ hash = hash + bindingParameterTypeName.toString();
+ } else {
+ hash = hash + "typeNull";
+ }
+
+ if (isBindingParameterCollection != null) {
+ hash = hash + isBindingParameterCollection.toString();
+ } else {
+ hash = hash + "collectionNull";
+ }
+
+ if (!parameterNames.isEmpty()) {
+ for (String name : parameterNames) {
+ hash = hash + name;
+ }
+ } else {
+ hash = hash + "parameterNamesEmpty";
+ }
+
+ return hash.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if ((obj == null) || !(obj instanceof FunctionMapKey)) {
+ return false;
+ }
+ final FunctionMapKey other = (FunctionMapKey) obj;
+
+ if (functionName.equals(other.functionName)
+ && (bindingParameterTypeName == null && other.bindingParameterTypeName == null)
+ || (bindingParameterTypeName != null && bindingParameterTypeName.equals(other.bindingParameterTypeName))
+ && (isBindingParameterCollection == null
+ && other.isBindingParameterCollection == null)
+ || (isBindingParameterCollection != null
+ && isBindingParameterCollection.equals(other.isBindingParameterCollection))) {
+
+ if (parameterNames == null && other.parameterNames == null) {
+ return true;
+ } else if (parameterNames.size() == other.parameterNames.size()) {
+ for (String name : parameterNames) {
+ if (!other.parameterNames.contains(name)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java
new file mode 100644
index 0000000..09ceb31
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm.primitivetype;
+
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+
+/**
+ * Abstract implementation of the EDM primitive-type interface.
+ */
+abstract class AbstractPrimitiveType implements EdmPrimitiveType {
+
+ protected String uriPrefix = "";
+
+ protected String uriSuffix = "";
+
+ @Override
+ public boolean isCompatible(final EdmPrimitiveType primitiveType) {
+ return equals(primitiveType);
+ }
+
+ @Override
+ public boolean validate(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
+ final Boolean isUnicode) {
+
+ try {
+ valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, getDefaultType());
+ return true;
+ } catch (final EdmPrimitiveTypeException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public final <T> T valueOfString(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode, final Class<T> returnType)
+ throws EdmPrimitiveTypeException {
+
+ if (value == null) {
+ if (isNullable != null && !isNullable) {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED");
+ }
+ return null;
+ }
+ return internalValueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
+ }
+
+ protected abstract <T> T internalValueOfString(String value,
+ Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode,
+ Class<T> returnType) throws EdmPrimitiveTypeException;
+
+ @Override
+ public final String valueToString(final Object value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
+ if (value == null) {
+ if (isNullable != null && !isNullable) {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED");
+ }
+ return null;
+ }
+ return internalValueToString(value, isNullable, maxLength, precision, scale, isUnicode);
+ }
+
+ protected abstract <T> String internalValueToString(T value,
+ Boolean isNullable, Integer maxLength, Integer precision, Integer scale,
+ Boolean isUnicode) throws EdmPrimitiveTypeException;
+
+ @Override
+ public String toUriLiteral(final String literal) {
+ return literal == null
+ ? null
+ : uriPrefix.isEmpty() && uriSuffix.isEmpty()
+ ? literal
+ : uriPrefix + literal + uriSuffix;
+ }
+
+ @Override
+ public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
+ if (literal == null) {
+ return null;
+ } else if (uriPrefix.isEmpty() && uriSuffix.isEmpty()) {
+ return literal;
+ } else if (literal.length() >= uriPrefix.length() + uriSuffix.length()
+ && literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) {
+
+ return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
+ } else {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)");
+ }
+ }
+
+ @Override
+ public String toString() {
+ return new FullQualifiedName(getNamespace(), getName()).getFullQualifiedNameAsString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java
new file mode 100644
index 0000000..7611045
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm.primitivetype;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+
+/**
+ * Implementation of the EDM primitive type Binary.
+ */
+public class EdmBinary extends SingletonPrimitiveType {
+
+ private static final EdmBinary INSTANCE = new EdmBinary();
+
+ {
+ uriPrefix = "binary'";
+ uriSuffix = "'";
+ }
+
+ public static EdmBinary getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public Class<?> getDefaultType() {
+ return byte[].class;
+ }
+
+ @Override
+ public boolean validate(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) {
+
+ return value == null
+ ? isNullable == null || isNullable
+ : Base64.isBase64(value) && validateMaxLength(value, maxLength);
+ }
+
+ private static boolean validateMaxLength(final String value, final Integer maxLength) {
+ return maxLength == null ? true
+ : // Every three bytes are represented as four base-64 characters.
+ // Additionally, there could be up to two padding "=" characters
+ // if the number of bytes is not a multiple of three.
+ maxLength >= value.length() * 3 / 4 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0);
+ }
+
+ @Override
+ protected <T> T internalValueOfString(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
+
+ if (!Base64.isBase64(value)) {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
+ }
+ if (!validateMaxLength(value, maxLength)) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
+ }
+
+ final byte[] result = Base64.decodeBase64(value);
+
+ if (returnType.isAssignableFrom(byte[].class)) {
+ return returnType.cast(result);
+ } else if (returnType.isAssignableFrom(Byte[].class)) {
+ final Byte[] byteArray = new Byte[result.length];
+ for (int i = 0; i < result.length; i++) {
+ byteArray[i] = result[i];
+ }
+ return returnType.cast(byteArray);
+ } else {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
+ }
+ }
+
+ @Override
+ protected <T> String internalValueToString(final T value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
+
+ byte[] byteArrayValue;
+ if (value instanceof byte[]) {
+ byteArrayValue = (byte[]) value;
+ } else if (value instanceof Byte[]) {
+ final int length = ((Byte[]) value).length;
+ byteArrayValue = new byte[length];
+ for (int i = 0; i < length; i++) {
+ byteArrayValue[i] = ((Byte[]) value)[i].byteValue();
+ }
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
+ }
+
+ if (maxLength != null && byteArrayValue.length > maxLength) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
+ }
+
+ return Base64.encodeBase64URLSafeString(byteArrayValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBoolean.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBoolean.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBoolean.java
new file mode 100644
index 0000000..a3de59f
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBoolean.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm.primitivetype;
+
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+
+/**
+ * Implementation of the EDM primitive type Boolean.
+ */
+public final class EdmBoolean extends SingletonPrimitiveType {
+
+ private static final EdmBoolean INSTANCE = new EdmBoolean();
+
+ public static EdmBoolean getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public Class<?> getDefaultType() {
+ return Boolean.class;
+ }
+
+ @Override
+ public boolean validate(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) {
+
+ return value == null ? isNullable == null || isNullable : validateLiteral(value);
+ }
+
+ private static boolean validateLiteral(final String value) {
+ return "true".equals(value) || "false".equals(value);
+ }
+
+ @Override
+ protected <T> T internalValueOfString(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
+
+ if (validateLiteral(value)) {
+ if (returnType.isAssignableFrom(Boolean.class)) {
+ return returnType.cast(Boolean.valueOf("true".equals(value)));
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
+ }
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
+ }
+ }
+
+ @Override
+ protected <T> String internalValueToString(final T value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
+
+ if (value instanceof Boolean) {
+ return Boolean.toString((Boolean) value);
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmByte.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmByte.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmByte.java
new file mode 100644
index 0000000..6c105eb
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmByte.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm.primitivetype;
+
+import java.math.BigInteger;
+
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+
+/**
+ * Implementation of the EDM primitive type Byte.
+ */
+public final class EdmByte extends SingletonPrimitiveType {
+
+ private static final EdmByte INSTANCE = new EdmByte();
+
+ public static EdmByte getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public boolean isCompatible(final EdmPrimitiveType primitiveType) {
+ return primitiveType instanceof Uint7
+ || primitiveType instanceof EdmByte;
+ }
+
+ @Override
+ public Class<?> getDefaultType() {
+ return Short.class;
+ }
+
+ @Override
+ protected <T> T internalValueOfString(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
+
+ Short valueShort;
+ try {
+ valueShort = Short.parseShort(value);
+ } catch (final NumberFormatException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
+ }
+ if (valueShort < 0 || valueShort >= 1 << Byte.SIZE) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
+ }
+
+ try {
+ return EdmInt64.convertNumber(valueShort, returnType);
+ } catch (final IllegalArgumentException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
+ } catch (final ClassCastException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
+ }
+ }
+
+ @Override
+ protected <T> String internalValueToString(final T value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
+
+ if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
+ if (((Number) value).longValue() >= 0 && ((Number) value).longValue() < 1 << Byte.SIZE) {
+ return value.toString();
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
+ }
+ } else if (value instanceof BigInteger) {
+ if (((BigInteger) value).compareTo(BigInteger.ZERO) >= 0
+ && ((BigInteger) value).compareTo(BigInteger.valueOf(1 << Byte.SIZE)) < 0) {
+ return value.toString();
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
+ }
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java
new file mode 100644
index 0000000..5f141c0
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm.primitivetype;
+
+import java.util.Calendar;
+import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+
+/**
+ * Implementation of the EDM primitive type Date.
+ */
+public final class EdmDate extends SingletonPrimitiveType {
+
+ private static final Pattern PATTERN = Pattern.compile("(-?\\p{Digit}{4,})-(\\p{Digit}{2})-(\\p{Digit}{2})");
+
+ private static final EdmDate INSTANCE = new EdmDate();
+
+ public static EdmDate getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public Class<?> getDefaultType() {
+ return Calendar.class;
+ }
+
+ @Override
+ protected <T> T internalValueOfString(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
+
+ final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ dateTimeValue.clear();
+
+ final Matcher matcher = PATTERN.matcher(value);
+ if (!matcher.matches()) {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
+ }
+
+ dateTimeValue.set(
+ Integer.parseInt(matcher.group(1)),
+ Byte.parseByte(matcher.group(2)) - 1, // month is zero-based
+ Byte.parseByte(matcher.group(3)));
+
+ try {
+ return EdmDateTimeOffset.convertDateTime(dateTimeValue, returnType);
+ } catch (final IllegalArgumentException e) {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e");
+ } catch (final ClassCastException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
+ }
+ }
+
+ @Override
+ protected <T> String internalValueToString(final T value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
+
+ final Calendar dateTimeValue = EdmDateTimeOffset.createDateTime(value);
+
+ final StringBuilder result = new StringBuilder(10); // Ten characters are enough for "normal" dates.
+ final int year = dateTimeValue.get(Calendar.YEAR);
+ if (year < 0 || year >= 10000) {
+ result.append(year);
+ } else {
+ EdmDateTimeOffset.appendTwoDigits(result, (year / 100) % 100);
+ EdmDateTimeOffset.appendTwoDigits(result, year % 100);
+ }
+ result.append('-');
+ EdmDateTimeOffset.appendTwoDigits(result, dateTimeValue.get(Calendar.MONTH) + 1); // month is zero-based
+ result.append('-');
+ EdmDateTimeOffset.appendTwoDigits(result, dateTimeValue.get(Calendar.DAY_OF_MONTH));
+ return result.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
new file mode 100644
index 0000000..7a511d6
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
@@ -0,0 +1,239 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.olingo.commons.core.edm.primitivetype;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+
+/**
+ * Implementation of the EDM primitive type DateTimeOffset.
+ */
+public final class EdmDateTimeOffset extends SingletonPrimitiveType {
+
+ private static final Pattern PATTERN = Pattern.compile(
+ "(-?\\p{Digit}{4,})-(\\p{Digit}{2})-(\\p{Digit}{2})"
+ + "T(\\p{Digit}{2}):(\\p{Digit}{2})(?::(\\p{Digit}{2})(\\.(\\p{Digit}{0,3}?)0*)?)?"
+ + "(Z|([-+]\\p{Digit}{2}:\\p{Digit}{2}))?");
+
+ private static final EdmDateTimeOffset INSTANCE = new EdmDateTimeOffset();
+
+ public static EdmDateTimeOffset getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public Class<?> getDefaultType() {
+ return Calendar.class;
+ }
+
+ @Override
+ protected <T> T internalValueOfString(final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
+
+ final Matcher matcher = PATTERN.matcher(value);
+ if (!matcher.matches()) {
+ throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
+ }
+
+ final String timeZoneOffset = matcher.group(9) != null && matcher.group(10) != null
+ && !matcher.group(10).matches("[-+]0+:0+") ? matcher.group(10) : null;
+ final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT" + timeZoneOffset));
+ if (dateTimeValue.get(Calendar.ZONE_OFFSET) == 0 && timeZoneOffset != null) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
+ }
+ dateTimeValue.clear();
+
+ dateTimeValue.set(
+ Short.parseShort(matcher.group(1)),
+ Byte.parseByte(matcher.group(2)) - 1, // month is zero-based
+ Byte.parseByte(matcher.group(3)),
+ Byte.parseByte(matcher.group(4)),
+ Byte.parseByte(matcher.group(5)),
+ matcher.group(6) == null ? 0 : Byte.parseByte(matcher.group(6)));
+
+ if (matcher.group(7) != null) {
+ if (matcher.group(7).length() == 1 || matcher.group(7).length() > 13) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
+ }
+ final String decimals = matcher.group(8);
+ if (decimals.length() > (precision == null ? 0 : precision)) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
+ }
+ final String milliSeconds = decimals + "000".substring(decimals.length());
+ dateTimeValue.set(Calendar.MILLISECOND, Short.parseShort(milliSeconds));
+ }
+
+ try {
+ return convertDateTime(dateTimeValue, returnType);
+ } catch (final IllegalArgumentException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e");
+ } catch (final ClassCastException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
+ }
+ }
+
+ /**
+ * Converts a {@link Calendar} value into the requested return type if possible.
+ *
+ * @param dateTimeValue the value
+ * @param returnType the class of the returned value; it must be one of {@link Calendar}, {@link Long}, or
+ * {@link Date}
+ * @return the converted value
+ * @throws IllegalArgumentException if the Calendar value is not valid
+ * @throws ClassCastException if the return type is not allowed
+ */
+ protected static <T> T convertDateTime(final Calendar dateTimeValue, final Class<T> returnType)
+ throws IllegalArgumentException, ClassCastException {
+
+ // The Calendar class does not check any values until a get method is called,
+ // so we do just that to validate the fields that may have been set,
+ // not because we want to return something else.
+ // For strict checks, the lenient mode is switched off.
+ dateTimeValue.setLenient(false);
+
+ if (returnType.isAssignableFrom(Calendar.class)) {
+ // Ensure that all fields are recomputed.
+ dateTimeValue.get(Calendar.MILLISECOND); // may throw IllegalArgumentException
+ // Reset the lenient mode to its default.
+ dateTimeValue.setLenient(true);
+ return returnType.cast(dateTimeValue);
+ } else if (returnType.isAssignableFrom(Long.class)) {
+ return returnType.cast(dateTimeValue.getTimeInMillis()); // may throw IllegalArgumentException
+ } else if (returnType.isAssignableFrom(Date.class)) {
+ return returnType.cast(dateTimeValue.getTime()); // may throw IllegalArgumentException
+ } else {
+ throw new ClassCastException("unsupported return type " + returnType.getSimpleName());
+ }
+ }
+
+ @Override
+ protected <T> String internalValueToString(final T value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
+
+ final Calendar dateTimeValue = createDateTime(value);
+
+ final StringBuilder result = new StringBuilder(23); // 23 characters are enough for millisecond precision.
+ final int year = dateTimeValue.get(Calendar.YEAR);
+ appendTwoDigits(result, year / 100);
+ appendTwoDigits(result, year % 100);
+ result.append('-');
+ appendTwoDigits(result, dateTimeValue.get(Calendar.MONTH) + 1); // month is zero-based
+ result.append('-');
+ appendTwoDigits(result, dateTimeValue.get(Calendar.DAY_OF_MONTH));
+ result.append('T');
+ appendTwoDigits(result, dateTimeValue.get(Calendar.HOUR_OF_DAY));
+ result.append(':');
+ appendTwoDigits(result, dateTimeValue.get(Calendar.MINUTE));
+ result.append(':');
+ appendTwoDigits(result, dateTimeValue.get(Calendar.SECOND));
+
+ try {
+ appendMilliseconds(result, dateTimeValue.get(Calendar.MILLISECOND), precision);
+ } catch (final IllegalArgumentException e) {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets), e");
+ }
+
+ final int offsetInMinutes = (dateTimeValue.get(Calendar.ZONE_OFFSET)
+ + dateTimeValue.get(Calendar.DST_OFFSET)) / 60 / 1000;
+ final int offsetHours = offsetInMinutes / 60;
+ final int offsetMinutes = Math.abs(offsetInMinutes % 60);
+ final String offsetString = offsetInMinutes == 0 ? "Z" : String.format("%+03d:%02d", offsetHours, offsetMinutes);
+ result.append(offsetString);
+
+ return result.toString();
+ }
+
+ /**
+ * Creates a date/time value from the given value.
+ *
+ * @param value the value as {@link Calendar}, {@link Date}, or {@link Long}
+ * @return the value as {@link Calendar}
+ * @throws EdmPrimitiveTypeException if the type of the value is not supported
+ */
+ protected static <T> Calendar createDateTime(final T value) throws EdmPrimitiveTypeException {
+ Calendar dateTimeValue;
+ if (value instanceof Date) {
+ // Although java.util.Date, as stated in its documentation,
+ // "is intended to reflect coordinated universal time (UTC)",
+ // its toString() method uses the default time zone. And so do we.
+ dateTimeValue = Calendar.getInstance();
+ dateTimeValue.setTime((Date) value);
+ } else if (value instanceof Calendar) {
+ dateTimeValue = (Calendar) ((Calendar) value).clone();
+ } else if (value instanceof Long) {
+ dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ dateTimeValue.setTimeInMillis((Long) value);
+ } else {
+ throw new EdmPrimitiveTypeException(
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
+ }
+ return dateTimeValue;
+ }
+
+ /**
+ * Appends the given number to the given string builder, assuming that the number has at most two digits,
+ * performance-optimized.
+ *
+ * @param result a {@link StringBuilder}
+ * @param number an integer that must satisfy <code>0 <= number <= 99</code>
+ */
+ protected static void appendTwoDigits(final StringBuilder result, final int number) {
+ result.append((char) ('0' + number / 10));
+ result.append((char) ('0' + number % 10));
+ }
+
+ /**
+ * Appends the given number of milliseconds to the given string builder, assuming that the number has at most three
+ * digits, performance-optimized.
+ *
+ * @param result a {@link StringBuilder}
+ * @param milliseconds an integer that must satisfy <code>0 <= milliseconds <= 999</code>
+ * @param precision the upper limit for decimal digits (optional, defaults to zero)
+ */
+ protected static void appendMilliseconds(final StringBuilder result, final long milliseconds,
+ final Integer precision) throws IllegalArgumentException {
+ final int digits = milliseconds % 1000 == 0 ? 0 : milliseconds % 100 == 0 ? 1 : milliseconds % 10 == 0 ? 2 : 3;
+ if (digits > 0) {
+ result.append('.');
+ for (int d = 100; d > 0; d /= 10) {
+ final byte digit = (byte) (milliseconds % (d * 10) / d);
+ if (digit > 0 || milliseconds % d > 0) {
+ result.append((char) ('0' + digit));
+ }
+ }
+
+ if (precision == null || precision < digits) {
+ throw new IllegalArgumentException();
+ }
+ }
+ }
+}