Index: src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java =================================================================== --- src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java (revision 112453) +++ src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java (working copy) @@ -115,7 +115,7 @@ */ public static AttributeType createDateTimeAttributeType(String attrID, String issuer) { - return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_DATE_TIME); + return getBareAttributeType(attrID, issuer, getXMLDateTime(), XMLSchemaConstants.DATATYPE_DATE_TIME); } /** * Create Date Time attribute with the passed {@link XMLGregorianCalendar} @@ -221,7 +221,7 @@ */ public static AttributeType createTimeAttributeType(String attrID, String issuer) { - return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_TIME); + return getBareAttributeType(attrID, issuer, getXMLTime(), XMLSchemaConstants.DATATYPE_TIME); } /** @@ -309,7 +309,7 @@ return attributeType; } - private static String getXMLDate() + private static String getXMLDateTime() { DatatypeFactory dtf; try @@ -323,4 +323,34 @@ XMLGregorianCalendar value = dtf.newXMLGregorianCalendar((GregorianCalendar) Calendar.getInstance()); return value.toXMLFormat(); } + private static String getXMLDate() + { + DatatypeFactory dtf; + try + { + dtf = DatatypeFactory.newInstance(); + } + catch (DatatypeConfigurationException e) + { + throw new RuntimeException(e); + } + GregorianCalendar cal=(GregorianCalendar) Calendar.getInstance(); + XMLGregorianCalendar value = dtf.newXMLGregorianCalendarDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.getTimeZone().getRawOffset()/60000); + return value.toXMLFormat(); + } + private static String getXMLTime() + { + DatatypeFactory dtf; + try + { + dtf = DatatypeFactory.newInstance(); + } + catch (DatatypeConfigurationException e) + { + throw new RuntimeException(e); + } + GregorianCalendar cal=(GregorianCalendar) Calendar.getInstance(); + XMLGregorianCalendar value = dtf.newXMLGregorianCalendarTime(cal.get(Calendar.HOUR),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND),cal.get(Calendar.MILLISECOND), cal.getTimeZone().getRawOffset()/60000); + return value.toXMLFormat(); + } } \ No newline at end of file Index: src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java =================================================================== --- src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java (revision 0) +++ src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java (working copy) @@ -0,0 +1,52 @@ +package org.jboss.test.security.xacml.factories; + +import java.util.GregorianCalendar; + +import javax.xml.XMLConstants; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +import junit.framework.Assert; + +import org.jboss.security.xacml.core.model.context.ActionType; +import org.jboss.security.xacml.core.model.context.AttributeType; +import org.jboss.security.xacml.core.model.context.EnvironmentType; +import org.jboss.security.xacml.core.model.context.RequestType; +import org.jboss.security.xacml.core.model.context.ResourceType; +import org.jboss.security.xacml.core.model.context.SubjectType; +import org.jboss.security.xacml.factories.RequestAttributeFactory; +import org.jboss.security.xacml.factories.RequestResponseContextFactory; +import org.jboss.security.xacml.interfaces.RequestContext; +import org.junit.Test; + +public class RequestAttributeFactoryTestCase { + + + @Test + public void shouldCreateDefaultTimeAttributeValue() throws Exception{ + AttributeType type= + RequestAttributeFactory.createTimeAttributeType("x", null); + //get the + String time=(String)type.getAttributeValue().get(0).getContent().get(0); + XMLGregorianCalendar cal=DatatypeFactory.newInstance().newXMLGregorianCalendar(time); + Assert.assertEquals("{http://www.w3.org/2001/XMLSchema}time", cal.getXMLSchemaType().toString()); + } + @Test + public void shouldCreateDefaultDateTimeAttributeValue() throws Exception{ + AttributeType type= + RequestAttributeFactory.createDateTimeAttributeType("x", null); + //get the + String datetime=(String)type.getAttributeValue().get(0).getContent().get(0); + XMLGregorianCalendar cal=DatatypeFactory.newInstance().newXMLGregorianCalendar(datetime); + Assert.assertEquals("{http://www.w3.org/2001/XMLSchema}dateTime", cal.getXMLSchemaType().toString()); + } + @Test + public void shouldCreateDefaultDateAttributeValue() throws Exception{ + AttributeType type= + RequestAttributeFactory.createDateAttributeType("x", null); + //get the + String datetime=(String)type.getAttributeValue().get(0).getContent().get(0); + XMLGregorianCalendar cal=DatatypeFactory.newInstance().newXMLGregorianCalendar(datetime); + Assert.assertEquals("{http://www.w3.org/2001/XMLSchema}date", cal.getXMLSchemaType().toString()); + } +}