http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java deleted file mode 100644 index 3bf8a7a..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java +++ /dev/null @@ -1,327 +0,0 @@ -/* - * 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.server.core.serializer.utils; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.util.Queue; -import java.util.concurrent.LinkedBlockingQueue; - -/** - * Circular stream buffer to write/read into/from one single buffer. - * With support of {@link InputStream} and {@link OutputStream} access to buffered data. - * - * - */ -public class CircleStreamBuffer { - - private static final int NEW_BUFFER_RESIZE_FACTOR = 2; - private static final int READ_EOF = -1; - private static final int DEFAULT_CAPACITY = 8192; - private static final int MAX_CAPACITY = DEFAULT_CAPACITY * 32; - - private int currentAllocateCapacity = DEFAULT_CAPACITY; - - private boolean writeMode = true; - private boolean writeClosed = false; - private boolean readClosed = false; - - private Queue<ByteBuffer> bufferQueue = new LinkedBlockingQueue<ByteBuffer>(); - private ByteBuffer currentWriteBuffer; - - private InternalInputStream inStream; - private InternalOutputStream outStream; - - /** - * Creates a {@link CircleStreamBuffer} with default buffer size. - */ - public CircleStreamBuffer() { - this(DEFAULT_CAPACITY); - } - - /** - * Create a {@link CircleStreamBuffer} with given buffer size in bytes. - * - * @param bufferSize - */ - public CircleStreamBuffer(final int bufferSize) { - currentAllocateCapacity = bufferSize; - createNewWriteBuffer(); - inStream = new InternalInputStream(this); - outStream = new InternalOutputStream(this); - } - - /** - * Get {@link InputStream} for data read access. - * - * @return the stream - */ - public InputStream getInputStream() { - return inStream; - } - - /** - * Get {@link OutputStream} for write data. - * - * @return the stream - */ - public OutputStream getOutputStream() { - return outStream; - } - - // ############################################# - // # - // # Common parts - // # - // ############################################# - - /** - * Closes the write (input) part of the {@link CircleStreamBuffer}. - * After this call the buffer can only be read out. - */ - public void closeWrite() { - writeClosed = true; - } - - /** - * Closes the read (output) part of the {@link CircleStreamBuffer}. - * After this call it is possible to write into the buffer (but can never be read out). - */ - public void closeRead() { - readClosed = true; - // clear references to byte buffers - ByteBuffer buffer = bufferQueue.poll(); - while (buffer != null) { - buffer.clear(); - buffer = bufferQueue.poll(); - } - } - - /** - * Closes write and read part (and hence the complete buffer). - */ - public void close() { - closeWrite(); - closeRead(); - } - - private int remaining() throws IOException { - if (writeMode) { - return currentWriteBuffer.remaining(); - } else { - ByteBuffer toRead = getReadBuffer(); - if (toRead == null) { - return 0; - } - return toRead.remaining(); - } - } - - // ############################################# - // # - // # Reading parts - // # - // ############################################# - - private ByteBuffer getReadBuffer() throws IOException { - if (readClosed) { - throw new IOException("Tried to read from closed stream."); - } - - boolean next = false; - ByteBuffer tmp = null; - if (writeMode) { - writeMode = false; - next = true; - } else { - tmp = bufferQueue.peek(); - if (tmp != null && !tmp.hasRemaining()) { - tmp = bufferQueue.poll(); - next = true; - } - } - - if (next) { - tmp = bufferQueue.peek(); - if (tmp != null) { - tmp.flip(); - } - tmp = getReadBuffer(); - } - - return tmp; - } - - private int read(final byte[] b, final int off, final int len) throws IOException { - ByteBuffer readBuffer = getReadBuffer(); - if (readBuffer == null) { - return READ_EOF; - } - - int toReadLength = readBuffer.remaining(); - if (len < toReadLength) { - toReadLength = len; - } - readBuffer.get(b, off, toReadLength); - return toReadLength; - } - - private int read() throws IOException { - ByteBuffer readBuffer = getReadBuffer(); - if (readBuffer == null) { - return READ_EOF; - } - - return readBuffer.get(); - } - - // ############################################# - // # - // # Writing parts - // # - // ############################################# - - private void write(final byte[] data, final int off, final int len) throws IOException { - ByteBuffer writeBuffer = getWriteBuffer(len); - writeBuffer.put(data, off, len); - } - - private ByteBuffer getWriteBuffer(final int size) throws IOException { - if (writeClosed) { - throw new IOException("Tried to write into closed stream."); - } - - if (writeMode) { - if (remaining() < size) { - createNewWriteBuffer(size); - } - } else { - writeMode = true; - createNewWriteBuffer(); - } - - return currentWriteBuffer; - } - - private void write(final int b) throws IOException { - ByteBuffer writeBuffer = getWriteBuffer(1); - writeBuffer.put((byte) b); - } - - private void createNewWriteBuffer() { - createNewWriteBuffer(currentAllocateCapacity); - } - - /** - * Creates a new buffer (per {@link #allocateBuffer(int)}) with the requested capacity as minimum capacity, add the - * new allocated - * buffer to the {@link #bufferQueue} and set it as {@link #currentWriteBuffer}. - * - * @param requestedCapacity minimum capacity for new allocated buffer - */ - private void createNewWriteBuffer(final int requestedCapacity) { - ByteBuffer b = allocateBuffer(requestedCapacity); - bufferQueue.add(b); - currentWriteBuffer = b; - } - - /** - * - * @param requestedCapacity - * @return the buffer - */ - private ByteBuffer allocateBuffer(final int requestedCapacity) { - int allocateCapacity = requestedCapacity; - if (allocateCapacity < currentAllocateCapacity) { - allocateCapacity = currentAllocateCapacity * NEW_BUFFER_RESIZE_FACTOR; - } - if (allocateCapacity > MAX_CAPACITY) { - allocateCapacity = MAX_CAPACITY; - } - // update current - currentAllocateCapacity = allocateCapacity; - return ByteBuffer.allocate(allocateCapacity); - } - - // ############################################# - // # - // # Inner classes (streams) - // # - // ############################################# - - /** - * - */ - private static class InternalInputStream extends InputStream { - - private final CircleStreamBuffer inBuffer; - - public InternalInputStream(final CircleStreamBuffer csBuffer) { - inBuffer = csBuffer; - } - - @Override - public int available() throws IOException { - return inBuffer.remaining(); - } - - @Override - public int read() throws IOException { - return inBuffer.read(); - } - - @Override - public int read(final byte[] b, final int off, final int len) throws IOException { - return inBuffer.read(b, off, len); - } - - @Override - public void close() throws IOException { - inBuffer.closeRead(); - } - } - - /** - * - */ - private static class InternalOutputStream extends OutputStream { - private final CircleStreamBuffer outBuffer; - - public InternalOutputStream(final CircleStreamBuffer csBuffer) { - outBuffer = csBuffer; - } - - @Override - public void write(final int b) throws IOException { - outBuffer.write(b); - } - - @Override - public void write(final byte[] b, final int off, final int len) throws IOException { - outBuffer.write(b, off, len); - } - - @Override - public void close() throws IOException { - outBuffer.closeWrite(); - } - } -}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java deleted file mode 100644 index 4a3f82a..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.server.core.serializer.utils; - -import java.net.URI; - -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.ContextURL; -import org.apache.olingo.commons.core.Encoder; - -/** - * Builder to build a context URL (as defined in the <a - * href="http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Toc372793655"> - * protocol specification</a>). - */ -public final class ContextURLBuilder { - - public static URI create(final ContextURL contextURL) { - StringBuilder result = new StringBuilder(); - if (contextURL.getServiceRoot() != null) { - result.append(contextURL.getServiceRoot()); - } - result.append(Constants.METADATA); - if (contextURL.getEntitySetOrSingletonOrType() != null) { - result.append('#'); - if(contextURL.isCollection()) { - result.append("Collection(") - .append(Encoder.encode(contextURL.getEntitySetOrSingletonOrType())) - .append(")"); - } else { - result.append(Encoder.encode(contextURL.getEntitySetOrSingletonOrType())); - } - } - if (contextURL.getDerivedEntity() != null) { - if (contextURL.getEntitySetOrSingletonOrType() == null) { - throw new IllegalArgumentException("ContextURL: Derived Type without anything to derive from!"); - } - result.append('/').append(Encoder.encode(contextURL.getDerivedEntity())); - } - if (contextURL.getKeyPath() != null) { - result.append('(').append(contextURL.getKeyPath()).append(')'); - } - if (contextURL.getNavOrPropertyPath() != null) { - result.append('/').append(contextURL.getNavOrPropertyPath()); - } - if (contextURL.getSelectList() != null) { - result.append('(').append(contextURL.getSelectList()).append(')'); - } - if (contextURL.isReference()) { - if (contextURL.getEntitySetOrSingletonOrType() != null) { - throw new IllegalArgumentException("ContextURL: $ref with Entity Set"); - } - result.append('#').append(ContextURL.Suffix.REFERENCE.getRepresentation()); - } else if (contextURL.getSuffix() != null) { - if (contextURL.getEntitySetOrSingletonOrType() == null) { - throw new IllegalArgumentException("ContextURL: Suffix without preceding Entity Set!"); - } - result.append('/').append(contextURL.getSuffix().getRepresentation()); - } - return URI.create(result.toString()); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java deleted file mode 100644 index e9eb880..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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.server.core.serializer.utils; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmProperty; -import org.apache.olingo.commons.api.edm.EdmStructuredType; -import org.apache.olingo.commons.core.Encoder; -import org.apache.olingo.server.api.serializer.SerializerException; -import org.apache.olingo.server.api.uri.UriParameter; -import org.apache.olingo.server.api.uri.queryoption.ExpandItem; -import org.apache.olingo.server.api.uri.queryoption.ExpandOption; -import org.apache.olingo.server.api.uri.queryoption.SelectItem; -import org.apache.olingo.server.api.uri.queryoption.SelectOption; - -public final class ContextURLHelper { - - /** Builds a list of selected Properties for the ContextURL, - * taking care to preserve the order as defined in the EDM; - * returns NULL if no selection has taken place. - * @param type the structured type - * @param expand the Expand option (from the URL's $expand query option) - * @param select the Select option (from the URL's $select query option) - * @return a select-list String - * @throws SerializerException if an unsupported feature is used - */ - public static String buildSelectList(final EdmStructuredType type, - final ExpandOption expand, final SelectOption select) throws SerializerException { - StringBuilder result = new StringBuilder(); - if (ExpandSelectHelper.hasSelect(select)) { - handleSelect(type, select, result); - } - - if (ExpandSelectHelper.hasExpand(expand) && !ExpandSelectHelper.isExpandAll(expand)) { - handleExpand(type, expand, result); - } - return result.length() == 0 ? null : result.toString(); - } - - private static void handleSelect(final EdmStructuredType type, final SelectOption select, StringBuilder result) { - if (ExpandSelectHelper.isAll(select)) { - result.append('*'); - } else { - final List<SelectItem> selectItems = select.getSelectItems(); - final Set<String> selectedPropertyNames = ExpandSelectHelper.getSelectedPropertyNames(selectItems); - for (final String propertyName : type.getPropertyNames()) { - if (selectedPropertyNames.contains(propertyName)) { - if (result.length() > 0) { - result.append(','); - } - final EdmProperty edmProperty = type.getStructuralProperty(propertyName); - final Set<List<String>> selectedPaths = ExpandSelectHelper.getSelectedPaths(selectItems, propertyName); - if (selectedPaths == null) { - result.append(Encoder.encode(propertyName)); - } else { - final List<List<String>> complexSelectedPaths = getComplexSelectedPaths(edmProperty, selectedPaths); - boolean first = true; - for (final List<String> path : complexSelectedPaths) { - if (first) { - first = false; - } else { - result.append(','); - } - boolean innerFirst = true; - for (final String name : path) { - if (innerFirst) { - innerFirst = false; - } else { - result.append('/'); - } - result.append(Encoder.encode(name)); - } - } - } - } - } - } - } - - private static void handleExpand(final EdmStructuredType type, final ExpandOption expand, StringBuilder result) - throws SerializerException { - final Set<String> expandedPropertyNames = ExpandSelectHelper.getExpandedPropertyNames(expand.getExpandItems()); - for (final String propertyName : type.getNavigationPropertyNames()) { - if (expandedPropertyNames.contains(propertyName)) { - final ExpandItem expandItem = ExpandSelectHelper.getExpandItem(expand.getExpandItems(), propertyName); - if (ExpandSelectHelper.hasExpand(expandItem.getExpandOption()) - && !ExpandSelectHelper.isExpandAll(expandItem.getExpandOption()) - || ExpandSelectHelper.hasSelect(expandItem.getSelectOption())) { - final String innerSelectList = buildSelectList(type.getNavigationProperty(propertyName).getType(), - expandItem.getExpandOption(), expandItem.getSelectOption()); - if (innerSelectList != null) { - if (result.length() > 0) { - result.append(','); - } - result.append(Encoder.encode(propertyName)).append('(').append(innerSelectList).append(')'); - } - } - } - } - } - - private static List<List<String>> getComplexSelectedPaths(final EdmProperty edmProperty, - final Set<List<String>> selectedPaths) { - List<List<String>> result = new ArrayList<List<String>>(); - if (selectedPaths == null) { - List<String> path = new LinkedList<String>(); - path.add(edmProperty.getName()); - result.add(path); - } else { - final EdmComplexType type = (EdmComplexType) edmProperty.getType(); - for (final String complexPropertyName : type.getPropertyNames()) { - if (ExpandSelectHelper.isSelected(selectedPaths, complexPropertyName)) { - List<List<String>> complexSelectedPaths = getComplexSelectedPaths( - (EdmProperty) type.getProperty(complexPropertyName), - ExpandSelectHelper.getReducedSelectedPaths(selectedPaths, complexPropertyName)); - for (final List<String> path : complexSelectedPaths) { - path.add(0, edmProperty.getName()); - result.add(path); - } - } - } - } - return result; - } - - /** - * Builds a key predicate for the ContextURL. - * @param keys the keys as a list of {@link UriParameter} instances - * @return a String with the key predicate - */ - public static String buildKeyPredicate(List<UriParameter> keys) throws SerializerException { - if (keys == null || keys.isEmpty()) { - return null; - } else if (keys.size() == 1) { - return Encoder.encode(keys.get(0).getText()); - } else { - StringBuilder result = new StringBuilder(); - for (final UriParameter key : keys) { - if (result.length() > 0) { - result.append(','); - } - result.append(Encoder.encode(key.getName())).append('=').append(Encoder.encode(key.getText())); - } - return result.toString(); - } - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java deleted file mode 100644 index c537fbd..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ExpandSelectHelper.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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.server.core.serializer.utils; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.olingo.server.api.serializer.SerializerException; -import org.apache.olingo.server.api.uri.UriResource; -import org.apache.olingo.server.api.uri.UriResourceNavigation; -import org.apache.olingo.server.api.uri.UriResourceProperty; -import org.apache.olingo.server.api.uri.queryoption.ExpandItem; -import org.apache.olingo.server.api.uri.queryoption.ExpandOption; -import org.apache.olingo.server.api.uri.queryoption.SelectItem; -import org.apache.olingo.server.api.uri.queryoption.SelectOption; - -public abstract class ExpandSelectHelper { - - public static boolean hasSelect(final SelectOption select) { - return select != null && select.getSelectItems() != null && !select.getSelectItems().isEmpty(); - } - - public static boolean isAll(final SelectOption select) { - if (hasSelect(select)) { - for (final SelectItem item : select.getSelectItems()) { - if (item.isStar()) { - return true; - } - } - return false; - } else { - return true; - } - } - - public static Set<String> getSelectedPropertyNames(final List<SelectItem> selectItems) { - Set<String> selected = new HashSet<String>(); - for (final SelectItem item : selectItems) { - final UriResource resource = item.getResourcePath().getUriResourceParts().get(0); - if (resource instanceof UriResourceProperty) { - selected.add(((UriResourceProperty) resource).getProperty().getName()); - } - } - return selected; - } - - public static Set<List<String>> getSelectedPaths(final List<SelectItem> selectItems, final String propertyName) { - Set<List<String>> selectedPaths = new HashSet<List<String>>(); - for (final SelectItem item : selectItems) { - final List<UriResource> parts = item.getResourcePath().getUriResourceParts(); - final UriResource resource = parts.get(0); - if (resource instanceof UriResourceProperty - && propertyName.equals(((UriResourceProperty) resource).getProperty().getName())) { - if (parts.size() > 1) { - List<String> path = new ArrayList<String>(); - for (final UriResource part : parts.subList(1, parts.size())) { - if (part instanceof UriResourceProperty) { - path.add(((UriResourceProperty) part).getProperty().getName()); - } - } - selectedPaths.add(path); - } else { - return null; - } - } - } - return selectedPaths.isEmpty() ? null : selectedPaths; - } - - - public static boolean isSelected(final Set<List<String>> selectedPaths, final String propertyName) { - for (final List<String> path : selectedPaths) { - if (propertyName.equals(path.get(0))) { - return true; - } - } - return false; - } - - public static Set<List<String>> getReducedSelectedPaths(final Set<List<String>> selectedPaths, - final String propertyName) { - Set<List<String>> reducedPaths = new HashSet<List<String>>(); - for (final List<String> path : selectedPaths) { - if (propertyName.equals(path.get(0))) { - if (path.size() > 1) { - reducedPaths.add(path.subList(1, path.size())); - } else { - return null; - } - } - } - return reducedPaths.isEmpty() ? null : reducedPaths; - } - - public static boolean hasExpand(final ExpandOption expand) { - return expand != null && expand.getExpandItems() != null && !expand.getExpandItems().isEmpty(); - } - - public static boolean isExpandAll(final ExpandOption expand) { - for (final ExpandItem item : expand.getExpandItems()) { - if (item.isStar()) { - return true; - } - } - return false; - } - - public static Set<String> getExpandedPropertyNames(final List<ExpandItem> expandItems) - throws SerializerException { - Set<String> expanded = new HashSet<String>(); - for (final ExpandItem item : expandItems) { - final List<UriResource> resourceParts = item.getResourcePath().getUriResourceParts(); - if (resourceParts.size() == 1) { - final UriResource resource = resourceParts.get(0); - if (resource instanceof UriResourceNavigation) { - expanded.add(((UriResourceNavigation) resource).getProperty().getName()); - } - } else { - throw new SerializerException("Expand is not supported within complex properties.", - SerializerException.MessageKeys.NOT_IMPLEMENTED); - } - } - return expanded; - } - - public static ExpandItem getExpandItem(final List<ExpandItem> expandItems, final String propertyName) { - for (final ExpandItem item : expandItems) { - final UriResource resource = item.getResourcePath().getUriResourceParts().get(0); - if (resource instanceof UriResourceNavigation - && propertyName.equals(((UriResourceNavigation) resource).getProperty().getName())) { - return item; - } - } - return null; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java deleted file mode 100644 index 25610fb..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java +++ /dev/null @@ -1,645 +0,0 @@ -/* - * 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.server.core.serializer.xml; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.olingo.commons.api.edm.EdmAction; -import org.apache.olingo.commons.api.edm.EdmActionImport; -import org.apache.olingo.commons.api.edm.EdmBindingTarget; -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmEntitySet; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmEnumType; -import org.apache.olingo.commons.api.edm.EdmFunction; -import org.apache.olingo.commons.api.edm.EdmFunctionImport; -import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; -import org.apache.olingo.commons.api.edm.EdmNavigationProperty; -import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding; -import org.apache.olingo.commons.api.edm.EdmOperation; -import org.apache.olingo.commons.api.edm.EdmParameter; -import org.apache.olingo.commons.api.edm.EdmProperty; -import org.apache.olingo.commons.api.edm.EdmReferentialConstraint; -import org.apache.olingo.commons.api.edm.EdmReturnType; -import org.apache.olingo.commons.api.edm.EdmSchema; -import org.apache.olingo.commons.api.edm.EdmSingleton; -import org.apache.olingo.commons.api.edm.EdmStructuredType; -import org.apache.olingo.commons.api.edm.EdmType; -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; -import org.apache.olingo.server.api.ServiceMetadata; -import org.apache.olingo.server.api.edmx.EdmxReference; -import org.apache.olingo.server.api.edmx.EdmxReferenceInclude; -import org.apache.olingo.server.api.edmx.EdmxReferenceIncludeAnnotation; -import org.apache.olingo.server.api.serializer.ODataSerializer; - -public class MetadataDocumentXmlSerializer { - - private static final String TRUE = "true"; - private static final String XML_EXTENDS = "Extends"; - private static final String XML_TARGET = "Target"; - private static final String XML_PATH = "Path"; - private static final String XML_NAVIGATION_PROPERTY_BINDING = "NavigationPropertyBinding"; - private static final String XML_VALUE = "Value"; - private static final String XML_MEMBER = "Member"; - private static final String XML_UNDERLYING_TYPE = "UnderlyingType"; - private static final String XML_IS_FLAGS = "IsFlags"; - private static final String XML_ENUM_TYPE = "EnumType"; - private static final String XML_PROPERTY_REF = "PropertyRef"; - private static final String XML_KEY = "Key"; - private static final String XML_SCALE = "Scale"; - private static final String XML_PRECISION = "Precision"; - private static final String XML_MAX_LENGTH = "MaxLength"; - private static final String XML_DEFAULT_VALUE = "DefaultValue"; - private static final String XML_UNICODE = "Unicode"; - private static final String XML_PROPERTY = "Property"; - private static final String XML_PARTNER = "Partner"; - private static final String XML_NULLABLE = "Nullable"; - private static final String XML_NAVIGATION_PROPERTY = "NavigationProperty"; - private static final String XML_HAS_STREAM = "HasStream"; - private static final String XML_BASE_TYPE = "BaseType"; - private static final String XML_COMPLEX_TYPE = "ComplexType"; - private static final String XML_RETURN_TYPE = "ReturnType"; - private static final String XML_TYPE = "Type"; - private static final String XML_PARAMETER = "Parameter"; - private static final String XML_IS_COMPOSABLE = "IsComposable"; - private static final String XML_IS_BOUND = "IsBound"; - private static final String XML_ENTITY_TYPE = "EntityType"; - private static final String XML_SINGLETON = "Singleton"; - private static final String XML_ACTION = "Action"; - private static final String XML_ACTION_IMPORT = "ActionImport"; - private static final String XML_INCLUDE_IN_SERVICE_DOCUMENT = "IncludeInServiceDocument"; - private static final String XML_ENTITY_SET = "EntitySet"; - private static final String XML_FUNCTION = "Function"; - private static final String XML_FUNCTION_IMPORT = "FunctionImport"; - private static final String XML_NAME = "Name"; - private static final String XML_ENTITY_CONTAINER = "EntityContainer"; - private static final String XML_ALIAS = "Alias"; - private static final String XML_NAMESPACE = "Namespace"; - private static final String XML_TYPE_DEFINITION = "TypeDefinition"; - private static final String REFERENCE = "Reference"; - private static final String INCLUDE = "Include"; - private static final String INCLUDE_ANNOTATIONS = "IncludeAnnotations"; - private static final String XML_TERM_NAMESPACE = "TermNamespace"; - private static final String XML_TARGET_NAMESPACE = "TargetNamespace"; - private static final String XML_QUALIFIER = "Qualifier"; - private static final String URI = "Uri"; - private static final String SCHEMA = "Schema"; - private static final String DATA_SERVICES = "DataServices"; - private static final String ABSTRACT = "Abstract"; - - private final static String EDMX = "Edmx"; - private final static String PREFIX_EDMX = "edmx"; - private final static String NS_EDMX = "http://docs.oasis-open.org/odata/ns/edmx"; - - private final static String NS_EDM = "http://docs.oasis-open.org/odata/ns/edm"; - - private final ServiceMetadata serviceMetadata; - private final Map<String, String> namespaceToAlias = new HashMap<String, String>(); - - public MetadataDocumentXmlSerializer(final ServiceMetadata serviceMetadata) { - this.serviceMetadata = serviceMetadata; - } - - public void writeMetadataDocument(final XMLStreamWriter writer) throws XMLStreamException { - writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0"); - writer.setPrefix(PREFIX_EDMX, NS_EDMX); - writer.setDefaultNamespace(NS_EDMX); - writer.writeStartElement(PREFIX_EDMX, EDMX, NS_EDMX); - writer.writeAttribute("Version", "4.0"); - writer.writeNamespace(PREFIX_EDMX, NS_EDMX); - - appendReference(writer); - appendDataServices(writer); - - writer.writeEndDocument(); - } - - private void appendDataServices(final XMLStreamWriter writer) throws XMLStreamException { - writer.setDefaultNamespace(NS_EDM); - writer.writeStartElement(NS_EDMX, DATA_SERVICES); - for (EdmSchema schema : serviceMetadata.getEdm().getSchemas()) { - appendSchema(writer, schema); - } - writer.writeEndElement(); - } - - private void appendSchema(final XMLStreamWriter writer, final EdmSchema schema) throws XMLStreamException { - writer.writeStartElement(NS_EDM, SCHEMA); - writer.writeDefaultNamespace(NS_EDM); - writer.writeAttribute(XML_NAMESPACE, schema.getNamespace()); - if (schema.getAlias() != null) { - writer.writeAttribute(XML_ALIAS, schema.getAlias()); - namespaceToAlias.put(schema.getNamespace(), schema.getAlias()); - } - - // EnumTypes - appendEnumTypes(writer, schema.getEnumTypes()); - - // EntityTypes - appendEntityTypes(writer, schema.getEntityTypes()); - - // ComplexTypes - appendComplexTypes(writer, schema.getComplexTypes()); - - // TypeDefinitions - appendTypeDefinitions(writer, schema.getTypeDefinitions()); - - // Actions - appendActions(writer, schema.getActions()); - - // Functions - appendFunctions(writer, schema.getFunctions()); - - // EntityContainer - appendEntityContainer(writer, schema.getEntityContainer()); - - writer.writeEndElement(); - } - - private void appendTypeDefinitions(final XMLStreamWriter writer, final List<EdmTypeDefinition> typeDefinitions) - throws XMLStreamException { - for (EdmTypeDefinition definition : typeDefinitions) { - writer.writeEmptyElement(XML_TYPE_DEFINITION); - writer.writeAttribute(XML_NAME, definition.getName()); - writer.writeAttribute(XML_UNDERLYING_TYPE, getFullQualifiedName(definition.getUnderlyingType(), false)); - - // Facets - if (definition.getMaxLength() != null) { - writer.writeAttribute(XML_MAX_LENGTH, "" + definition.getMaxLength()); - } - - if (definition.getPrecision() != null) { - writer.writeAttribute(XML_PRECISION, "" + definition.getPrecision()); - } - - if (definition.getScale() != null) { - writer.writeAttribute(XML_SCALE, "" + definition.getScale()); - } - } - } - - private void appendEntityContainer(final XMLStreamWriter writer, final EdmEntityContainer container) - throws XMLStreamException { - if (container != null) { - writer.writeStartElement(XML_ENTITY_CONTAINER); - - writer.writeAttribute(XML_NAME, container.getName()); - FullQualifiedName parentContainerName = container.getParentContainerName(); - if (parentContainerName != null) { - String parentContainerNameString; - if (namespaceToAlias.get(parentContainerName.getNamespace()) != null) { - parentContainerNameString = - namespaceToAlias.get(parentContainerName.getNamespace()) + "." + parentContainerName.getName(); - } else { - parentContainerNameString = parentContainerName.getFullQualifiedNameAsString(); - } - writer.writeAttribute(XML_EXTENDS, parentContainerNameString); - } - - // EntitySets - appendEntitySets(writer, container.getEntitySets()); - - // Singletons - appendSingletons(writer, container.getSingletons()); - - // ActionImports - appendActionImports(writer, container.getActionImports()); - - // FunctionImports - String containerNamespace; - if (namespaceToAlias.get(container.getNamespace()) != null) { - containerNamespace = namespaceToAlias.get(container.getNamespace()); - } else { - containerNamespace = container.getNamespace(); - } - appendFunctionImports(writer, container.getFunctionImports(), containerNamespace); - - writer.writeEndElement(); - } - } - - private void appendFunctionImports(final XMLStreamWriter writer, final List<EdmFunctionImport> functionImports, - final String containerNamespace) throws XMLStreamException { - for (EdmFunctionImport functionImport : functionImports) { - writer.writeStartElement(XML_FUNCTION_IMPORT); - writer.writeAttribute(XML_NAME, functionImport.getName()); - - String functionFQNString; - FullQualifiedName functionFqn = functionImport.getFunctionFqn(); - if (namespaceToAlias.get(functionFqn.getNamespace()) != null) { - functionFQNString = namespaceToAlias.get(functionFqn.getNamespace()) + "." + functionFqn.getName(); - } else { - functionFQNString = functionFqn.getFullQualifiedNameAsString(); - } - writer.writeAttribute(XML_FUNCTION, functionFQNString); - - EdmEntitySet returnedEntitySet = functionImport.getReturnedEntitySet(); - if (returnedEntitySet != null) { - writer.writeAttribute(XML_ENTITY_SET, containerNamespace + "." + returnedEntitySet.getName()); - } - writer.writeAttribute(XML_INCLUDE_IN_SERVICE_DOCUMENT, "" + functionImport.isIncludeInServiceDocument()); - - // TODO: Annotations - writer.writeEndElement(); - } - } - - private void appendActionImports(final XMLStreamWriter writer, final List<EdmActionImport> actionImports) - throws XMLStreamException { - for (EdmActionImport actionImport : actionImports) { - writer.writeStartElement(XML_ACTION_IMPORT); - writer.writeAttribute(XML_NAME, actionImport.getName()); - writer.writeAttribute(XML_ACTION, getAliasedFullQualifiedName(actionImport.getUnboundAction(), false)); - // TODO: Annotations - writer.writeEndElement(); - } - } - - private void appendSingletons(final XMLStreamWriter writer, final List<EdmSingleton> singletons) - throws XMLStreamException { - for (EdmSingleton singleton : singletons) { - writer.writeStartElement(XML_SINGLETON); - writer.writeAttribute(XML_NAME, singleton.getName()); - writer.writeAttribute(XML_ENTITY_TYPE, getAliasedFullQualifiedName(singleton.getEntityType(), false)); - - appendNavigationPropertyBindings(writer, singleton); - // TODO: Annotations - writer.writeEndElement(); - } - - } - - private void appendNavigationPropertyBindings(final XMLStreamWriter writer, final EdmBindingTarget bindingTarget) - throws XMLStreamException { - if (bindingTarget.getNavigationPropertyBindings() != null) { - for (EdmNavigationPropertyBinding binding : bindingTarget.getNavigationPropertyBindings()) { - writer.writeEmptyElement(XML_NAVIGATION_PROPERTY_BINDING); - writer.writeAttribute(XML_PATH, binding.getPath()); - writer.writeAttribute(XML_TARGET, binding.getTarget()); - } - } - } - - private void appendEntitySets(final XMLStreamWriter writer, final List<EdmEntitySet> entitySets) - throws XMLStreamException { - for (EdmEntitySet entitySet : entitySets) { - writer.writeStartElement(XML_ENTITY_SET); - writer.writeAttribute(XML_NAME, entitySet.getName()); - writer.writeAttribute(XML_ENTITY_TYPE, getAliasedFullQualifiedName(entitySet.getEntityType(), false)); - - appendNavigationPropertyBindings(writer, entitySet); - // TODO: Annotations - writer.writeEndElement(); - } - } - - private void appendFunctions(final XMLStreamWriter writer, final List<EdmFunction> functions) - throws XMLStreamException { - for (EdmFunction function : functions) { - writer.writeStartElement(XML_FUNCTION); - writer.writeAttribute(XML_NAME, function.getName()); - // TODO: EntitySetPath - writer.writeAttribute(XML_IS_BOUND, "" + function.isBound()); - writer.writeAttribute(XML_IS_COMPOSABLE, "" + function.isComposable()); - - appendOperationParameters(writer, function); - - appendOperationReturnType(writer, function); - - writer.writeEndElement(); - } - } - - private void appendOperationReturnType(final XMLStreamWriter writer, final EdmOperation operation) - throws XMLStreamException { - EdmReturnType returnType = operation.getReturnType(); - if (returnType != null) { - writer.writeEmptyElement(XML_RETURN_TYPE); - String returnTypeFqnString; - if (EdmTypeKind.PRIMITIVE.equals(returnType.getType().getKind())) { - returnTypeFqnString = getFullQualifiedName(returnType.getType(), returnType.isCollection()); - } else { - returnTypeFqnString = getAliasedFullQualifiedName(returnType.getType(), returnType.isCollection()); - } - writer.writeAttribute(XML_TYPE, returnTypeFqnString); - - appendReturnTypeFacets(writer, returnType); - } - } - - private void appendOperationParameters(final XMLStreamWriter writer, final EdmOperation operation) - throws XMLStreamException { - for (String parameterName : operation.getParameterNames()) { - EdmParameter parameter = operation.getParameter(parameterName); - writer.writeEmptyElement(XML_PARAMETER); - writer.writeAttribute(XML_NAME, parameterName); - String typeFqnString; - if (EdmTypeKind.PRIMITIVE.equals(parameter.getType().getKind())) { - typeFqnString = getFullQualifiedName(parameter.getType(), parameter.isCollection()); - } else { - typeFqnString = getAliasedFullQualifiedName(parameter.getType(), parameter.isCollection()); - } - writer.writeAttribute(XML_TYPE, typeFqnString); - - appendParameterFacets(writer, parameter); - } - } - - private void appendActions(final XMLStreamWriter writer, final List<EdmAction> actions) throws XMLStreamException { - for (EdmAction action : actions) { - writer.writeStartElement(XML_ACTION); - writer.writeAttribute(XML_NAME, action.getName()); - writer.writeAttribute(XML_IS_BOUND, "" + action.isBound()); - - appendOperationParameters(writer, action); - - appendOperationReturnType(writer, action); - - writer.writeEndElement(); - } - } - - private void appendReturnTypeFacets(final XMLStreamWriter writer, final EdmReturnType returnType) - throws XMLStreamException { - if (returnType.isNullable() != null) { - writer.writeAttribute(XML_NULLABLE, "" + returnType.isNullable()); - } - if (returnType.getMaxLength() != null) { - writer.writeAttribute(XML_MAX_LENGTH, "" + returnType.getMaxLength()); - } - if (returnType.getPrecision() != null) { - writer.writeAttribute(XML_PRECISION, "" + returnType.getPrecision()); - } - if (returnType.getScale() != null) { - writer.writeAttribute(XML_SCALE, "" + returnType.getScale()); - } - } - - private void appendParameterFacets(final XMLStreamWriter writer, final EdmParameter parameter) - throws XMLStreamException { - if (parameter.isNullable() != null) { - writer.writeAttribute(XML_NULLABLE, "" + parameter.isNullable()); - } - if (parameter.getMaxLength() != null) { - writer.writeAttribute(XML_MAX_LENGTH, "" + parameter.getMaxLength()); - } - if (parameter.getPrecision() != null) { - writer.writeAttribute(XML_PRECISION, "" + parameter.getPrecision()); - } - if (parameter.getScale() != null) { - writer.writeAttribute(XML_SCALE, "" + parameter.getScale()); - } - } - - private void appendComplexTypes(final XMLStreamWriter writer, final List<EdmComplexType> complexTypes) - throws XMLStreamException { - for (EdmComplexType complexType : complexTypes) { - writer.writeStartElement(XML_COMPLEX_TYPE); - writer.writeAttribute(XML_NAME, complexType.getName()); - - if (complexType.getBaseType() != null) { - writer.writeAttribute(XML_BASE_TYPE, getAliasedFullQualifiedName(complexType.getBaseType(), false)); - } - - if(complexType.isAbstract()) { - writer.writeAttribute(ABSTRACT, TRUE); - } - - appendProperties(writer, complexType); - - appendNavigationProperties(writer, complexType); - - writer.writeEndElement(); - } - } - - private void appendEntityTypes(final XMLStreamWriter writer, final List<EdmEntityType> entityTypes) - throws XMLStreamException { - for (EdmEntityType entityType : entityTypes) { - writer.writeStartElement(XML_ENTITY_TYPE); - writer.writeAttribute(XML_NAME, entityType.getName()); - - if (entityType.hasStream()) { - writer.writeAttribute(XML_HAS_STREAM, "" + entityType.hasStream()); - } - - if (entityType.getBaseType() != null) { - writer.writeAttribute(XML_BASE_TYPE, getAliasedFullQualifiedName(entityType.getBaseType(), false)); - } - - if (entityType.isAbstract()) { - writer.writeAttribute(ABSTRACT, TRUE); - } - - appendKey(writer, entityType); - - appendProperties(writer, entityType); - - appendNavigationProperties(writer, entityType); - - writer.writeEndElement(); - } - } - - private void appendNavigationProperties(final XMLStreamWriter writer, final EdmStructuredType type) - throws XMLStreamException { - List<String> navigationPropertyNames = type.getNavigationPropertyNames(); - if (type.getBaseType() != null) { - navigationPropertyNames.removeAll(type.getBaseType().getNavigationPropertyNames()); - } - for (String navigationPropertyName : navigationPropertyNames) { - EdmNavigationProperty navigationProperty = type.getNavigationProperty(navigationPropertyName); - - writer.writeStartElement(XML_NAVIGATION_PROPERTY); - writer.writeAttribute(XML_NAME, navigationPropertyName); - writer.writeAttribute(XML_TYPE, getAliasedFullQualifiedName(navigationProperty.getType(), navigationProperty - .isCollection())); - if (navigationProperty.isNullable() != null) { - writer.writeAttribute(XML_NULLABLE, "" + navigationProperty.isNullable()); - } - - if (navigationProperty.getPartner() != null) { - EdmNavigationProperty partner = navigationProperty.getPartner(); - writer.writeAttribute(XML_PARTNER, partner.getName()); - } - - if (navigationProperty.getReferentialConstraints() != null) { - for (EdmReferentialConstraint constraint : navigationProperty.getReferentialConstraints()) { - writer.writeEmptyElement("ReferentialConstraint"); - writer.writeAttribute(XML_PROPERTY, constraint.getPropertyName()); - writer.writeAttribute("ReferencedProperty", constraint.getReferencedPropertyName()); - } - } - - writer.writeEndElement(); - } - } - - private void appendProperties(final XMLStreamWriter writer, final EdmStructuredType type) throws XMLStreamException { - List<String> propertyNames = type.getPropertyNames(); - if (type.getBaseType() != null) { - propertyNames.removeAll(type.getBaseType().getPropertyNames()); - } - for (String propertyName : propertyNames) { - EdmProperty property = type.getStructuralProperty(propertyName); - writer.writeEmptyElement(XML_PROPERTY); - writer.writeAttribute(XML_NAME, propertyName); - String fqnString; - if (property.isPrimitive()) { - fqnString = getFullQualifiedName(property.getType(), property.isCollection()); - } else { - fqnString = getAliasedFullQualifiedName(property.getType(), property.isCollection()); - } - writer.writeAttribute(XML_TYPE, fqnString); - - // Facets - if (property.isNullable() != null) { - writer.writeAttribute(XML_NULLABLE, "" + property.isNullable()); - } - - if (property.isUnicode() != null) { - writer.writeAttribute(XML_UNICODE, "" + property.isUnicode()); - } - - if (property.getDefaultValue() != null) { - writer.writeAttribute(XML_DEFAULT_VALUE, property.getDefaultValue()); - } - - if (property.getMaxLength() != null) { - writer.writeAttribute(XML_MAX_LENGTH, "" + property.getMaxLength()); - } - - if (property.getPrecision() != null) { - writer.writeAttribute(XML_PRECISION, "" + property.getPrecision()); - } - - if (property.getScale() != null) { - writer.writeAttribute(XML_SCALE, "" + property.getScale()); - } - } - } - - private void appendKey(final XMLStreamWriter writer, final EdmEntityType entityType) throws XMLStreamException { - List<EdmKeyPropertyRef> keyPropertyRefs = entityType.getKeyPropertyRefs(); - if (keyPropertyRefs != null && !keyPropertyRefs.isEmpty()) { - // Resolve Base Type key as it is shown in derived type - EdmEntityType baseType = entityType.getBaseType(); - if (baseType != null && baseType.getKeyPropertyRefs() != null && !(baseType.getKeyPropertyRefs().isEmpty())) { - return; - } - - writer.writeStartElement(XML_KEY); - for (EdmKeyPropertyRef keyRef : keyPropertyRefs) { - writer.writeEmptyElement(XML_PROPERTY_REF); - final String keyName; - if (keyRef.getPath() != null) { - keyName = keyRef.getPath() + "/" + keyRef.getKeyPropertyName(); - } else { - keyName = keyRef.getKeyPropertyName(); - } - writer.writeAttribute(XML_NAME, keyName); - - if (keyRef.getAlias() != null) { - writer.writeAttribute(XML_ALIAS, keyRef.getAlias()); - } - } - writer.writeEndElement(); - } - } - - private void appendEnumTypes(final XMLStreamWriter writer, final List<EdmEnumType> enumTypes) - throws XMLStreamException { - for (EdmEnumType enumType : enumTypes) { - writer.writeStartElement(XML_ENUM_TYPE); - writer.writeAttribute(XML_NAME, enumType.getName()); - writer.writeAttribute(XML_IS_FLAGS, "" + enumType.isFlags()); - writer.writeAttribute(XML_UNDERLYING_TYPE, getFullQualifiedName(enumType.getUnderlyingType(), false)); - - for (String memberName : enumType.getMemberNames()) { - writer.writeEmptyElement(XML_MEMBER); - writer.writeAttribute(XML_NAME, memberName); - writer.writeAttribute(XML_VALUE, enumType.getMember(memberName).getValue()); - } - - writer.writeEndElement(); - } - } - - private String getFullQualifiedName(final EdmType type, final boolean isCollection) { - final String name = type.getFullQualifiedName().getFullQualifiedNameAsString(); - return isCollection ? "Collection(" + name + ")" : name; - } - - private String getAliasedFullQualifiedName(final EdmType type, final boolean isCollection) { - FullQualifiedName fqn = type.getFullQualifiedName(); - final String name; - if (namespaceToAlias.get(fqn.getNamespace()) != null) { - name = namespaceToAlias.get(fqn.getNamespace()) + "." + fqn.getName(); - } else { - name = fqn.getFullQualifiedNameAsString(); - } - - return isCollection ? "Collection(" + name + ")" : name; - } - - /** - * Appends references, e.g., to the OData Core Vocabulary, as defined in the OData specification - * and mentioned in its Common Schema Definition Language (CSDL) document. - */ - private void appendReference(final XMLStreamWriter writer) throws XMLStreamException { - for (final EdmxReference reference : serviceMetadata.getReferences()) { - writer.writeStartElement(PREFIX_EDMX, REFERENCE, NS_EDMX); - writer.writeAttribute(URI, reference.getUri().toASCIIString()); - - List<EdmxReferenceInclude> includes = reference.getIncludes(); - for (EdmxReferenceInclude include : includes) { - writer.writeStartElement(PREFIX_EDMX, INCLUDE, NS_EDMX); - writer.writeAttribute(XML_NAMESPACE, include.getNamespace()); - if (include.getAlias() != null) { - // Reference Aliases are ignored for now since they are not V2 compatible - writer.writeAttribute(XML_ALIAS, include.getAlias()); - } - writer.writeEndElement(); - } - - List<EdmxReferenceIncludeAnnotation> includeAnnotations = reference.getIncludeAnnotations(); - for (EdmxReferenceIncludeAnnotation includeAnnotation : includeAnnotations) { - writer.writeStartElement(PREFIX_EDMX, INCLUDE_ANNOTATIONS, NS_EDMX); - writer.writeAttribute(XML_TERM_NAMESPACE, includeAnnotation.getTermNamespace()); - if (includeAnnotation.getQualifier() != null) { - writer.writeAttribute(XML_QUALIFIER, includeAnnotation.getQualifier()); - } - if (includeAnnotation.getTargetNamespace() != null) { - writer.writeAttribute(XML_TARGET_NAMESPACE, includeAnnotation.getTargetNamespace()); - } - writer.writeEndElement(); - } - - writer.writeEndElement(); - } - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java deleted file mode 100644 index ac856a7..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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.server.core.serializer.xml; - -import java.io.InputStream; - -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.EntitySet; -import org.apache.olingo.commons.api.data.Property; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmPrimitiveType; -import org.apache.olingo.server.api.ODataServerError; -import org.apache.olingo.server.api.ServiceMetadata; -import org.apache.olingo.server.api.serializer.ComplexSerializerOptions; -import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions; -import org.apache.olingo.server.api.serializer.EntitySerializerOptions; -import org.apache.olingo.server.api.serializer.ODataSerializer; -import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions; -import org.apache.olingo.server.api.serializer.SerializerException; -import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ODataXmlSerializerImpl implements ODataSerializer { - - /** The default character set is UTF-8. */ - public static final String DEFAULT_CHARSET = "UTF-8"; - - private static final Logger log = LoggerFactory.getLogger(ODataXmlSerializerImpl.class); - - @Override - public InputStream serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException { - throw new SerializerException("Service Document not implemented for XML format", - SerializerException.MessageKeys.NOT_IMPLEMENTED); - } - - @Override - public InputStream metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException { - CircleStreamBuffer buffer; - XMLStreamWriter xmlStreamWriter = null; - - // TODO: move stream initialization into separate method - try { - buffer = new CircleStreamBuffer(); - xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(), DEFAULT_CHARSET); - MetadataDocumentXmlSerializer serializer = new MetadataDocumentXmlSerializer(serviceMetadata); - serializer.writeMetadataDocument(xmlStreamWriter); - xmlStreamWriter.flush(); - xmlStreamWriter.close(); - - return buffer.getInputStream(); - } catch (final XMLStreamException e) { - log.error(e.getMessage(), e); - throw new SerializerException("An I/O exception occurred.", e, - SerializerException.MessageKeys.IO_EXCEPTION); - } finally { - if (xmlStreamWriter != null) { - try { - xmlStreamWriter.close(); - } catch (XMLStreamException e) { - throw new SerializerException("An I/O exception occurred.", e, - SerializerException.MessageKeys.IO_EXCEPTION); - } - } - } - } - - @Override - public InputStream entity(final EdmEntityType entityType, final Entity entity, - final EntitySerializerOptions options) throws SerializerException { - throw new SerializerException("Entity serialization not implemented for XML format", - SerializerException.MessageKeys.NOT_IMPLEMENTED); - } - - @Override - public InputStream entityCollection(final EdmEntityType entityType, final EntitySet entitySet, - final EntityCollectionSerializerOptions options) throws SerializerException { - throw new SerializerException("Entityset serialization not implemented for XML format", - SerializerException.MessageKeys.NOT_IMPLEMENTED); - } - - @Override - public InputStream error(ODataServerError error) throws SerializerException { - throw new SerializerException("error serialization not implemented for XML format", - SerializerException.MessageKeys.NOT_IMPLEMENTED); - } - - @Override - public InputStream primitive(final EdmPrimitiveType type, final Property property, - final PrimitiveSerializerOptions options) throws SerializerException { - throw new SerializerException("Serialization not implemented for XML format.", - SerializerException.MessageKeys.NOT_IMPLEMENTED); - } - - @Override - public InputStream complex(final EdmComplexType type, final Property property, - final ComplexSerializerOptions options) throws SerializerException { - throw new SerializerException("Serialization not implemented for XML format.", - SerializerException.MessageKeys.NOT_IMPLEMENTED); - } - - @Override - public InputStream primitiveCollection(final EdmPrimitiveType type, final Property property, - final PrimitiveSerializerOptions options) throws SerializerException { - throw new SerializerException("Serialization not implemented for XML format.", - SerializerException.MessageKeys.NOT_IMPLEMENTED); - } - - @Override - public InputStream complexCollection(final EdmComplexType type, final Property property, - final ComplexSerializerOptions options) throws SerializerException { - throw new SerializerException("Serialization not implemented for XML format.", - SerializerException.MessageKeys.NOT_IMPLEMENTED); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java deleted file mode 100644 index 8bbbc3f..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.server.core.uri; - -import java.util.List; - -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.edm.EdmEntitySet; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmPrimitiveType; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.edm.EdmProperty; -import org.apache.olingo.commons.api.edm.EdmStructuredType; -import org.apache.olingo.commons.core.Encoder; -import org.apache.olingo.server.api.serializer.SerializerException; -import org.apache.olingo.server.api.uri.UriHelper; -import org.apache.olingo.server.api.uri.UriParameter; -import org.apache.olingo.server.api.uri.queryoption.ExpandOption; -import org.apache.olingo.server.api.uri.queryoption.SelectOption; -import org.apache.olingo.server.core.serializer.utils.ContextURLHelper; - -public class UriHelperImpl implements UriHelper { - - @Override - public String buildContextURLSelectList(final EdmStructuredType type, - final ExpandOption expand, final SelectOption select) throws SerializerException { - return ContextURLHelper.buildSelectList(type, expand, select); - } - - @Override - public String buildContextURLKeyPredicate(final List<UriParameter> keys) throws SerializerException { - return ContextURLHelper.buildKeyPredicate(keys); - } - - @Override - public String buildCanonicalURL(final EdmEntitySet edmEntitySet, final Entity entity) throws SerializerException { - StringBuilder result = new StringBuilder(edmEntitySet.getName()); - result.append('('); - final EdmEntityType entityType = edmEntitySet.getEntityType(); - final List<String> keyNames = entityType.getKeyPredicateNames(); - boolean first = true; - for (final String keyName : keyNames) { - if (first) { - first = false; - } else { - result.append(','); - } - if (keyNames.size() > 1) { - result.append(Encoder.encode(keyName)).append('='); - } - final EdmProperty edmProperty = entityType.getStructuralProperty(keyName); - final EdmPrimitiveType type = (EdmPrimitiveType) edmProperty.getType(); - final Object propertyValue = entity.getProperty(keyName).getValue(); - try { - final String value = type.toUriLiteral( - type.valueToString(propertyValue, - edmProperty.isNullable(), edmProperty.getMaxLength(), - edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode())); - result.append(Encoder.encode(value)); - } catch (final EdmPrimitiveTypeException e) { - throw new SerializerException("Wrong key value!", - SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, edmProperty.getName(), propertyValue.toString()); - } - } - result.append(')'); - return result.toString(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java deleted file mode 100644 index 9990da6..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * 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.server.core.uri; - -import org.apache.olingo.commons.api.ODataRuntimeException; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.server.api.uri.UriInfo; -import org.apache.olingo.server.api.uri.UriInfoAll; -import org.apache.olingo.server.api.uri.UriInfoBatch; -import org.apache.olingo.server.api.uri.UriInfoCrossjoin; -import org.apache.olingo.server.api.uri.UriInfoEntityId; -import org.apache.olingo.server.api.uri.UriInfoKind; -import org.apache.olingo.server.api.uri.UriInfoMetadata; -import org.apache.olingo.server.api.uri.UriInfoResource; -import org.apache.olingo.server.api.uri.UriInfoService; -import org.apache.olingo.server.api.uri.UriResource; -import org.apache.olingo.server.api.uri.queryoption.CountOption; -import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption; -import org.apache.olingo.server.api.uri.queryoption.ExpandOption; -import org.apache.olingo.server.api.uri.queryoption.FilterOption; -import org.apache.olingo.server.api.uri.queryoption.FormatOption; -import org.apache.olingo.server.api.uri.queryoption.IdOption; -import org.apache.olingo.server.api.uri.queryoption.OrderByOption; -import org.apache.olingo.server.api.uri.queryoption.SearchOption; -import org.apache.olingo.server.api.uri.queryoption.SelectOption; -import org.apache.olingo.server.api.uri.queryoption.SkipOption; -import org.apache.olingo.server.api.uri.queryoption.SkipTokenOption; -import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption; -import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind; -import org.apache.olingo.server.api.uri.queryoption.TopOption; -import org.apache.olingo.server.core.uri.queryoption.CustomQueryOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.QueryOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.SystemQueryOptionImpl; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class UriInfoImpl implements UriInfo { - - private UriInfoKind kind; - - private List<String> entitySetNames = new ArrayList<String>(); // for $entity - private EdmEntityType entityTypeCast; // for $entity - - private List<CustomQueryOptionImpl> customQueryOptions = new ArrayList<CustomQueryOptionImpl>(); - private Map<String, String> aliasToValue = new HashMap<String, String>(); - - Map<SystemQueryOptionKind, SystemQueryOption> systemQueryOptions = - new HashMap<SystemQueryOptionKind, SystemQueryOption>(); - - private String fragment; - - private UriResource lastResourcePart; - private List<UriResource> pathParts = new ArrayList<UriResource>(); - - @Override - public UriInfoAll asUriInfoAll() { - return this; - } - - @Override - public UriInfoBatch asUriInfoBatch() { - return this; - } - - @Override - public UriInfoCrossjoin asUriInfoCrossjoin() { - return this; - } - - @Override - public UriInfoEntityId asUriInfoEntityId() { - return this; - } - - @Override - public UriInfoMetadata asUriInfoMetadata() { - return this; - } - - @Override - public UriInfoResource asUriInfoResource() { - return this; - } - - @Override - public List<String> getEntitySetNames() { - return Collections.unmodifiableList(entitySetNames); - } - - public void addEntitySetName(final String entitySet) { - entitySetNames.add(entitySet); - } - - @Override - public List<UriResource> getUriResourceParts() { - List<UriResource> returnList = new ArrayList<UriResource>(); - for (UriResource item : pathParts) { - returnList.add(item); - } - return Collections.unmodifiableList(returnList); - } - - public UriInfoImpl addResourcePart(final UriResourceImpl uriPathInfo) { - pathParts.add(uriPathInfo); - lastResourcePart = uriPathInfo; - return this; - } - - @Override - public List<CustomQueryOption> getCustomQueryOptions() { - List<CustomQueryOption> retList = new ArrayList<CustomQueryOption>(); - for (CustomQueryOptionImpl item : customQueryOptions) { - retList.add(item); - } - return retList; - } - - @Override - public String getValueForAlias(String alias) { - return aliasToValue.get(alias); - } - - @Override - public EdmEntityType getEntityTypeCast() { - return entityTypeCast; - } - - public UriInfoImpl setEntityTypeCast(final EdmEntityType type) { - entityTypeCast = type; - return this; - } - - @Override - public ExpandOption getExpandOption() { - return (ExpandOption) systemQueryOptions.get(SystemQueryOptionKind.EXPAND); - } - - @Override - public FilterOption getFilterOption() { - return (FilterOption) systemQueryOptions.get(SystemQueryOptionKind.FILTER); - } - - @Override - public FormatOption getFormatOption() { - return (FormatOption) systemQueryOptions.get(SystemQueryOptionKind.FORMAT); - } - - @Override - public IdOption getIdOption() { - return (IdOption) systemQueryOptions.get(SystemQueryOptionKind.ID); - } - - @Override - public CountOption getCountOption() { - return (CountOption) systemQueryOptions.get(SystemQueryOptionKind.COUNT); - } - - @Override - public UriInfoKind getKind() { - return kind; - } - - public UriInfoImpl setKind(final UriInfoKind kind) { - this.kind = kind; - return this; - } - - public UriResource getLastResourcePart() { - return lastResourcePart; - } - - @Override - public OrderByOption getOrderByOption() { - return (OrderByOption) systemQueryOptions.get(SystemQueryOptionKind.ORDERBY); - } - - @Override - public SearchOption getSearchOption() { - - return (SearchOption) systemQueryOptions.get(SystemQueryOptionKind.SEARCH); - } - - @Override - public SelectOption getSelectOption() { - return (SelectOption) systemQueryOptions.get(SystemQueryOptionKind.SELECT); - } - - @Override - public SkipOption getSkipOption() { - return (SkipOption) systemQueryOptions.get(SystemQueryOptionKind.SKIP); - } - - @Override - public SkipTokenOption getSkipTokenOption() { - return (SkipTokenOption) systemQueryOptions.get(SystemQueryOptionKind.SKIPTOKEN); - } - - @Override - public TopOption getTopOption() { - return (TopOption) systemQueryOptions.get(SystemQueryOptionKind.TOP); - } - - public UriInfoImpl setQueryOptions(final List<QueryOptionImpl> list) { - - for (QueryOptionImpl item : list) { - if (item instanceof SystemQueryOptionImpl) { - setSystemQueryOption((SystemQueryOptionImpl) item); - } else if (item instanceof CustomQueryOptionImpl) { - addCustomQueryOption(item); - } - } - return this; - } - - public void addCustomQueryOption(final QueryOptionImpl item) { - customQueryOptions.add((CustomQueryOptionImpl) item); - if (item.getName().startsWith("@")) { - aliasToValue.put(item.getName(), item.getText()); - } - } - - /** Adds system query option. - * @param systemOption the option to be added - * @return this object for method chaining - * @throws ODataRuntimeException if an unsupported option is provided - * or an option of this kind has been added before - */ - public UriInfoImpl setSystemQueryOption(final SystemQueryOption systemOption) { - final SystemQueryOptionKind kind = systemOption.getKind(); - switch (kind) { - case EXPAND: - case FILTER: - case FORMAT: - case ID: - case COUNT: - case ORDERBY: - case SEARCH: - case SELECT: - case SKIP: - case SKIPTOKEN: - case TOP: - case LEVELS: - if (systemQueryOptions.containsKey(kind)) { - throw new ODataRuntimeException("Double System Query Option: " + systemOption.getName()); - } else { - systemQueryOptions.put(kind, systemOption); - } - break; - default: - throw new ODataRuntimeException("Unsupported System Query Option: " + systemOption.getName()); - } - return this; - } - - @Override - public UriInfoService asUriInfoService() { - return this; - } - - @Override - public String getFragment() { - return fragment; - } - - public UriInfoImpl setFragment(final String fragment) { - this.fragment = fragment; - return this; - } - - public void removeResourcePart(final int index) { - pathParts.remove(index); - } - - @Override - public Collection<SystemQueryOption> getSystemQueryOptions() { - return Collections.unmodifiableCollection(systemQueryOptions.values()); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriParameterImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriParameterImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriParameterImpl.java deleted file mode 100644 index ddbcd57..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriParameterImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.server.core.uri; - -import org.apache.olingo.server.api.uri.UriParameter; -import org.apache.olingo.server.api.uri.queryoption.expression.Expression; -import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl; - -public class UriParameterImpl implements UriParameter { - private String name; - private String text; - private String alias; - private Expression expression; - private String referencedProperty; - - @Override - public String getName() { - return name; - } - - public UriParameterImpl setName(final String name) { - this.name = name; - return this; - } - - @Override - public String getAlias() { - return alias; - } - - public UriParameterImpl setAlias(final String alias) { - this.alias = alias; - return this; - } - - @Override - public String getText() { - return text; - } - - public UriParameterImpl setText(final String text) { - this.text = text; - return this; - } - - @Override - public Expression getExpression() { - return expression; - } - - public UriParameterImpl setExpression(final ExpressionImpl expression) { - this.expression = expression; - return this; - } - - @Override - public String getReferencedProperty() { - return referencedProperty; - } - - public UriParameterImpl setRefencedProperty(final String referencedProperty) { - this.referencedProperty = referencedProperty; - return this; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java deleted file mode 100644 index 4ca162c..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.server.core.uri; - -import org.apache.olingo.commons.api.edm.EdmAction; -import org.apache.olingo.commons.api.edm.EdmActionImport; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.server.api.uri.UriResourceAction; -import org.apache.olingo.server.api.uri.UriResourceKind; - -public class UriResourceActionImpl extends UriResourceTypedImpl implements UriResourceAction { - - protected EdmAction action; - protected EdmActionImport actionImport; - - public UriResourceActionImpl() { - super(UriResourceKind.action); - } - - @Override - public EdmAction getAction() { - return action; - } - - public UriResourceActionImpl setAction(final EdmAction action) { - this.action = action; - return this; - } - - @Override - public EdmActionImport getActionImport() { - return actionImport; - } - - public UriResourceActionImpl setActionImport(final EdmActionImport actionImport) { - this.actionImport = actionImport; - setAction(actionImport.getUnboundAction()); - return this; - } - - @Override - public boolean isCollection() { - return action.getReturnType().isCollection(); - } - - @Override - public EdmType getType() { - return action.getReturnType().getType(); - } - - @Override - public String toString() { - if (actionImport != null) { - return actionImport.getName(); - } else if (action != null) { - return action.getName(); - } - return ""; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceComplexPropertyImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceComplexPropertyImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceComplexPropertyImpl.java deleted file mode 100644 index f7a8502..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceComplexPropertyImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.server.core.uri; - -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmProperty; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.server.api.uri.UriResourceComplexProperty; -import org.apache.olingo.server.api.uri.UriResourceKind; - -public class UriResourceComplexPropertyImpl extends UriResourceTypedImpl implements UriResourceComplexProperty { - - protected EdmProperty property; - - public UriResourceComplexPropertyImpl() { - super(UriResourceKind.complexProperty); - } - - @Override - public EdmProperty getProperty() { - return property; - } - - public UriResourceComplexPropertyImpl setProperty(final EdmProperty property) { - this.property = property; - return this; - } - - @Override - public EdmComplexType getComplexType() { - return (EdmComplexType) getType(); - } - - @Override - public EdmComplexType getComplexTypeFilter() { - return (EdmComplexType) typeFilter; - } - - @Override - public EdmType getType() { - return property.getType(); - } - - @Override - public boolean isCollection() { - return property.isCollection(); - } - - @Override - public String toString() { - return property.getName(); - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceCountImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceCountImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceCountImpl.java deleted file mode 100644 index 14f43ec..0000000 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceCountImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.server.core.uri; - -import org.apache.olingo.server.api.uri.UriResourceCount; -import org.apache.olingo.server.api.uri.UriResourceKind; - -public class UriResourceCountImpl extends UriResourceImpl implements UriResourceCount { - - public UriResourceCountImpl() { - super(UriResourceKind.count); - } - - @Override - public String toString() { - return "$count"; - } - -}
