forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Azure#8 from WindowsAzure/dev
forward integration from WindowsAzure/dev to gcheng/dev
- Loading branch information
Showing
15 changed files
with
469 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
.project | ||
target | ||
node_modules | ||
.settings | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...soft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright 2011 Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.microsoft.windowsazure.services.media; | ||
|
||
import com.microsoft.windowsazure.services.core.FilterableService; | ||
|
||
/** | ||
* | ||
* Defines the methods available for Windows Azure Media Services | ||
* | ||
*/ | ||
public interface MediaContract extends FilterableService<MediaContract> { | ||
|
||
// Will fill in as we implement the various Media Services entities | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
...osoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright 2011 Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.microsoft.windowsazure.services.media; | ||
|
||
import com.microsoft.windowsazure.services.core.Configuration; | ||
|
||
/** | ||
* | ||
* Access media services functionality. This class cannot | ||
* be instantiated. | ||
* | ||
*/ | ||
public class MediaService { | ||
|
||
private MediaService() { | ||
} | ||
|
||
/** | ||
* Creates an instance of the <code>MediaServicesContract</code> API. | ||
* | ||
*/ | ||
public static MediaContract create() { | ||
return Configuration.getInstance().create(MediaContract.class); | ||
} | ||
|
||
/** | ||
* Creates an instance of the <code>MediaServicesContract</code> API using the specified configuration. | ||
* | ||
* @param config | ||
* A <code>Configuration</code> object that represents the configuration for the service bus service. | ||
* | ||
*/ | ||
public static MediaContract create(Configuration config) { | ||
return config.create(MediaContract.class); | ||
} | ||
|
||
/** | ||
* Creates an instance of the <code>MediaServicesContract</code> API. | ||
* | ||
*/ | ||
public static MediaContract create(String profile) { | ||
return Configuration.getInstance().create(profile, MediaContract.class); | ||
} | ||
|
||
/** | ||
* Creates an instance of the <code>MediaServicesContract</code> API using the specified configuration. | ||
* | ||
* @param config | ||
* A <code>Configuration</code> object that represents the configuration for the service bus service. | ||
* | ||
*/ | ||
public static MediaContract create(String profile, Configuration config) { | ||
return config.create(profile, MediaContract.class); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ava/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright 2011 Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.microsoft.windowsazure.services.media.implementation; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import com.microsoft.windowsazure.services.core.ServiceException; | ||
import com.microsoft.windowsazure.services.core.ServiceFilter; | ||
import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; | ||
import com.microsoft.windowsazure.services.media.MediaContract; | ||
|
||
/** | ||
* Wrapper implementation of <code>MediaServicesContract</code> that | ||
* translates exceptions into ServiceExceptions. | ||
* | ||
*/ | ||
public class MediaExceptionProcessor implements MediaContract { | ||
|
||
private final MediaContract next; | ||
static Log log = LogFactory.getLog(MediaContract.class); | ||
|
||
public MediaExceptionProcessor(MediaContract next) { | ||
this.next = next; | ||
} | ||
|
||
@Inject | ||
public MediaExceptionProcessor(MediaRestProxy next) { | ||
this.next = next; | ||
} | ||
|
||
@Override | ||
public MediaContract withFilter(ServiceFilter filter) { | ||
return new MediaExceptionProcessor(next.withFilter(filter)); | ||
} | ||
|
||
private ServiceException processCatch(ServiceException e) { | ||
log.warn(e.getMessage(), e.getCause()); | ||
return ServiceExceptionFactory.process("MediaServices", e); | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...rc/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Copyright 2011 Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.microsoft.windowsazure.services.media.implementation; | ||
|
||
import java.util.Arrays; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import com.microsoft.windowsazure.services.core.ServiceFilter; | ||
import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; | ||
import com.microsoft.windowsazure.services.media.MediaContract; | ||
import com.sun.jersey.api.client.Client; | ||
import com.sun.jersey.api.client.WebResource; | ||
|
||
public class MediaRestProxy implements MediaContract { | ||
|
||
private Client channel; | ||
static Log log = LogFactory.getLog(MediaContract.class); | ||
|
||
ServiceFilter[] filters; | ||
|
||
@Inject | ||
public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter) { | ||
this.channel = channel; | ||
this.filters = new ServiceFilter[0]; | ||
channel.addFilter(redirectFilter); | ||
channel.addFilter(authFilter); | ||
} | ||
|
||
public MediaRestProxy(Client channel, ServiceFilter[] filters) { | ||
this.channel = channel; | ||
this.filters = filters; | ||
} | ||
|
||
@Override | ||
public MediaContract withFilter(ServiceFilter filter) { | ||
ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1); | ||
newFilters[filters.length] = filter; | ||
return new MediaRestProxy(channel, newFilters); | ||
} | ||
|
||
public Client getChannel() { | ||
return channel; | ||
} | ||
|
||
public void setChannel(Client channel) { | ||
this.channel = channel; | ||
} | ||
|
||
private WebResource getResource(String entityName) { | ||
WebResource resource = getChannel().resource(entityName); | ||
for (ServiceFilter filter : filters) { | ||
resource.addFilter(new ClientFilterAdapter(filter)); | ||
} | ||
return resource; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...rc/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright 2011 Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.microsoft.windowsazure.services.media.models; | ||
|
||
import java.util.EnumSet; | ||
|
||
/** | ||
* Permissions available to an access policy | ||
* | ||
*/ | ||
public enum AccessPolicyPermission { | ||
NONE(0), READ(1), WRITE(2), DELETE(4), LIST(8); | ||
|
||
private int flagValue; | ||
|
||
private AccessPolicyPermission(int value) { | ||
flagValue = value; | ||
} | ||
|
||
/** | ||
* Get the flag bit value associated with this permission | ||
* | ||
* @return The integer permission value | ||
*/ | ||
public int getFlagValue() { | ||
return flagValue; | ||
} | ||
|
||
/** | ||
* Given an integer representing the permissions as a bit vector, | ||
* convert it into an <code>EnumSet<AccessPolicyPermission></code> object containing the correct permissions | ||
* * | ||
* | ||
* @param bits | ||
* The bit vector of permissions | ||
* @return The set of permissions in an <code>EnumSet</code> object. | ||
*/ | ||
public static EnumSet<AccessPolicyPermission> permissionsFromBits(int bits) { | ||
EnumSet<AccessPolicyPermission> perms = EnumSet.of(AccessPolicyPermission.NONE); | ||
|
||
for (AccessPolicyPermission p : AccessPolicyPermission.values()) { | ||
if ((bits & p.getFlagValue()) != 0) { | ||
perms.remove(AccessPolicyPermission.NONE); | ||
perms.add(p); | ||
} | ||
} | ||
|
||
return perms; | ||
} | ||
|
||
/** | ||
* Convert an <code>EnumSet</code> containing permissions into the | ||
* corresponding integer bit vector to be passed to Media services. | ||
* | ||
* @param perms | ||
* The permissions | ||
* @return The bit vector to go out over the wire. | ||
*/ | ||
public static int bitsFromPermissions(EnumSet<AccessPolicyPermission> perms) { | ||
int result = 0; | ||
for (AccessPolicyPermission p : perms) { | ||
result |= p.getFlagValue(); | ||
} | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.